Revert "impulse list and velocity for physics"
This reverts commit 2d7b32b7a3.
This commit is contained in:
@@ -114,7 +114,6 @@ public:
|
|||||||
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
std::shared_ptr<Components::Transform> transform = m_World->AddComponent<Components::Transform>(ent);
|
||||||
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
transform->Position = glm::vec3(0.5f, 0.f, -10.f);
|
||||||
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
transform->Scale = glm::vec3(1.f, 1.f, 1.f);
|
||||||
transform->Velocity = glm::vec3(0.0f, 0.f, 0.f);
|
|
||||||
|
|
||||||
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
std::shared_ptr<Components::Sprite> sprite = m_World->AddComponent<Components::Sprite>(ent);
|
||||||
sprite->SpriteFile = "Textures/Ball.png";
|
sprite->SpriteFile = "Textures/Ball.png";
|
||||||
|
|||||||
@@ -65,16 +65,6 @@ private:
|
|||||||
void CreateBody(EntityID entity);
|
void CreateBody(EntityID entity);
|
||||||
|
|
||||||
|
|
||||||
struct Impulse
|
|
||||||
{
|
|
||||||
b2Body* Body;
|
|
||||||
b2Vec2 Impulse;
|
|
||||||
b2Vec2 Point;
|
|
||||||
};
|
|
||||||
std::list<Impulse> m_Impulses;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ContactListener : public b2ContactListener
|
class ContactListener : public b2ContactListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -37,13 +37,7 @@ bool dd::Systems::PhysicsSystem::SetImpulse(const Events::SetImpulse &event)
|
|||||||
point.x = event.Point.x;
|
point.x = event.Point.x;
|
||||||
point.y = event.Point.y;
|
point.y = event.Point.y;
|
||||||
|
|
||||||
|
body->ApplyLinearImpulse(impulse, point, true);
|
||||||
Impulse i;
|
|
||||||
i.Body = body;
|
|
||||||
i.Impulse = impulse;
|
|
||||||
i.Point = point;
|
|
||||||
|
|
||||||
m_Impulses.push_back(i);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -57,7 +51,7 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||||
|
|
||||||
|
|
||||||
if (m_World->GetEntityParent(entity) == 0) { //TODO: Make this work with childs too
|
if (m_World->GetEntityParent(entity) == 0) {
|
||||||
b2Vec2 position;
|
b2Vec2 position;
|
||||||
position.x = transformComponent->Position.x;
|
position.x = transformComponent->Position.x;
|
||||||
position.y = transformComponent->Position.y;
|
position.y = transformComponent->Position.y;
|
||||||
@@ -65,15 +59,10 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
float angle = -glm::eulerAngles(transformComponent->Orientation).z;
|
||||||
|
|
||||||
body->SetTransform(position, angle);
|
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;
|
m_Accumulator += dt;
|
||||||
@@ -105,13 +94,8 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
|||||||
|
|
||||||
float angle = body->GetAngle();
|
float angle = body->GetAngle();
|
||||||
|
|
||||||
|
//TODO: CHECK IF THIS IS CORRECT
|
||||||
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle));
|
||||||
|
|
||||||
b2Vec2 velocity = body->GetLinearVelocity();
|
|
||||||
|
|
||||||
transformComponent->Velocity.x = velocity.x;
|
|
||||||
transformComponent->Velocity.y = velocity.y;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user