3#include "../../../Components.h"
4#include "../../../Animators/MovingAnimation.h"
9 glm::vec3 velocity = glm::vec3(0);
10 glm::vec3 rotation = { 0.0f,0.0f,0.0f };
11 glm::vec3 position = glm::vec3(0);
12 glm::vec3 local_position = glm::vec3(0);
13 glm::vec3 local_normal_position = glm::vec3(0);
14 glm::vec3 size = glm::vec3(0);
16 glm::vec3 last_position = glm::vec3(0);
17 glm::vec3 last_size = glm::vec3(0);
18 glm::vec3 last_velocity = glm::vec3(0);
37 position.x = m_position.x;
38 position.y = m_position.y;
43 position = m_position;
47 position = { m_position.x, m_position.y, getLayerDepth(layer) };
48 size = { m_size.x, m_size.y, 0.0f };
75 void update(
float deltaTime)
override
78 if (entity->getParentEntity()
79 && (
dynamic_cast<NodeEntity*
>(entity->getParentEntity())
80 ||
dynamic_cast<EmptyEntity*
>(entity->getParentEntity())))
82 Entity* parent = entity->getParentEntity();
84 if (!glm::all(glm::equal(local_normal_position, glm::vec3(0.0f)))) {
85 position = parentTR->getPosition() + local_normal_position * parentTR->size / 2.0f;
88 position = parentTR->getPosition() + local_position;
93 if (position == last_position && size == last_size && velocity == last_velocity) {
99 last_position = position;
101 last_velocity = velocity;
103 position.x += velocity.x * speed * deltaTime;
104 position.y += velocity.y * speed * deltaTime;
111 if (entity->getParentEntity()
112 && (
dynamic_cast<NodeEntity*
>(entity->getParentEntity())
113 ||
dynamic_cast<EmptyEntity*
>(entity->getParentEntity())))
115 Entity* parent = entity->getParentEntity();
118 if (!glm::all(glm::equal(local_normal_position, glm::vec3(0.0f)))) {
119 position = parentTR->getPosition() + local_normal_position * parentTR->size / 2.0f;
122 position = parentTR->getPosition() + local_position;
128 glm::vec3 getSizeCenter() {
129 return glm::vec3(size.x * scale / 2, size.y * scale / 2, size.z * scale / 2);
132 glm::vec3 getPosition() {
136 void setPosition_X(
float newPosition_X) {
137 position.x = newPosition_X;
139 void setPosition_Y(
float newPosition_Y) {
140 position.y = newPosition_Y;
143 glm::vec3 getVelocity() {
147 void setVelocity_X(
float newVelocity_X) {
148 velocity.x = newVelocity_X;
150 void setVelocity_Y(
float newVelocity_Y) {
151 velocity.y = newVelocity_Y;
154 void setRotation(glm::vec3 m_rotation) {
155 rotation = m_rotation;
158 void SetMovingAnimation(
159 glm::vec3 m_startingPos,
162 const Animation::animType type,
163 const glm::vec3 distance,
164 const glm::vec3 dest_rotation,
167 moving_animation =
MovingAnimation(m_startingPos, fr, sp, type, distance, dest_rotation, reps);
170 void setMoveFrame() {
172 float progress = (float)moving_animation.cur_frame_index /
173 (
float)moving_animation.total_frames;
176 float newX = moving_animation.startingPosition.x +
177 ((moving_animation.distance.x) * progress);
179 float newY = moving_animation.startingPosition.y +
180 ((moving_animation.distance.y) * progress);
186 std::string GetComponentName()
override {
187 return "TransformComponent";
190 void showGUI(std::vector<BaseComponent*> otherComponents = {})
override {
191 showGUI(otherComponents, { entity });
194 void showGUI(std::vector<BaseComponent*> otherComponents, std::vector<Entity*> otherEntities)
override {
198 ImGui::Text(
"TazPosition:");
199 ImGui::SliderFloat3(
"##position", &position.x, -1000.0f, 1000.0f);
201 if (ImGui::Button(
"Apply TazPosition to All##transform_pos")) {
202 modifyPosition =
true;
204 if (modifyPosition && !otherComponents.empty()) {
205 for (
auto& comp : otherComponents) {
207 other->position = position;
213 ImGui::Text(
"TazSize:");
214 ImGui::SliderFloat3(
"##size", &size.x, 1.0f, 100.0f);
217 ImGui::Text(
"TazRotation:");
218 ImGui::SliderFloat3(
"##rotation", glm::value_ptr(rotation), -180.0f, 180.0f);
220 ImGui::Text(
"Scale:");
221 ImGui::SliderFloat(
"##scale", &scale, 0.1f, 10.0f);
224 ImGui::Text(
"Speed:");
225 ImGui::InputInt(
"##speed", &speed);
233 velocity = tr.velocity;
234 rotation = tr.rotation;
235 position = tr.position;
236 local_position = tr.local_position;
237 local_normal_position = tr.local_normal_position;
Definition GECSEntity.h:7
Definition MovingAnimation.h:9
Definition GECSEntity.h:40