-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera3d.cpp
More file actions
52 lines (44 loc) · 1.83 KB
/
Copy pathcamera3d.cpp
File metadata and controls
52 lines (44 loc) · 1.83 KB
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
#include "camera3d.h"
#include <QDebug>
//Left hand co-ordinate system
const QVector3D Camera3D::LocalForward(0.0f, 0.0f, -1.0f);
const QVector3D Camera3D::LocalUp(0.0f, 1.0f, 0.0f);
const QVector3D Camera3D::LocalRight(1.0f, 0.0f, 0.0f);
void Camera3D::translate(const QVector3D& dt){ m_dirty = true; m_translation += dt; }
void Camera3D::rotate(const QQuaternion& dr) { m_dirty = true; m_rotation = dr * m_rotation; }
void Camera3D::setRotation(const QQuaternion& r) {m_dirty = true; m_rotation = r; }
void Camera3D::setTranslation(const QVector3D& t) {m_dirty = true; m_translation = t; }
const QMatrix4x4 &Camera3D::toMatrix()
{
if (m_dirty)
{
m_dirty = false;
m_world.setToIdentity();
m_world.rotate(m_rotation.conjugate());
m_world.translate(-m_translation);
}
return m_world;
}
QVector3D Camera3D::forward() const { return m_rotation.rotatedVector(LocalForward); }
QVector3D Camera3D::right() const{ return m_rotation.rotatedVector(LocalRight);}
QVector3D Camera3D::up() const { return m_rotation.rotatedVector(LocalUp); }
QDebug operator<<(QDebug dbg, const Camera3D &transform)
{
dbg << "Camera3D\n{\n";
dbg << "Position: <" << transform.translation().x() << ", " << transform.translation().y() << ", " << transform.translation().z() << ">\n";
dbg << "Rotation: <" << transform.rotation().x() << ", " << transform.rotation().y() << ", " << transform.rotation().z() << " | " << transform.rotation().scalar() << ">\n}";
return dbg;
}
QDataStream& operator<<(QDataStream& out, const Camera3D& transform)
{
out << transform.m_translation;
out << transform.m_rotation;
return out;
}
QDataStream& operator>>(QDataStream& in, Camera3D& transform)
{
in >> transform.m_translation;
in >> transform.m_rotation;
transform.m_dirty = true;
return in;
}