Changed bool CPhysics->Static to enum CPhysics->CollisionType, Which added support for kinematic bodies

This commit is contained in:
viktorljung
2015-10-02 14:36:41 +02:00
parent 39f4215c2b
commit dca06a46a5
5 changed files with 46 additions and 30 deletions
+2 -2
View File
@@ -174,7 +174,7 @@ void dd::Systems::LevelSystem::CreateBrick(int row, int line, glm::vec2 spacesBe
std::shared_ptr<Components::Brick> cBrick = m_World->AddComponent<Components::Brick>(brick);
std::shared_ptr<Components::RectangleShape> cRec = m_World->AddComponent<Components::RectangleShape>(brick);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(brick);
cPhys->Static = false;
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->GravityScale = 0.f;
cPhys->Category = CollisionLayer::Type::Brick;
cPhys->Mask = CollisionLayer::Type::Ball;
@@ -331,7 +331,7 @@ bool dd::Systems::LevelSystem::OnCreatePowerUp(const dd::Events::CreatePowerUp &
auto model = m_World->AddComponent<Components::Model>(powerUp);
std::shared_ptr<Components::CircleShape> cRec = m_World->AddComponent<Components::CircleShape>(powerUp);
std::shared_ptr<Components::Physics> cPhys = m_World->AddComponent<Components::Physics>(powerUp);
cPhys->Static = false;
cPhys->CollisionType = CollisionType::Type::Dynamic;
cPhys->Category = CollisionLayer::Type::PowerUp;
cPhys->Mask = CollisionLayer::Type::Pad;
+1 -1
View File
@@ -108,7 +108,7 @@ EntityID dd::Systems::PadSystem::CreateBall()
std::shared_ptr<Components::CircleShape> circleShape = m_World->AddComponent<Components::CircleShape>(ent);
std::shared_ptr<Components::Ball> cball = m_World->AddComponent<Components::Ball>(ent);
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(ent);
physics->Static = false;
physics->CollisionType = CollisionType::Type::Dynamic;
physics->Category = CollisionLayer::Type::Ball;
physics->Mask = CollisionLayer::Type::Pad | CollisionLayer::Type::Brick | CollisionLayer::Type::Wall;
physics->Calculate = true;
+6 -5
View File
@@ -240,11 +240,12 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
bodyDef.position.Set(absoluteTransform.Position.x, absoluteTransform.Position.y);
bodyDef.angle = -glm::eulerAngles(absoluteTransform.Orientation).z;
if (physicsComponent->Static) {
if (physicsComponent->CollisionType == CollisionType::Type::Static) {
bodyDef.type = b2_staticBody;
} else {
} else if (physicsComponent->CollisionType == CollisionType::Type::Dynamic) {
bodyDef.type = b2_dynamicBody;
} else if (physicsComponent->CollisionType == CollisionType::Type::Kinematic) {
bodyDef.type = b2_dynamicBody;
}
b2Body* body = m_PhysicsWorld->CreateBody(&bodyDef);
@@ -284,11 +285,11 @@ void dd::Systems::PhysicsSystem::CreateBody(EntityID entity)
delete pShape;
if(physicsComponent->Static) {
/* if(physicsComponent->Static) {
body->SetType(b2BodyType::b2_staticBody);
} else if (! physicsComponent->Static) {
body->SetType(b2BodyType::b2_dynamicBody);
}
}*/
body->SetGravityScale(physicsComponent->GravityScale);
m_EntitiesToBodies.insert(std::make_pair(entity, body));