Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 868 vs 869 for /trunk/Source Code/Rendering/Camera/Camera.cpp

Diff revisions: vs.
  @@ -6,8 +6,7 @@
6 6 : Resource(ResourceType::DEFAULT, name),
7 7 _isOrthoCamera(false),
8 8 _projectionDirty(true),
9 - _viewMatrixDirty(true),
10 - _viewMatrixLocked(false),
9 + _viewMatrixDirty(false),
11 10 _rotationLocked(false),
12 11 _movementLocked(false),
13 12 _frustumLocked(false),
  @@ -52,7 +51,6 @@
52 51 _cameraTurnSpeed = camera._cameraTurnSpeed;
53 52 _cameraZoomSpeed = camera._cameraZoomSpeed;
54 53
55 - lockView(camera._viewMatrixLocked);
56 54 lockFrustum(camera._frustumLocked);
57 55 _accumPitchDegrees = camera._accumPitchDegrees;
58 56
  @@ -109,13 +107,14 @@
109 107 }
110 108
111 109 if (_type == CameraType::FIRST_PERSON) {
112 - vec3<F32> euler;
110 + vec3<Angle::DEGREES<F32>> euler;
113 111 q.getEuler(euler);
112 + euler = Angle::to_DEGREES(euler);
114 113 rotate(euler.yaw, euler.pitch, euler.roll);
115 114 } else {
116 - Quaternion<F32> tempOrientation(q);
115 + Quaternion<F32> tempOrientation = q * _orientation;
117 116 tempOrientation.normalize();
118 - _orientation = tempOrientation * _orientation;
117 + _orientation = tempOrientation;
119 118 }
120 119
121 120 _viewMatrixDirty = true;
  @@ -165,6 +164,18 @@
165 164 _viewMatrixDirty = true;
166 165 }
167 166
167 + void Camera::rotateYaw(Angle::DEGREES<F32> angle) {
168 + rotate(Quaternion<F32>(_yawFixed ? _fixedYawAxis : _orientation * WORLD_Y_AXIS, -angle * _cameraTurnSpeed));
169 + }
170 +
171 + void Camera::rotateRoll(Angle::DEGREES<F32> angle) {
172 + rotate(Quaternion<F32>(_orientation * WORLD_Z_AXIS, -angle * _cameraTurnSpeed));
173 + }
174 +
175 + void Camera::rotatePitch(Angle::DEGREES<F32> angle) {
176 + rotate(Quaternion<F32>(_orientation * WORLD_X_AXIS, -angle * _cameraTurnSpeed));
177 + }
178 +
168 179 void Camera::move(F32 dx, F32 dy, F32 dz) {
169 180 if (_movementLocked) {
170 181 return;
  @@ -236,7 +247,7 @@
236 247 _zPlanes.x,
237 248 _zPlanes.y);
238 249 } else {
239 - _projectionMatrix.perspective(Angle::to_RADIANS(_verticalFoV),
250 + _projectionMatrix.perspective(_verticalFoV,
240 251 _aspectRatio,
241 252 _zPlanes.x,
242 253 _zPlanes.y);
  @@ -277,37 +288,34 @@
277 288 _projectionDirty = true;
278 289 }
279 290
280 - void Camera::setVerticalFoV(F32 verticalFoV) {
291 + void Camera::setVerticalFoV(Angle::DEGREES<F32> verticalFoV) {
281 292 _verticalFoV = verticalFoV;
282 293 _projectionDirty = true;
283 294 }
284 295
285 - void Camera::setHorizontalFoV(F32 horizontalFoV) {
296 + void Camera::setHorizontalFoV(Angle::DEGREES<F32> horizontalFoV) {
286 297 _verticalFoV = Angle::to_DEGREES(2.0f * std::atan(tan(Angle::to_RADIANS(horizontalFoV) * 0.5f) / _aspectRatio));
287 298 _projectionDirty = true;
288 299 }
289 300
290 301 bool Camera::updateViewMatrix() {
291 - if (!_viewMatrixDirty || _viewMatrixLocked) {
302 + if (!_viewMatrixDirty) {
292 303 return false;
293 304 }
294 305
295 - vec3<F32> xAxis, yAxis, zAxis;
296 -
297 306 _orientation.normalize();
298 307
299 308 // Reconstruct the view matrix.
300 - _orientation.getMatrix(_viewMatrix);
301 -
302 - xAxis.set(_viewMatrix.m[0][0], _viewMatrix.m[1][0], _viewMatrix.m[2][0]);
303 - yAxis.set(_viewMatrix.m[0][1], _viewMatrix.m[1][1], _viewMatrix.m[2][1]);
304 - zAxis.set(_viewMatrix.m[0][2], _viewMatrix.m[1][2], _viewMatrix.m[2][2]);
309 + mat3<F32> rotation;
310 + _orientation.getMatrix(rotation);
311 + vec3<F32> xAxis = _orientation.xAxis();
312 + vec3<F32> yAxis = _orientation.yAxis();
313 + vec3<F32> zAxis = _orientation.zAxis();
305 314
306 315 _target = -zAxis + _eye;
307 316
308 - _viewMatrix.m[3][0] = -xAxis.dot(_eye);
309 - _viewMatrix.m[3][1] = -yAxis.dot(_eye);
310 - _viewMatrix.m[3][2] = -zAxis.dot(_eye);
317 + _viewMatrix.set(rotation);
318 + _viewMatrix.setRow(3, -xAxis.dot(_eye), -yAxis.dot(_eye), -zAxis.dot(_eye), 1.0f);
311 319 _orientation.getEuler(_euler);
312 320 _euler = Angle::to_DEGREES(_euler);
313 321
  @@ -344,4 +352,4 @@
344 352 return temp.xyz();
345 353 }
346 354
347 - };
355 + };