Class Camera

 
MEMBERS
X, Y, Z Orig wL, wR, wB, wT Near, Far

 
METHODS
Camera (class constructor) GetFrustumParams GetViewportMatrix GetPixelRay
Copy wCOP GetInvModelviewMatrix WriteToFile
LookAt ViewDir GetInvProjectionMatrix ReadFromFile
Perspective ViewDirOffAxis GetInvViewportMatrix CalcVerts
Frustum GetXform_Screen2Obj WorldToCam Print
TightlyFitToSphere GetXform_Obj2Screen CamToWorld Display
GetLookAtParams GetModelviewMatrix LoadIdentityXform
GetPerspectiveParams GetProjectionMatrix Xform

 

Camera utility functions

 
CAMERA OVERLAP TESTS
CamTriOverlap CamQuadOverlap CamMinMaxBoxOverlap CamCamOverlap

 
MISCELLANEOUS FUNCTIONS
CalcCamPlanes CamReflectAboutPlane



Vec3f X, Y, Z Normalized camera coordinate-axis vectors. Vec3f Orig Eye point and origin of camera coordinate system in world coordinates. float wL, wR, wB, wT Window extents (left, right, bottom, top) defined as a rectangle on the near clipping plane. float Near, Far Distances to the near and far clipping planes along the viewing direction. Camera()
Camera(Camera &Cam) Class constructor; first form is the default class constructor, the second form is the copy constructor.

parameter:

Camera &Cam: Camera object from which to copy parameters.
void Copy(Camera &Cam) Copies the parameters of a Camera object (passed by reference) to the invoking Camera object.

parameter:

Camera &Cam: Camera object from which to copy parameters.
void LookAt(Vec3f Eye, Vec3f ViewRefPt, Vec3f ViewUp) Sets the viewing transformation for the camera by using an eye point, a reference point, and an up-vector.

parameters:

Vec3f Eye: Eye point and origin of camera space.
Vec3f ViewRefPt: Reference point indicating the center of the scene.
Vec3f ViewUp: Vector defining the up direction for camera space.
void Perspective(float Yfov, float Aspect,
                 float Ndist, float Fdist) Sets the perspective projection transformation for the camera.

parameters:

float Yfov: Width of the vertical field-of-view in degrees.
float Aspect: Aspect ratio (width / height) of the camera's angle of view.
float Ndist: Distance from the eye point to the near clipping plane.
float Fdist: Distance from the eye point to the far clipping plane.
void Frustum(float l, float r,
             float b, float t,
             float Ndist, float Fdist) Sets the perspective projection transformation for the camera, by describing the extents of the window on the near clipping plane and the distances to near and far clipping planes.

parameters:

float l: x-coordinate of left vertical clipping plane at near clipping plane.
float r: x-coordinate of right vertical clipping plane at near clipping plane.
float b: y-coordinate of bottom horizontal clipping plane at near clipping plane.
float t: y-coordinate of top horizontal clipping plane at near clipping plane.
float Ndist: Distance from the eye point to the near clipping plane.
float Fdist: Distance from the eye point to the far clipping plane.
void TightlyFitToSphere(Vec3f Eye, Vec3f ViewUp,
                        Vec3f Cntr, float Rad) Defines the camera parameters by computing a tight-fitting frustum surrounding a given bounding sphere.

parameters:

Vec3f Eye: Eye point and origin of camera space.
Vec3f ViewUp: Vector defining the up direction for camera space.
Vec3f Cntr: Center of the bounding sphere.
float Rad: Radius of the bounding sphere.
void GetLookAtParams(Vec3f *Eye, Vec3f *ViewRefPt, Vec3f *ViewUp) Returns the camera's eye point, view-reference point, and up vector.

parameters:

Vec3f *Eye: Eye point and origin of camera space.
Vec3f *ViewRefPt: Reference point indicating center of the scene.
Vec3f *ViewUp: Vector defining the up direction for camera space.
void GetPerspectiveParams(float *Yfov, float *Aspect,
                          float *Ndist, float *Fdist) Returns the camera's perspective parameters: vertical field-of-view, aspect ratio, and distances to near and far clipping planes.

parameters:

float *Yfov: Width of the vertical field-of-view in degrees.
float *Aspect: Aspect ratio (width / height) of the camera's angle of view.
float *Ndist: Distance from the eye point to the near clipping plane.
float *Fdist: Distance from the eye point to the far clipping plane.
void GetFrustumParams(float *l, float *r,
                      float *b, float *t,
                      float *Ndist, float *Fdist) Returns the camera's frustum parameters: extents of the window on the near clipping plane and distances to near and far clipping planes.

parameters:

float *l: x-coordinate of left vertical clipping plane at near clipping plane.
float *r: x-coordinate of right vertical clipping plane at near clipping plane.
float *b: y-coordinate of bottom horizontal clipping plane at near clipping plane.
float *t: y-coordinate of top horizontal clipping plane at near clipping plane.
float *Ndist: Distance from the eye point to the near clipping plane.
float *Fdist: Distance from the eye point to the far clipping plane.
Vec3f wCOP() Returns the eye point (center of camera space) in world coordinates.

return value:

Eye point and center of camera space.
Vec3f ViewDir() Returns the viewing direction (eye point to reference point) in world coordinates.

return value:

Vector of viewing direction.
Vec3f ViewDirOffAxis() Returns

return value:

Vector of off-axis viewing direction.
float* GetXform_Screen2Obj(float* M, int WW, int WH) Returns a composite 4x4 OpenGL-style transformation matrix which transforms a point in world (object) space to a point in screen (pixel) space , the inverse of the matrix returned by GetXform_Obj2Screen.

parameters:

float* M: The 4x4 transformation matrix returned.
int WW: Width of the viewport/window in pixels.
int WH: Height of the viewport/window in pixels.


return value:

Same as value returned through *M.
float* GetXform_Obj2Screen(float* M, int WW, int WH)
Returns a composite 4x4 OpenGL-style transformation matrix which transforms a point in screen (pixel) space to a point in world (object) space, the inverse of the matrix returned by GetXform_Screen2Obj.
parameters: float* M: The 4x4 transformation matrix returned.
int WW: Width of the viewport/window in pixels.
int WH: Height of the viewport/window in pixels.

return value: Same as value returned through *M.
float* GetModelviewMatrix(float* M) Returns an OpenGL-style modelview transformation matrix. The inverse is returned by GetInvModelviewMatrix.

parameter:

float* M: The 4x4 transformation matrix.

return value: Same as value returned through *M.
float* GetProjectionMatrix(float* M) Returns an OpenGL-style projection transformation matrix. The inverse is returned by GetInvProjectionMatrix.

parameter:

float* M: The 4x4 fransformation matrix.

return value: Same as value returned through *M.
float* GetViewportMatrix(float* M, int WW, int WH) Returns an OpenGL-style viewport transformation matrix. The inverse is returned by GetInvViewportMatrix.

parameters:

float* M: The 4x4 transformation matrix.
int WW: Width of the viewport/window in pixels.
int WH: Height of the viewport/window in pixels.

return value: Same as value returned through *M.
float* GetInvModelviewMatrix(float* M) Returns an OpenGL-style matrix which is the inverse of the modelview matrix returned by GetModelviewMatrix.

parameter:

float* M: The 4x4 inverse fransformation matrix.

return value: Same as value returned through *M.
float* GetInvProjectionMatrix(float* M) Returns an OpenGL-style matrix which is the inverse of the projection matrix returned by GetProjectionMatrix.

parameter:

float* M: The 4x4 inverse fransformation matrix.
 
return value: Same as value returned through *M.
float* GetInvViewportMatrix(float* M, int WW, int WH) Returns an OpenGL-style matrix which is the inverse of the viewport matrix returned by GetViewportMatrix.

parameters:

float* M: The 4x4 inverse transformation matrix.
int WW: Width of the viewport/window in pixels.
int WH: Height of the viewport/window in pixels.
 
return value: Same as value returned through *M.
Vec3f WorldToCam(Vec3f wP) Transforms a point (vector) in world space to a point (vector) in camera space. The inverse operation is provided by CamToWorld.

parameter:

Vec3f wP: Point (vector) in world space coordinates.
 
return value: Point (vector) in camera space coordinates.
Vec3f CamToWorld(Vec3f cP) Transforms a point (vector) in camera space to a point (vector) in world space. The inverse operation is provided by WorldToCam.

parameter:

Vec3f cP: Point (vector) in camera space coordinates.

return value: Point (vector) in world space coordinates.
void LoadIdentityXform() Sets the camera pose to the identity so that world space and camera space coincide. void Xform(float M[16]) Applies an OpenGL-style 4x4 transformation matrix to the camera's coordinate frame. Only rotations, translations, and uniform scales allowed; window extents and distances to near and far clipping planes are affected by scaling.

parameter:

float M[16]: An OpenGL-style 4x4 transformation matrix.
void GetPixelRay(float sx, float sy,
                 int ww, int wh,
                 Vec3f *Start, Vec3f *Dir) Returns a ray from the eye point (origin of camera space) to the center of the selected pixel.

parameters:

float sx: x-coordinate of the selected pixel.
float sy: y-coordinate of the selected pixel.
int ww: Width of the window (viewport) in pixels.
int wh: Height of the window (viewport) in pixels.
Vec3f *Start: Origin of ray (i.e. eye point in world coordinates).
Vec3f *Dir: Direction of ray in world coordinates.
void WriteToFile(FILE *fp) Writes camera parameters (camera space coordinate-axes and origin) to a file.

parameter:

FILE *fp: A file pointer to the destination file.
int ReadFromFile(FILE *fp) Reads camera parameters (camera space coordinate-axes and origin) from a file.

parameter:

FILE *fp: A file pointer to the source file.

return value: A boolean value denoting success of the read; 0 if the read is unsuccessful, 1 if the read is successful.
void CalcVerts(Vec3f *V) Calculates and returns the vertices of the camera frustum (world space coordinates).

parameter:

Vec3f *V: An array of eight vertices given in this order: [0]: right-top-near
[1]: right-bottom-near
[2]: left-bottom-near
[3]: left-top-near
[4]: right-top-far
[5]: right-bottom-far
[6]: left-bottom-far
[7]: left-top-far
The array must be allocated for at least eight elements before the call to Calcverts is made.
void Print() Prints something related to the camera. void Display() Displays something related to the camera int CamTriOverlap(Vec3f V[8], float P[][4],
                  Vec3f A, Vec3f B, Vec3f C)
int CamTriOverlap(Camera *Cam, Vec3f A, Vec3f B, Vec3f C) Determines whether a camera frustrum and a triangle intersect.

parameters:

Vec3f V[8]: An array of vectors
float P[][4]: An array of points
Camera *Cam: A pointer to a Camera object
Vec3f A: One vertex of the triangle
Vec3f B: One vertex of the triangle
Vec3f C: One vertex of the triangle
return value: The results of the intersection test; 0 (false) if no intersection, 1 (true) if an intersection exists
int CamQuadOverlap(Camera *Cam, Vec3f A, Vec3f B, Vec3f C, Vec3f D)
int CamQuadOverlap(Camera *Cam, float A[3], float B[3],
                   float C[3], float D[3]) Determines whether a camera frustrum and a quadrilateral intersect.

parameters:

Camera *Cam:
Vec3f A:
Vec3f B:
Vec3f C:
Vec3f D:
float A[3]:
float B[3]:
float C[3]:
float D[3]:
return value: The results of the intersection test; 0 (false) if no intersection, 1 (true) if an intersection exists
void CalcCamPlanes(Vec3f V[8], float P[][4])
void CalcCamPlanes(Camera *Cam, float P[][4]) Computes the planes which make up the camera frustrum.

parameters:

Vec3f V[8]:
Camera *Cam:
float P[][4]:
int CamMinMaxBoxOverlap(Camera *Cam, Vec3f cV[8],
                        float cP[][4], Vec3f m, Vec3f M)
int CamMinMaxBoxOverlap(Camera *Cam, float m[3], float M[3]) Determines whether a camera frustum and an axis-aligned box intersect.  The first form's parameters are ; the second form

parameters:

Camera *Cam:
Vec3f cV[8]:
float cP[][4]:
Vec3f m:
Vec3f M:
float m[3]:
float M[3]:
return value: 0 (false) if the frustum and box do not intersect; 1 (true) if they do.
int CamCamOverlap(Vec3f V1[8], float P1[][4],
                  Vec3f V2[8], float P2[][4])
int CamCamOverlap(Camera *Cam1, Camera *Cam2) Determines whether two camera frusta (fields of view) intersect one another.

parameters:

Vec3f V1[8]:
float P1[][4]:
Vec3f V2[8]:
float P2[][4]:
Camera *Cam1:
Camera *Cam2:
return value: 0 (false) if no intersect; 1 (true) if they do intersect
void CamReflectAboutPlane(Camera *Cam, float Plane[4]) Reflects a camera's field of view about a plane.

parameters:

Camera *Cam:
float Plane[4]: