-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScope.cpp
More file actions
83 lines (70 loc) · 2.2 KB
/
Copy pathScope.cpp
File metadata and controls
83 lines (70 loc) · 2.2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "Scope.h"
#include "glm/ext.hpp"
Scope::Scope()
: position(0.0f)
, size(1.0f)
, x(1.0f, 0.0f, 0.0f)
, y (0.0f, 1.0f, 0.0f)
, z (0.0f, 0.0f, 1.0f)
{}
Scope::Scope(const Scope &other)
: position(other.position)
, size(other.size)
, x(other.x)
, y(other.y)
, z(other.z)
{}
void Scope::T(const glm::vec3 &translation)
{
position += translation;
}
void Scope::S(const glm::vec3 &size_)
{
size = size_;
}
void Scope::Rx(float angle)
{
float c = glm::cos(angle);
float s = glm::sin(angle);
glm::mat3 rotation(glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, c, s), glm::vec3(0.0f, -s, c));
glm::mat3 basis(x, y, z);
y = basis * rotation * glm::vec3(0.0f, 1.0f, 0.0f);
z = basis * rotation * glm::vec3(0.0f, 0.0f, 1.0f);
}
void Scope::Ry(float angle)
{
float c = glm::cos(angle);
float s = glm::sin(angle);
glm::mat3 rotation(glm::vec3(c, 0.0f, -s), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(s, 0.0f, c));
glm::mat3 basis(x, y, z);
x = basis * rotation * glm::vec3(1.0f, 0.0f, 0.0f);
z = basis * rotation * glm::vec3(0.0f, 0.0f, 1.0f);
}
void Scope::Rz(float angle)
{
float c = glm::cos(angle);
float s = glm::sin(angle);
glm::mat3 rotation(glm::vec3(c, s, 0.0f), glm::vec3(-s, c, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat3 basis(x, y, z);
x = basis * rotation * glm::vec3(1.0f, 0.0f, 0.0f);
y = basis * rotation * glm::vec3(0.0f, 1.0f, 0.0f);
}
glm::mat4 Scope::getTransform()
{
glm::mat4 rotation(glm::vec4(x, 0.0f), glm::vec4(y, 0.0f), glm::vec4(z, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
glm::mat4 translation(glm::vec4(1.0f, 0.0f, 0.0f, 0.0f), glm::vec4(0.0f, 1.0f, 0.0f, 0.0f), glm::vec4(0.0f, 0.0f, 1.0f, 0.0f), glm::vec4(position, 1.0f));
glm::mat4 scale(glm::vec4(size.x, 0.0f, 0.0f, 0.0f), glm::vec4(0.0f, size.y, 0.0f, 0.0f), glm::vec4(0.0f, 0.0f, size.z, 0.0f), glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
glm::mat4 transform = rotation * scale;
transform[3][0] = position.x;
transform[3][1] = position.y;
transform[3][2] = position.z;
return transform;
}
glm::vec3 Scope::getPosition() const
{
return position;
}
glm::vec3 Scope::getSize() const
{
return size;
}