Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 781 vs 784 for /trunk/Source Code/Rendering/Camera/Camera.cpp

Diff revisions: vs.
  @@ -1,8 +1,5 @@
1 1 #include "Headers/Camera.h"
2 2
3 - #include "Platform/Video/Headers/GFXDevice.h"
4 - #include "Managers/Headers/SceneManager.h"
5 -
6 3 namespace Divide {
7 4
8 5 Camera::Camera(const stringImpl& name, const CameraType& type, const vec3<F32>& eye)
  @@ -62,39 +59,18 @@
62 59 _accumPitchDegrees = camera._accumPitchDegrees;
63 60 }
64 61
65 - void Camera::update(const U64 deltaTime) {
62 + void Camera::updateInternal(const U64 deltaTime) {
66 63 F32 timeFactor = Time::MicrosecondsToSeconds<F32>(deltaTime);
67 64 _cameraMoveSpeed = _moveSpeedFactor * timeFactor;
68 65 _cameraTurnSpeed = _turnSpeedFactor * timeFactor;
69 66 _cameraZoomSpeed = _zoomSpeedFactor * timeFactor;
70 67 }
71 68
72 - void Camera::updateProjection() {
73 - if (_projectionDirty) {
74 - if (_isOrthoCamera) {
75 - _projectionMatrix.ortho(_orthoRect.x,
76 - _orthoRect.y,
77 - _orthoRect.z,
78 - _orthoRect.w,
79 - _zPlanes.x,
80 - _zPlanes.y);
81 - } else {
82 - _projectionMatrix.perspective(Angle::DegreesToRadians(_verticalFoV),
83 - _aspectRatio,
84 - _zPlanes.x,
85 - _zPlanes.y);
86 - }
87 - _frustumDirty = true;
88 - _projectionDirty = false;
89 - }
90 -
91 - }
92 -
93 - void Camera::onActivate() {
69 + void Camera::setActiveInternal(bool state) {
70 + // nothing yet;
71 + ACKNOWLEDGE_UNUSED(state);
94 72 }
95 73
96 - void Camera::onDeactivate() {
97 - }
98 74
99 75 void Camera::setGlobalRotation(F32 yaw, F32 pitch, F32 roll) {
100 76 if (_rotationLocked) {
  @@ -247,7 +223,6 @@
247 223 updateViewMatrix();
248 224 updateProjection();
249 225 updateFrustum();
250 - // Inform all listeners of a new event
251 226 updateListeners();
252 227 }
253 228
  @@ -257,28 +232,68 @@
257 232 lookAt(reflectedMatrix * getEye(), getTarget(), reflectedMatrix * getUpDir());
258 233 }
259 234
260 - void Camera::setProjection(F32 aspectRatio, F32 verticalFoV,
261 - const vec2<F32>& zPlanes, bool updateOnSet) {
235 + bool Camera::updateProjection() {
236 + if (_projectionDirty) {
237 + if (_isOrthoCamera) {
238 + _projectionMatrix.ortho(_orthoRect.x,
239 + _orthoRect.y,
240 + _orthoRect.z,
241 + _orthoRect.w,
242 + _zPlanes.x,
243 + _zPlanes.y);
244 + } else {
245 + _projectionMatrix.perspective(Angle::DegreesToRadians(_verticalFoV),
246 + _aspectRatio,
247 + _zPlanes.x,
248 + _zPlanes.y);
249 + }
250 +
251 + _frustumDirty = true;
252 + _projectionDirty = false;
253 + return true;
254 + }
255 +
256 + return false;
257 + }
258 +
259 + const mat4<F32>& Camera::setProjection(F32 aspectRatio, F32 verticalFoV, const vec2<F32>& zPlanes) {
260 + setAspectRatio(_aspectRatio);
261 + setVerticalFoV(verticalFoV);
262 +
262 263 _zPlanes = zPlanes;
263 - _aspectRatio = aspectRatio;
264 - _verticalFoV = verticalFoV;
265 264 _isOrthoCamera = false;
266 265 _projectionDirty = true;
266 + updateProjection();
267 267
268 - if (updateOnSet) {
269 - updateProjection();
270 - }
268 + return getProjectionMatrix();
271 269 }
272 270
273 - void Camera::setProjection(const vec4<F32>& rect, const vec2<F32>& zPlanes, bool updateOnSet) {
271 + const mat4<F32>& Camera::setProjection(const vec4<F32>& rect, const vec2<F32>& zPlanes) {
274 272 _zPlanes = zPlanes;
275 273 _orthoRect = rect;
276 274 _isOrthoCamera = true;
277 275 _projectionDirty = true;
276 + updateProjection();
278 277
279 - if (updateOnSet) {
280 - updateProjection();
281 - }
278 + return getProjectionMatrix();
279 + }
280 +
281 + void Camera::setAspectRatio(F32 ratio) {
282 + _aspectRatio = ratio;
283 + _projectionDirty = true;
284 + }
285 +
286 + void Camera::setVerticalFoV(F32 verticalFoV) {
287 + _verticalFoV = verticalFoV;
288 + _projectionDirty = true;
289 + }
290 +
291 + void Camera::setHorizontalFoV(F32 horizontalFoV) {
292 + _verticalFoV = Angle::RadiansToDegrees(
293 + 2.0f *
294 + std::atan(tan(Angle::DegreesToRadians(horizontalFoV) * 0.5f) /
295 + _aspectRatio));
296 + _projectionDirty = true;
282 297 }
283 298
284 299 bool Camera::updateViewMatrix() {
  @@ -332,14 +347,7 @@
332 347 return true;
333 348 }
334 349
335 - vec3<F32> Camera::unProject(F32 winCoordsX, F32 winCoordsY, F32 winCoordsZ) const {
336 - const vec4<I32>& viewport = GFX_DEVICE.getCurrentViewport();
337 -
338 - return unProject(winCoordsX, winCoordsY, winCoordsZ, viewport);
339 - }
340 -
341 - vec3<F32> Camera::unProject(F32 winCoordsX, F32 winCoordsY, F32 winCoordsZ,
342 - const vec4<I32>& viewport) const {
350 + vec3<F32> Camera::unProject(F32 winCoordsX, F32 winCoordsY, F32 winCoordsZ, const vec4<I32>& viewport) const {
343 351 vec4<F32> temp(winCoordsX, winCoordsY, winCoordsZ, 1.0f);
344 352 temp.x = (temp.x - F32(viewport[0])) / F32(viewport[2]);
345 353 temp.y = (temp.y - F32(viewport[1])) / F32(viewport[3]);
  @@ -349,4 +357,5 @@
349 357
350 358 return temp.xyz();
351 359 }
360 +
352 361 };