Added support for SHORT/WORD indices

Removed references to m_userPointer (in CollisionObject), called it m_userObjectPointer
increased view distance in glut demo file
This commit is contained in:
ejcoumans
2006-09-06 22:21:12 +00:00
parent 400376289c
commit fa4fd1369c
4 changed files with 58 additions and 52 deletions

View File

@@ -60,7 +60,11 @@ struct CollisionObject
BroadphaseProxy* m_broadphaseHandle;
CollisionShape* m_collisionShape;
void* m_userPointer;//not use by Bullet internally
//users can point to their objects, m_userPointer is not used by Bullet
void* m_userObjectPointer;
//m_internalOwner one is used by optional Bullet high level interface
void* m_internalOwner;
///time of impact calculation
float m_hitFraction;

View File

@@ -23,62 +23,64 @@ StridingMeshInterface::~StridingMeshInterface()
void StridingMeshInterface::InternalProcessAllTriangles(InternalTriangleIndexCallback* callback,const SimdVector3& aabbMin,const SimdVector3& aabbMax) const
{
int numtotalphysicsverts = 0;
int part,graphicssubparts = getNumSubParts();
const unsigned char * vertexbase;
const unsigned char * indexbase;
int indexstride;
PHY_ScalarType type;
PHY_ScalarType gfxindextype;
int stride,numverts,numtriangles;
int gfxindex;
SimdVector3 triangle[3];
int tempIndices[3] = {0,0,0};
int graphicsindex=0;
float* graphicsbase;
SimdVector3 meshScaling = getScaling();
int numtotalphysicsverts = 0;
int part,graphicssubparts = getNumSubParts();
///if the number of parts is big, the performance might drop due to the innerloop switch on indextype
for (part=0;part<graphicssubparts ;part++)
{
const unsigned char * vertexbase;
const unsigned char * indexbase;
int indexstride;
PHY_ScalarType type;
PHY_ScalarType gfxindextype;
int stride,numverts,numtriangles;
getLockedReadOnlyVertexIndexBase(&vertexbase,numverts,type,stride,&indexbase,indexstride,numtriangles,gfxindextype,part);
numtotalphysicsverts+=numtriangles*3; //upper bound
int gfxindex;
SimdVector3 triangle[3];
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
switch (gfxindextype)
{
int graphicsindex=0;
#ifdef DEBUG_TRIANGLE_MESH
printf("triangle indices:\n");
#endif //DEBUG_TRIANGLE_MESH
ASSERT(gfxindextype == PHY_INTEGER);
int* gfxbase = (int*)(indexbase+gfxindex*indexstride);
for (int j=2;j>=0;j--)
case PHY_INTEGER:
{
graphicsindex = gfxbase[j];
#ifdef DEBUG_TRIANGLE_MESH
printf("%d ,",graphicsindex);
#endif //DEBUG_TRIANGLE_MESH
float* graphicsbase = (float*)(vertexbase+graphicsindex*stride);
triangle[j] = SimdVector3(
graphicsbase[0]*meshScaling.getX(),
graphicsbase[1]*meshScaling.getY(),
graphicsbase[2]*meshScaling.getZ());
#ifdef DEBUG_TRIANGLE_MESH
printf("triangle vertices:%f,%f,%f\n",triangle[j].x(),triangle[j].y(),triangle[j].z());
#endif //DEBUG_TRIANGLE_MESH
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
int* tri_indices= (int*)(indexbase+gfxindex*indexstride);
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
//check aabb in triangle-space, before doing this
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
case PHY_SHORT:
{
for (gfxindex=0;gfxindex<numtriangles;gfxindex++)
{
short int* tri_indices= (short int*)(indexbase+gfxindex*indexstride);
graphicsbase = (float*)(vertexbase+tri_indices[0]*stride);
triangle[0].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[1]*stride);
triangle[1].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
graphicsbase = (float*)(vertexbase+tri_indices[2]*stride);
triangle[2].setValue(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(), graphicsbase[2]*meshScaling.getZ());
callback->InternalProcessTriangleIndex(triangle,part,gfxindex);
}
break;
}
default:
ASSERT((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT));
}
unLockReadOnlyVertexBase(part);
}
}

View File

@@ -149,7 +149,7 @@ void setCamera() {
eye[1] = eyePos.getY();
eye[2] = eyePos.getZ();
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 100.0);
glFrustum(-1.0, 1.0, -1.0, 1.0, 1.0, 10000.0);
gluLookAt(eye[0], eye[1], eye[2],
center[0], center[1], center[2],
gCameraUp.getX(),gCameraUp.getY(),gCameraUp.getZ());

View File

@@ -374,7 +374,7 @@ void CcdPhysicsEnvironment::addCcdPhysicsController(CcdPhysicsController* ctrl)
RigidBody* body = ctrl->GetRigidBody();
//this m_userPointer is just used for triggers, see CallbackTriggers
body->m_userPointer = ctrl;
body->m_internalOwner = ctrl;
body->setGravity( m_gravity );
m_controllers.push_back(ctrl);
@@ -1429,7 +1429,7 @@ void CcdPhysicsEnvironment::removeConstraint(int constraintId)
virtual float AddSingleResult(const CollisionWorld::LocalRayResult& rayResult)
{
CcdPhysicsController* curHit = static_cast<CcdPhysicsController*>(rayResult.m_collisionObject->m_userPointer);
CcdPhysicsController* curHit = static_cast<CcdPhysicsController*>(rayResult.m_collisionObject->m_internalOwner);
//ignore client...
if (curHit != m_ignoreClient)
{
@@ -1464,7 +1464,7 @@ PHY_IPhysicsController* CcdPhysicsEnvironment::rayTest(PHY_IPhysicsController* i
m_collisionWorld->RayTest(rayFrom,rayTo,rayCallback);
if (rayCallback.HasHit())
{
nearestHit = static_cast<CcdPhysicsController*>(rayCallback.m_collisionObject->m_userPointer);
nearestHit = static_cast<CcdPhysicsController*>(rayCallback.m_collisionObject->m_internalOwner);
hitX = rayCallback.m_hitPointWorld.getX();
hitY = rayCallback.m_hitPointWorld.getY();
hitZ = rayCallback.m_hitPointWorld.getZ();
@@ -1654,9 +1654,9 @@ void CcdPhysicsEnvironment::CallbackTriggers()
RigidBody* obj0 = static_cast<RigidBody* >(manifold->GetBody0());
RigidBody* obj1 = static_cast<RigidBody* >(manifold->GetBody1());
//m_userPointer is set in 'addPhysicsController
CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(obj0->m_userPointer);
CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(obj1->m_userPointer);
//m_internalOwner is set in 'addPhysicsController'
CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(obj0->m_internalOwner);
CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(obj1->m_internalOwner);
std::vector<CcdPhysicsController*>::iterator i =
std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl0);