GlobeEngine
Camera.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_Camera_h
10 #define GlobeEngine_Camera_h
11 
12 #include "OpenGL_Includes.h"
13 #include <vmmlib/vmmlib.hpp>
14 #include "ViewFrustum.h"
15 
16 namespace ge {
17 
18  class Camera
19  {
20  public:
22  enum AXIS {XZ_AXIS = 0, XY_AXIS, YZ_AXIS };
23 
24  public:
25 
26  Camera();
27  ~Camera ();
28 
29  // hidden overrides from component
30  virtual void changeSetup(ViewFrustumProperties _in);
31  virtual void clear();
32  virtual void destroy();
33  virtual void update() = 0;
34  virtual void calculateViewMatrix()=0;
35  virtual void print();
36 
37  void setOrthographic();
38  void setPerspective(int _w = 0, int _h = 0);
39  void setOrthoCoordinates(vmml::Vector4d _coords);
40  void setViewportSize(int _w, int _h);
41  void setViewportSize(vmml::Vector2d _viewport);
42  vmml::Vector2d getScreenposForPoint(vmml::Vector3d _p, vmml::Matrix4d _modelMatrix);
43 
45  enum Camera::AXIS getOrientationFromString(std::string _input);
46  void setOrientationAxis(enum AXIS _in);
47 
48  vmml::Vector2d getViewport() const;
49  void applyViewport();
50  std::shared_ptr<ge::ViewFrustum> const& getViewFrustum() const;
51 
52  vmml::Matrix4d getViewMatrix() const;
53  void setViewMatrix(vmml::Matrix4d _viewMatrix);
54  vmml::Vector3d getRelativePositionToCenter() const;
55  vmml::Vector3d getScenePosition() const;
56  void setScenePosition(vmml::Vector3d _pos);
57  void setRelativePositionToCenter(vmml::Vector3d _pos);
58  double getDistanceToCamera(vmml::Vector3d _p) const;
59  vmml::Vector3d getDirection() const;
60 
61  enum CAMERATYPE getType() { return type; };
62 
63  bool hasChanged() { return changed; };
64  vmml::Matrix4d getProjectionMatrix() const;
65  void setProjectionMatrix(vmml::Matrix4d _projectionMatrix);
66  vmml::Matrix4d getViewProjectionMatrix() const;
67  void setViewProjectionMatrix(vmml::Matrix4d _viewprojectionMatrix);
68  static vmml::Matrix4d createOrthoProjectionMatrix(double l, double r, double b, double t, double n, double f);
69  void enableOrthoProjection();
71  void setChanged();
72 
73  vmml::Matrix4d getInverseViewMatrix() const;
74  vmml::Matrix4d getInverseProjectionMatrix() const;
75  vmml::Matrix4d getInverseProjectionViewMatrix() const;
76 
77  vmml::Vector4d getOrthoCoordinates() const;
78 
79  protected:
80  void moveFrustum();
81  void setStandardVectors();
82 
83  vmml::Matrix4d createPerspectiveProjectionMatrix(double fovy, double aspect, double zNear, double zFar);
84  vmml::Matrix4d createFrustumMatrix(double left, double right,
85  double bottom, double top,
86  double zNear, double zFar);
87 
88  vmml::Matrix4d getRotationMatrix(const vmml::Quaterniond& quat);
89 
92 
93  std::shared_ptr<ge::ViewFrustum> viewfrustum;
94  vmml::Vector2d viewport;
95 
96  vmml::Vector3d camPosition;
97  vmml::Vector3d camRight;
98  vmml::Vector3d camUp;
99  vmml::Vector3d camDirection;
100 
101  vmml::Matrix4d viewMatrix;
102  vmml::Matrix4d projectionMatrix;
103  /* viewProjectionMatrix is only a storage for faster access while rendering */
104  vmml::Matrix4d viewProjectionMatrix;
105 
107  vmml::Matrix4d orthoProjectionMatrix;
108  vmml::Vector4d orthoCoord;
109 
110  bool changed;
112 
113  /* uniform camera objects */
114  GLuint cameraBuffers[2];
115  };
116 }
117 #endif
void setScenePosition(vmml::Vector3d _pos)
Definition: Camera.cpp:114
vmml::Vector4d orthoCoord
Definition: Camera.h:108
vmml::Matrix4d getInverseProjectionMatrix() const
Definition: Camera.cpp:89
double getDistanceToCamera(vmml::Vector3d _p) const
Definition: Camera.cpp:251
vmml::Matrix4d getViewMatrix() const
Definition: Camera.cpp:53
void enableOrthoProjection()
Definition: Camera.cpp:304
vmml::Matrix4d viewProjectionMatrix
Definition: Camera.h:104
enum Camera::AXIS getOrientationAxis()
Definition: Camera.cpp:314
vmml::Vector3d getDirection() const
Definition: Camera.cpp:329
vmml::Matrix4d createFrustumMatrix(double left, double right, double bottom, double top, double zNear, double zFar)
Definition: Camera.cpp:210
Definition: Camera.h:21
std::shared_ptr< ge::ViewFrustum > viewfrustum
Definition: Camera.h:93
Definition: Camera.h:22
void setViewProjectionMatrix(vmml::Matrix4d _viewprojectionMatrix)
Definition: Camera.cpp:77
vmml::Matrix4d orthoProjectionMatrix
Definition: Camera.h:107
vmml::Vector3d camUp
Definition: Camera.h:98
static vmml::Matrix4d createOrthoProjectionMatrix(double l, double r, double b, double t, double n, double f)
Definition: Camera.cpp:180
void disableOrthoProjection()
Definition: Camera.cpp:309
void setViewMatrix(vmml::Matrix4d _viewMatrix)
Definition: Camera.cpp:58
Camera()
Definition: Camera.cpp:14
virtual void calculateViewMatrix()=0
virtual void changeSetup(ViewFrustumProperties _in)
Definition: Camera.cpp:36
void setOrthographic()
Definition: Camera.cpp:165
void applyViewport()
Definition: Camera.cpp:144
void setProjectionMatrix(vmml::Matrix4d _projectionMatrix)
Definition: Camera.cpp:67
void setPerspective(int _w=0, int _h=0)
Definition: Camera.cpp:154
vmml::Matrix4d projectionMatrix
Definition: Camera.h:102
bool changed
Definition: Camera.h:110
Definition: Camera.h:22
vmml::Vector3d getScenePosition() const
Definition: Camera.cpp:107
void setViewportSize(int _w, int _h)
std::shared_ptr< ge::ViewFrustum > const & getViewFrustum() const
Definition: Camera.cpp:48
enum Camera::AXIS orientation_axis
Definition: Camera.h:91
bool orthoProjMode
Definition: Camera.h:111
Definition: Camera.h:21
vmml::Matrix4d viewMatrix
Definition: Camera.h:101
enum CAMERATYPE type
Definition: Camera.h:90
virtual void print()
Definition: Camera.cpp:127
void setOrthoCoordinates(vmml::Vector4d _coords)
Definition: Camera.cpp:299
bool hasChanged()
Definition: Camera.h:63
Definition: Camera.h:18
virtual void clear()
Definition: Camera.cpp:23
virtual void destroy()
Definition: Camera.cpp:43
vmml::Vector3d camRight
Definition: Camera.h:97
vmml::Matrix4d createPerspectiveProjectionMatrix(double fovy, double aspect, double zNear, double zFar)
Definition: Camera.cpp:200
~Camera()
Definition: Camera.cpp:19
vmml::Vector3d getRelativePositionToCenter() const
Definition: Camera.cpp:103
vmml::Vector3d camDirection
Definition: Camera.h:99
void setChanged()
Definition: Camera.cpp:324
vmml::Vector2d viewport
Definition: Camera.h:94
vmml::Matrix4d getRotationMatrix(const vmml::Quaterniond &quat)
Definition: Camera.cpp:222
Definition: ViewFrustum.h:18
Definition: AvalancheTrainingSimulationEngine.h:28
vmml::Vector4d getOrthoCoordinates() const
Definition: Camera.cpp:333
vmml::Vector3d camPosition
Definition: Camera.h:96
vmml::Vector2d getViewport() const
Definition: Camera.cpp:149
CAMERATYPE
Definition: Camera.h:21
enum Camera::AXIS getOrientationFromString(std::string _input)
Definition: Camera.cpp:272
vmml::Matrix4d getProjectionMatrix() const
Definition: Camera.cpp:62
void setOrientationAxis(enum AXIS _in)
Definition: Camera.cpp:319
GLuint cameraBuffers[2]
Definition: Camera.h:114
enum CAMERATYPE getType()
Definition: Camera.h:61
vmml::Matrix4d perspectiveProjectionMatrix
Definition: Camera.h:106
Definition: Camera.h:22
virtual void update()=0
void setRelativePositionToCenter(vmml::Vector3d _pos)
Definition: Camera.cpp:121
void moveFrustum()
Definition: Camera.cpp:285
vmml::Matrix4d getInverseProjectionViewMatrix() const
Definition: Camera.cpp:96
Definition: Camera.h:21
vmml::Matrix4d getViewProjectionMatrix() const
Definition: Camera.cpp:72
AXIS
Definition: Camera.h:22
void setStandardVectors()
Definition: Camera.cpp:292
vmml::Matrix4d getInverseViewMatrix() const
Definition: Camera.cpp:82
vmml::Vector2d getScreenposForPoint(vmml::Vector3d _p, vmml::Matrix4d _modelMatrix)
Definition: Camera.cpp:255