8 glm::vec3 velocity = glm::vec3(0);
9 glm::vec3 rotation = { 0.0f,0.0f,0.0f };
10 glm::vec3 position = glm::vec3(0);
11 glm::vec3 size = glm::vec3(0);
13 glm::vec3 last_position = glm::vec3(0);
14 glm::vec3 last_size = glm::vec3(0);
15 glm::vec3 last_velocity = glm::vec3(0);
18 glm::vec3 bodyCenter = { 0.0f,0.0f,0.0f };
35 position.x = m_position.x;
36 position.y = m_position.y;
37 bodyCenter = position + (size / 2.0f);
42 position = m_position;
43 bodyCenter = position + (size / 2.0f);
47 position = { m_position.x, m_position.y, getLayerDepth(layer) };
48 size = { m_size.x, m_size.y, 0.0f };
50 bodyCenter = position + (size / 2.0f);
76 void update(
float deltaTime)
override
79 if (entity->getParentEntity()
80 && (
dynamic_cast<NodeEntity*
>(entity->getParentEntity())
81 ||
dynamic_cast<EmptyEntity*
>(entity->getParentEntity())))
83 Entity* parent = entity->getParentEntity();
86 parentTR->position == parentTR->last_position
87 && parentTR->size == parentTR->last_size
88 && parentTR->velocity == parentTR->last_velocity
93 bodyCenter = parentTR->getCenterTransform() + position;
97 bodyCenter = position + (size / 2.0f);
100 if (position == last_position && size == last_size && velocity == last_velocity) {
104 entity->cellUpdate();
106 last_position = position;
108 last_velocity = velocity;
110 position.x += velocity.x * speed * deltaTime;
111 position.y += velocity.y * speed * deltaTime;
121 glm::vec3 getCenterTransform()
126 glm::vec3 getSizeCenter() {
127 return glm::vec3(size.x * scale / 2, size.y * scale / 2, size.z * scale / 2);
130 glm::vec3 getPosition() {
134 void setPosition_X(
float newPosition_X) {
135 position.x = newPosition_X;
137 void setPosition_Y(
float newPosition_Y) {
138 position.y = newPosition_Y;
141 glm::vec3 getVelocity() {
145 void setVelocity_X(
float newVelocity_X) {
146 velocity.x = newVelocity_X;
148 void setVelocity_Y(
float newVelocity_Y) {
149 velocity.y = newVelocity_Y;
152 void setRotation(glm::vec3 m_rotation) {
153 rotation = m_rotation;
156 std::string GetComponentName()
override {
157 return "TransformComponent";
160 void showGUI()
override {
164 ImGui::Text(
"Position:");
165 ImGui::SliderFloat3(
"##position", &position.x, -1000.0f, 1000.0f);
168 ImGui::Text(
"Size:");
169 ImGui::SliderFloat3(
"##size", &size.x, 1.0f, 100.0f);
172 ImGui::Text(
"Rotation:");
173 ImGui::SliderFloat3(
"##rotation", glm::value_ptr(rotation), -180.0f, 180.0f);
175 ImGui::Text(
"Scale:");
176 ImGui::SliderFloat(
"##scale", &scale, 0.1f, 10.0f);
179 ImGui::Text(
"Speed:");
180 ImGui::InputInt(
"##speed", &speed);