|
|
@@ -26,8 +26,11 @@ OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
-#include "PxSimulationEventCallback.h"
|
|
|
+#include "EventStream.h"
|
|
|
+#include "PhysicsTypes.h"
|
|
|
+#include "PxActor.h"
|
|
|
#include "PxController.h"
|
|
|
+#include "PxSimulationEventCallback.h"
|
|
|
|
|
|
using physx::PxSimulationEventCallback;
|
|
|
using physx::PxContactPairHeader;
|
|
|
@@ -41,47 +44,88 @@ using physx::PxUserControllerHitReport;
|
|
|
using physx::PxControllerShapeHit;
|
|
|
using physx::PxControllersHit;
|
|
|
using physx::PxControllerObstacleHit;
|
|
|
+using physx::PxContactPairHeader;
|
|
|
+using physx::PxContactPairHeaderFlag;
|
|
|
+using physx::PxContactPairPoint;
|
|
|
+using physx::PxVec3;
|
|
|
|
|
|
namespace crown
|
|
|
{
|
|
|
|
|
|
+class PhysicsWorld;
|
|
|
+
|
|
|
//-----------------------------------------------------------------------------
|
|
|
class PhysicsSimulationCallback : public PxSimulationEventCallback
|
|
|
{
|
|
|
public:
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
- PhysicsSimulationCallback() {}
|
|
|
+ PhysicsSimulationCallback(EventStream& stream)
|
|
|
+ : m_events(stream)
|
|
|
+ {
|
|
|
+ }
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onConstraintBreak(PxConstraintInfo* /*constraints*/, PxU32 /*count*/)
|
|
|
{
|
|
|
- // Log::i("COSTRAINTBREAK");
|
|
|
+ // printf("COSTRAINTBREAK\n");
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
- void onContact(const PxContactPairHeader& /*pairHeader*/, const PxContactPair* /*pairs*/, PxU32 /*nbPairs*/)
|
|
|
+ void onContact(const PxContactPairHeader& pair_header, const PxContactPair* pairs, PxU32 num_pairs)
|
|
|
{
|
|
|
- // Log::i("CONTACT");
|
|
|
+ // printf("CONTACT\n");
|
|
|
+
|
|
|
+ // Do not report contact if either actor0 or actor1 has been deleted
|
|
|
+ if (pair_header.flags & PxContactPairHeaderFlag::eDELETED_ACTOR_0 || pair_header.flags & PxContactPairHeaderFlag::eDELETED_ACTOR_1) return;
|
|
|
+
|
|
|
+ // printf("ACTOR0 = %.4X\n", pair_header.actors[0]->userData);
|
|
|
+ // printf("ACTOR1 = %.4X\n", pair_header.actors[1]->userData);
|
|
|
+
|
|
|
+ PxVec3 where;
|
|
|
+
|
|
|
+ // printf("Num pairs = %d\n", num_pairs);
|
|
|
+ for (PxU32 pp = 0; pp < num_pairs; pp++)
|
|
|
+ {
|
|
|
+ PxContactPairPoint points[8];
|
|
|
+ const PxU32 num_points = pairs[pp].extractContacts(points, 8);
|
|
|
+ // printf("Num points = %d\n", num_points);
|
|
|
+
|
|
|
+ for (PxU32 i = 0; i < num_points; i++)
|
|
|
+ {
|
|
|
+ where = points[i].position;
|
|
|
+ // printf("where = %.2f %.2f %.2f\n", where.x, where.y, where.z);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ physics_world::CollisionEvent ev;
|
|
|
+ ev.actors[0] = (Actor*) pair_header.actors[0]->userData;
|
|
|
+ ev.actors[1] = (Actor*) pair_header.actors[1]->userData;
|
|
|
+ ev.where = Vector3(where.x, where.y, where.z);
|
|
|
+ event_stream::write(m_events, physics_world::EventType::COLLISION, ev);
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onTrigger(PxTriggerPair* /*pairs*/, PxU32 /*count*/)
|
|
|
{
|
|
|
- // Log::i("TRIGGER");
|
|
|
+ // printf("TRIGGER\n");
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onWake(PxActor** /*actors*/, PxU32 /*count*/)
|
|
|
{
|
|
|
- // Log::i("WAKE");
|
|
|
+ // printf("WAKE\n");
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onSleep(PxActor** /*actors*/, PxU32 /*count*/)
|
|
|
{
|
|
|
- // Log::i("SLEEP");
|
|
|
+ // printf("SLEEP\n");
|
|
|
}
|
|
|
+
|
|
|
+private:
|
|
|
+
|
|
|
+ EventStream& m_events;
|
|
|
};
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
@@ -90,19 +134,19 @@ class PhysicsControllerCallback : public PxUserControllerHitReport
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onShapeHit(const PxControllerShapeHit& hit)
|
|
|
{
|
|
|
- // Log::i("SHAPE HIT");
|
|
|
+ // printf("SHAPE HIT\n");
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onControllerHit(const PxControllersHit& hit)
|
|
|
{
|
|
|
- // Log::i("CONTROLLER HIT");
|
|
|
+ // printf("CONTROLLER HIT\n");
|
|
|
}
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
void onObstacleHit(const PxControllerObstacleHit& hit)
|
|
|
{
|
|
|
- // Log::i("OBSTACLE HIT");
|
|
|
+ // printf("OBSTACLE HIT\n");
|
|
|
}
|
|
|
};
|
|
|
|