-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEntity.cpp
More file actions
45 lines (39 loc) · 838 Bytes
/
Entity.cpp
File metadata and controls
45 lines (39 loc) · 838 Bytes
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
#include "Entity.h"
#include <cmath>
Entity::Entity(const std::string & name)
: name_(name)
{
}
void Entity::setPosition(const QVector3D & position)
{
position_ = position;
markTransformDirty();
}
void Entity::setRotation(const QVector3D & rotation)
{
rotation_ = rotation;
markTransformDirty();
}
void Entity::setScale(const QVector3D & scale)
{
scale_ = scale;
markTransformDirty();
}
const QMatrix4x4 & Entity::getTransform() const
{
if (transformDirty_)
{
updateTransform();
transformDirty_ = false;
}
return transform_;
}
void Entity::updateTransform() const
{
transform_.setToIdentity();
transform_.translate(position_);
transform_.rotate(rotation_.x(), 1.0f, 0.0f, 0.0f);
transform_.rotate(rotation_.y(), 0.0f, 1.0f, 0.0f);
transform_.rotate(rotation_.z(), 0.0f, 0.0f, 1.0f);
transform_.scale(scale_);
}