home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / graphics / povsrc20 / camera.c < prev    next >
C/C++ Source or Header  |  1993-07-28  |  3KB  |  101 lines

  1. /****************************************************************************
  2. *                camera.c
  3. *
  4. *  This module implements methods for managing the viewpoint.
  5. *
  6. *  from Persistence of Vision Raytracer
  7. *  Copyright 1993 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  NOTICE: This source code file is provided so that users may experiment
  10. *  with enhancements to POV-Ray and to port the software to platforms other 
  11. *  than those supported by the POV-Ray Team.  There are strict rules under
  12. *  which you are permitted to use this file.  The rules are in the file
  13. *  named POVLEGAL.DOC which should be distributed with this file. If 
  14. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  16. *  Forum.  The latest version of POV-Ray may be found there as well.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. *****************************************************************************/
  23.  
  24. #include "frame.h"
  25. #include "vector.h"
  26. #include "povproto.h"
  27.  
  28. void Translate_Camera (Camera, Vector)
  29. CAMERA *Camera;
  30. VECTOR *Vector;
  31.   {
  32.   VAdd (((CAMERA *) Camera) -> Location, 
  33.     ((CAMERA *) Camera) -> Location,
  34.     *Vector);
  35.   }
  36.  
  37. void Rotate_Camera (Camera, Vector)
  38. CAMERA *Camera;
  39. VECTOR *Vector;
  40.   {
  41.   TRANSFORM Trans;
  42.  
  43.   Compute_Rotation_Transform(&Trans, Vector);
  44.   Transform_Camera (Camera, &Trans);
  45.   }
  46.  
  47. void Scale_Camera (Camera, Vector)
  48. CAMERA *Camera;
  49. VECTOR *Vector;
  50.   {
  51.   TRANSFORM Trans;
  52.  
  53.   Compute_Scaling_Transform(&Trans, Vector);
  54.   Transform_Camera (Camera, &Trans);
  55.   }
  56.  
  57. void Transform_Camera (Camera, Trans)
  58. CAMERA *Camera;
  59. TRANSFORM *Trans;
  60.   {
  61.   MTransPoint (&(Camera -> Location), &(Camera -> Location), Trans);
  62.  
  63.   MTransPoint (&(Camera -> Direction), &(Camera -> Direction), Trans);
  64.  
  65.   MTransPoint (&(Camera -> Up), &(Camera -> Up), Trans);
  66.  
  67.   MTransPoint (&(Camera -> Right), &(Camera -> Right), Trans);
  68.   }
  69.  
  70. CAMERA *Copy_Camera (Old)
  71. CAMERA *Old;
  72.   {
  73.   CAMERA *New;
  74.  
  75.   if (Old != NULL)
  76.     {
  77.     New = Create_Camera ();
  78.     *New = *Old;
  79.     }
  80.   else
  81.     New = NULL;
  82.  
  83.   return (New);   
  84.   }
  85.  
  86. CAMERA *Create_Camera ()
  87.   {
  88.   CAMERA *New;
  89.  
  90.   if ((New = (CAMERA *) malloc (sizeof (CAMERA))) == NULL)
  91.     MAError ("camera");
  92.  
  93.   Make_Vector (&(New->Location), 0.0, 0.0, 0.0);
  94.   Make_Vector (&(New->Direction), 0.0, 0.0, 1.0);
  95.   Make_Vector (&(New->Up), 0.0, 1.0, 0.0);
  96.   Make_Vector (&(New->Right), 1.33, 0.0, 0.0);
  97.   Make_Vector (&(New->Sky), 0.0, 1.0, 0.0);
  98.   return (New);
  99.   }
  100.  
  101.