camera 0.1 (C) Benedict Verhegghe
A dict to keep named camera angle settings.
This class keeps a dictionary of named angle settings. Each value is a tuple of (longitude, latitude, twist) camera angles. This is a static class which should not need to be instantiated.
There are seven predefined values: six for looking along global coordinate axes, one isometric view.
ViewAngles objects have the following methods:
Get the angles for a named view.
Returns a tuple of angles (longitude, latitude, twist) if the named view was defined, or None otherwise
This class defines a camera for OpenGL rendering.
It provides functions for manipulating the camera position, the viewing direction and the lens parameters.
The camera viewing line can be defined by two points : the position of the camera and the center of the scene the camera is looking at. To enable continuous camera rotations however, it is essential that the camera angles are stored as such, and not be calculated from the camera position and the center point, because the transformation from cartesian to spherical coordinates is not unique. Furthermore, to enable smooth mouse-controlled camera rotation based on the current camera angles, it is essential to store the camera angles as the combined rotation matrix, not as the individual angles.
rot: twist : rotation angle around the camera’s viewing axis
The default camera is at [0,0,0] and looking in the -z direction. Near and far clipping planes are by default set to 0.1, resp 10 times the camera distance.
Some camera terminology: Position (eye) : position of the camera Scene center (ctr) : the point the camera is looking at. Up Vector : a vector pointing up from the camera. Viewing direction (rotx,roty,rotz) Lens angle (fovy) Aspect ratio (aspect) Clip (front/back) Perspective/Orthogonal
We assume that matrixmode is always MODELVIEW. For other operations we explicitely switch before and afterwards back to MODELVIEW.
Create a new camera at position (0,0,0) looking along the -z axis
Camera objects have the following methods:
Set the rotation angles.
Move the camera eye towards/away from the scene center.
This has the effect of zooming. A value > 1 zooms out, a value < 1 zooms in. The resulting enlargement of the view will approximately be 1/val. A zero value will move the camera to the center of the scene. The front and back clipping planes may need adjustment after a dolly operation.
Rotate the camera around axis through its eye.
The camera is rotated around an axis through the eye point. For axes 0 and 1, this will move the center, creating a panning effect. The default axis is parallel to the y-axis, resulting in horizontal panning. For vertical panning (axis=1) a convenience alias tilt is created. For axis = 2 the operation is equivalent to the rotate operation.
Rotate the camera up/down around its own horizontal axis.
The camera is rotated around and perpendicular to the plane of the y-axis and the viewing axis. This has the effect of a vertical pan. A positive value tilts the camera up, shifting the scene down. The value is specified in degrees.
Move the camera over translation (dx,dy,dz) in global coordinates.
The center of the camera is moved over the specified translation vector. This has the effect of moving the scene in opposite direction.
Set the ModelView matrix from camera parameters.
These are the transformations applied on the model space. Rotations and translations need be taken negatively.
Transform a vertex from camera to world coordinates.
The specified vector can have 3 or 4 (homogoneous) components. This uses the currently saved rotation matrix.
Set the field of view of the camera.
We set the field of view by the vertical opening angle fovy and the aspect ratio (width/height) of the viewing volume. A parameter that is not specified is left unchanged.
Set maximal camera area.
Resets the camera window area to its maximum values corresponding to the fovy setting, symmetrical about the camera axes.
Zoom in/out by shrinking/enlarging the camera view area.
The zoom factor is relative to the current setting. Values smaller than 1.0 zoom in, larger values zoom out.
Pan by moving the vamera area.
dx and dy are relative movements in fractions of the current area size.
Load the projection/perspective matrix.
The caller will have to setup the correct GL environment beforehand. No need to set matrix mode though. This function will switch to GL_PROJECTION mode before loading the matrix
!! CHANGED: does not switch back to GL_MODELVIEW mode!
A pick region can be defined to use the camera in picking mode. pick defines the picking region center and size (x,y,w,h).
This function does it best at autodetecting changes in the lens settings, and will only reload the matrix if such changes are detected. You can optionally force loading the matrix.
Functions defined in the module camera
- camera.tand(arg)¶
- Return the tan of an angle in degrees.
- camera.printModelviewMatrix(s="%s")¶