PrismaticJointX::PrismaticJointX(PhysXManager *pMan , kge::ph::Actor *a1, kge::ph::Actor *a2, kge::math::Vector *Anchor, kge::math::Vector *axis) { NxActor *nxA1,*nxA2; NxPrismaticJointDesc nxPrismaticJointDesc; if( !a1 ) return; nxPrismaticJointDesc.setToDefault(); if( a1->getType() == EATP_DYNAMIC || a1->getType() == EATP_KINEMATIC ) nxA1 = ((ActorDynamicX*)(a1))->getPhActor(); if( a2 && ( a2->getType() == EATP_DYNAMIC || a2->getType() == EATP_KINEMATIC ) ) nxA2 = ((ActorDynamicX*)(a1))->getPhActor(); nxPrismaticJointDesc.actor[0] = nxA1; if( a2 ) nxPrismaticJointDesc.actor[1] = nxA2; nxPrismaticJointDesc.setGlobalAnchor( NxVec3( Anchor->x , Anchor->y , Anchor->z ) ); if( axis ) nxPrismaticJointDesc.setGlobalAxis( NxVec3( axis->x , axis->y , axis->z ) ); m_pPrismaticJoint = ((NxPrismaticJoint*)(pMan->getPhysxScene()->createJoint( nxPrismaticJointDesc ))); }
void create(NxScene& scene, const NxVec3& pos, float rad, NxActor* holder) { NxActorDesc actorDesc; NxBodyDesc bodyDesc; NxSphereShapeDesc sphereDesc; bodyDesc.solverIterationCount = 20; // wheel sphereDesc.radius = rad; sphereDesc.materialIndex = wheelMaterialIndex; actorDesc.shapes.pushBack(&sphereDesc); bodyDesc.mass = 400; actorDesc.body = &bodyDesc; actorDesc.globalPose.t = pos; wheel = scene.createActor(actorDesc); // roll axis bodyDesc.mass = 50; bodyDesc.massSpaceInertia = NxVec3(1,1,1); actorDesc.body = &bodyDesc; actorDesc.shapes.clear(); actorDesc.globalPose.t = pos; rollAxis = scene.createActor(actorDesc); // revolute joint connecting wheel with rollAxis NxRevoluteJointDesc revJointDesc; revJointDesc.projectionMode = NX_JPM_POINT_MINDIST; revJointDesc.actor[0] = wheel; revJointDesc.actor[1] = rollAxis; revJointDesc.setGlobalAnchor(pos); revJointDesc.setGlobalAxis(NxVec3(0,0,1)); rollJoint = (NxRevoluteJoint*)scene.createJoint(revJointDesc); // prismatic joint connecting rollAxis with holder NxPrismaticJointDesc prisJointDesc; prisJointDesc.actor[0] = rollAxis; prisJointDesc.actor[1] = holder; prisJointDesc.setGlobalAnchor(pos); prisJointDesc.setGlobalAxis(NxVec3(0,1,0)); scene.createJoint(prisJointDesc); // add springs and dampers to the suspension (i.e. the related actors) float springLength = 0.1f; NxSpringAndDamperEffector * springNdamp = scene.createSpringAndDamperEffector(NxSpringAndDamperEffectorDesc()); springNdamp->setBodies(rollAxis, pos, holder, pos + NxVec3(0,springLength,0)); springNdamp->setLinearSpring(0, springLength, 2*springLength, 100000, 100000); springNdamp->setLinearDamper(-1, 1, 1e5, 1e5); // disable collision detection scene.setActorPairFlags(*wheel, *holder, NX_IGNORE_PAIR); }
NxPrismaticJoint* CreatePrismaticJoint(NxActor* a0, NxActor* a1, const NxVec3& globalAnchor, const NxVec3& globalAxis, NxScene* gScene) { NxPrismaticJointDesc prismaticDesc; prismaticDesc.actor[0] = a0; prismaticDesc.actor[1] = a1; prismaticDesc.setGlobalAnchor(globalAnchor); prismaticDesc.setGlobalAxis(globalAxis); NxJoint* joint = gScene->createJoint(prismaticDesc); // joint->setLimitPoint(globalAnchor); // joint->addLimitPlane(-globalAxis, globalAnchor + 1.5*globalAxis); // joint->addLimitPlane(globalAxis, globalAnchor - 1.5*globalAxis); return static_cast<NxPrismaticJoint*>(joint); }
NxPrismaticJoint* World::CreatePrismaticJoint(NxActor* a0, NxActor* a1, NxVec3 globalAnchor, NxVec3 globalAxis) { NxPrismaticJointDesc prismaticDesc; prismaticDesc.actor[0] = a0; prismaticDesc.actor[1] = a1; prismaticDesc.setGlobalAnchor(globalAnchor); // 0 7 0 prismaticDesc.setGlobalAxis(globalAxis); // 0 1 0 NxJoint* joint = gScene->createJoint(prismaticDesc); joint->setLimitPoint(globalAnchor); joint->addLimitPlane(-globalAxis, globalAnchor + 1*globalAxis, 0.5f); joint->addLimitPlane(globalAxis, globalAnchor - 1*globalAxis, 0.5f); return (NxPrismaticJoint*)joint; }