From b58cdc813d1b1042dd50b4fece6b94a3eb64f596 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Tue, 15 Sep 2015 14:31:10 +0200 Subject: [PATCH] Revert "impulse list and velocity for physics" This reverts commit 2d7b32b7a37ad8839e94937ce850a0916e31027d. --- include/Core/Engine.h | 1 - include/Physics/PhysicsSystem.h | 10 ---------- src/game/Physics/PhysicsSystem.cpp | 24 ++++-------------------- 3 files changed, 4 insertions(+), 31 deletions(-) diff --git a/include/Core/Engine.h b/include/Core/Engine.h index 5c560f1..1df8465 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -114,7 +114,6 @@ public: std::shared_ptr transform = m_World->AddComponent(ent); transform->Position = glm::vec3(0.5f, 0.f, -10.f); transform->Scale = glm::vec3(1.f, 1.f, 1.f); - transform->Velocity = glm::vec3(0.0f, 0.f, 0.f); std::shared_ptr sprite = m_World->AddComponent(ent); sprite->SpriteFile = "Textures/Ball.png"; diff --git a/include/Physics/PhysicsSystem.h b/include/Physics/PhysicsSystem.h index 559d815..57bad34 100644 --- a/include/Physics/PhysicsSystem.h +++ b/include/Physics/PhysicsSystem.h @@ -65,16 +65,6 @@ private: void CreateBody(EntityID entity); - struct Impulse - { - b2Body* Body; - b2Vec2 Impulse; - b2Vec2 Point; - }; - std::list m_Impulses; - - - class ContactListener : public b2ContactListener { public: diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index 863ad74..3d244a7 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -37,13 +37,7 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event) point.x = event.Point.x; point.y = event.Point.y; - - Impulse i; - i.Body = body; - i.Impulse = impulse; - i.Point = point; - - m_Impulses.push_back(i); + body->ApplyLinearImpulse(impulse, point, true); return true; } @@ -57,7 +51,7 @@ void dd::Systems::PhysicsSystem::Update(double dt) auto transformComponent = m_World->GetComponent(entity); - if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too + if (m_World->GetEntityParent(entity) == 0) { b2Vec2 position; position.x = transformComponent->Position.x; position.y = transformComponent->Position.y; @@ -65,15 +59,10 @@ void dd::Systems::PhysicsSystem::Update(double dt) float angle = -glm::eulerAngles(transformComponent->Orientation).z; body->SetTransform(position, angle); - - body->SetLinearVelocity(b2Vec2(transformComponent->Velocity.x, transformComponent->Velocity.y)); } } - for (auto i : m_Impulses) { - i.Body->ApplyLinearImpulse(i.Impulse, i.Point, true); - } - m_Impulses.clear(); + m_Accumulator += dt; @@ -105,13 +94,8 @@ void dd::Systems::PhysicsSystem::Update(double dt) float angle = body->GetAngle(); - + //TODO: CHECK IF THIS IS CORRECT transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle)); - - b2Vec2 velocity = body->GetLinearVelocity(); - - transformComponent->Velocity.x = velocity.x; - transformComponent->Velocity.y = velocity.y; } } }