Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

Cameras, Skyboxes
http://ec-lang.org/community/viewtopic.php?f=7&t=19
Page 1 of 1
Author:  sacrebleu [ Thu Jan 21, 2010 12:33 am ]
Post subject:  Cameras, Skyboxes

Tell me about controlling and using Cameras with background skyboxes. :shock:
Author:  jerome [ Fri Mar 12, 2010 1:24 am ]
Post subject:  Re: Cameras, Skyboxes

Sorry for the long delay :)

Let's start with the Camera API.

You must create a Camera object. You then use this camera object in a Window's OnRedraw method by 'setting it' on the surface to enter '3D graphics' mode, and then unsetting it to return to 2D mode:

Code: Select all

void OnRedraw(Surface surface)
{
   display.SetCamera(surface, camera);
   // --> Draw 3D things here <--
   display.SetCamera(surface, null);
}
A sample camera object instantiation could look like this:

Code: Select all

Camera camera
{
   type = fixed;
   position = { 0, 0, -300 };
   orientation = Euler { 0, 0, 0 };
   zMax = 340000;
};
This creates a fixed camera, at position (0, 0, -300) and looking straight ahead. It also sets the maximum depth range value to 340,000.

The Camera class as some sensible defaults (fixed, position of (0,0,0), orientation of (0,0,0), 90 degrees field of view, zMin = 5, zMax = 10000) which could let you get by with a simple "Camera { }" assuming there is something to see from the (0,0,0) location in your scene.

Note that you will need to call Camera::Setup() with the width and height of the viewport in which you wish to use the camera, for example in a Window's OnResize() event. You will also need to call Camera::Update() prior to using it after any modification to the camera's settings.

Code: Select all

void OnResize(int w, int h)
{
   camera.Setup(w, h, null);
}
The camera defines the following properties:

Camera Type
The type can be:
  • fixed: Simple position and orientation.
    fixedQuaternion: Same as fixed, except orientation will be stored and modified as a quaternion.
    attached: Always at a specific position offset from a target object (Specified in 'target' property), and rotation object to that object's orientation. Changing the orientation spins around the center of that object, increasing the z component of the position brings the camera further away from the center of the object.
    attachedQuaternion: Same as attached, except the orientation is combined with the target object through quaternion multiplication.
    lookAt: The camera looks from its position and orientation towards the 'target' object's position.
    lookAtObject: The camera is defined itself as an Object, and looking towards another 'target' Object. This is generated by camera objects loaded from 3DS files.
... To be continued...

Checkout the terrain & camera sample.

position
orientation

Computed Position (cPosition)
Computed Orientation (cOrientation)
Field of View (fov)
zMin
zMax
Object targe
FovDirection fovDirection
aspectRatio
focal
All times are UTC-05:00 Page 1 of 1