Unravel Engine C++ Reference
Loading...
Searching...
No Matches
transform_actions.cpp
Go to the documentation of this file.
1#include "transform_actions.h"
2#include "base/basetypes.hpp"
4
5namespace unravel
6{
7
8// Transform Move Action Implementation
9transform_move_action_t::transform_move_action_t(entt::handle ent, const math::vec3& old_pos, const math::vec3& new_pos)
10 : entity(ent), old_position(old_pos), new_position(new_pos)
11{
12 name = "Position";
13}
14
16{
17 if (entity)
18 {
19 if (auto transform = entity.try_get<transform_component>())
20 {
21 transform->set_position_local(new_position);
23 }
24 }
25}
26
28{
29 if (entity)
30 {
31 if (auto transform = entity.try_get<transform_component>())
32 {
33 transform->set_position_local(old_position);
35 }
36 }
37}
38
40{
41 const auto& prev = static_cast<const transform_move_action_t&>(previous);
42 return entity == prev.entity && name == prev.name;
43}
44
46{
47 const auto& prev = static_cast<const transform_move_action_t&>(previous);
48 old_position = prev.old_position; // Extend the range of the move
49}
50
52{
53 return entity.valid() && entity.try_get<transform_component>();
54}
55
56
58{
60 {"name", "position"},
61 {"pretty_name", "Position"}}
62 );
63 draw_in_inspector_impl(ctx, old_position, new_position, custom);
64}
65
66// Transform Move Global Action Implementation
67transform_move_global_action_t::transform_move_global_action_t(entt::handle ent, const math::vec3& old_pos, const math::vec3& new_pos)
68 : entity(ent), old_position(old_pos), new_position(new_pos)
69{
70 name = "Global Position";
71}
72
74{
75 if (entity)
76 {
77 if (auto transform = entity.try_get<transform_component>())
78 {
79 transform->set_position_global(new_position);
81 }
82 }
83}
84
86{
87 if (entity)
88 {
89 if (auto transform = entity.try_get<transform_component>())
90 {
91 transform->set_position_global(old_position);
93 }
94 }
95}
96
98{
99 const auto& prev = static_cast<const transform_move_global_action_t&>(previous);
100 return entity == prev.entity && name == prev.name;
101}
102
104{
105 const auto& prev = static_cast<const transform_move_global_action_t&>(previous);
106 old_position = prev.old_position; // Extend the range of the move
107}
108
110{
111 return entity.valid() && entity.try_get<transform_component>();
112}
113
115{
117 {"name", "global_position"},
118 {"pretty_name", "Global Position"}}
119 );
120 draw_in_inspector_impl(ctx, old_position, new_position, custom);
121}
122
123// Transform Rotate Action Implementation
124transform_rotate_action_t::transform_rotate_action_t(entt::handle ent, const math::quat& old_rot, const math::quat& new_rot)
125 : entity(ent), old_rotation(old_rot), new_rotation(new_rot)
126{
127 name = "Rotation";
128}
129
131{
132 if (entity)
133 {
134 if (auto transform = entity.try_get<transform_component>())
135 {
136 transform->set_rotation_local(new_rotation);
138 }
139 }
140}
141
143{
144 if (entity)
145 {
146 if (auto transform = entity.try_get<transform_component>())
147 {
148 transform->set_rotation_local(old_rotation);
150 }
151 }
152}
153
155{
156 const auto& prev = static_cast<const transform_rotate_action_t&>(previous);
157 return entity == prev.entity && name == prev.name;
158}
159
161{
162 const auto& prev = static_cast<const transform_rotate_action_t&>(previous);
163 old_rotation = prev.old_rotation; // Extend the range of the rotation
164}
165
167{
168 return entity.valid() && entity.try_get<transform_component>();
169}
170
172{
174 {"name", "rotation"},
175 {"pretty_name", "Rotation"}}
176 );
177 draw_in_inspector_impl(ctx, old_rotation, new_rotation, custom);
178}
179
180
181// Transform Scale Action Implementation
182transform_scale_action_t::transform_scale_action_t(entt::handle ent, const math::vec3& old_sc, const math::vec3& new_sc)
183 : entity(ent), old_scale(old_sc), new_scale(new_sc)
184{
185 name = "Scale";
186}
187
189{
190 if (entity)
191 {
192 if (auto transform = entity.try_get<transform_component>())
193 {
194 transform->set_scale_local(new_scale);
196 }
197 }
198}
199
201{
202 if (entity)
203 {
204 if (auto transform = entity.try_get<transform_component>())
205 {
206 transform->set_scale_local(old_scale);
208 }
209 }
210}
211
213{
214 const auto& prev = static_cast<const transform_scale_action_t&>(previous);
215 return entity == prev.entity && name == prev.name;
216}
217
219{
220 const auto& prev = static_cast<const transform_scale_action_t&>(previous);
221 old_scale = prev.old_scale; // Extend the range of the scale
222}
223
225{
226 return entity.valid() && entity.try_get<transform_component>();
227}
228
230{
232 {"name", "scale"},
233 {"pretty_name", "Scale"}}
234 );
235 draw_in_inspector_impl(ctx, old_scale, new_scale, custom);
236}
237
238
239// Transform Skew Action Implementation
240transform_skew_action_t::transform_skew_action_t(entt::handle ent, const math::vec3& old_sk, const math::vec3& new_sk)
241 : entity(ent), old_skew(old_sk), new_skew(new_sk)
242{
243 name = "Skew";
244}
245
247{
248 if (entity)
249 {
250 if (auto transform = entity.try_get<transform_component>())
251 {
252 transform->set_skew_local(new_skew);
254 }
255 }
256}
257
259{
260 if (entity)
261 {
262 if (auto transform = entity.try_get<transform_component>())
263 {
264 transform->set_skew_local(old_skew);
266 }
267 }
268}
269
271{
272 const auto& prev = static_cast<const transform_skew_action_t&>(previous);
273 return entity == prev.entity && name == prev.name;
274}
275
277{
278 const auto& prev = static_cast<const transform_skew_action_t&>(previous);
279 old_skew = prev.old_skew; // Extend the range of the skew
280}
281
283{
284 return entity.valid() && entity.try_get<transform_component>();
285}
286
288{
290 {"name", "skew"},
291 {"pretty_name", "Skew"}}
292 );
293 draw_in_inspector_impl(ctx, old_skew, new_skew, custom);
294}
295
296
297} // namespace unravel
Component that handles transformations (position, rotation, scale, etc.) in the ACE framework.
std::string name
Definition hub.cpp:27
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto make_custom(Args &&...args) -> entt::meta_custom
Definition reflection.h:91
entt::entity entity
static void mark_transform_global_as_changed(entt::handle entity, bool position, bool rotation, bool scale, bool skew)
static void mark_transform_as_changed(entt::handle entity, bool position, bool rotation, bool scale, bool skew)
Marks transform properties as changed in prefab override system.
auto is_valid() const -> bool override
void draw_in_inspector(rtti::context &ctx) override
transform_move_action_t(entt::handle ent, const math::vec3 &old_pos, const math::vec3 &new_pos)
void merge_with(const editing_action_t &previous) override
auto is_mergeable(const editing_action_t &previous) const -> bool override
transform_move_global_action_t(entt::handle ent, const math::vec3 &old_pos, const math::vec3 &new_pos)
void draw_in_inspector(rtti::context &ctx) override
auto is_mergeable(const editing_action_t &previous) const -> bool override
void merge_with(const editing_action_t &previous) override
auto is_mergeable(const editing_action_t &previous) const -> bool override
transform_rotate_action_t(entt::handle ent, const math::quat &old_rot, const math::quat &new_rot)
void merge_with(const editing_action_t &previous) override
auto is_valid() const -> bool override
void draw_in_inspector(rtti::context &ctx) override
void draw_in_inspector(rtti::context &ctx) override
auto is_mergeable(const editing_action_t &previous) const -> bool override
transform_scale_action_t(entt::handle ent, const math::vec3 &old_sc, const math::vec3 &new_sc)
void merge_with(const editing_action_t &previous) override
auto is_valid() const -> bool override
auto is_mergeable(const editing_action_t &previous) const -> bool override
auto is_valid() const -> bool override
void draw_in_inspector(rtti::context &ctx) override
void merge_with(const editing_action_t &previous) override
transform_skew_action_t(entt::handle ent, const math::vec3 &old_sk, const math::vec3 &new_sk)