PxVehicleDriveNW* PxVehicleDriveNW::allocate(const PxU32 numWheels) { PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal"); PX_CHECK_AND_RETURN_NULL(gToleranceScaleLength > 0, "PxVehicleDriveNW::allocate - need to call PxInitVehicleSDK"); //Compute the bytes needed. const PxU32 byteSize = sizeof(PxVehicleDriveNW) + PxVehicleDrive::computeByteSize(numWheels); //Allocate the memory. PxVehicleDriveNW* veh = static_cast<PxVehicleDriveNW*>(PX_ALLOC(byteSize, "PxVehicleDriveNW")); Cm::markSerializedMem(veh, byteSize); new(veh) PxVehicleDriveNW(); //Patch up the pointers. PxU8* ptr = reinterpret_cast<PxU8*>(veh) + sizeof(PxVehicleDriveNW); ptr=PxVehicleDrive::patchupPointers(numWheels, veh, ptr); //Initialise veh->init(numWheels); //Set the vehicle type. veh->mType = PxVehicleTypes::eDRIVENW; return veh; }
PxArticulationDriveCache* NpArticulation::createDriveCache(PxReal compliance, PxU32 driveIterations) const { PX_CHECK_AND_RETURN_NULL(getAPIScene(), "PxArticulation::createDriveCache: object must be in a scene"); NP_READ_CHECK(getOwnerScene()); // doesn't modify the scene, only reads return reinterpret_cast<PxArticulationDriveCache*>(mArticulation.getScArticulation().createDriveCache(compliance, driveIterations)); }
PxArticulationLink* NpArticulation::createLink(PxArticulationLink* parent, const PxTransform& pose) { PX_CHECK_AND_RETURN_NULL(pose.isSane(), "NpArticulation::createLink pose is not valid."); NP_WRITE_CHECK(getOwnerScene()); if(parent && mArticulationLinks.empty()) { Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "Root articulation link must have NULL parent pointer!"); return NULL; } if(!parent && !mArticulationLinks.empty()) { Ps::getFoundation().error(PxErrorCode::eINVALID_OPERATION, __FILE__, __LINE__, "Non-root articulation link must have valid parent pointer!"); return NULL; } NpArticulationLink* parentLink = static_cast<NpArticulationLink*>(parent); NpArticulationLink* link = static_cast<NpArticulationLink*>(NpFactory::getInstance().createArticulationLink(*this, parentLink, pose.getNormalized())); if(link) { NpScene* scene = getAPIScene(); if(scene) scene->addArticulationLink(*link); } return link; }
PxRigidDynamic* PxCreateKinematic(PxPhysics& sdk, const PxTransform& transform, PxShape& shape, PxReal density) { PX_CHECK_AND_RETURN_NULL(transform.isValid(), "PxCreateKinematic: transform is not valid."); bool isDynGeom = isDynamicGeometry(shape.getGeometryType()); if(isDynGeom && density <= 0.0f) return NULL; PxRigidDynamic* actor = sdk.createRigidDynamic(transform); if(actor) { actor->setRigidBodyFlag(PxRigidBodyFlag::eKINEMATIC, true); if(!isDynGeom) shape.setFlag(PxShapeFlag::eSIMULATION_SHAPE, false); actor->attachShape(shape); if(isDynGeom) PxRigidBodyExt::updateMassAndInertia(*actor, density); else { actor->setMass(1.f); actor->setMassSpaceInertiaTensor(PxVec3(1.f,1.f,1.f)); } } return actor; }
PxVehicleNoDrive* PxVehicleNoDrive::allocate(const PxU32 numWheels) { PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal"); //Compute the bytes needed. const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2); const PxU32 inputByteSize16 = sizeof(PxReal)*numWheels4*4; const PxU32 byteSize = sizeof(PxVehicleNoDrive) + 3*inputByteSize16 + PxVehicleWheels::computeByteSize(numWheels4); //Allocate the memory. PxVehicleNoDrive* veh = (PxVehicleNoDrive*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleNoDrive")); Cm::markSerializedMem(veh, byteSize); new(veh) PxVehicleNoDrive(); //Patch up the pointers. PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleNoDrive); ptr=PxVehicleWheels::patchupPointers(veh,ptr,numWheels4,numWheels); veh->mSteerAngles = (PxReal*)ptr; ptr+=inputByteSize16; veh->mDriveTorques = (PxReal*)ptr; ptr+=inputByteSize16; veh->mBrakeTorques = (PxReal*)ptr; ptr+=inputByteSize16; PxMemZero(veh->mSteerAngles, inputByteSize16); PxMemZero(veh->mDriveTorques, inputByteSize16); PxMemZero(veh->mBrakeTorques, inputByteSize16); //Set the vehicle type. veh->mType = PxVehicleTypes::eNODRIVE; return veh; }
PxRigidStatic* PxCreatePlane(PxPhysics& sdk, const PxPlane& plane, PxMaterial& material) { PX_CHECK_AND_RETURN_NULL(plane.n.isFinite(), "PxCreatePlane: plane normal is not valid."); if (!plane.n.isNormalized()) return NULL; return PxCreateStatic(sdk, PxTransformFromPlaneEquation(plane), PxPlaneGeometry(), material); }
PxRigidStatic* PxCreateStatic(PxPhysics& sdk, const PxTransform& transform, const PxGeometry& geometry, PxMaterial& material, const PxTransform& shapeOffset) { PX_CHECK_AND_RETURN_NULL(transform.isValid(), "PxCreateStatic: transform is not valid."); PX_CHECK_AND_RETURN_NULL(shapeOffset.isValid(), "PxCreateStatic: shapeOffset is not valid."); PxShape* shape = sdk.createShape(geometry, material, true); if(!shape) return NULL; shape->setLocalPose(shapeOffset); PxRigidStatic* s = PxCreateStatic(sdk, transform, *shape); shape->release(); return s; }
PxRigidStatic* PxCreateStatic(PxPhysics& sdk, const PxTransform& transform, PxShape& shape) { PX_CHECK_AND_RETURN_NULL(transform.isValid(), "PxCreateStatic: transform is not valid."); PxRigidStatic* s = sdk.createRigidStatic(transform); if(s) s->attachShape(shape); return s; }
PxRigidDynamic* PxCreateDynamic(PxPhysics& sdk, const PxTransform& transform, const PxGeometry& geometry, PxMaterial& material, PxReal density, const PxTransform& shapeOffset) { PX_CHECK_AND_RETURN_NULL(transform.isValid(), "PxCreateDynamic: transform is not valid."); PX_CHECK_AND_RETURN_NULL(shapeOffset.isValid(), "PxCreateDynamic: shapeOffset is not valid."); if(!isDynamicGeometry(geometry.getType()) || density <= 0.0f) return NULL; PxShape* shape = sdk.createShape(geometry, material, true); if(!shape) return NULL; shape->setLocalPose(shapeOffset); PxRigidDynamic* body = shape ? PxCreateDynamic(sdk, transform, *shape, density) : NULL; shape->release(); return body; }
PxRigidDynamic* PxCreateDynamic(PxPhysics& sdk, const PxTransform& transform, PxShape& shape, PxReal density) { PX_CHECK_AND_RETURN_NULL(transform.isValid(), "PxCreateDynamic: transform is not valid."); PxRigidDynamic* actor = sdk.createRigidDynamic(transform); if(actor) { actor->attachShape(shape); PxRigidBodyExt::updateMassAndInertia(*actor, density); } return actor; }
PxVehicleDriveNW* PxVehicleDriveNW::allocate(const PxU32 numWheels) { PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal"); //Compute the bytes needed. const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2); const PxU32 byteSize = sizeof(PxVehicleDriveNW) + PxVehicleDrive::computeByteSize(numWheels4); //Allocate the memory. PxVehicleDriveNW* veh = (PxVehicleDriveNW*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleDriveNW")); Cm::markSerializedMem(veh, byteSize); new(veh) PxVehicleDriveNW(); //Patch up the pointers. PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleDriveNW); ptr=PxVehicleDrive::patchupPointers(veh,ptr,numWheels4,numWheels); //Set the vehicle type. veh->mType = PxVehicleTypes::eDRIVENW; return veh; }
PxVehicleDriveTank* PxVehicleDriveTank::allocate(const PxU32 numWheels) { PX_CHECK_AND_RETURN_NULL(numWheels>0, "Cars with zero wheels are illegal"); //Compute the bytes needed. const PxU32 numWheels4 = (((numWheels + 3) & ~3) >> 2); const PxU32 byteSize = sizeof(PxVehicleDriveTank) + + PxVehicleDrive::computeByteSize(numWheels4); //Allocate the memory. PxVehicleDriveTank* veh = (PxVehicleDriveTank*)PX_ALLOC(byteSize, PX_DEBUG_EXP("PxVehicleDriveTank")); //Patch up the pointers. PxU8* ptr = (PxU8*)veh + sizeof(PxVehicleDriveTank); PxVehicleDrive::patchupPointers(veh,ptr,numWheels4,numWheels); //Set the vehicle type. veh->mType = eVEHICLE_TYPE_DRIVETANK; //Set the default drive model. veh->mDriveModel = eDRIVE_MODEL_STANDARD; return veh; }