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