-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotationComponent.cpp
More file actions
59 lines (40 loc) · 1.23 KB
/
RotationComponent.cpp
File metadata and controls
59 lines (40 loc) · 1.23 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
53
54
55
56
57
58
59
#include "RotationComponent.h"
//Easy set and get to access Rotation of each object
rotation_component::rotation_component() : m_rotation_(0.0f, 0.0f, 0.0f, 0.0f)
{
}
rotation_component::rotation_component(const XMFLOAT4 rotation) : m_rotation_(rotation) {
}
rotation_component::rotation_component(const float x, const float y, const float z, const float w) : m_rotation_(x, y, z, w) {
}
void rotation_component::set_rotation(const XMFLOAT4 newRotation) {
m_rotation_ = newRotation;
normalize();
}
void rotation_component::set_rotation(const float x, const float y, const float z, const float w) {
m_rotation_ = XMFLOAT4(x, y, z, w);
normalize();
}
void rotation_component::add_rotation(const XMFLOAT4 otherRotation) {
//m_rotation += otherRotation;
}
void rotation_component::add_rotation(const float x, const float y, const float z, const float w) {
//m_rotation += XMFLOAT4(x, y, z, w);
}
void rotation_component::normalize()
{
auto d = m_rotation_.x * m_rotation_.x +
m_rotation_.y * m_rotation_.y +
m_rotation_.z * m_rotation_.z +
m_rotation_.w * m_rotation_.w;
if (d == 0.f)
{
m_rotation_.x = 1;
return;
}
d = (1.0f) / sqrt(d);
m_rotation_.x *= d;
m_rotation_.y *= d;
m_rotation_.z *= d;
m_rotation_.w *= d;
}