int CLPhysicsDemo::registerPhysicsInstance(float mass, const float* position, const float* orientation, int collidableIndex, int userIndex) { btVector3 aabbMin(0,0,0),aabbMax(0,0,0); if (collidableIndex>=0) { btAABBHost hostLocalAabbMin = m_data->m_localShapeAABBCPU->at(collidableIndex*2); btAABBHost hostLocalAabbMax = m_data->m_localShapeAABBCPU->at(collidableIndex*2+1); btVector3 localAabbMin(hostLocalAabbMin.fx,hostLocalAabbMin.fy,hostLocalAabbMin.fz); btVector3 localAabbMax(hostLocalAabbMax.fx,hostLocalAabbMax.fy,hostLocalAabbMax.fz); btScalar margin = 0.01f; btTransform t; t.setIdentity(); t.setOrigin(btVector3(position[0],position[1],position[2])); t.setRotation(btQuaternion(orientation[0],orientation[1],orientation[2],orientation[3])); btTransformAabb(localAabbMin,localAabbMax, margin,t,aabbMin,aabbMax); //(position[0],position[0],position[0]); //aabbMin -= btVector3(400.f,410.f,400.f); //aabbMax += btVector3(400.f,410.f,400.f); //btBroadphaseProxy* proxy = m_data->m_Broadphase->createProxy(aabbMin,aabbMax,collisionShapeIndex,userPointer,1,1,0,0);//m_dispatcher); if (useSapGpuBroadphase) m_data->m_BroadphaseSap->createProxy(aabbMin,aabbMax,userIndex,1,1);//m_dispatcher); else { void* userPtr = (void*)userIndex; m_data->m_BroadphaseGrid->createProxy(aabbMin,aabbMax,collidableIndex,userPtr ,1,1);//m_dispatcher); } } bool writeToGpu = false; int bodyIndex = -1; m_data->m_linVelHost.push_back(btVector3(0,0,0)); m_data->m_angVelHost.push_back(btVector3(0,0,0)); m_data->m_bodyTimesHost.push_back(0.f); if (narrowphaseAndSolver) { //bodyIndex = narrowphaseAndSolver->registerRigidBody(collisionShapeIndex,CollisionShape::SHAPE_CONVEX_HEIGHT_FIELD,mass,position,orientation,&aabbMin.getX(),&aabbMax.getX(),writeToGpu); bodyIndex = narrowphaseAndSolver->registerRigidBody(collidableIndex,mass,position,orientation,&aabbMin.getX(),&aabbMax.getX(),writeToGpu); } if (mass>0.f) m_numDynamicPhysicsInstances++; m_numPhysicsInstances++; return bodyIndex; }
void btRayShape::getAabb(const btTransform &t, btVector3 &aabbMin, btVector3 &aabbMax) const { #define MARGIN_BROADPHASE 0.1 btVector3 localAabbMin(0, 0, 0); btVector3 localAabbMax(m_shapeAxis * m_length); btTransformAabb(localAabbMin, localAabbMax, MARGIN_BROADPHASE, t, aabbMin, aabbMax); }