home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Graphics / source / camera_3d.cp < prev    next >
Encoding:
Text File  |  1995-03-17  |  2.9 KB  |  49 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    camera.cp
  3. //    Date:                    9/4/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains the methods for a camera
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "utility.h"
  11. #include "vector_3d.h"
  12. #include "camera_3d.h"
  13. #include "transform_3d.h"
  14.  
  15. //------------------------------------------------------------------------------
  16. //    constructor
  17. //------------------------------------------------------------------------------
  18. camera::camera (const point_3d &eye, const point_3d &to, real fov)                            //    default constructor
  19. {                                                                                                                                                                //    begin
  20.     Look (eye, to, fov);                                                                                                                    //    set the camera view as requested
  21. }                                                                                                                                                                //    end
  22.  
  23. //------------------------------------------------------------------------------
  24. //    Set the camera location and viewing direction
  25. //------------------------------------------------------------------------------
  26. void    camera::Look (const point_3d &e, const point_3d &to, real fov)                        //    assign the viewing parameters
  27. {                                                                                                                                                                //    begin
  28.     eye = e;                                                                                                                                            //    copy the eye point_3d
  29.     real        tanfov = TAN (DegreesToRadians (fov * R(0.5))),                                                //    compute the tangent of the field of view half-angle
  30.                     distance = R(1.0) / tanfov;                                                                                        //    compute the distance from the eye to the view plane_3d
  31.     vector_3d    vpn = (eye - to).Normalize (),                                                                            //    view is vector_3d from eye, to
  32.                     u = (vector_3d (R(0.0), R(1.0), R(0.0)) ^ vpn).Normalize (),                    //    calculate the x' axis vector_3d
  33.                     v = vpn ^ u;                                                                                                                    //    calculate the y' axis vector_3d
  34.     point_3d        vrp = eye + (vpn * -distance);                                                                        //    compute the view reference point_3d, along the view plane_3d normal vector_3d
  35.     viewing = ViewMatrix (u, v, vpn, vrp) * Perspective (distance);                                //    set up the viewing transformation matrix_3d
  36.     inverse = viewing.Inverse ();                                                                                                    //    set up the inverse transformation matrix_3d
  37. }                                                                                                                                                                //    end
  38.  
  39. //------------------------------------------------------------------------------
  40. //    compute the fov from a lens focal length and film size
  41. //------------------------------------------------------------------------------
  42. real    LensToFOV (int focal_length, real film_size)                                                            //    compute the fov from a film size and lens focal length
  43. {                                                                                                                                                                //    begin
  44.     real    fov = R(2.0) * ATAN2 (film_size * R(0.5) , real (focal_length));                //    compute the fov angle in radians
  45.     return RadiansToDegrees (fov);                                                                                                //    convert the fov to degrees
  46. }                                                                                                                                                                //    end
  47.  
  48. //------------------------------------------------------------------------------
  49.