Camera.h
Go to the documentation of this file.
1 #ifndef B_CAMERA_H
2 #define B_CAMERA_H
3 
4 #include <memory>
5 #include <iostream>
6 #include "Renderer_GL.h"
7 #include "vmmlib/vector.hpp"
8 #include "vmmlib/matrix.hpp"
9 #include "vmmlib/util.hpp"
10 
14 class Camera
15 {
16 public:
17 
18  /* Functions */
19 
22  Camera();
23 
30  Camera(GLfloat fov, GLfloat aspect, GLfloat near, GLfloat far);
31 
36  Camera(const vmml::Vector3f &position, const vmml::Vector3f &rotationAxes);
37 
46  Camera(const vmml::Vector3f &position, const vmml::Vector3f &rotationAxes, GLfloat fov, GLfloat aspect, GLfloat near, GLfloat far);
47 
50  virtual ~Camera() {}
51 
55  virtual void moveCameraForward(GLfloat camSpeed);
56 
60  virtual void moveCameraSideward(GLfloat camSpeed);
61 
65  virtual void moveCameraUpward(GLfloat camSpeed);
66 
72  virtual void rotateCamera(GLfloat rotationX, GLfloat rotationY, GLfloat rotationZ);
73 
76  virtual void resetCamera();
77 
81  void setPosition(const vmml::Vector3f &position) { _position = position; }
82 
86  void setRotation(const vmml::Vector3f &rotationAxes) { _rotationAxes = rotationAxes; }
87 
91  void setFieldOfView(GLfloat fov) { _fov = fov; }
92 
96  void setAspectRatio(GLfloat aspect) { _aspect = aspect; }
97 
101  void setNearClippingPlane(GLfloat near) { _near = near; }
102 
106  void setFarClippingPlane(GLfloat far) { _far = far; }
107 
110  virtual vmml::Matrix4f getViewMatrix();
111 
116  virtual vmml::Matrix4f getInverseViewMatrix();
117 
120  virtual vmml::Matrix4f getProjectionMatrix();
121 
124  const vmml::Vector3f &getPosition() { return _position; }
125 
128  virtual vmml::Matrix4f getRotation();
129 
134  virtual vmml::Matrix4f getInverseRotation();
135 
138  virtual vmml::Matrix4f getInverseRotationX();
139 
142  virtual vmml::Matrix4f getInverseRotationY();
143 
146  virtual vmml::Matrix4f getInverseRotationZ();
147 
150  virtual vmml::Vector3f getForward();
151 
154  virtual vmml::Vector3f getRight();
155 
158  virtual vmml::Vector3f getUp();
159 
160  /* Static Functions */
161 
167  static vmml::Matrix4f lookAt(const vmml::Vector3f &eye, const vmml::Vector3f &target, const vmml::Vector3f &up);
168 
175  static vmml::Matrix4f createPerspective(GLfloat fov, GLfloat aspect, GLfloat near, GLfloat far);
176 
177 private:
178 
179  /* Variables */
180 
181  vmml::Vector3f _position;
182  vmml::Vector3f _rotationAxes;
183 
184  GLfloat _fov, _aspect, _near, _far;
185 };
186 
187 typedef std::shared_ptr<Camera> CameraPtr;
188 
189 #endif /* defined(B_CAMERA_H) */
virtual vmml::Vector3f getForward()
Returns the orientation of the camera.
Definition: Camera.cpp:99
virtual vmml::Matrix4f getInverseViewMatrix()
Returns the inverse of the view matrix of the camera.
Definition: Camera.cpp:57
void setRotation(const vmml::Vector3f &rotationAxes)
Sets the rotation matrix of the camera.
Definition: Camera.h:86
virtual vmml::Matrix4f getProjectionMatrix()
Returns the view projection of the camera.
Definition: Camera.cpp:61
std::shared_ptr< Camera > CameraPtr
Definition: Camera.h:187
virtual void moveCameraForward(GLfloat camSpeed)
Moves the camera forward with a certain speed (based on previous position)
Definition: Camera.cpp:25
virtual vmml::Vector3f getRight()
Returns the right vector of the camera.
Definition: Camera.cpp:105
void setFieldOfView(GLfloat fov)
Sets field of view.
Definition: Camera.h:91
void setNearClippingPlane(GLfloat near)
Sets near clipping plane.
Definition: Camera.h:101
The camera object defines the view and projection matrices of a scene.
Definition: Camera.h:14
virtual vmml::Matrix4f getInverseRotation()
Returns the inverse of the rotation matrix of the camera.
Definition: Camera.cpp:71
virtual vmml::Matrix4f getViewMatrix()
Returns the view matrix of the camera.
Definition: Camera.cpp:53
virtual void rotateCamera(GLfloat rotationX, GLfloat rotationY, GLfloat rotationZ)
Rotates the camera based on previous orientation.
Definition: Camera.cpp:40
void setFarClippingPlane(GLfloat far)
Sets far clipping plane.
Definition: Camera.h:106
static vmml::Matrix4f createPerspective(GLfloat fov, GLfloat aspect, GLfloat near, GLfloat far)
Create a 3D perspective.
Definition: Camera.cpp:133
virtual vmml::Matrix4f getRotation()
Returns the rotation matrix of the camera.
Definition: Camera.cpp:66
Camera()
Constructor loading standard values for position, orientation and projection.
Definition: Camera.cpp:7
static vmml::Matrix4f lookAt(const vmml::Vector3f &eye, const vmml::Vector3f &target, const vmml::Vector3f &up)
Create a simple look at matrix.
Definition: Camera.cpp:119
virtual vmml::Matrix4f getInverseRotationZ()
Returns the inverse of the z-axis of the rotation matrix.
Definition: Camera.cpp:92
virtual vmml::Matrix4f getInverseRotationX()
Returns the inverse of the x-axis of the rotation matrix.
Definition: Camera.cpp:78
const vmml::Vector3f & getPosition()
Returns the position of the camera.
Definition: Camera.h:124
virtual void resetCamera()
Resets camera to the default position orientation.
Definition: Camera.cpp:47
void setAspectRatio(GLfloat aspect)
Sets aspect ratio.
Definition: Camera.h:96
virtual void moveCameraSideward(GLfloat camSpeed)
Moves the camera to the right with a certain speed (based on previous position)
Definition: Camera.cpp:30
virtual vmml::Matrix4f getInverseRotationY()
Returns the inverse of the y-axis of the rotation matrix.
Definition: Camera.cpp:85
virtual void moveCameraUpward(GLfloat camSpeed)
Moves the camera upwards with a certain speed (based on previous position)
Definition: Camera.cpp:35
virtual vmml::Vector3f getUp()
Returns the up vector of the camera.
Definition: Camera.cpp:111
virtual ~Camera()
Virtual destructor.
Definition: Camera.h:50
void setPosition(const vmml::Vector3f &position)
Sets the position of the camera.
Definition: Camera.h:81