WIP Collision meshes

This commit is contained in:
2014-04-07 23:36:06 +02:00
parent 4a6f0cad32
commit 28c7ab4b3e
6 changed files with 48 additions and 3 deletions
+14
View File
@@ -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__
+14
View File
@@ -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__
+10 -3
View File
@@ -58,8 +58,10 @@ void Systems::PhysicsSystem::UpdateEntity(double dt, EntityID entity, EntityID p
auto physicsComponent = m_World->GetComponent<Components::Physics>(entity, "Physics");
auto sphereShapeComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
auto boxShapeComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape>(entity, "MeshShape");
auto staticMeshShapeComponent = m_World->GetComponent<Components::StaticMeshShape>(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<Components::CompoundShape>(entity, "CompoundShape");
auto sphereShapeComponent = m_World->GetComponent<Components::SphereShape>(entity, "SphereShape");
auto boxShapeComponent = m_World->GetComponent<Components::BoxShape>(entity, "BoxShape");
auto meshShapeComponent = m_World->GetComponent<Components::MeshShape>(entity, "MeshShape");
auto staticMeshShapeComponent = m_World->GetComponent<Components::StaticMeshShape>(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)));
+2
View File
@@ -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"
+2
View File
@@ -118,6 +118,7 @@
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
<ClInclude Include="..\..\src\Components\HingeConstraint.h" />
<ClInclude Include="..\..\src\Components\Input.h" />
<ClInclude Include="..\..\src\Components\MeshShape.h" />
<ClInclude Include="..\..\src\Components\Model.h" />
<ClInclude Include="..\..\src\Components\ParticleEmitter.h" />
<ClInclude Include="..\..\src\Components\Physics.h" />
@@ -128,6 +129,7 @@
<ClInclude Include="..\..\src\Components\SphereShape.h" />
<ClInclude Include="..\..\src\Components\Sprite.h" />
<ClInclude Include="..\..\src\Components\Stat.h" />
<ClInclude Include="..\..\src\Components\StaticMeshShape.h" />
<ClInclude Include="..\..\src\Components\Template.h" />
<ClInclude Include="..\..\src\Components\Transform.h" />
<ClInclude Include="..\..\src\CubemapTexture.h" />
@@ -154,6 +154,12 @@
<ClInclude Include="..\..\src\Components\BallSocketConstraint.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\MeshShape.h">
<Filter>Components</Filter>
</ClInclude>
<ClInclude Include="..\..\src\Components\StaticMeshShape.h">
<Filter>Components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\src\Shaders\AABB.frag.glsl">