home *** CD-ROM | disk | FTP | other *** search
- /*
- name: camera.c
-
- Camera-routines
- ---------------
-
- These routines are used for handling the camera (positioning, scanning
- rotation etc).
-
- */
-
-
- #include "defs.h"
-
-
- void CreateCamera(CAMERA *Camera, POINT *Loc, POINT *VP, VECTOR *Asp)
- {
- double length,scale,theta;
- VECTOR D,R,U;
-
- CopyPoint(&(Camera->Location),Loc); /* Declare camera location */
- CopyPoint(&(Camera->ViewPoint),VP); /* Declare view-point */
-
- D.x=(VP->x-Loc->x); /* Calculate direction-vector */
- D.y=(VP->y-Loc->y);
- D.z=(VP->z-Loc->z);
- length=VectorLength(&D); /* Make direction-vector unit-sized */
- scale=1/length; /* This is important for the calcu- */
- ScaleVector(&D, scale, &D); /* lations of the up- and right- */
- /* vectors! */
-
- CopyVector(&(Camera->Direction),&D); /* Declare camera direction */
-
- theta=asin(D.z); /* Calculate right-vector */
- R.x=D.y/cos(theta); /* "/cos(theta)" => |R| = 1 */
- R.y=-(D.x/cos(theta));
- R.z=(double) 0;
-
- CopyVector(&(Camera->Right),&R); /* Declare camera right-vector */
-
- CrossProduct(&U,&R,&D); /* U = R x D */
-
- CopyVector(&(Camera->Up),&U); /* Declare camera up-vector */
-
- CopyVector(&(Camera->Aspect),Asp); /* Declare camera aspect */
-
- }
-