diff --git a/include/Core/Engine.h b/include/Core/Engine.h index d314fc9..2a34013 100644 --- a/include/Core/Engine.h +++ b/include/Core/Engine.h @@ -116,9 +116,9 @@ public: { auto ent = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(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->Velocity = glm::vec3(1.0f, -5.f, 0.f); + transform->Velocity = glm::vec3(-1.0f, -5.f, 0.f); std::shared_ptr sprite = m_World->AddComponent(ent); sprite->SpriteFile = "Textures/Ball.png"; @@ -141,7 +141,7 @@ public: auto topWall = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(topWall); transform->Position = glm::vec3(0.f, 5.f, -10.f); - transform->Scale = glm::vec3(15.f, 0.5f, 1.f); + transform->Scale = glm::vec3(20.f, 0.5f, 1.f); std::shared_ptr sprite = m_World->AddComponent(topWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; @@ -157,7 +157,7 @@ public: auto leftWall = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(leftWall); transform->Position = glm::vec3(-9.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 10.f, 1.f); + transform->Scale = glm::vec3(0.5f, 20.f, 1.f); std::shared_ptr sprite = m_World->AddComponent(leftWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; @@ -173,7 +173,7 @@ public: auto rightWall = m_World->CreateEntity(); std::shared_ptr transform = m_World->AddComponent(rightWall); transform->Position = glm::vec3(9.f, 1.f, -10.f); - transform->Scale = glm::vec3(0.5f, 10.f, 1.f); + transform->Scale = glm::vec3(0.5f, 20.f, 1.f); std::shared_ptr sprite = m_World->AddComponent(rightWall); sprite->SpriteFile = "Textures/Core/ErrorTexture.png"; diff --git a/include/Physics/EContact.h b/include/Physics/EContact.h index c27e3b8..4a6f3a9 100644 --- a/include/Physics/EContact.h +++ b/include/Physics/EContact.h @@ -20,6 +20,7 @@ struct Contact : Event EntityID Entity1; EntityID Entity2; glm::vec2 Normal; + glm::vec2 SignificantNormal; }; } diff --git a/include/Physics/PhysicsSystem.h b/include/Physics/PhysicsSystem.h index dd63b33..16c2cb7 100644 --- a/include/Physics/PhysicsSystem.h +++ b/include/Physics/PhysicsSystem.h @@ -90,11 +90,12 @@ private: Events::Contact e; e.Entity1 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureA()->GetBody()]; e.Entity2 = m_PhysicsSystem->m_BodiesToEntities[contact->GetFixtureB()->GetBody()]; - e.Normal = glm::normalize(glm::vec2(worldManifold.normal.x, worldManifold.normal.y)); + e.Normal = glm::normalize(glm::vec2(contact->GetManifold()->localNormal.x, contact->GetManifold()->localNormal.y)); + e.SignificantNormal = glm::normalize((glm::abs(e.Normal.x) > glm::abs(e.Normal.y)) ? glm::vec2(e.Normal.x, 0) : glm::vec2(0, e.Normal.y)); m_PhysicsSystem->EventBroker->Publish(e); - LOG_INFO("Entity1 = %i, Entity2 = %i\n", e.Entity1, e.Entity2); + LOG_INFO("Entity1 = %i, Entity2 = %i\n Normal: %f, %f", e.Entity1, e.Entity2, e.SignificantNormal.x, e.SignificantNormal.y); } void EndContact(b2Contact* contact) { diff --git a/src/game/Game/BallSystem.cpp b/src/game/Game/BallSystem.cpp index 29aa6ef..93fdf26 100644 --- a/src/game/Game/BallSystem.cpp +++ b/src/game/Game/BallSystem.cpp @@ -47,25 +47,26 @@ bool dd::Systems::BallSystem::Contact(const Events::Contact &event) if (ballComponent1 != nullptr) { ballEntity = event.Entity1; otherEntitiy = event.Entity2; - - //Make normal point from the other entity to the ball - normal = event.Normal * -1.f; } else if (ballComponent2 != nullptr) { ballEntity = event.Entity2; otherEntitiy = event.Entity1; - - //Make normal point from the other entity to the ball - normal = event.Normal * 1.f; } + else { + return false; + //TODO: Add support for power-up collisions + } + + //normal.x = -normal.x; auto ballTransform = m_World->GetComponent(ballEntity); auto otherTransform = m_World->GetComponent(otherEntitiy); glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y); - glm::vec2 reflectedVelocity = ballVelocity - 2.f * glm::dot(ballVelocity, normal)*normal; + glm::vec2 reflectedVelocity = glm::reflect(ballVelocity, event.Normal); ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f); + //LOG_INFO("Velocity: %f, %f\n", ballTransform->Velocity.x, ballTransform->Velocity.y); return true; diff --git a/src/game/Physics/PhysicsSystem.cpp b/src/game/Physics/PhysicsSystem.cpp index a06f754..431db63 100644 --- a/src/game/Physics/PhysicsSystem.cpp +++ b/src/game/Physics/PhysicsSystem.cpp @@ -103,6 +103,7 @@ void dd::Systems::PhysicsSystem::Update(double dt) transformComponent->Orientation = glm::quat(glm::vec3(0, 0, -angle)); + //TODO: Fix this back for real bodies b2Vec2 velocity = body->GetLinearVelocity(); transformComponent->Velocity.x = velocity.x; transformComponent->Velocity.y = velocity.y;