Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Rendering/Camera/Headers/Camera.h

Diff revisions: vs.
  @@ -24,8 +24,11 @@
24 24 #define _CAMERA_H
25 25
26 26 #include "core.h"
27 +
28 + #include "Core/Math/Headers/Quaternion.h"
27 29 #include "Core/Resources/Headers/Resource.h"
28 30
31 + class SceneGraphNode;
29 32 class Camera : public Resource {
30 33 public:
31 34 enum CameraType {
  @@ -37,59 +40,87 @@
37 40 };
38 41
39 42 public:
40 - Camera(CameraType type);
43 + Camera(const CameraType& type);
41 44 virtual ~Camera() {}
42 45
43 - void Refresh();
44 - void SaveCamera();
45 - void RestoreCamera();
46 -
47 - void MoveForward(F32 factor);
48 - void MoveStrafe(F32 factor);
49 - void TranslateForward(F32 factor);
50 - void TranslateStrafe(F32 factor);
51 - void MoveAnaglyph(F32 factor);
52 -
53 - inline CameraType getType() const {return _type;}
54 - inline const vec3<F32>& getEye() const {return _eye;}
55 - inline const vec3<F32>& getCenter() const {return _center;}
56 - inline const vec3<F32>& getViewDir() const {return _view;}
57 - inline F32 getAngleX() const {return _angleX;}
58 - inline F32 getAngleY() const {return _angleY;}
59 -
60 - void setType(CameraType t) {_type = t; Refresh();}
61 - void setEye(vec3<F32> vPos) {_eye = vPos; Refresh();}
62 - void setCenter(vec3<F32> vPos) {_center = vPos; Refresh();}
63 - void setAngleX(F32 Angle) {_angleX = Angle; Refresh();}
64 - void setAngleY(F32 Angle) {_angleY = Angle; Refresh();}
65 - void setAngle(F32 AngleX, F32 AngleY) {_angleX = AngleX; _angleY = AngleY; Refresh();}
66 - void Translate(vec3<F32> vector) {_eye += vector * _frameSpeedFactor; Refresh();}
67 -
68 - void RotateX(F32 AngleX){
69 - _angleX += AngleX * _frameSpeedFactor;
70 - if(_angleX<0.0f) _angleX += M_PI*2;
71 - else if(_angleX>M_PI*2) _angleX -= M_PI*2;
72 - Refresh();
73 - }
74 -
75 - void RotateY(F32 AngleY){
76 - _angleY += AngleY * _frameSpeedFactor;
77 - if(_angleY<0.0f || _angleY>M_PI) _angleY -= AngleY;
78 - Refresh();
79 - }
80 -
81 - void Rotate(F32 AngleX, F32 AngleY){
82 - _angleX += AngleX * _frameSpeedFactor;
83 - _angleY += AngleY * _frameSpeedFactor;
84 - if(_angleX<0.0f) _angleX += M_PI*2;
85 - else if(_angleX>M_PI*2) _angleX -= M_PI*2;
86 - if(_angleY<0 || _angleY>M_PI) _angleY -= AngleY;
87 - Refresh();
88 - }
89 -
90 - void RenderLookAt(bool invertx = false, bool inverty=false, F32 planey=0.0f);
91 - ///Position the camera so that it faces a side of a cube with a 90 degree FOV
92 - void RenderLookAtToCubeMap(const vec3<F32>& eye, U8 nFace);
46 + virtual void tick(U32 elapsedTime);
47 + ///Camera save/load system
48 + ///Saves the minimum ammount of information in order to restore the camera at a later stage
49 + void saveCamera();
50 + ///Restores the previous camera's position, orientation, etc. based on save data
51 + void restoreCamera();
52 +
53 + ///Rendering calls
54 + ///Creates a viewMatrix and passes it to the rendering API
55 + void renderLookAt(bool invertX = false);
56 + ///Creates a reflection matrix using the specified plane height and passes it to the rendering API
57 + void renderLookAtReflected(const Plane<F32>& reflectionPlane, bool invertX = false);
58 + ///Creates the appropriate eye offset and frustum depending on the desired eye.This method calls "renderLookAt"
59 + ///rightEye = false => left eye's frustum+view; rightEye = true => right eye's frustum + view.
60 + void renderAnaglyph(bool rightEye = false);
61 + ///Moves the camera by the specified offsets in each direction
62 + void move(F32 dx, F32 dy, F32 dz);
63 + ///Global rotations are applied relative to the world axis, not the camera's
64 + void setGlobalRotation(F32 yaw, F32 pitch, F32 roll = 0.0f);
65 + ///Sets the camera's position, target and up directions
66 + void lookAt(const vec3<F32>& eye, const vec3<F32>& target, const vec3<F32>& up = WORLD_Y_AXIS);
67 + ///Rotates the camera (changes its orientation) by the specified quaternion (_orientation *= q)
68 + void rotate(const Quaternion<F32>& q);
69 + ///Sets the camera to point at the specified target point
70 + inline void lookAt(const vec3<F32>& target) { lookAt(_eye, target, _yAxis); }
71 + ///Sets the camera's orientation to match the specified yaw, pitch and roll values;
72 + ///Creates a quaternion based on the specified euler angles and calls "rotate" to change the orientation
73 + void rotate(F32 yaw, F32 pitch, F32 roll);
74 + ///Creates a quaternion based on the specified axis-angle and calls "rotate" to change the orientation
75 + inline void rotate(const vec3<F32>& axis, F32 angle) { rotate(Quaternion<F32>(axis,angle * _cameraTurnSpeed)); }
76 + ///Change camera's pitch - Yaw, Pitch and Roll call "rotate" with a apropriate quaternion for each rotation.
77 + ///Because the camera is facing the -Z axis, a positive angle will create a positive Yaw behind the camera
78 + ///and a negative one in front of the camera (so we invert the angle - left will turn left when facing -Z)
79 + inline void rotateYaw(F32 angle) { rotate(Quaternion<F32>(_yawFixed ? _fixedYawAxis : _orientation * WORLD_Y_AXIS,-angle * _cameraTurnSpeed)); }
80 + ///Change camera's roll.
81 + inline void rotateRoll(F32 angle) { rotate(Quaternion<F32>(_orientation * WORLD_Z_AXIS,-angle * _cameraTurnSpeed)); }
82 + ///Change camera's pitch
83 + inline void rotatePitch(F32 angle) { rotate(Quaternion<F32>(_orientation * WORLD_X_AXIS,-angle * _cameraTurnSpeed)); }
84 + ///Sets the camera's Yaw angle. This creates a new orientation quaternion for the camera and extracts the euler angles
85 + inline void setYaw(F32 angle) { setRotation(angle,_euler.pitch,_euler.roll); }
86 + ///Sets the camera's Pitch angle. Yaw and Roll are previous extracted values
87 + inline void setPitch(F32 angle) { setRotation(_euler.yaw,angle,_euler.roll); }
88 + ///Sets the camera's Roll angle. Yaw and Pitch are previous extracted values
89 + inline void setRoll(F32 angle) { setRotation(_euler.yaw,_euler.pitch,angle); }
90 + ///Sets the camera's Yaw angle. This creates a new orientation quaternion for the camera and extracts the euler angles
91 + inline void setGlobalYaw(F32 angle) { setGlobalRotation(angle,_euler.pitch,_euler.roll); }
92 + ///Sets the camera's Pitch angle. Yaw and Roll are previous extracted values
93 + inline void setGlobalPitch(F32 angle) { setGlobalRotation(_euler.yaw,angle,_euler.roll); }
94 + ///Sets the camera's Roll angle. Yaw and Pitch are previous extracted values
95 + inline void setGlobalRoll(F32 angle) { setGlobalRotation(_euler.yaw,_euler.pitch,angle); }
96 + ///Moves the camera forward or backwards
97 + inline void moveForward(F32 factor) { move(0.0f, 0.0f, factor * _cameraMoveSpeed); }
98 + ///Moves the camera left or right
99 + inline void moveStrafe(F32 factor) { move(factor * _cameraMoveSpeed, 0.0f, 0.0f); }
100 + ///Moves the camera up or down
101 + inline void moveUp(F32 factor) { move(0.0f, factor * _cameraMoveSpeed, 0.0f); }
102 + ///Anaglyph rendering: Set intraocular distance
103 + inline void setIOD(F32 distance) { _camIOD = distance; }
104 + inline void setEye(F32 x, F32 y, F32 z) { _eye.set(x,y,z); _viewMatrixDirty = true; }
105 + inline void setEye(const vec3<F32>& position) { _eye = position; _viewMatrixDirty = true; }
106 + inline void setRotation(const Quaternion<F32>& q) { _orientation = q; _viewMatrixDirty = true; }
107 + inline void setRotation(F32 yaw, F32 pitch, F32 roll = 0.0f) { setRotation(Quaternion<F32>(-pitch,-yaw,-roll)); }
108 + inline void setMouseSensitivity(F32 sensitivity) {_mouseSensitivity = sensitivity;}
109 + inline void setMoveSpeedFactor(F32 moveSpeedFactor) {_moveSpeedFactor = moveSpeedFactor;}
110 + inline void setTurnSpeedFactor(F32 turnSpeedFactor) {_turnSpeedFactor = turnSpeedFactor;}
111 + ///Exactly as in Ogre3D: locks the yaw movement to the specified axis
112 + inline void setFixedYawAxis( bool useFixed, const vec3<F32>& fixedAxis = WORLD_Y_AXIS) { _yawFixed = useFixed; _fixedYawAxis = fixedAxis; }
113 +
114 + // Getter methods.
115 + inline F32 getMouseSensitivity() const {return _mouseSensitivity;}
116 + inline F32 getMoveSpeedFactor() const {return _moveSpeedFactor;}
117 + inline F32 getTurnSpeedFactor() const {return _turnSpeedFactor;}
118 + inline const CameraType& getType() const {return _type; }
119 + inline const vec3<F32>& getEye() const {return _eye;}
120 + inline const vec3<F32>& getViewDir() const {return _viewDir;}
121 + inline const vec3<F32>& getEuler() const {return _euler;}
122 + inline const vec3<F32>& getTarget() const {return _target;}
123 +
93 124 ///Nothing really to unload
94 125 virtual bool unload() {return true;}
95 126 ///Add an event listener called after every RenderLookAt or RenderLookAtCube call
  @@ -98,23 +129,35 @@
98 129 virtual void updateListeners();
99 130
100 131 protected:
132 + void updateViewMatrix();
101 133
102 - vec3<F32> _eye;
103 - vec3<F32> _center;
104 - vec3<F32> _view;
105 - vec3<F32> _left;
106 - vec3<F32> _up;
107 - vec3<F32> _savedVectors[5];
108 -
109 - F32 _angleX;
110 - F32 _angleY;
111 - F32 _savedFloats[2];
112 - ///Used for frame rate independend movement
113 - F32 _frameSpeedFactor;
114 - bool _saved;
115 -
134 + protected:
135 + mat4<F32> _viewMatrix;
136 + mat4<F32> _reflectedViewMatrix;
137 + Quaternion<F32> _orientation;
138 + vec3<F32> _eye, _viewDir, _target;
139 + vec3<F32> _xAxis, _yAxis, _zAxis;
140 + vec3<F32> _euler, _fixedYawAxis;
141 +
142 + F32 _accumPitchDegrees;
143 + F32 _turnSpeedFactor;
144 + F32 _moveSpeedFactor;
145 + F32 _mouseSensitivity;
146 + F32 _cameraMoveSpeed;
147 + F32 _cameraTurnSpeed;
148 + F32 _camIOD;
116 149 CameraType _type;
117 150
118 151 vectorImpl<boost::function0<void> > _listeners;
152 +
153 + //Save/Load Camera
154 + vec3<F32> _savedVectors[3];
155 + F32 _savedFloats[4];
156 + Quaternion<F32> _savedOrientation;
157 + bool _savedYawState;
158 + bool _saved;
159 + bool _viewMatrixDirty;
160 + bool _yawFixed;
119 161 };
162 +
120 163 #endif