Collision callbacks
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
#ifndef Components_Health_h__
|
||||||
|
#define Components_Health_h__
|
||||||
|
|
||||||
|
#include "Component.h"
|
||||||
|
|
||||||
|
namespace Components
|
||||||
|
{
|
||||||
|
|
||||||
|
struct Health : Component
|
||||||
|
{
|
||||||
|
Health()
|
||||||
|
: health(1.0f){ }
|
||||||
|
|
||||||
|
float health;
|
||||||
|
|
||||||
|
virtual Health* Clone() const override { return new Health(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // Components_Health_h__
|
||||||
+1
-1
@@ -340,7 +340,7 @@ void GameWorld::Initialize()
|
|||||||
//Create wheels
|
//Create wheels
|
||||||
float wheelOffset = 0.4f;
|
float wheelOffset = 0.4f;
|
||||||
float springLength = 0.3f;
|
float springLength = 0.3f;
|
||||||
float suspensionStrength = 25.f;
|
float suspensionStrength = 15.f;
|
||||||
|
|
||||||
{
|
{
|
||||||
auto wheel = CreateEntity(tank);
|
auto wheel = CreateEntity(tank);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
void Systems::PhysicsSystem::Initialize()
|
void Systems::PhysicsSystem::Initialize()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
m_Accumulator = 0;
|
m_Accumulator = 0;
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
@@ -102,6 +104,8 @@ void Systems::PhysicsSystem::Initialize()
|
|||||||
SetupVisualDebugger(m_Context);
|
SetupVisualDebugger(m_Context);
|
||||||
|
|
||||||
m_PhysicsWorld->unmarkForWrite();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
|
m_collisionResolution = new MyCollisionResolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -324,9 +328,11 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
m_PhysicsWorld->markForWrite();
|
m_PhysicsWorld->markForWrite();
|
||||||
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
vehicleSetup.buildVehicle(m_World, m_PhysicsWorld, *m_Vehicles[entity], entity, m_Wheels);
|
||||||
// Add the vehicle's entities and phantoms to the world
|
// Add the vehicle's entities and phantoms to the world
|
||||||
|
rigidBody->addContactListener( m_collisionResolution );
|
||||||
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
m_Vehicles[entity]->addToWorld(m_PhysicsWorld);
|
||||||
|
|
||||||
m_RigidBodies[entity] = rigidBody;
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||||
|
|
||||||
|
|
||||||
// The vehicle is an action
|
// The vehicle is an action
|
||||||
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
m_PhysicsWorld->addAction(m_Vehicles[entity]);
|
||||||
@@ -340,8 +346,10 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_PhysicsWorld->markForWrite();
|
m_PhysicsWorld->markForWrite();
|
||||||
|
rigidBody->addContactListener( m_collisionResolution );
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
m_PhysicsWorld->addEntity(rigidBody);
|
||||||
m_RigidBodies[entity] = rigidBody;
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||||
m_PhysicsWorld->unmarkForWrite();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
shape->removeReference();
|
shape->removeReference();
|
||||||
@@ -394,6 +402,7 @@ void Systems::PhysicsSystem::OnEntityCommit( EntityID entity )
|
|||||||
m_PhysicsWorld->markForWrite();
|
m_PhysicsWorld->markForWrite();
|
||||||
m_PhysicsWorld->addEntity(rigidBody);
|
m_PhysicsWorld->addEntity(rigidBody);
|
||||||
m_RigidBodies[entity] = rigidBody;
|
m_RigidBodies[entity] = rigidBody;
|
||||||
|
m_collisionResolution->m_RigidBodies[rigidBody] = entity;
|
||||||
m_PhysicsWorld->unmarkForWrite();
|
m_PhysicsWorld->unmarkForWrite();
|
||||||
|
|
||||||
shape->removeReference();
|
shape->removeReference();
|
||||||
|
|||||||
@@ -60,9 +60,27 @@
|
|||||||
#include "Physics/VehicleSetup.h"
|
#include "Physics/VehicleSetup.h"
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
#include <Physics2012/Dynamics/Collide/ContactListener/hkpContactListener.h>
|
||||||
|
|
||||||
|
class MyCollisionResolution: public hkReferencedObject, public hkpContactListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
std::unordered_map<hkpRigidBody*, EntityID> m_RigidBodies;
|
||||||
|
|
||||||
|
virtual void contactPointCallback( const hkpContactPointEvent& event )
|
||||||
|
{
|
||||||
|
|
||||||
|
EntityID entity1 = m_RigidBodies[event.getBody(0)];
|
||||||
|
EntityID entity2 = m_RigidBodies[event.getBody(1)];
|
||||||
|
LOG_INFO("Entities colliding: %i, %i ", entity1, entity2);
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
namespace Systems
|
namespace Systems
|
||||||
{
|
{
|
||||||
|
|
||||||
class PhysicsSystem : public System
|
class PhysicsSystem : public System
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -77,7 +95,7 @@ public:
|
|||||||
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
void OnComponentCreated(std::string type, std::shared_ptr<Component> component) override;
|
||||||
void OnComponentRemoved(std::string type, Component* component) override;
|
void OnComponentRemoved(std::string type, Component* component) override;
|
||||||
void OnEntityCommit(EntityID entity) override;
|
void OnEntityCommit(EntityID entity) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_Accumulator;
|
double m_Accumulator;
|
||||||
hkpWorld* m_PhysicsWorld;
|
hkpWorld* m_PhysicsWorld;
|
||||||
@@ -145,8 +163,9 @@ private:
|
|||||||
hkpMoppBvTreeShape* MoppShape;
|
hkpMoppBvTreeShape* MoppShape;
|
||||||
};
|
};
|
||||||
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
|
std::unordered_map<EntityID, ExtendedShapeData > m_ExtendedMeshShapes;
|
||||||
|
|
||||||
|
MyCollisionResolution* m_collisionResolution;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // PhysicsSystem_h__
|
#endif // PhysicsSystem_h__
|
||||||
|
|||||||
@@ -131,6 +131,7 @@
|
|||||||
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
<ClInclude Include="..\..\src\Components\DirectionalLight.h" />
|
||||||
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
|
<ClInclude Include="..\..\src\Components\ExtendedMeshShape.h" />
|
||||||
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
<ClInclude Include="..\..\src\Components\FreeSteering.h" />
|
||||||
|
<ClInclude Include="..\..\src\Components\Health.h" />
|
||||||
<ClInclude Include="..\..\src\Components\HingeConstraint.h" />
|
<ClInclude Include="..\..\src\Components\HingeConstraint.h" />
|
||||||
<ClInclude Include="..\..\src\Components\Input.h" />
|
<ClInclude Include="..\..\src\Components\Input.h" />
|
||||||
<ClInclude Include="..\..\src\Components\MeshShape.h" />
|
<ClInclude Include="..\..\src\Components\MeshShape.h" />
|
||||||
|
|||||||
@@ -352,6 +352,9 @@
|
|||||||
<ClInclude Include="..\..\src\Events\BindGamepadButton.h">
|
<ClInclude Include="..\..\src\Events\BindGamepadButton.h">
|
||||||
<Filter>Input\Events</Filter>
|
<Filter>Input\Events</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\src\Components\Health.h">
|
||||||
|
<Filter>Physics\Components</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="..\..\src\Shaders\AABB.frag.glsl">
|
<None Include="..\..\src\Shaders\AABB.frag.glsl">
|
||||||
|
|||||||
Reference in New Issue
Block a user