Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 330 vs 331 for /trunk/Source Code/Rendering/Camera/Headers/Camera.h

Diff revisions: vs.
  @@ -50,90 +50,221 @@
50 50
51 51 virtual void update(const U64 deltaTime);
52 52
53 - ///Rendering calls
54 - ///Creates a viewMatrix and passes it to the rendering API
53 + /// Rendering calls
54 + /// Creates a viewMatrix and passes it to the rendering API
55 55 void renderLookAt();
56 - ///Creates a reflection matrix using the specified plane height and passes it to the rendering API
56 + /// Creates a reflection matrix using the specified plane height and passes it to the rendering API
57 57 void renderLookAtReflected(const Plane<F32>& reflectionPlane);
58 - ///Creates the appropriate eye offset and frustum depending on the desired eye.This method does not calls "renderLookAt"
59 - ///rightEye = false => left eye's frustum+view; rightEye = true => right eye's frustum + view.
58 + /// Creates the appropriate eye offset and frustum depending on the desired eye.
59 + /// This method does not calls "renderLookAt"
60 + /// rightEye = false => left eye's frustum+view; rightEye = true => right eye's frustum + view.
60 61 void setAnaglyph(bool rightEye = false);
61 - ///Moves the camera by the specified offsets in each direction
62 + /// Moves the camera by the specified offsets in each direction
62 63 virtual void move(F32 dx, F32 dy, F32 dz);
63 - ///Global rotations are applied relative to the world axis, not the camera's
64 + /// Global rotations are applied relative to the world axis, not the camera's
64 65 void setGlobalRotation(F32 yaw, F32 pitch, F32 roll = 0.0f);
65 - ///Sets the camera's position, target and up directions
66 - const mat4<F32>& 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)
66 + /// Sets the camera's position, target and up directions
67 + const mat4<F32>& lookAt(const vec3<F32>& eye,
68 + const vec3<F32>& target,
69 + const vec3<F32>& up = WORLD_Y_AXIS);
70 + /// Rotates the camera (changes its orientation) by the specified quaternion (_orientation *= q)
68 71 void rotate(const Quaternion<F32>& q);
69 - ///Sets the camera to point at the specified target point
70 - inline const mat4<F32>& lookAt(const vec3<F32>& target) { return 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
72 + /// Sets the camera to point at the specified target point
73 + inline const mat4<F32>& lookAt(const vec3<F32>& target) {
74 + return lookAt(_eye, target, _yAxis);
75 + }
76 + /// Sets the camera's orientation to match the specified yaw, pitch and roll values;
77 + /// Creates a quaternion based on the specified euler angles and calls "rotate" to change
78 + /// the orientation
73 79 virtual 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 intra-ocular 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 setAspectRatio(F32 ratio) { _aspectRatio = ratio; _projectionDirty = true;}
109 - inline void setVerticalFoV(F32 vFoV) { _verticalFoV = vFoV; _projectionDirty = true;}
110 - inline void setHorizontalFoV(F32 hFoV) { _verticalFoV = Util::xfov_to_yfov(hFoV, _aspectRatio); _projectionDirty = true;}
111 - ///Mouse sensitivity: amount of pixels per radian
112 - inline void setMouseSensitivity(F32 sensitivity) {_mouseSensitivity = sensitivity;}
113 - inline void setMoveSpeedFactor(F32 moveSpeedFactor) {_moveSpeedFactor = moveSpeedFactor;}
114 - inline void setTurnSpeedFactor(F32 turnSpeedFactor) {_turnSpeedFactor = turnSpeedFactor;}
115 - inline void setZoomSpeedFactor(F32 zoomSpeedFactor) {_zoomSpeedFactor = zoomSpeedFactor;}
116 - ///Exactly as in Ogre3D: locks the yaw movement to the specified axis
117 - inline void setFixedYawAxis( bool useFixed, const vec3<F32>& fixedAxis = WORLD_Y_AXIS) { _yawFixed = useFixed; _fixedYawAxis = fixedAxis; }
118 -
119 - // Getter methods.
120 - inline F32 getMouseSensitivity() const {return _mouseSensitivity;}
121 - inline F32 getMoveSpeedFactor() const {return _moveSpeedFactor;}
122 - inline F32 getTurnSpeedFactor() const {return _turnSpeedFactor;}
123 - inline F32 getZoomSpeedFactor() const {return _zoomSpeedFactor;}
124 -
125 - inline const CameraType& getType() const {return _type; }
126 - inline const vec3<F32>& getEye() const {return _reflectionRendering ? _reflectedEye : _eye; }
127 - inline vec3<F32> getViewDir() const {return _reflectionRendering ? _reflectedViewMatrix * _viewDir : _viewDir; }
128 - inline vec3<F32> getUpDir() const {return _reflectionRendering ? _reflectedViewMatrix * _yAxis : _yAxis; }
129 - inline vec3<F32> getRightDir() const {return _reflectionRendering ? _reflectedViewMatrix * _xAxis : _xAxis; }
130 - inline const vec3<F32>& getEuler() const {return _euler;}
131 - inline const vec3<F32>& getTarget() const {return _target;}
132 - inline const mat4<F32>& getProjectionMatrix() const { return _projectionMatrix; }
133 - inline const vec2<F32>& getZPlanes() const { return _zPlanes; }
134 - inline const F32 getVerticalFoV() const { return _verticalFoV; }
135 - inline const F32 getHorizontalFoV() const { return Util::yfov_to_xfov(_verticalFoV, _aspectRatio); }
136 - inline const F32 getAspectRatio() const { return _aspectRatio; }
80 + /// Creates a quaternion based on the specified axis-angle and calls "rotate" to change
81 + /// the orientation
82 + inline void rotate(const vec3<F32>& axis, F32 angle) {
83 + rotate(Quaternion<F32>(axis,
84 + angle * _cameraTurnSpeed));
85 + }
86 + /// Yaw, Pitch and Roll call "rotate" with a apropriate quaternion for each rotation.
87 + /// Because the camera is facing the -Z axis, a positive angle will create a positive Yaw
88 + /// behind the camera and a negative one in front of the camera
89 + /// (so we invert the angle - left will turn left when facing -Z)
90 + inline void rotateYaw(F32 angle) {
91 + rotate(Quaternion<F32>(_yawFixed ? _fixedYawAxis : _orientation * WORLD_Y_AXIS,
92 + -angle * _cameraTurnSpeed));
93 + }
94 + /// Change camera's roll.
95 + inline void rotateRoll(F32 angle) {
96 + rotate(Quaternion<F32>(_orientation * WORLD_Z_AXIS,
97 + -angle * _cameraTurnSpeed));
98 + }
99 + /// Change camera's pitch
100 + inline void rotatePitch(F32 angle) {
101 + rotate(Quaternion<F32>(_orientation * WORLD_X_AXIS,
102 + -angle * _cameraTurnSpeed));
103 + }
104 + /// Sets the camera's Yaw angle.
105 + /// This creates a new orientation quaternion for the camera and extracts the euler angles
106 + inline void setYaw(F32 angle) {
107 + setRotation(angle, _euler.pitch, _euler.roll);
108 + }
109 + /// Sets the camera's Pitch angle. Yaw and Roll are previous extracted values
110 + inline void setPitch(F32 angle) {
111 + setRotation(_euler.yaw, angle, _euler.roll);
112 + }
113 + /// Sets the camera's Roll angle. Yaw and Pitch are previous extracted values
114 + inline void setRoll(F32 angle) {
115 + setRotation(_euler.yaw, _euler.pitch, angle);
116 + }
117 + /// Sets the camera's Yaw angle.
118 + /// This creates a new orientation quaternion for the camera and extracts the euler angles
119 + inline void setGlobalYaw(F32 angle) {
120 + setGlobalRotation(angle, _euler.pitch, _euler.roll);
121 + }
122 + /// Sets the camera's Pitch angle. Yaw and Roll are previous extracted values
123 + inline void setGlobalPitch(F32 angle) {
124 + setGlobalRotation(_euler.yaw, angle, _euler.roll);
125 + }
126 + /// Sets the camera's Roll angle. Yaw and Pitch are previous extracted values
127 + inline void setGlobalRoll(F32 angle) {
128 + setGlobalRotation(_euler.yaw, _euler.pitch, angle);
129 + }
130 + /// Moves the camera forward or backwards
131 + inline void moveForward(F32 factor) {
132 + move(0.0f, 0.0f, factor * _cameraMoveSpeed);
133 + }
134 + /// Moves the camera left or right
135 + inline void moveStrafe(F32 factor) {
136 + move(factor * _cameraMoveSpeed, 0.0f, 0.0f);
137 + }
138 + /// Moves the camera up or down
139 + inline void moveUp(F32 factor) {
140 + move(0.0f, factor * _cameraMoveSpeed, 0.0f);
141 + }
142 + /// Anaglyph rendering: Set intra-ocular distance
143 + inline void setIOD(F32 distance) {
144 + _camIOD = distance;
145 + }
146 +
147 + inline void setEye(F32 x, F32 y, F32 z) {
148 + _eye.set(x,y,z);
149 + _viewMatrixDirty = true;
150 + }
151 +
152 + inline void setEye(const vec3<F32>& position) {
153 + _eye = position;
154 + _viewMatrixDirty = true;
155 + }
156 +
157 + inline void setRotation(const Quaternion<F32>& q) {
158 + _orientation = q;
159 + _viewMatrixDirty = true;
160 + }
161 +
162 + inline void setRotation(F32 yaw, F32 pitch, F32 roll = 0.0f) {
163 + setRotation(Quaternion<F32>(-pitch, -yaw, -roll));
164 + }
165 +
166 + inline void setAspectRatio(F32 ratio) {
167 + _aspectRatio = ratio;
168 + _projectionDirty = true;
169 + }
170 +
171 + inline void setVerticalFoV(F32 verticalFoV) {
172 + _verticalFoV = verticalFoV;
173 + _projectionDirty = true;
174 + }
175 +
176 + inline void setHorizontalFoV(F32 horizontalFoV) {
177 + _verticalFoV = Util::xfov_to_yfov(horizontalFoV, _aspectRatio);
178 + _projectionDirty = true;
179 + }
180 +
181 + /// Mouse sensitivity: amount of pixels per radian (this should be moved out of the camera class)
182 + inline void setMouseSensitivity(F32 sensitivity) {
183 + _mouseSensitivity = sensitivity;
184 + }
185 +
186 + inline void setMoveSpeedFactor(F32 moveSpeedFactor) {
187 + _moveSpeedFactor = moveSpeedFactor;
188 + }
189 +
190 + inline void setTurnSpeedFactor(F32 turnSpeedFactor) {
191 + _turnSpeedFactor = turnSpeedFactor;
192 + }
193 +
194 + inline void setZoomSpeedFactor(F32 zoomSpeedFactor) {
195 + _zoomSpeedFactor = zoomSpeedFactor;
196 + }
197 +
198 + /// Exactly as in Ogre3D: locks the yaw movement to the specified axis
199 + inline void setFixedYawAxis(bool useFixed, const vec3<F32>& fixedAxis = WORLD_Y_AXIS) {
200 + _yawFixed = useFixed;
201 + _fixedYawAxis = fixedAxis;
202 + }
203 +
204 + /// Getter methods.
205 + inline F32 getMouseSensitivity() const {
206 + return _mouseSensitivity;
207 + }
208 +
209 + inline F32 getMoveSpeedFactor() const {
210 + return _moveSpeedFactor;
211 + }
212 +
213 + inline F32 getTurnSpeedFactor() const {
214 + return _turnSpeedFactor;
215 + }
216 +
217 + inline F32 getZoomSpeedFactor() const {
218 + return _zoomSpeedFactor;
219 + }
220 +
221 + inline const CameraType& getType() const {
222 + return _type;
223 + }
224 +
225 + inline const vec3<F32>& getEye() const {
226 + return _reflectionRendering ? _reflectedEye : _eye;
227 + }
228 +
229 + inline vec3<F32> getViewDir() const {
230 + return _reflectionRendering ? _reflectedViewMatrix * _viewDir : _viewDir;
231 + }
232 +
233 + inline vec3<F32> getUpDir() const {
234 + return _reflectionRendering ? _reflectedViewMatrix * _yAxis : _yAxis;
235 + }
236 +
237 + inline vec3<F32> getRightDir() const {
238 + return _reflectionRendering ? _reflectedViewMatrix * _xAxis : _xAxis;
239 + }
240 +
241 + inline const vec3<F32>& getEuler() const {
242 + return _euler;
243 + }
244 +
245 + inline const vec3<F32>& getTarget() const {
246 + return _target;
247 + }
248 +
249 + inline const mat4<F32>& getProjectionMatrix() const {
250 + return _projectionMatrix;
251 + }
252 +
253 + inline const vec2<F32>& getZPlanes() const {
254 + return _zPlanes;
255 + }
256 +
257 + inline const F32 getVerticalFoV() const {
258 + return _verticalFoV;
259 + }
260 +
261 + inline const F32 getHorizontalFoV() const {
262 + return Util::yfov_to_xfov(_verticalFoV, _aspectRatio);
263 + }
264 +
265 + inline const F32 getAspectRatio() const {
266 + return _aspectRatio;
267 + }
137 268
138 269 inline const mat4<F32>& getViewMatrix() {
139 270 updateViewMatrix();
  @@ -144,48 +275,87 @@
144 275 if ( updateViewMatrix() ) {
145 276 _viewMatrix.getInverse( _worldMatrix );
146 277 }
278 +
147 279 return _worldMatrix;
148 280 }
149 281
150 - ///Nothing really to unload
151 - virtual bool unload() {return true;}
152 - ///Add an event listener called after every RenderLookAt or RenderLookAtCube call
153 - virtual void addUpdateListener(const DELEGATE_CBK<>& f) { _listeners.push_back(f); }
154 - ///Informs all listeners of a new event
282 + /// Nothing really to unload
283 + virtual bool unload() {
284 + return true;
285 + }
286 + /// Add an event listener called after every RenderLookAt or RenderLookAtCube call
287 + virtual void addUpdateListener(const DELEGATE_CBK<>& f) {
288 + _listeners.push_back(f);
289 + }
290 + /// Informs all listeners of a new event
155 291 virtual void updateListeners();
156 - ///Clear all listeners from the current camera
157 - virtual void clearListeners() { _listeners.clear(); }
158 - ///Inject mouse events
159 - virtual bool mouseMoved(const Input::MouseEvent& arg) {return true;}
160 - ///Called when the camera becomes active
292 + /// Clear all listeners from the current camera
293 + virtual void clearListeners() {
294 + _listeners.clear();
295 + }
296 + /// Inject mouse events
297 + virtual bool mouseMoved(const Input::MouseEvent& arg) {
298 + return true;
299 + }
300 + /// Called when the camera becomes active
161 301 virtual void onActivate();
162 - ///Called when the camera becomes inactive
302 + /// Called when the camera becomes inactive
163 303 virtual void onDeactivate();
164 304
165 - void setProjection(F32 aspectRatio, F32 verticalFoV, const vec2<F32>& zPlanes, bool updateOnSet = false);
166 - void setProjection(const vec4<F32>& rect, const vec2<F32>& zPlanes, bool updateOnSet = false);
167 - ///Extract the frustum associated with our current PoV
305 + void setProjection(F32 aspectRatio,
306 + F32 verticalFoV,
307 + const vec2<F32>& zPlanes,
308 + bool updateOnSet = false);
309 +
310 + void setProjection(const vec4<F32>& rect,
311 + const vec2<F32>& zPlanes,
312 + bool updateOnSet = false);
313 + /// Extract the frustum associated with our current PoV
168 314 virtual bool updateFrustum();
169 - ///Get the camera's current frustum
170 - inline const Frustum& getFrustumConst() const { return *_frustum; }
171 - inline Frustum& getFrustum() { return *_frustum; }
172 -
173 - inline void lockMovement(bool state) { _movementLocked = state;}
174 - inline void lockRotation(bool state) { _rotationLocked = state; }
175 - inline void lockView(bool state) { _viewMatrixLocked = state; }
176 - inline void lockFrustum(bool state) { _frustumLocked = state; }
315 + /// Get the camera's current frustum
316 + inline const Frustum& getFrustumConst() const {
317 + return *_frustum;
318 + }
319 +
320 + inline Frustum& getFrustum() {
321 + return *_frustum;
322 + }
323 +
324 + inline void lockMovement(bool state) {
325 + _movementLocked = state;
326 + }
177 327
178 - vec3<F32> unProject(const vec3<F32>& winCoords) const;
179 - vec3<F32> unProject(const vec3<F32>& winCoords, const vec4<I32>& viewport) const;
328 + inline void lockRotation(bool state) {
329 + _rotationLocked = state;
330 + }
331 +
332 + inline void lockView(bool state) {
333 + _viewMatrixLocked = state;
334 + }
335 +
336 + inline void lockFrustum(bool state) {
337 + _frustumLocked = state;
338 + }
339 +
340 + /// Get the world space pozition from the specified screen coordinates
341 + /// (use winCoords.z for depth from 0 to 1)
342 + vec3<F32> unProject(const vec3<F32>& winCoords) const;
343 +
344 + /// Get the world space pozition from the specified screen coordinates
345 + /// (use winCoords.z for depth from 0 to 1)
346 + vec3<F32> unProject(const vec3<F32>& winCoords,
347 + const vec4<I32>& viewport) const;
180 348
181 349 protected:
182 350 virtual void lookAtInternal();
183 351 virtual bool updateViewMatrix();
184 352 virtual void updateProjection(bool force = false);
353 +
185 354 inline void updateMatrices() {
186 355 updateViewMatrix();
187 356 updateProjection();
188 357 }
358 +
189 359 protected:
190 360 mat4<F32> _viewMatrix;
191 361 mat4<F32> _worldMatrix;