Changed bool CPhysics->Static to enum CPhysics->CollisionType, Which added support for kinematic bodies
This commit is contained in:
@@ -145,7 +145,7 @@ public:
|
||||
std::shared_ptr<Components::Ball> ball = m_World->AddComponent<Components::Ball>(ent);
|
||||
ball->Speed = 5.f;
|
||||
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;
|
||||
@@ -225,7 +225,7 @@ public:
|
||||
std::shared_ptr<Components::RectangleShape> boxShape = m_World->AddComponent<Components::RectangleShape>(
|
||||
topWall);
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||
physics->Static = true;
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
m_World->CommitEntity(topWall);
|
||||
}
|
||||
//SideBox
|
||||
@@ -271,7 +271,7 @@ public:
|
||||
topWall);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(topWall);
|
||||
physics->Static = true;
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
@@ -292,7 +292,7 @@ public:
|
||||
leftWall);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(leftWall);
|
||||
physics->Static = true;
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
@@ -313,7 +313,7 @@ public:
|
||||
rightWall);
|
||||
|
||||
std::shared_ptr<Components::Physics> physics = m_World->AddComponent<Components::Physics>(rightWall);
|
||||
physics->Static = true;
|
||||
physics->CollisionType = CollisionType::Type::Static;
|
||||
physics->Category = CollisionLayer::Type::Wall;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::Brick;
|
||||
|
||||
@@ -328,7 +328,7 @@ public:
|
||||
ctransform->Scale = glm::vec3(1.0f, 1.0f, 1.f);
|
||||
auto rectangle = m_World->AddComponent<Components::RectangleShape>(ent);
|
||||
auto physics = m_World->AddComponent<Components::Physics>(ent);
|
||||
physics->Static = false;
|
||||
physics->CollisionType = CollisionType::Type::Kinematic;
|
||||
physics->Category = CollisionLayer::Type::Pad;
|
||||
physics->Mask = CollisionLayer::Type::Ball | CollisionLayer::Type::PowerUp;
|
||||
physics->Calculate = true;
|
||||
|
||||
+31
-16
@@ -18,26 +18,41 @@ enum Type
|
||||
Wall = 1 << 6
|
||||
};
|
||||
}
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Physics: public Component
|
||||
namespace CollisionType
|
||||
{
|
||||
bool Static = true;
|
||||
bool Calculate = false;
|
||||
float GravityScale = 0.f;
|
||||
CollisionLayer::Type Category = CollisionLayer::Type::Other;
|
||||
CollisionLayer::Type Mask =
|
||||
CollisionLayer::Type::Pad |
|
||||
CollisionLayer::Type::Ball |
|
||||
CollisionLayer::Type::Brick |
|
||||
CollisionLayer::Type::Water |
|
||||
CollisionLayer::Type::PowerUp |
|
||||
CollisionLayer::Type::Wall |
|
||||
CollisionLayer::Type::Other;
|
||||
enum Type
|
||||
{
|
||||
Static = 0,
|
||||
Kinematic = 1,
|
||||
Dynamic = 2,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace Components
|
||||
{
|
||||
|
||||
struct Physics: public Component
|
||||
{
|
||||
CollisionType::Type CollisionType = CollisionType::Type::Static;
|
||||
|
||||
bool Calculate = false;
|
||||
float GravityScale = 0.f;
|
||||
|
||||
|
||||
CollisionLayer::Type Category = CollisionLayer::Type::Other;
|
||||
CollisionLayer::Type Mask =
|
||||
CollisionLayer::Type::Pad |
|
||||
CollisionLayer::Type::Ball |
|
||||
CollisionLayer::Type::Brick |
|
||||
CollisionLayer::Type::Water |
|
||||
CollisionLayer::Type::PowerUp |
|
||||
CollisionLayer::Type::Wall |
|
||||
CollisionLayer::Type::Other;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif //DAYDREAM_CPHYSICS_H
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user