void CPhysicsManager::ReleaseActorCapsule (CPhysicActor* actor) { assert(actor != NULL); assert(m_pScene != NULL); assert(m_pPhysicsSDK != NULL); NxActor* nxActor = actor->GetPhXActor(); if( nxActor != 0) { NxArray<NxCCDSkeleton*> skeletons; for (NxU32 i = 0; i < nxActor->getNbShapes(); i++) { NxShape* shape = nxActor->getShapes()[i]; if (shape->isCapsule()) shape->setGroup(ECG_LAST_GROUP); } } }
void CPhysicsActor::AddVisualization() { // get the CPhysicsObject's name PHYSICSUSERDATA* userData = (PHYSICSUSERDATA*)m_Actor->userData; if( userData == NULL ) return; CPhysicsObject* physObj = userData->physObj; IHashString* cpoName = physObj->GetParentName(); // Loop through shapes in the actor unsigned int numShapes = m_Actor->getNbShapes(); NxShape*const* shapes = m_Actor->getShapes(); NxShape* shape; // we need to unscale before feeding it to the shape objects since they // get the scale from the parent Vec3 invScale; invScale.x = 1.0f / m_CurrentScale.x; invScale.y = 1.0f / m_CurrentScale.y; invScale.z = 1.0f / m_CurrentScale.z; // Add visualizations for each shape while( numShapes-- ) { shape = shapes[numShapes]; // Add shape to be rendered if( shape->isBox() ) { NxBoxShape* boxShape = (NxBoxShape*)shape; Matrix4x4 localTransform; localTransform.SetIdentity(); float tempRot[9]; boxShape->getLocalOrientation().getColumnMajor( tempRot ); localTransform.SetFrom3x3( tempRot ); NxVec3 tempPos = boxShape->getLocalPosition(); tempPos.x *= invScale.x; tempPos.y *= invScale.y; tempPos.z *= invScale.z; localTransform.SetTranslation( Vec3(tempPos.x, tempPos.y, tempPos.z) ); NxVec3 boxDimensions = boxShape->getDimensions(); float halfXDimension = boxDimensions.x * invScale.x; float halfYDimension = boxDimensions.y * invScale.y; float halfZDimension = boxDimensions.z * invScale.z; // Add a debug render object to visualize the object ADDOBJECTORIENTEDBOXPARAMS oobbParams; oobbParams.name = cpoName; oobbParams.min = Vec3( -halfXDimension, -halfYDimension, -halfZDimension ); oobbParams.max = Vec3( halfXDimension, halfYDimension, halfZDimension ); oobbParams.localTransform = localTransform; static DWORD msgHash_AddObjectOrientedBox = CHashString(_T("AddObjectOrientedBox")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_AddObjectOrientedBox, sizeof(ADDOBJECTORIENTEDBOXPARAMS), &oobbParams ); } if( shape->isSphere() ) { NxSphereShape* sphereShape = (NxSphereShape*)shape; float radius = sphereShape->getRadius(); // Add a debug render object to visualize the object ADDSPHEREPARAMS sphereParams; sphereParams.name = cpoName; sphereParams.radius = radius * invScale.x; sphereParams.red = 0; sphereParams.green = 255; // making the sphere green to distinguish it from AABBs sphereParams.blue = 0; static DWORD msgHash_AddSphere = CHashString(_T("AddSphere")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_AddSphere, sizeof(ADDSPHEREPARAMS), &sphereParams ); } if( shape->isCapsule() ) { // Draw as a red box for now NxCapsuleShape* capsuleShape = (NxCapsuleShape*)shape; Matrix4x4 localTransform; localTransform.SetIdentity(); float tempRot[9]; capsuleShape->getLocalOrientation().getColumnMajor( tempRot ); localTransform.SetFrom3x3( tempRot ); NxVec3 tempPos = capsuleShape->getLocalPosition(); tempPos.x *= invScale.x; tempPos.y *= invScale.y; tempPos.z *= invScale.z; localTransform.SetTranslation( Vec3(tempPos.x, tempPos.y, tempPos.z) ); float halfXDimension = capsuleShape->getRadius(); float halfYDimension = capsuleShape->getHeight() - capsuleShape->getRadius(); float halfZDimension = capsuleShape->getRadius(); // Add a debug render object to visualize the object ADDOBJECTORIENTEDBOXPARAMS oobbParams; oobbParams.name = cpoName; oobbParams.min = Vec3( -halfXDimension, -halfYDimension, -halfZDimension ); oobbParams.max = Vec3( halfXDimension, halfYDimension, halfZDimension ); oobbParams.localTransform = localTransform; oobbParams.red = 255; oobbParams.green = 0; oobbParams.blue = 0; static DWORD msgHash_AddObjectOrientedBox = CHashString(_T("AddObjectOrientedBox")).GetUniqueID(); m_ToolBox->SendMessage(msgHash_AddObjectOrientedBox, sizeof(ADDOBJECTORIENTEDBOXPARAMS), &oobbParams ); } if( shape->isConvexMesh() ) { // not yet implemented } } }