From fa4fd1369cb1b6d41ad07494f5beef469deb9ad6 Mon Sep 17 00:00:00 2001 From: ejcoumans Date: Wed, 6 Sep 2006 22:21:12 +0000 Subject: [PATCH] Added support for SHORT/WORD indices Removed references to m_userPointer (in CollisionObject), called it m_userObjectPointer increased view distance in glut demo file --- Bullet/CollisionDispatch/CollisionObject.h | 6 +- .../CollisionShapes/StridingMeshInterface.cpp | 90 ++++++++++--------- Demos/OpenGL/GlutStuff.cpp | 2 +- .../CcdPhysics/CcdPhysicsEnvironment.cpp | 12 +-- 4 files changed, 58 insertions(+), 52 deletions(-) diff --git a/Bullet/CollisionDispatch/CollisionObject.h b/Bullet/CollisionDispatch/CollisionObject.h index da4e9b934..877a8fb72 100644 --- a/Bullet/CollisionDispatch/CollisionObject.h +++ b/Bullet/CollisionDispatch/CollisionObject.h @@ -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; diff --git a/Bullet/CollisionShapes/StridingMeshInterface.cpp b/Bullet/CollisionShapes/StridingMeshInterface.cpp index 874660c7e..8c254e478 100644 --- a/Bullet/CollisionShapes/StridingMeshInterface.cpp +++ b/Bullet/CollisionShapes/StridingMeshInterface.cpp @@ -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=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;gfxindexInternalProcessTriangleIndex(triangle,part,gfxindex); + } + break; } - - - //check aabb in triangle-space, before doing this - callback->InternalProcessTriangleIndex(triangle,part,gfxindex); - + case PHY_SHORT: + { + for (gfxindex=0;gfxindexInternalProcessTriangleIndex(triangle,part,gfxindex); + } + break; + } + default: + ASSERT((gfxindextype == PHY_INTEGER) || (gfxindextype == PHY_SHORT)); } - + unLockReadOnlyVertexBase(part); } } diff --git a/Demos/OpenGL/GlutStuff.cpp b/Demos/OpenGL/GlutStuff.cpp index 88ea4c204..d3cfe834b 100644 --- a/Demos/OpenGL/GlutStuff.cpp +++ b/Demos/OpenGL/GlutStuff.cpp @@ -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()); diff --git a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp index ba068ee79..032e136bc 100644 --- a/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp +++ b/Extras/PhysicsInterface/CcdPhysics/CcdPhysicsEnvironment.cpp @@ -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(rayResult.m_collisionObject->m_userPointer); + CcdPhysicsController* curHit = static_cast(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(rayCallback.m_collisionObject->m_userPointer); + nearestHit = static_cast(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(manifold->GetBody0()); RigidBody* obj1 = static_cast(manifold->GetBody1()); - //m_userPointer is set in 'addPhysicsController - CcdPhysicsController* ctrl0 = static_cast(obj0->m_userPointer); - CcdPhysicsController* ctrl1 = static_cast(obj1->m_userPointer); + //m_internalOwner is set in 'addPhysicsController' + CcdPhysicsController* ctrl0 = static_cast(obj0->m_internalOwner); + CcdPhysicsController* ctrl1 = static_cast(obj1->m_internalOwner); std::vector::iterator i = std::find(m_triggerControllers.begin(), m_triggerControllers.end(), ctrl0);