Collisions kind of working
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
#include "PrecompiledHeader.h"
|
||||
#include "Game/BallSystem.h"
|
||||
|
||||
dd::Systems::BallSystem::~BallSystem() {
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::RegisterComponents(ComponentFactory *cf)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::Initialize()
|
||||
{
|
||||
|
||||
EVENT_SUBSCRIBE_MEMBER(m_Contact, BallSystem::Contact);
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::Update(double dt)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::UpdateEntity(double dt, EntityID entity, EntityID parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::OnEntityCommit(EntityID entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void dd::Systems::BallSystem::OnEntityRemoved(EntityID entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool dd::Systems::BallSystem::Contact(const Events::Contact &event)
|
||||
{
|
||||
auto ballComponent1 = m_World->GetComponent<Components::Ball>(event.Entity1);
|
||||
auto ballComponent2 = m_World->GetComponent<Components::Ball>(event.Entity2);
|
||||
|
||||
//Which is the ball?
|
||||
EntityID ballEntity, otherEntitiy;
|
||||
glm::vec2 normal;
|
||||
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;
|
||||
}
|
||||
|
||||
auto ballTransform = m_World->GetComponent<Components::Transform>(ballEntity);
|
||||
auto otherTransform = m_World->GetComponent<Components::Transform>(otherEntitiy);
|
||||
|
||||
glm::vec2 ballVelocity = glm::vec2(ballTransform->Velocity.x, ballTransform->Velocity.y);
|
||||
glm::vec2 reflectedVelocity = ballVelocity - 2.f * glm::dot(ballVelocity, normal)*normal;
|
||||
ballTransform->Velocity = glm::vec3(reflectedVelocity, 0.f);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -51,9 +51,8 @@ void dd::Systems::PadSystem::Update(double dt)
|
||||
transform->Position += transform->Velocity * (float)dt;
|
||||
transform->Velocity += acceleration * (float)dt;
|
||||
transform->Velocity -= transform->Velocity * (0.9f * (float)dt);
|
||||
transform->Position.y = -5.f;
|
||||
//transform->Orientation = glm::quat();
|
||||
std::cout << transform->Velocity.x << ", " << transform->Velocity.y << std::endl;
|
||||
|
||||
|
||||
|
||||
if (left)
|
||||
{
|
||||
@@ -121,6 +120,7 @@ bool dd::Systems::PadSystem::OnKeyUp(const dd::Events::KeyUp &event)
|
||||
|
||||
bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||
{
|
||||
/*
|
||||
EntityID entityBall = event.Entity2;
|
||||
auto ball = m_World->GetComponent<Components::Ball>(entityBall);
|
||||
if (ball == NULL)
|
||||
@@ -150,6 +150,7 @@ bool dd::Systems::PadSystem::OnContact(const dd::Events::Contact &event)
|
||||
|
||||
|
||||
//transform->Velocity = glm::vec3(movementX, movementY, 0.f);
|
||||
*/
|
||||
}
|
||||
|
||||
bool dd::Systems::PadSystem::PadSteeringInputController::OnCommand(const Events::InputCommand &event)
|
||||
|
||||
@@ -93,8 +93,6 @@ void dd::Systems::PhysicsSystem::Update(double dt)
|
||||
|
||||
auto transformComponent = m_World->GetComponent<Components::Transform>(entity);
|
||||
|
||||
|
||||
|
||||
if (m_World->GetEntityParent(entity) == 0) {
|
||||
b2Vec2 position = body->GetPosition();
|
||||
transformComponent->Position.x = position.x;
|
||||
|
||||
Reference in New Issue
Block a user