Go to the documentation of this file.
1 #pragma once
3 #include <QMatrix3x3>
4 #include <QMatrix4x4>
5 #include <QPoint>
6 #include <QVector3D>
7 #include <QVector2D>
9 #include <resources/program.h>
11 namespace terminus
12 {
14 class AbstractGraphicsObject;
26 class Camera
27 {
28 public:
29  Camera(const QVector3D & eye = QVector3D(0.0, 0.0, 1.0),
30  const QVector3D & center = QVector3D(0.0, 0.0, 0.0),
31  const QVector3D & up = QVector3D(0.0, 1.0, 0.0) );
33  virtual ~Camera();
35  const QVector3D & eye() const;
36  void setEye(const QVector3D & eye);
37  const QVector3D & center() const;
38  void setCenter(const QVector3D & center);
39  const QVector3D & up() const;
40  void setUp(const QVector3D & up);
42  QVector3D normalizedLook() const;
44  float zNear() const;
45  void setZNear(float zNear);
46  float zFar() const;
47  void setZFar(float zFar);
49  float fovy() const;
50  void setFovy(float fovy);
52  const QPoint & viewport() const;
53  void setViewport(const QPoint & viewport);
54  void setViewport(int width, int height);
56  float aspectRatio() const;
58  const QMatrix4x4 & view() const;
59  const QMatrix4x4 & projection() const;
60  const QMatrix4x4 & viewProjection() const;
61  const QMatrix4x4 & viewInverted() const;
62  const QMatrix4x4 & projectionInverted() const;
63  const QMatrix4x4 & viewProjectionInverted() const;
64  const QMatrix3x3 & normal() const;
72  void setMatrices(Program & program, const QMatrix4x4 & model) const;
80  void bindTo(AbstractGraphicsObject * object);
84  void unbind();
89  void unbound(AbstractGraphicsObject * object);
94  bool isBound() const;
104  void moveEvent(QVector3D movement);
113  void rotateEvent(QVector2D rotation);
115 protected:
116  void invalidateMatrices() const;
118 protected:
119  QVector3D m_eye;
120  QVector3D m_center;
121  QVector3D m_up;
123  float m_fovy;
124  float m_aspect;
125  float m_zNear;
126  float m_zFar;
128  QPoint m_viewport;
130  mutable QMatrix4x4 m_view;
131  mutable QMatrix4x4 m_viewInverted;
132  mutable QMatrix4x4 m_projection;
133  mutable QMatrix4x4 m_projectionInverted;
134  mutable QMatrix4x4 m_viewProjection;
135  mutable QMatrix4x4 m_viewProjectionInverted;
136  mutable QMatrix3x3 m_normal;
138  mutable bool m_viewChanged;
139  mutable bool m_viewInvertedChanged;
140  mutable bool m_projectionChanged;
144  mutable bool m_normalChanged;
150 };
152 } // namespace terminus
void setZNear(float zNear)
Definition: camera.cpp:108
const QVector3D & eye() const
Definition: camera.cpp:50
void rotateEvent(QVector2D rotation)
called if the GUI requests the camera to be rotated
Definition: camera.cpp:212
QPoint m_viewport
Definition: camera.h:128
float zFar() const
Definition: camera.cpp:121
bool isBound() const
Definition: camera.cpp:340
float m_aspect
Definition: camera.h:124
void moveEvent(QVector3D movement)
called if the GUI requests the camera to be moved
Definition: camera.cpp:185
const QMatrix4x4 & viewInverted() const
Definition: camera.cpp:268
Camera(const QVector3D &eye=QVector3D(0.0, 0.0, 1.0), const QVector3D &center=QVector3D(0.0, 0.0, 0.0), const QVector3D &up=QVector3D(0.0, 1.0, 0.0))
Definition: camera.cpp:13
void setFovy(float fovy)
Definition: camera.cpp:144
void unbound(AbstractGraphicsObject *object)
is called if an object releases this camera
Definition: camera.cpp:332
float aspectRatio() const
Definition: camera.cpp:180
const QMatrix4x4 & viewProjection() const
Definition: camera.cpp:257
void setCenter(const QVector3D &center)
Definition: camera.cpp:71
void setMatrices(Program &program, const QMatrix4x4 &model) const
sets the view and projection as well as the given model matrix as uniforms on the given shader progra...
Definition: camera.cpp:345
float m_zFar
Definition: camera.h:126
QMatrix3x3 m_normal
Definition: camera.h:136
float m_fovy
Definition: camera.h:123
const QMatrix4x4 & projection() const
Definition: camera.cpp:245
void setEye(const QVector3D &eye)
Definition: camera.cpp:55
bool m_viewProjectionInvertedChanged
Definition: camera.h:143
bool m_projectionInvertedChanged
Definition: camera.h:141
The AbstractGraphicsObject class is the root of a class hierarchy of objects that contain independen ...
Definition: abstractgraphicsobject.h:27
const QMatrix4x4 & viewProjectionInverted() const
Definition: camera.cpp:290
QMatrix4x4 m_viewProjection
Definition: camera.h:134
void invalidateMatrices() const
Definition: camera.cpp:39
const QMatrix3x3 & normal() const
Definition: camera.cpp:301
QMatrix4x4 m_viewInverted
Definition: camera.h:131
QMatrix4x4 m_projection
Definition: camera.h:132
QMatrix4x4 m_projectionInverted
Definition: camera.h:133
virtual ~Camera()
Definition: camera.cpp:35
QVector3D m_up
Definition: camera.h:121
float fovy() const
Definition: camera.cpp:139
bool m_viewInvertedChanged
Definition: camera.h:139
void setUp(const QVector3D &up)
Definition: camera.cpp:87
The program class implements the basic functionality used for binding programs to openGL...
Definition: program.h:18
bool m_viewChanged
Definition: camera.h:138
QMatrix4x4 m_viewProjectionInverted
Definition: camera.h:135
float zNear() const
Definition: camera.cpp:103
const QMatrix4x4 & projectionInverted() const
Definition: camera.cpp:279
QMatrix4x4 m_view
Definition: camera.h:130
void setZFar(float zFar)
Definition: camera.cpp:126
void bindTo(AbstractGraphicsObject *object)
bind camera to track an AbstractGraphicsObject
Definition: camera.cpp:312
const QMatrix4x4 & view() const
Definition: camera.cpp:233
Definition: eventhandler.cpp:18
AbstractGraphicsObject * m_associatedObject
object that this camera is bound to in order to track it
Definition: camera.h:149
bool m_viewProjectionChanged
Definition: camera.h:142
bool m_normalChanged
Definition: camera.h:144
The Camera class manages view and projection matrices that define a view of a 3D scene.
Definition: camera.h:26
const QVector3D & up() const
Definition: camera.cpp:82
const QVector3D & center() const
Definition: camera.cpp:66
void setViewport(const QPoint &viewport)
Definition: camera.cpp:167
QVector3D normalizedLook() const
Definition: camera.cpp:98
QVector3D m_center
Definition: camera.h:120
void unbind()
release the camera from the object it is currently bound to
Definition: camera.cpp:327
bool m_projectionChanged
Definition: camera.h:140
QVector3D m_eye
Definition: camera.h:119
float m_zNear
Definition: camera.h:125
const QPoint & viewport() const
Definition: camera.cpp:157