Added btGhostObject and btPairCachingGhostObject functionality.

It is a fast way to keep track of overlapping objects in an area, and doing rayTest and convexSweepTest for overlapping objects, instead of btCollisionWorld::rayTest/convexSweepTest.

Updated KinematicCharacterController to use btPairCachingGhostObject.
This commit is contained in:
erwin.coumans
2008-10-18 01:33:23 +00:00
parent 7f52613c45
commit 4cbb3f2e7b
14 changed files with 488 additions and 569 deletions

View File

@@ -16,9 +16,11 @@ subject to the following restrictions:
#define CHARACTER_DEMO_H
///DYNAMIC_CHARACTER_CONTROLLER is not supported/obsolete at the moment
///DYNAMIC_CHARACTER_CONTROLLER is not at the moment
//#define DYNAMIC_CHARACTER_CONTROLLER 1
#include "BulletCollision/CollisionShapes/btConvexHullShape.h"
class CharacterControllerInterface;
class DynamicCharacterController;
class KinematicCharacterController;
@@ -37,6 +39,7 @@ class CharacterDemo : public DemoApplication
CharacterControllerInterface* m_character;
#else
KinematicCharacterController* m_character;
class btPairCachingGhostObject* m_ghostObject;
#endif
btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
@@ -51,8 +54,6 @@ class CharacterDemo : public DemoApplication
class btTriangleIndexVertexArray* m_indexVertexArrays;
class MyCustomOverlappingPairCallback* m_customPairCallback;
btVector3* m_vertices;
void debugDrawContacts();
@@ -93,6 +94,59 @@ class CharacterDemo : public DemoApplication
}
};
#define QUAKE_BSP_IMPORTING 1
#ifdef QUAKE_BSP_IMPORTING
#include "../BspDemo/BspLoader.h"
#include "../BspDemo/BspConverter.h"
class BspToBulletConverter : public BspConverter
{
CharacterDemo* m_demoApp;
public:
BspToBulletConverter(CharacterDemo* demoApp)
:m_demoApp(demoApp)
{
}
virtual void addConvexVerticesCollider(btAlignedObjectArray<btVector3>& vertices, bool isEntity, const btVector3& entityTargetLocation)
{
///perhaps we can do something special with entities (isEntity)
///like adding a collision Triggering (as example)
if (vertices.size() > 0)
{
float mass = 0.f;
btTransform startTransform;
//can use a shift
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,-10.0f,0.0f));
//this create an internal copy of the vertices
for (int i = 0; i < vertices.size(); i++)
{
vertices[i] *= btScalar(0.5);
float t = vertices[i].getZ() * btScalar(0.75);
vertices[i].setZ(-vertices[i].getY());
vertices[i].setY(t);
}
btCollisionShape* shape = new btConvexHullShape(&(vertices[0].getX()),vertices.size());
m_demoApp->m_collisionShapes.push_back(shape);
//btRigidBody* body = m_demoApp->localCreateRigidBody(mass, startTransform,shape);
m_demoApp->localCreateRigidBody(mass, startTransform,shape);
}
}
};
#endif //QUAKE_BSP_IMPORTING
#endif //CHARACTER_DEMO_H