Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 750 vs 769 for /trunk/Source Code/Rendering/Camera/Camera.cpp

Diff revisions: vs.
  @@ -28,19 +28,11 @@
28 28 _type(type)
29 29 {
30 30 _eye.set(eye);
31 - _reflectedEye.set(eye * vec3<F32>(1.0f, -1.0f, 1.0f));
32 - _xAxis.set(WORLD_X_AXIS);
33 - _yAxis.set(WORLD_Y_AXIS);
34 - _zAxis.set(WORLD_Z_AXIS);
35 - _viewDir.set(WORLD_Z_NEG_AXIS);
36 31 _fixedYawAxis.set(WORLD_Y_AXIS);
37 32 _accumPitchDegrees = 0.0f;
38 33 _orientation.identity();
39 - _tempOrientation.identity();
40 34 _viewMatrix.identity();
41 - _reflectedViewMatrix.identity();
42 35 _yawFixed = false;
43 - _reflectionRendering = false;
44 36 _zPlanes.set(0.1f, 1.0f);
45 37 _frustum = MemoryManager_NEW Frustum(*this);
46 38 }
  @@ -52,18 +44,23 @@
52 44
53 45 void Camera::fromCamera(const Camera& camera) {
54 46 if (camera._isOrthoCamera) {
55 - setProjection(camera._orthoRect, camera.getZPlanes());
47 + setProjection(camera._orthoRect,
48 + camera.getZPlanes());
56 49 } else {
57 - setProjection(camera.getAspectRatio(), camera.getVerticalFoV(),
50 + setProjection(camera.getAspectRatio(),
51 + camera.getVerticalFoV(),
58 52 camera.getZPlanes());
59 53 }
60 54
55 + lookAt(camera.getEye(), camera.getTarget(), camera.getUpDir());
61 56 setMoveSpeedFactor(camera.getMoveSpeedFactor());
62 57 setTurnSpeedFactor(camera.getTurnSpeedFactor());
63 58 setZoomSpeedFactor(camera.getZoomSpeedFactor());
64 59 setFixedYawAxis(camera._yawFixed, camera._fixedYawAxis);
65 60 lockView(camera._viewMatrixLocked);
66 61 lockFrustum(camera._frustumLocked);
62 +
63 + _accumPitchDegrees = camera._accumPitchDegrees;
67 64 }
68 65
69 66 void Camera::update(const U64 deltaTime) {
  @@ -131,8 +128,8 @@
131 128 Quaternion<F32> yawRot(WORLD_Y_AXIS, -yaw);
132 129
133 130 if (!IS_ZERO(roll)) {
134 - _tempOrientation.fromAxisAngle(WORLD_Z_AXIS, -roll);
135 - setRotation(yawRot * pitchRot * _tempOrientation);
131 + Quaternion<F32> tempOrientation(WORLD_Z_AXIS, -roll);
132 + setRotation(yawRot * pitchRot * tempOrientation);
136 133 } else {
137 134 setRotation(yawRot * pitchRot);
138 135 }
  @@ -148,9 +145,9 @@
148 145 q.getEuler(euler);
149 146 rotate(euler.yaw, euler.pitch, euler.roll);
150 147 } else {
151 - _tempOrientation.set(q);
152 - _tempOrientation.normalize();
153 - _orientation = _tempOrientation * _orientation;
148 + Quaternion<F32> tempOrientation(q);
149 + tempOrientation.normalize();
150 + _orientation = tempOrientation * _orientation;
154 151 }
155 152
156 153 _viewMatrixDirty = true;
  @@ -165,6 +162,7 @@
165 162 pitch = -pitch * _cameraTurnSpeed;
166 163 roll = -roll * _cameraTurnSpeed;
167 164
165 + Quaternion<F32> tempOrientation;
168 166 if (_type == CameraType::FIRST_PERSON) {
169 167 _accumPitchDegrees += pitch;
170 168
  @@ -181,19 +179,19 @@
181 179 // Rotate camera about the world y axis.
182 180 // Note the order the quaternions are multiplied. That is important!
183 181 if (!IS_ZERO(yaw)) {
184 - _tempOrientation.fromAxisAngle(WORLD_Y_AXIS, yaw);
185 - _orientation = _tempOrientation * _orientation;
182 + tempOrientation.fromAxisAngle(WORLD_Y_AXIS, yaw);
183 + _orientation = tempOrientation * _orientation;
186 184 }
187 185
188 186 // Rotate camera about its local x axis.
189 187 // Note the order the quaternions are multiplied. That is important!
190 188 if (!IS_ZERO(pitch)) {
191 - _tempOrientation.fromAxisAngle(WORLD_X_AXIS, pitch);
192 - _orientation = _orientation * _tempOrientation;
189 + tempOrientation.fromAxisAngle(WORLD_X_AXIS, pitch);
190 + _orientation = _orientation * tempOrientation;
193 191 }
194 192 } else {
195 - _tempOrientation.fromEuler(pitch, yaw, roll);
196 - _orientation *= _tempOrientation;
193 + tempOrientation.fromEuler(pitch, yaw, roll);
194 + _orientation *= tempOrientation;
197 195 }
198 196
199 197 _viewMatrixDirty = true;
  @@ -207,7 +205,7 @@
207 205 dy *= _cameraMoveSpeed;
208 206 dz *= _cameraMoveSpeed;
209 207
210 - _eye += _xAxis * dx;
208 + _eye += getRightDir() * dx;
211 209 _eye += WORLD_Y_AXIS * dy;
212 210
213 211 if (_type == CameraType::FIRST_PERSON) {
  @@ -215,11 +213,11 @@
215 213 // z axis as doing so will cause the camera to move more slowly as the
216 214 // camera's view approaches 90 degrees straight up and down.
217 215 vec3<F32> forward;
218 - forward.cross(WORLD_Y_AXIS, _xAxis);
216 + forward.cross(WORLD_Y_AXIS, getRightDir());
219 217 forward.normalize();
220 218 _eye += forward * dz;
221 219 } else {
222 - _eye += _viewDir * dz;
220 + _eye += getForwardDir() * dz;
223 221 }
224 222
225 223 _viewMatrixDirty = true;
  @@ -228,35 +226,35 @@
228 226 const mat4<F32>& Camera::lookAt(const vec3<F32>& eye,
229 227 const vec3<F32>& target,
230 228 const vec3<F32>& up) {
229 + vec3<F32> xAxis, yAxis, zAxis;
230 +
231 231 _eye.set(eye);
232 232 _target.set(target);
233 - _zAxis.set(eye - target);
233 + zAxis.set(eye - target);
234 234
235 - _zAxis.normalize();
236 - _xAxis.cross(up, _zAxis);
237 - _xAxis.normalize();
238 - _yAxis.cross(_zAxis, _xAxis);
239 - _yAxis.normalize();
240 -
241 - _viewDir.set(-_zAxis);
242 -
243 - _viewMatrix.m[0][0] = _xAxis.x;
244 - _viewMatrix.m[1][0] = _xAxis.y;
245 - _viewMatrix.m[2][0] = _xAxis.z;
246 - _viewMatrix.m[3][0] = -_xAxis.dot(eye);
247 -
248 - _viewMatrix.m[0][1] = _yAxis.x;
249 - _viewMatrix.m[1][1] = _yAxis.y;
250 - _viewMatrix.m[2][1] = _yAxis.z;
251 - _viewMatrix.m[3][1] = -_yAxis.dot(eye);
252 -
253 - _viewMatrix.m[0][2] = _zAxis.x;
254 - _viewMatrix.m[1][2] = _zAxis.y;
255 - _viewMatrix.m[2][2] = _zAxis.z;
256 - _viewMatrix.m[3][2] = -_zAxis.dot(eye);
235 + zAxis.normalize();
236 + xAxis.cross(up, zAxis);
237 + xAxis.normalize();
238 + yAxis.cross(zAxis, xAxis);
239 + yAxis.normalize();
240 +
241 + _viewMatrix.m[0][0] = xAxis.x;
242 + _viewMatrix.m[1][0] = xAxis.y;
243 + _viewMatrix.m[2][0] = xAxis.z;
244 + _viewMatrix.m[3][0] = xAxis.dot(eye);
245 +
246 + _viewMatrix.m[0][1] = yAxis.x;
247 + _viewMatrix.m[1][1] = yAxis.y;
248 + _viewMatrix.m[2][1] = yAxis.z;
249 + _viewMatrix.m[3][1] = yAxis.dot(eye);
250 +
251 + _viewMatrix.m[0][2] = zAxis.x;
252 + _viewMatrix.m[1][2] = zAxis.y;
253 + _viewMatrix.m[2][2] = zAxis.z;
254 + _viewMatrix.m[3][2] = zAxis.dot(eye);
257 255
258 256 // Extract the pitch angle from the view matrix.
259 - _accumPitchDegrees = Angle::RadiansToDegrees(asinf(_zAxis.y));
257 + _accumPitchDegrees = Angle::RadiansToDegrees(asinf(zAxis.y));
260 258
261 259 _orientation.fromMatrix(_viewMatrix);
262 260
  @@ -267,39 +265,21 @@
267 265 }
268 266
269 267 /// Tell the rendering API to set up our desired PoV
270 - void Camera::renderLookAt() {
271 - if (_reflectionRendering) {
272 - _reflectionRendering = false;
273 - _frustumDirty = true;
274 - }
275 -
276 - lookAtInternal();
277 - }
278 -
279 - void Camera::renderLookAtReflected(const Plane<F32>& reflectionPlane) {
280 - _reflectionRendering = true;
281 - _reflectedViewMatrix.reflect(reflectionPlane);
282 - _reflectedEye = _reflectedViewMatrix * _eye;
283 - _frustumDirty = true;
284 -
285 - lookAtInternal();
286 - }
287 -
288 - void Camera::lookAtInternal() {
289 - assert(_isActive);
290 -
268 + void Camera::renderLookAt(mat4<F32>& viewMatrixOut, vec3<F32>& eyeVecOut) {
291 269 updateViewMatrix();
292 270 updateProjection();
293 -
294 - // Tell the Rendering API to draw from our desired PoV
295 - GFX_DEVICE.lookAt(_reflectionRendering
296 - ? (_reflectedViewMatrix * _viewMatrix)
297 - : _viewMatrix,
298 - _reflectionRendering ? _reflectedEye : _eye);
299 -
300 271 updateFrustum();
301 272 // Inform all listeners of a new event
302 273 updateListeners();
274 +
275 + viewMatrixOut = _viewMatrix;
276 + eyeVecOut = _eye;
277 + }
278 +
279 + void Camera::reflect(const Plane<F32>& reflectionPlane) {
280 + mat4<F32> reflectedMatrix(getViewMatrix());
281 + reflectedMatrix.reflect(reflectionPlane);
282 + lookAt(reflectedMatrix * getEye(), getTarget(), reflectedMatrix * getUpDir());
303 283 }
304 284
305 285 void Camera::setProjection(F32 aspectRatio, F32 verticalFoV,
  @@ -333,20 +313,22 @@
333 313 return false;
334 314 }
335 315
316 + vec3<F32> xAxis, yAxis, zAxis;
317 +
336 318 _orientation.normalize();
337 319
338 320 // Reconstruct the view matrix.
339 321 _orientation.getMatrix(_viewMatrix);
340 322
341 - _xAxis.set(_viewMatrix.m[0][0], _viewMatrix.m[1][0], _viewMatrix.m[2][0]);
342 - _yAxis.set(_viewMatrix.m[0][1], _viewMatrix.m[1][1], _viewMatrix.m[2][1]);
343 - _zAxis.set(_viewMatrix.m[0][2], _viewMatrix.m[1][2], _viewMatrix.m[2][2]);
344 - _viewDir = -_zAxis;
345 - _target = _viewDir + _eye;
346 -
347 - _viewMatrix.m[3][0] = -_xAxis.dot(_eye);
348 - _viewMatrix.m[3][1] = -_yAxis.dot(_eye);
349 - _viewMatrix.m[3][2] = -_zAxis.dot(_eye);
323 + xAxis.set(_viewMatrix.m[0][0], _viewMatrix.m[1][0], _viewMatrix.m[2][0]);
324 + yAxis.set(_viewMatrix.m[0][1], _viewMatrix.m[1][1], _viewMatrix.m[2][1]);
325 + zAxis.set(_viewMatrix.m[0][2], _viewMatrix.m[1][2], _viewMatrix.m[2][2]);
326 +
327 + _target = -zAxis + _eye;
328 +
329 + _viewMatrix.m[3][0] = -xAxis.dot(_eye);
330 + _viewMatrix.m[3][1] = -yAxis.dot(_eye);
331 + _viewMatrix.m[3][2] = -zAxis.dot(_eye);
350 332 _orientation.getEuler(_euler, true);
351 333
352 334 _viewMatrixDirty = false;