From 28c7ab4b3ede2a9b3ea66c211d3432b1db0638d6 Mon Sep 17 00:00:00 2001 From: sippeangelo Date: Mon, 7 Apr 2014 23:36:06 +0200 Subject: [PATCH] WIP Collision meshes --- src/Components/MeshShape.h | 14 ++++++++++++++ src/Components/StaticMeshShape.h | 14 ++++++++++++++ src/Systems/PhysicsSystem.cpp | 13 ++++++++++--- src/Systems/PhysicsSystem.h | 2 ++ vs12/Returngeance/Returngeance.vcxproj | 2 ++ vs12/Returngeance/Returngeance.vcxproj.filters | 6 ++++++ 6 files changed, 48 insertions(+), 3 deletions(-) create mode 100755 src/Components/MeshShape.h create mode 100755 src/Components/StaticMeshShape.h diff --git a/src/Components/MeshShape.h b/src/Components/MeshShape.h new file mode 100755 index 0000000..e9b4844 --- /dev/null +++ b/src/Components/MeshShape.h @@ -0,0 +1,14 @@ +#ifndef Components_MeshShape_h__ +#define Components_MeshShape_h__ + +#include "Component.h" + +namespace Components +{ + struct MeshShape : Component + { + std::string Filename; + }; +} + +#endif // Components_MeshShape_h__ diff --git a/src/Components/StaticMeshShape.h b/src/Components/StaticMeshShape.h new file mode 100755 index 0000000..5347c25 --- /dev/null +++ b/src/Components/StaticMeshShape.h @@ -0,0 +1,14 @@ +#ifndef Components_StaticMeshShape_h__ +#define Components_StaticMeshShape_h__ + +#include "Component.h" + +namespace Components +{ + struct StaticMeshShape : Component + { + std::string Filename; + }; +} + +#endif // Components_StaticMeshShape_h__ diff --git a/src/Systems/PhysicsSystem.cpp b/src/Systems/PhysicsSystem.cpp index 30c1b88..b80674c 100644 --- a/src/Systems/PhysicsSystem.cpp +++ b/src/Systems/PhysicsSystem.cpp @@ -58,8 +58,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p auto physicsComponent = m_World->GetComponent(entity, "Physics"); auto sphereShapeComponent = m_World->GetComponent(entity, "SphereShape"); auto boxShapeComponent = m_World->GetComponent(entity, "BoxShape"); + auto meshShapeComponent = m_World->GetComponent(entity, "MeshShape"); + auto staticMeshShapeComponent = m_World->GetComponent(entity, "StaticMeshShape"); - if (physicsComponent || sphereShapeComponent || boxShapeComponent) + if (physicsComponent || sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent) { if (m_PhysicsData.find(entity) == m_PhysicsData.end()) { SetUpPhysicsState(entity, parent); @@ -177,8 +179,10 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent) auto compoundShapeComponent = m_World->GetComponent(entity, "CompoundShape"); auto sphereShapeComponent = m_World->GetComponent(entity, "SphereShape"); auto boxShapeComponent = m_World->GetComponent(entity, "BoxShape"); + auto meshShapeComponent = m_World->GetComponent(entity, "MeshShape"); + auto staticMeshShapeComponent = m_World->GetComponent(entity, "StaticMeshShape"); - if (compoundShapeComponent && (sphereShapeComponent || boxShapeComponent)) { + if (compoundShapeComponent && (sphereShapeComponent || boxShapeComponent || meshShapeComponent || staticMeshShapeComponent)) { LOG_WARNING("Entity %i has both compound shape and normal shape! Normal shapes must be children to entity with compound shape.", entity); } @@ -212,8 +216,11 @@ void Systems::PhysicsSystem::SetUpPhysicsState(EntityID entity, EntityID parent) physicsData->CollisionShape = new btBoxShape(btVector3(boxShapeComponent->Width, boxShapeComponent->Height, boxShapeComponent->Depth)); } else if (sphereShapeComponent) { physicsData->CollisionShape = new btSphereShape(sphereShapeComponent->Radius); + } else if (meshShapeComponent) { + // TODO: Collision mesh things go here + //new btConvexTriangleMeshShape() } - if (boxShapeComponent || sphereShapeComponent) { + if (boxShapeComponent || sphereShapeComponent || meshShapeComponent || staticMeshShapeComponent) { btTransform transform; transform.setFromOpenGLMatrix(glm::value_ptr(glm::translate(glm::mat4(), transformComponent->Position) * glm::toMat4(transformComponent->Orientation))); diff --git a/src/Systems/PhysicsSystem.h b/src/Systems/PhysicsSystem.h index 3e2d611..4f58ead 100644 --- a/src/Systems/PhysicsSystem.h +++ b/src/Systems/PhysicsSystem.h @@ -7,6 +7,8 @@ #include "Components/CompoundShape.h" #include "Components/BoxShape.h" #include "Components/SphereShape.h" +#include "Components/MeshShape.h" +#include "Components/StaticMeshShape.h" #include "Components/BallSocketConstraint.h" #include "Components/HingeConstraint.h" #include "Components/SliderConstraint.h" diff --git a/vs12/Returngeance/Returngeance.vcxproj b/vs12/Returngeance/Returngeance.vcxproj index ffd3d9e..ed3adf0 100755 --- a/vs12/Returngeance/Returngeance.vcxproj +++ b/vs12/Returngeance/Returngeance.vcxproj @@ -118,6 +118,7 @@ + @@ -128,6 +129,7 @@ + diff --git a/vs12/Returngeance/Returngeance.vcxproj.filters b/vs12/Returngeance/Returngeance.vcxproj.filters index 1df308b..cc54cba 100755 --- a/vs12/Returngeance/Returngeance.vcxproj.filters +++ b/vs12/Returngeance/Returngeance.vcxproj.filters @@ -154,6 +154,12 @@ Components + + Components + + + Components +