|
|
|
@ -14,13 +14,31 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include "Camera.h" |
|
|
|
#include "Camera.h" |
|
|
|
|
|
|
|
#include "Scene.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace Magnum { |
|
|
|
namespace Magnum { |
|
|
|
|
|
|
|
|
|
|
|
Camera::Camera(Object* parent): Object(parent), viewportWidth(0), viewportHeight(0), _aspectRatioPolicy(Extend) { |
|
|
|
Camera::Camera(Object* parent): Object(parent), _active(0), viewportWidth(0), viewportHeight(0), _aspectRatioPolicy(Extend) { |
|
|
|
setOrthographic(2, 1, 1000); |
|
|
|
setOrthographic(2, 1, 1000); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Camera::setActive(Scene* _scene) { |
|
|
|
|
|
|
|
if(_scene == _active || scene() != _scene) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Scene* oldActive = _active; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Set camera active in new scene */ |
|
|
|
|
|
|
|
_active = _scene; |
|
|
|
|
|
|
|
if(_active) _active->setCamera(this); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Remove the camera from current active scene, if the camera is still
|
|
|
|
|
|
|
|
active there */ |
|
|
|
|
|
|
|
if(oldActive && oldActive->camera() == this) oldActive->setCamera(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Clean the path to scene */ |
|
|
|
|
|
|
|
setClean(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Camera::setOrthographic(GLfloat size, GLfloat near, GLfloat far) { |
|
|
|
void Camera::setOrthographic(GLfloat size, GLfloat near, GLfloat far) { |
|
|
|
/* Scale the volume down so it fits in (-1, 1) in all directions */ |
|
|
|
/* Scale the volume down so it fits in (-1, 1) in all directions */ |
|
|
|
GLfloat xyScale = 2/size; |
|
|
|
GLfloat xyScale = 2/size; |
|
|
|
@ -55,11 +73,6 @@ void Camera::setPerspective(GLfloat fov, GLfloat near, GLfloat far) { |
|
|
|
fixAspectRatio(); |
|
|
|
fixAspectRatio(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Matrix4 Camera::cameraMatrix() const { |
|
|
|
|
|
|
|
/** @todo How to do that? */ |
|
|
|
|
|
|
|
return Matrix4(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Camera::setViewport(int width, int height) { |
|
|
|
void Camera::setViewport(int width, int height) { |
|
|
|
glViewport(0, 0, width, height); |
|
|
|
glViewport(0, 0, width, height); |
|
|
|
|
|
|
|
|
|
|
|
@ -68,6 +81,30 @@ void Camera::setViewport(int width, int height) { |
|
|
|
fixAspectRatio(); |
|
|
|
fixAspectRatio(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Camera::setClean() { |
|
|
|
|
|
|
|
if(!isDirty()) return; |
|
|
|
|
|
|
|
_cameraMatrix = transformation(true).inverse(); |
|
|
|
|
|
|
|
Object::setClean(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Camera::setDirty() { |
|
|
|
|
|
|
|
Object::setDirty(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Camera is active */ |
|
|
|
|
|
|
|
if(_active) { |
|
|
|
|
|
|
|
Scene* currentScene = scene(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Camera is not part of the scene anymore, remove it from there */ |
|
|
|
|
|
|
|
if(!currentScene) _active->setCamera(0); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Otherwise set the scene dirty */ |
|
|
|
|
|
|
|
else _active->setDirty(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Clean up the path to scene immediately */ |
|
|
|
|
|
|
|
setClean(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Camera::fixAspectRatio() { |
|
|
|
void Camera::fixAspectRatio() { |
|
|
|
/* Don't divide by zero */ |
|
|
|
/* Don't divide by zero */ |
|
|
|
if(viewportWidth == 0 || viewportHeight == 0) { |
|
|
|
if(viewportWidth == 0 || viewportHeight == 0) { |
|
|
|
|