KrisLibrary  1.0.0
camera.h
1 #ifndef CAMERA_H
2 #define CAMERA_H
3 
5 
6 namespace Camera {
7 
8 using namespace Math3D;
9 
10 // Notes:
11 // Remember: multiplying by the transform of the camera gets you
12 // from camera to world frame. camera->world
13 //
14 // For free cameras, Rz(roll)Rx(pitch)Ry(yaw) gives the camera frame
15 // in C0 coords. The "rot" vector has (x,y,z) = (pitch,yaw,roll),
16 // which gives the intuition that you're rotating about the camera's
17 // rotation axes. Positive roll rotates the camera ccw. Positive
18 // pitch tilts the camera upward. Positive yaw rotates the camera
19 // left.
20 //
21 // C0 coords define how the world coords line up with the initial free
22 // camera coords by the Orientation enum. It basically defines the
23 // y axis of the camera for the yaw.
24 //
25 // Orientation ABC denotes A=left in world coordinates,B=up,C=backward(!!).
26 // An 'n' denotes the negative direction.
27 //
28 // Target cameras explicitly give the up direction in world coordinates
29 // and therefore there is no need for a C0 orientation.
30 
31 struct Camera
32 {
33  enum Orientation {XYZ,XYnZ,XZY,XZnY};
34  static void GetOrientationMatrix(Orientation o,Matrix3& mat);
35  static void Orient(Orientation o,Matrix3& mat);
36  static void Unorient(Orientation o,Matrix3& mat);
37 
38  inline const Real* xDir() const { return xform.R.col1(); }
39  inline const Real* yDir() const { return xform.R.col2(); }
40  inline const Real* zDir() const { return xform.R.col3(); }
41  inline const Vector3& position() const { return xform.t; }
42 
43  void setFree(const Vector3& pos, const Vector3& rot, Orientation o=XYZ);
44  void setTarget(const Vector3& pos, const Vector3& tgt, const Vector3& up);
45  void setOrbit(const Vector3& rot, const Vector3& target, Real dist, Orientation o=XYZ);
46  void setCameraMatrix(const Matrix4&);
47 
48  void getCameraMatrix(Matrix4&) const;
49  void getFree(Vector3& pos, Vector3& rot, Orientation o=XYZ) const;
50  void getTarget(Vector3& pos, Vector3& tgt, Vector3& up, Real tgtdist=One) const;
51  void getOrbit(Vector3& rot, Vector3& target, Real tgtdist=One, Orientation o=XYZ) const;
52 
53  RigidTransform xform;
54 };
55 
56 // CameraController_XXXX
57 // These classes hold the state that is attached to different camera
58 // control types. Use toCamera and fromCamera to create the camera
59 // structure.
60 
62 {
63  void toCamera(Camera&) const;
64  void fromCamera(const Camera&);
65 
66  inline Real& pitch() { return rot.x; }
67  inline Real& yaw() { return rot.y; }
68  inline Real& roll() { return rot.z; }
69 
70  Vector3 pos;
71  Vector3 rot;
72  Camera::Orientation ori;
73 };
74 
76 {
77  void toCamera(Camera&) const;
78  void fromCamera(const Camera&, Real tgtdist);
79 
80  Vector3 pos;
81  Vector3 tgt;
82  Vector3 up;
83 };
84 
86 {
87  void toCamera(Camera&) const;
88  void fromCamera(const Camera&, Real tgtdist);
89 
90  inline Real& pitch() { return rot.x; }
91  inline Real& yaw() { return rot.z; }
92  inline Real& roll() { return rot.y; }
93 
94  Vector3 rot;
95  Vector3 tgt;
96  Real dist;
97  Camera::Orientation ori;
98 };
99 
100 } //namespace Camera
101 
102 #endif
A 3D vector class.
Definition: math3d/primitives.h:136
Class declarations for useful 3D math types.
A rigid-body transformation.
Definition: math3d/primitives.h:820
Definition: camera.h:85
A 4x4 matrix class.
Definition: math3d/primitives.h:626
Contains all the definitions in the Math3D package.
Definition: AnyGeometry.h:12
Definition: camera.h:61
A 3x3 matrix class.
Definition: math3d/primitives.h:469
Definition: camera.cpp:7
Definition: camera.h:75