void PxVehicleDriveTank::setup (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData, const PxVehicleDriveSimData& driveData, const PxU32 numDrivenWheels) { PX_CHECK_AND_RETURN(driveData.isValid(), "PxVehicleDriveTank::setup - illegal drive data"); //Set up the wheels. PxVehicleDrive::setup(physics,vehActor,wheelsData,numDrivenWheels,0); //Start setting up the drive. PX_CHECK_MSG(driveData.isValid(), "PxVehicle4WDrive - invalid driveData"); //Copy the simulation data. mDriveSimData = driveData; }
void PxVehicleWheels::setup (PxPhysics* physics, PxRigidDynamic* vehActor, const PxVehicleWheelsSimData& wheelsData, const PxU32 numDrivenWheels, const PxU32 numNonDrivenWheels) { PX_CHECK_AND_RETURN(wheelsData.getNumWheels() == mWheelsSimData.getNumWheels(), "PxVehicleWheels::setup - vehicle must be setup with same number of wheels as wheelsData"); PX_CHECK_AND_RETURN(vehActor, "PxVehicleWheels::setup - vehActor is null ptr : you need to instantiate an empty PxRigidDynamic for the vehicle"); PX_CHECK_AND_RETURN(vehActor->getNbShapes() >= (numDrivenWheels + numNonDrivenWheels + 1), "PxVehicleWheels::setup - not enough wheels shapes have been added to vehActor"); PX_CHECK_AND_RETURN(wheelsData.isValid(), "PxVehicleWheels::setup -invalid wheelsData"); #ifdef PX_CHECKED PxF32 totalSprungMass=0.0f; for(PxU32 i=0;i<(numDrivenWheels+numNonDrivenWheels);i++) { totalSprungMass+=wheelsData.getSuspensionData(i).mSprungMass; } PX_CHECK_MSG(PxAbs((vehActor->getMass()-totalSprungMass)/vehActor->getMass()) < 0.01f, "Sum of suspension sprung masses doesn't match actor mass"); #endif //Copy the simulation data. mWheelsSimData=wheelsData; //Set the actor pointer. mActor=vehActor; //Pose the wheels from the wheels offset data. const PxTransform chassisCMOffset=vehActor->getCMassLocalPose(); for(PxU32 i=0;i<wheelsData.mNumActiveWheels;i++) { if(mWheelShapeMap[i]!=PX_MAX_U8) { //Get the shape. const PxU32 shapeIndex=mWheelShapeMap[i]; PxShape* shapeBuffer[1]; vehActor->getShapes(shapeBuffer,1,shapeIndex); PxTransform wheelOffset=chassisCMOffset; wheelOffset.p+=wheelsData.getWheelCentreOffset(i); shapeBuffer[0]->setLocalPose(wheelOffset); } } //Set all the sq result ptrs to null. const PxU32 numSuspWheelTire4=wheelsData.mNumWheels4; for(PxU32 i=0;i<numSuspWheelTire4;i++) { mWheelsDynData.mWheels4DynData[i].mSqResults=NULL; } //Set up the suspension limits constraints. for(PxU32 i=0;i<numSuspWheelTire4;i++) { PxVehicleConstraintShader& shader=mWheelsDynData.mWheels4DynData[i].getVehicletConstraintShader(); for(PxU32 j=0;j<4;j++) { shader.mData.mSuspLimitData.mCMOffsets[j]=wheelsData.mWheels4SimData[i].getSuspForceAppPointOffset(j); shader.mData.mSuspLimitData.mDirs[j]=wheelsData.mWheels4SimData[i].getSuspTravelDirection(j); shader.mData.mSuspLimitData.mErrors[j]=0.0f; shader.mData.mSuspLimitData.mActiveFlags[j]=false; shader.mData.mStickyTireData.mCMOffsets[j]=PxVec3(0,0,0); shader.mData.mStickyTireData.mDirs[j]=PxVec3(0,0,0); shader.mData.mStickyTireData.mTargetSpeeds[j]=0.0f; shader.mData.mStickyTireData.mActiveFlags[j]=false; } #ifdef PX_PS3 PxConstraintShaderTable t = { PxVehicleConstraintShader::vehicleSuspLimitConstraintSolverPrep, PxVehicle4WSuspLimitConstraintShaderSpu, PXVEHICLE4WSUSPLIMITCONSTRAINTSHADERSPU_SIZE, 0, PxVehicleConstraintShader::visualiseConstraint }; #else PxConstraintShaderTable t = { PxVehicleConstraintShader::vehicleSuspLimitConstraintSolverPrep, 0, 0, 0, PxVehicleConstraintShader::visualiseConstraint }; #endif shader.mConstraint=physics->createConstraint(vehActor, NULL, shader, t, sizeof(PxVehicleConstraintShader::VehicleConstraintData)); shader.mConstraint->markDirty(); } //Set up the shader data ptrs. for(PxU32 i=0;i<wheelsData.mNumActiveWheels;i++) { mWheelsDynData.setTireForceShaderData(i,&mWheelsSimData.getTireData(i)); } //Disable the unused wheels. for(PxU32 i=wheelsData.mNumActiveWheels;i<4*mWheelsSimData.mNumWheels4;i++) { mWheelsSimData.disableWheel(i); } }
const PxVec3& PxVehicleWheelsSimData::getWheelCentreOffset(const PxU32 id) const { PX_CHECK_MSG(id < 4*mNumWheels4, "PxVehicleWheelsSimData::getWheelCentreOffset - Illegal wheel"); return mWheels4SimData[id>>2].getWheelCentreOffset(id & 3); }
const PxVec3& PxVehicleWheelsSimData::getSuspTravelDirection(const PxU32 id) const { PX_CHECK_MSG(id < 4*mNumWheels4, "PxVehicleWheelsSimData::getSuspTravelDirection - Illegal wheel"); return mWheels4SimData[id>>2].getSuspTravelDirection(id & 3); }
const PxVehicleTireData& PxVehicleWheelsSimData::getTireData(const PxU32 id) const { PX_CHECK_MSG(id < 4*mNumWheels4, "PxVehicleWheelsSimData::getTireData - Illegal wheel"); return mWheels4SimData[id>>2].getTireData(id & 3); }
void testValidAnalogValue(const PxF32 actualValue, const PxF32 minVal, const PxF32 maxVal, const char* errorString) { const PxF32 tolerance = 1e-2f; PX_CHECK_MSG((actualValue > (minVal - tolerance)) && (actualValue < (maxVal + tolerance)), errorString); }