-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera3d.h
84 lines (66 loc) · 2.62 KB
/
camera3d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef QCAMERA_H
#define QCAMERA_H
#include "transform3d.h"
class Camera3D
{
public:
// Constants
static const QVector3D LocalForward;
static const QVector3D LocalUp;
static const QVector3D LocalRight;
// Constructors
Camera3D();
void reset();
// Transform By (Add/Scale)
void translate(const QVector3D &dt);
void translate(float dx, float dy, float dz);
void rotate(const QQuaternion &dr);
void rotate(float angle, const QVector3D &axis);
void rotate(float angle, float ax, float ay, float az);
// Transform To (Setters)
void setTranslation(const QVector3D &t);
void setTranslation(float x, float y, float z);
void setRotation(const QQuaternion &r);
void setRotation(float angle, const QVector3D &axis);
void setRotation(float angle, float ax, float ay, float az);
// Accessors
const QVector3D& translation() const;
const QQuaternion& rotation() const;
const QMatrix4x4& toMatrix();
// Queries
QVector3D forward() const;
QVector3D up() const;
QVector3D right() const;
private:
bool m_dirty;
QVector3D m_translation;
QQuaternion m_rotation;
QMatrix4x4 m_world;
#ifndef QT_NO_DATASTREAM
friend QDataStream &operator<<(QDataStream &out, const Camera3D &transform);
friend QDataStream &operator>>(QDataStream &in, Camera3D &transform);
#endif
};
Q_DECLARE_TYPEINFO(Camera3D, Q_MOVABLE_TYPE);
// Constructors
inline Camera3D::Camera3D() : m_dirty(true) {}
// Transform By (Add/Scale)
inline void Camera3D::translate(float dx, float dy,float dz) { translate(QVector3D(dx, dy, dz)); }
inline void Camera3D::rotate(float angle, const QVector3D &axis) { rotate(QQuaternion::fromAxisAndAngle(axis, angle)); }
inline void Camera3D::rotate(float angle, float ax, float ay,float az) { rotate(QQuaternion::fromAxisAndAngle(ax, ay, az, angle)); }
// Transform To (Setters)
inline void Camera3D::setTranslation(float x, float y, float z) { setTranslation(QVector3D(x, y, z)); }
inline void Camera3D::setRotation(float angle, const QVector3D &axis) { setRotation(QQuaternion::fromAxisAndAngle(axis, angle)); }
inline void Camera3D::setRotation(float angle, float ax, float ay, float az) { setRotation(QQuaternion::fromAxisAndAngle(ax, ay, az, angle)); }
// Accessors
inline const QVector3D& Camera3D::translation() const { return m_translation; }
inline const QQuaternion& Camera3D::rotation() const { return m_rotation; }
// Qt Streams
#ifndef QT_NO_DEBUG_STREAM
QDebug operator<<(QDebug dbg, const Camera3D &transform);
#endif
#ifndef QT_NO_DATASTREAM
QDataStream &operator<<(QDataStream &out, const Camera3D &transform);
QDataStream &operator>>(QDataStream &in, Camera3D &transform);
#endif
#endif // QCAMERA_H