home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C++ / Snippets / QD3D Juggler / Juggler Sources / CCameraMaker.cp < prev    next >
Encoding:
Text File  |  1995-12-27  |  2.9 KB  |  114 lines  |  [TEXT/CWIE]

  1. //
  2. //    CCameraMaker.cp
  3. //
  4. //    class CCameraMaker
  5. //    A class that constructs a QuickDraw 3D View Angle Aspect camera.
  6. //
  7. //    It's designed to make it easy to override camera placement
  8. //    before calling Get() (or make) the first time.
  9. //
  10. //    by James Jennings
  11. //    November 26, 1995
  12. //
  13.  
  14. #pragma once
  15.  
  16. #include "CCameraMaker.h"
  17.  
  18. CCameraMaker::CCameraMaker(const SDimension16 &frameSize)
  19. {    // Fill in the structure default values.
  20.     // These values come from Apple's "Start Here" demo.
  21.     TQ3Point3D                     from     = { 0.0, 0.0, 7.0 };
  22.     TQ3Point3D                     to         = { 0.0, 0.0, 0.0 };
  23.     TQ3Vector3D                 up         = { 0.0, 1.0, 0.0 };
  24.  
  25.     float                         fieldOfView = 1.0;
  26.     float                         hither         = 0.001;
  27.     float                         yon         = 1000;
  28.     
  29.     SetLocation(from);
  30.     SetPointOfInterest(to);
  31.     SetUpVector(up);
  32. //    mData.cameraData.placement.cameraLocation     = from;
  33. //    mData.cameraData.placement.pointOfInterest     = to;
  34. //    mData.cameraData.placement.upVector         = up;
  35.  
  36.     mData.cameraData.range.hither= hither;
  37.     mData.cameraData.range.yon     = yon;
  38.  
  39.     mData.cameraData.viewPort.origin.x = -1.0;
  40.     mData.cameraData.viewPort.origin.y = 1.0;
  41.     mData.cameraData.viewPort.width     = 2.0;
  42.     mData.cameraData.viewPort.height = 2.0;
  43.     
  44.     mData.fov                = fieldOfView;
  45.     mData.aspectRatioXToY    =
  46.         (float) (frameSize.width) / (float) (frameSize.height);
  47. }
  48.  
  49. void
  50. CCameraMaker::Make()
  51. {
  52.     mObject = ::Q3ViewAngleAspectCamera_New(&mData);
  53.     ThrowIfNil_(mObject);
  54. }
  55.  
  56.  
  57. void
  58. CCameraMaker::SetLocation(TQ3Point3D &from)
  59. {
  60.     mData.cameraData.placement.cameraLocation     = from;
  61. }
  62.  
  63. void
  64. CCameraMaker::SetLocation(float x, float y, float z)
  65. {
  66.     ::Q3Point3D_Set(&(mData.cameraData.placement.cameraLocation), x, y, z);
  67. }
  68.  
  69. void
  70. CCameraMaker::SetPointOfInterest(TQ3Point3D &to)
  71. {
  72.     mData.cameraData.placement.pointOfInterest     = to;
  73. }
  74.  
  75. void
  76. CCameraMaker::SetPointOfInterest(float x, float y, float z)
  77. {
  78.     ::Q3Point3D_Set(&(mData.cameraData.placement.pointOfInterest), x, y, z);
  79. }
  80.  
  81. void
  82. CCameraMaker::SetUpVector(TQ3Vector3D &up, Boolean orthogonalize)
  83. {
  84.     mData.cameraData.placement.upVector = up;
  85.     if (orthogonalize) Orthogonalize();
  86. }
  87.  
  88. void
  89. CCameraMaker::SetUpVector(float x, float y, float z, Boolean orthogonalize)
  90. {
  91.     ::Q3Vector3D_Set(&(mData.cameraData.placement.upVector), x, y, z);
  92.     if (orthogonalize) Orthogonalize();
  93. }
  94.  
  95. void
  96. CCameraMaker::Orthogonalize()
  97. {    // make the upVector orthogonal to the line of sight vector
  98.     // (Uses Gramm-Smit orthogonalization.)
  99.     TQ3Vector3D lineOfSight;
  100.     ::Q3Point3D_Subtract(&(mData.cameraData.placement.pointOfInterest), 
  101.                          &(mData.cameraData.placement.cameraLocation), 
  102.                          &lineOfSight);
  103.     TQ3Vector3D up = mData.cameraData.placement.upVector;
  104.     ::Q3Vector3D_Normalize(&lineOfSight, &lineOfSight);
  105.     ::Q3Vector3D_Normalize(&up, &up);
  106.     float dot = ::Q3Vector3D_Dot(&lineOfSight, &up);
  107.     ::Q3Vector3D_Scale(&lineOfSight, dot, &lineOfSight);
  108.     ::Q3Vector3D_Subtract(&up, &lineOfSight, &up);
  109.     ThrowIf_(up.x==0 && up.y==0 && up.z==0);
  110.     
  111.     mData.cameraData.placement.upVector = up;
  112. }
  113.  
  114.