PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
Transform.hpp
1#pragma once
2
3#include <glm/glm.hpp>
4#include <glm/gtc/matrix_transform.hpp>
5#include <glm/gtx/quaternion.hpp>
6
7namespace PixelBullet
8{
9 struct Transform
10 {
11 glm::vec3 Position = glm::vec3(0.0f);
12 glm::vec3 Rotation = glm::vec3(0.0f);
13 glm::vec3 Scale = glm::vec3(1.0f);
14
15 Transform() = default;
16 Transform(const glm::vec3& pos)
17 : Position(pos)
18 {
19 }
20 Transform(const glm::vec3& pos, const glm::vec3& rot, const glm::vec3& scl)
21 : Position(pos)
22 , Rotation(rot)
23 , Scale(scl)
24 {
25 }
26
27 [[nodiscard]] glm::mat4 GetMatrix() const
28 {
29 glm::mat4 rotMat = glm::toMat4(glm::quat(Rotation));
30 return glm::translate(glm::mat4(1.0f), Position) * rotMat * glm::scale(glm::mat4(1.0f), Scale);
31 }
32 };
33
34 inline Node& operator<<(Node& node, const Transform& t)
35 {
36 node["position"] << t.Position;
37 node["rotation"] << t.Rotation;
38 node["scale"] << t.Scale;
39 return node;
40 }
41
42 inline const Node& operator>>(const Node& node, Transform& t)
43 {
44 node["position"] >> t.Position;
45 node["rotation"] >> t.Rotation;
46 node["scale"] >> t.Scale;
47 return node;
48 }
49} // namespace PixelBullet
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition Node.hpp:51
Definition Transform.hpp:10