-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.hpp
More file actions
33 lines (26 loc) · 772 Bytes
/
transform.hpp
File metadata and controls
33 lines (26 loc) · 772 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
#ifndef TRANSFORM_H
#define TRANSFORM_H
struct Transform2D
{
glm::vec2 position{0.0f},
scale{1.0f};
float rotation_radians{0.0f},
rotation_degrees{0.0f};
};
struct Transform3D
{
glm::vec3 position{0.0f},
rotation{0.0f},
rotation_degrees{0.0f},
scale{1.0f};
glm::quat quaternion{rotation};
glm::mat4 translation_matrix() const
{ return glm::translate(glm::mat4{1.0f}, position); }
glm::mat4 scaling_matrix() const
{ return glm::scale(glm::mat4{1.0f}, scale); }
glm::mat4 rotation_matrix() const
{ return glm::mat4_cast(glm::normalize(quaternion)); }
glm::mat4 model_matrix() const
{ return translation_matrix() * rotation_matrix() * scaling_matrix(); }
};
#endif // TRANSFORM_H