galaxy
1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
Transform.cpp
Go to the documentation of this file.
1
7
8
#include <nlohmann/json.hpp>
9
10
#include "
Transform.hpp
"
11
12
namespace
galaxy
13
{
14
namespace
components
15
{
16
Transform::Transform
()
17
: Serializable {}
18
{
19
}
20
21
Transform::Transform
(
const
nlohmann::json& json)
22
: Serializable {}
23
{
24
deserialize
(json);
25
}
26
27
Transform::Transform
(
Transform
&& t)
28
: Serializable {}
29
{
30
}
31
32
Transform
&
Transform::operator=
(
Transform
&& t)
33
{
34
if
(
this
!= &t)
35
{
36
this->
m_tf
= std::move(t.m_tf);
37
}
38
39
return
*
this
;
40
}
41
42
Transform::~Transform
()
43
{
44
}
45
46
nlohmann::json
Transform::serialize
()
47
{
48
nlohmann::json json =
"{}"
_json;
49
50
json[
"pos"
][
"x"
] =
m_tf
.
get_pos
().x;
51
json[
"pos"
][
"y"
] =
m_tf
.
get_pos
().y;
52
json[
"rotation"
] =
m_tf
.
get_rotation
();
53
json[
"scale"
][
"x"
] =
m_tf
.
get_scale
().x;
54
json[
"scale"
][
"y"
] =
m_tf
.
get_scale
().y;
55
json[
"origin"
][
"x"
] =
m_tf
.
get_origin
().x;
56
json[
"origin"
][
"y"
] =
m_tf
.
get_origin
().y;
57
58
return
json;
59
}
60
61
void
Transform::deserialize
(
const
nlohmann::json& json)
62
{
63
const
auto
& pos = json.at(
"pos"
);
64
m_tf
.
set_pos
(pos.at(
"x"
), pos.at(
"y"
));
65
66
m_tf
.
set_rotation
(json.at(
"rotation"
));
67
68
const
auto
& scale = json.at(
"scale"
);
69
m_tf
.
set_scale_horizontal
(scale.at(
"x"
));
70
m_tf
.
set_scale_vertical
(scale.at(
"y"
));
71
72
const
auto
& origin = json.at(
"origin"
);
73
m_tf
.
set_origin
(origin.at(
"x"
), origin.at(
"y"
));
74
}
75
}
// namespace components
76
}
// namespace galaxy
galaxy::components::Transform
Defines the 2D transformation of an entity.
Definition
Transform.hpp:22
galaxy::components::Transform::Transform
Transform()
Constructor.
Definition
Transform.cpp:16
galaxy::components::Transform::deserialize
void deserialize(const nlohmann::json &json) override
Deserializes from object.
Definition
Transform.cpp:61
galaxy::components::Transform::m_tf
graphics::Transform m_tf
Transformation object.
Definition
Transform.hpp:81
galaxy::components::Transform::~Transform
virtual ~Transform()
Destructor.
Definition
Transform.cpp:42
galaxy::components::Transform::serialize
nlohmann::json serialize() override
Serializes object.
Definition
Transform.cpp:46
galaxy::components::Transform::operator=
Transform & operator=(Transform &&)
Move assignment operator.
Definition
Transform.cpp:32
galaxy::graphics::Transform::get_origin
const glm::vec2 & get_origin() const
Get origin point.
Definition
Transform.cpp:168
galaxy::graphics::Transform::set_scale_vertical
void set_scale_vertical(const float y)
Set entity scale.
Definition
Transform.cpp:116
galaxy::graphics::Transform::set_pos
void set_pos(const float x, const float y)
Sets position without moving the entity.
Definition
Transform.cpp:122
galaxy::graphics::Transform::set_origin
void set_origin(const float x, const float y)
Set the origin point.
Definition
Transform.cpp:136
galaxy::graphics::Transform::get_pos
const glm::vec2 & get_pos() const
Get stored position.
Definition
Transform.cpp:153
galaxy::graphics::Transform::get_scale
const glm::vec2 & get_scale() const
Get stored scale.
Definition
Transform.cpp:163
galaxy::graphics::Transform::get_rotation
float get_rotation() const
Get stored rotation.
Definition
Transform.cpp:158
galaxy::graphics::Transform::set_rotation
void set_rotation(const float degrees)
Set the entity rotation.
Definition
Transform.cpp:130
galaxy::graphics::Transform::set_scale_horizontal
void set_scale_horizontal(const float x)
Set entity scale.
Definition
Transform.cpp:110
Transform.hpp
galaxy
Animated.cpp galaxy.
Definition
Animated.cpp:16
galaxy
src
galaxy
components
Transform.cpp
Generated on Fri Sep 12 2025 07:29:48 for galaxy by
1.12.0