void TumblingRobot::Create(){ if(this->pScene == NULL){ #ifdef _DEBUG std::cout<< "pScene == NULL at TumblingRobot::Create()" << std::endl; #endif //_DEBUG return; } TumblingBody* body = new TumblingBody(pScene, position); TumblingArm* leftArm = new TumblingArm(pScene, position, NxVec3(-2, 0, 0), NxQuat(-10, NxVec3(0, 1, 0)) ); TumblingArm* rightArm = new TumblingArm(pScene, position, NxVec3(2, 0, 0), NxQuat(10, NxVec3(0, 1, 0)) ); NxRevoluteJointDesc leftJointDesc; leftJointDesc.setToDefault(); leftJointDesc.actor[0] = body->getActor(); leftJointDesc.actor[1] = leftArm->getActor(); leftJointDesc.setGlobalAnchor(position + NxVec3(2, 0, 0)); leftJointDesc.setGlobalAxis(NxMat33(leftArm->getLocalOrientation()) * NxVec3(1, 0, 0)); NxJoint* leftJoint = pScene->createJoint( leftJointDesc ); NxRevoluteJointDesc rightJointDesc; rightJointDesc.setToDefault(); rightJointDesc.actor[0] = body->getActor(); rightJointDesc.actor[1] = rightArm->getActor(); rightJointDesc.setGlobalAnchor(position + NxVec3(2, 0, 0)); rightArm->getLocalOrientation(); rightJointDesc.setGlobalAxis(NxMat33(rightArm->getLocalOrientation()) * NxVec3(1, 0, 0)); NxJoint* rightJoint = pScene->createJoint( rightJointDesc ); //Register Parts this->parts.push_back(body); this->parts.push_back(leftArm); this->parts.push_back(rightArm); //Register Joints this->joints.push_back(leftJoint); this->joints.push_back(rightJoint); WalkControl* cWalk = new WalkControl(pHost); ArmControl* cLeftArm = new ArmControl(pHost); ArmControl* cRightArm = new ArmControl(pHost); cWalk->addTarget(cLeftArm); cWalk->addTarget(cRightArm); clients.push_back(cWalk); clients.push_back(cLeftArm); clients.push_back(cRightArm); pHost->addClient(cWalk); pHost->addClient(cLeftArm); pHost->addClient(cRightArm); leftArm->setClient(cLeftArm); rightArm->setClient(cRightArm); return; }
void create(NxScene& scene, const NxVec3& pos, float rad, NxActor* holder) { NxActorDesc actorDesc; NxBodyDesc bodyDesc; bodyDesc.solverIterationCount = 20; // steer axis bodyDesc.mass = 50; bodyDesc.massSpaceInertia = NxVec3(1,1,1); actorDesc.body = &bodyDesc; actorDesc.shapes.clear(); actorDesc.globalPose.t = pos; steerAxis = scene.createActor(actorDesc); wheel.create(scene, pos, rad, steerAxis); // revolute joint connecting steerAxis with the holder NxRevoluteJointDesc revJointDesc; revJointDesc.projectionMode = NX_JPM_POINT_MINDIST; revJointDesc.actor[0] = steerAxis; revJointDesc.actor[1] = holder; revJointDesc.setGlobalAnchor(pos); revJointDesc.setGlobalAxis(NxVec3(0,1,0)); steerJoint = (NxRevoluteJoint*)scene.createJoint(revJointDesc); // disable collision detection scene.setActorPairFlags(*wheel.wheel, *holder, NX_IGNORE_PAIR); }
NxRevoluteJoint* CreateChassisJoint(NxActor* a0, NxActor* a1, const NxVec3& globalAnchor, const NxVec3& globalAxis, NxScene* gScene) { NxRevoluteJointDesc revDesc; revDesc.actor[0] = a0; revDesc.actor[1] = a1; revDesc.setGlobalAnchor(globalAnchor); revDesc.setGlobalAxis(globalAxis); revDesc.flags |= NX_RJF_LIMIT_ENABLED; NxJointLimitPairDesc limitDesc; limitDesc.high.value = (NxReal)0.01*NxPi; limitDesc.low.value = -(NxReal)0.01*NxPi;; revDesc.limit = limitDesc; revDesc.flags |= NX_RJF_SPRING_ENABLED; NxSpringDesc springDesc; springDesc.targetValue = 0; springDesc.spring = 5000; // motorDesc.maxForce = 100; // motorDesc.freeSpin = 0; // // revDesc.motor = motorDesc; return static_cast<NxRevoluteJoint*>(gScene->createJoint(revDesc)); }
NxRevoluteJoint* CreateRevoluteJoint(NxActor* a0, NxActor* a1, const NxVec3& globalAnchor, const NxVec3& globalAxis, NxScene* gScene) { NxRevoluteJointDesc revDesc; revDesc.actor[0] = a0; revDesc.actor[1] = a1; revDesc.setGlobalAnchor(globalAnchor); revDesc.setGlobalAxis(globalAxis); return static_cast<NxRevoluteJoint*>(gScene->createJoint(revDesc)); }
//----------------------------------------------------------------------------- // CreateRevoluteJoint //----------------------------------------------------------------------------- NxRevoluteJoint* CPhysicScene::CreateRevoluteJoint(NxActor* a0, NxActor* a1, const NxVec3& globalAnchor, const NxVec3& globalAxis) { NxRevoluteJointDesc revDesc; revDesc.actor[0] = a0; revDesc.actor[1] = a1; revDesc.setGlobalAnchor(globalAnchor); revDesc.setGlobalAxis(globalAxis); return (NxRevoluteJoint*)m_pScene->createJoint(revDesc); }
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); }
NxRevoluteJoint* World::CreateRevoluteJoint(NxActor* a0, NxActor* a1, NxVec3 globalAnchor, NxVec3 globalAxis, bool isMotor) { NxRevoluteJointDesc revDesc; revDesc.actor[0] = a0; revDesc.actor[1] = a1; revDesc.setGlobalAnchor(globalAnchor); revDesc.setGlobalAxis(globalAxis); //revDesc.jointFlags |= NX_JF_COLLISION_ENABLED; if (!isMotor) { //revDesc.flags |= NX_RJF_SPRING_ENABLED; //NxSpringDesc springDesc; //springDesc.spring = 5000; //springDesc.damper = 50; //springDesc.targetValue = 1.5*NxPi; //revDesc.spring = springDesc; } else // motor enabled { revDesc.flags |= NX_RJF_MOTOR_ENABLED; NxMotorDesc motorDesc; motorDesc.setToDefault(); motorDesc.velTarget = 3; motorDesc.maxForce = 10; motorDesc.freeSpin = true; revDesc.motor = motorDesc; } revDesc.projectionMode = NX_JPM_POINT_MINDIST; revDesc.projectionDistance = 1.0f; revDesc.projectionAngle = 0.0872f; return (NxRevoluteJoint*)gScene->createJoint(revDesc); }
TriPod::TriPod(IVehicle *vehicle, string fname, bool FrontTriPod) { m_tractor = true; m_vehicle = vehicle; m_triPodDimms = new TriPodDimms; m_isLifted = false; m_attachedDevice = NULL; m_attachedTrailer = NULL; m_jointTopPodDevice = NULL; m_jointBottomLeftPodDevice = NULL; m_jointBottomRightPodDevice = NULL; m_jointTrailer = NULL; string topPodModel; string bottomPodModel; m_triPodDimms->getVariableList()->push_back(new CfgVariable(V_STRING, &topPodModel, getVarName(topPodModel))); m_triPodDimms->getVariableList()->push_back(new CfgVariable(V_STRING, &bottomPodModel, getVarName(bottomPodModel))); CfgLoader(fname, m_triPodDimms->getVariableList()); m_objTop = new Surface(topPodModel, new Material(MT_DEFAULT, "wood.jpg"), Vec3(0, 0, 0)); m_objBottom = new Surface(bottomPodModel, new Material(MT_DEFAULT, "wood.jpg"), Vec3(0, 0, 0)); NxVec3 actorTopPos = NxVec3(m_vehicle->getVehicleController()->getVehicleParams()->posTriPodBack) + NxVec3(m_triPodDimms->posTopPodTractorConnector); NxVec3 actorBottomPos = NxVec3(m_vehicle->getVehicleController()->getVehicleParams()->posTriPodBack) + NxVec3(m_triPodDimms->posBottomPodTractorConnector); NxVec3 actorTopDimm = NxVec3(m_objTop->boundingBox.getWidth()/2, m_objTop->boundingBox.getHeight()/2, m_objTop->boundingBox.getDepth()/2); NxVec3 actorBottomDimm = NxVec3(m_objBottom->boundingBox.getWidth()/2, m_objBottom->boundingBox.getHeight()/2, m_objBottom->boundingBox.getDepth()/2); /*m_actorTop = core.dynamics->createBox(actorTopPos, actorTopDimm, 1); m_actorBottom = core.dynamics->createBox(actorBottomPos, actorBottomDimm, 1);*/ m_actorTop = core.dynamics->createBox(actorTopPos, NxVec3(D3DXVec3Length(&Vec3(m_triPodDimms->posTopPodTractorConnector - m_triPodDimms->posTopPodDeviceConnector))/2, 0.1f, 0.1f), 500); m_actorBottom = core.dynamics->createBox(actorBottomPos, NxVec3(D3DXVec3Length(&Vec3(m_triPodDimms->posBottomPodTractorConnector - m_triPodDimms->posBottomPodDeviceConnector))/2, 0.1f, m_triPodDimms->width / 2), 500); /*m_triPodDimms->posTopPodDeviceConnector.x -= 0.2f; m_triPodDimms->posBottomPodDeviceConnector.x -= 0.2f;*/ /*SetActorCollisionGroup(m_actorTop, GROUP_COLLIDABLE_NON_PUSHABLE); SetActorCollisionGroup(m_actorBottom, GROUP_COLLIDABLE_NON_PUSHABLE);*/ SetActorCollisionGroup(m_actorTop, GROUP_COLLIDABLE_NON_PUSHABLE); SetActorCollisionGroup(m_actorBottom, GROUP_COLLIDABLE_NON_PUSHABLE); core.game->getWorld()->addToWorld(m_objTop, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1); core.game->getWorld()->addToWorld(m_objBottom, NO_COLLISION, 0, GROUP_NON_COLLIDABLE, NULL, 1); m_frontPod = FrontTriPod; if(!m_frontPod) { float highLimit = D3DX_PI * 0.12f; float lowLimit = D3DX_PI * -0.1f; m_jointMotorTop = new NxMotorDesc(0, NX_MAX_REAL, 0); m_jointMotorBottom = new NxMotorDesc(0, NX_MAX_REAL, 0); Vec3 newPosTop = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posTopPod) - m_triPodDimms->posTopPodTractorConnector; Vec3 newPosBottom = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posBottomPod) - m_triPodDimms->posBottomPodTractorConnector; Vec3 moveTop = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posTopPod);// - m_triPodDimms->posTopPodTractorConnector; Vec3 moveBottom = m_vehicle->getVehicleController()->getBackJointPoint() + (m_triPodDimms->posBottomPod);// - m_triPodDimms->posBottomPodTractorConnector; /*Vec3 moveTop = Vec3(actorTopPos.x, actorTopPos.y, actorTopPos.z) - m_vehicle->getVehicleController()->getBackJointPoint(); Vec3 moveBottom = Vec3(actorBottomPos.x, actorBottomPos.y, actorBottomPos.z) - m_vehicle->getVehicleController()->getBackJointPoint();*/ /*m_actorTop->setGlobalPosition(m_actorTop->getGlobalPosition() + NxVec3(moveTop)); m_actorBottom->setGlobalPosition(m_actorBottom->getGlobalPosition() + NxVec3(moveBottom));*/ m_actorTop->setGlobalPosition(NxVec3(newPosTop)); m_actorBottom->setGlobalPosition(NxVec3(newPosBottom)); NxRevoluteJointDesc revDescTop; revDescTop.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescTop.actor[1] = m_actorTop; revDescTop.localNormal[0] = NxVec3(0, 1, 0); revDescTop.localNormal[1] = NxVec3(0, 1, 0); revDescTop.limit.high.value = highLimit; revDescTop.limit.low.value = lowLimit; revDescTop.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescTop.setGlobalAnchor(NxVec3(moveTop)); //Reference point that the axis passes through. revDescTop.projectionMode = NX_JPM_POINT_MINDIST; revDescTop.projectionDistance = 0.1f; revDescTop.motor = *m_jointMotorTop; revDescTop.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointTop = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescTop); /*NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom)); //Reference point that the axis passes through. revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; //m_jointBottom = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom);*/ Vec3 leftPos = Vec3(0, 0, m_triPodDimms->width/2); Mat temp; m_actorTop->getGlobalPose().getColumnMajor44((NxF32*)&temp); temp._41 = 0; temp._42 = 0; temp._43 = 0; D3DXVec3TransformCoord(&leftPos, &leftPos, &temp); NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom + leftPos)); //Reference point that the axis passes through. revDescBottom.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom.projectionDistance = 0.1f; revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomLeft = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom); NxRevoluteJointDesc revDescBottom1; revDescBottom1.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom1.actor[1] = m_actorBottom; revDescBottom1.localNormal[0] = NxVec3(0, 1, 0); revDescBottom1.localNormal[1] = NxVec3(0, 1, 0); revDescBottom1.setGlobalAxis(NxVec3(0, 0, 1)); //The direction of the axis the bodies revolve around. revDescBottom1.setGlobalAnchor(NxVec3(moveBottom - leftPos)); revDescBottom1.limit.high.value = highLimit; revDescBottom1.limit.low.value = lowLimit; revDescBottom1.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom1.projectionDistance = 0.1f; revDescBottom1.motor = *m_jointMotorBottom; revDescBottom1.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomRight = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom1); } else { Vec3 switchVec; switchVec = m_triPodDimms->posBottomPodDeviceConnector; m_triPodDimms->posBottomPodDeviceConnector = m_triPodDimms->posBottomPodTractorConnector; m_triPodDimms->posBottomPodTractorConnector = switchVec; switchVec = m_triPodDimms->posTopPodDeviceConnector; m_triPodDimms->posTopPodDeviceConnector = m_triPodDimms->posTopPodTractorConnector; m_triPodDimms->posTopPodTractorConnector = switchVec; float highLimit = D3DX_PI * 0.12f; float lowLimit = D3DX_PI * -0.1f; m_jointMotorTop = new NxMotorDesc(0, NX_MAX_REAL, 0); m_jointMotorBottom = new NxMotorDesc(0, NX_MAX_REAL, 0); Vec3 newPosTop = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posTopPod) - m_triPodDimms->posTopPodTractorConnector; Vec3 newPosBottom = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posBottomPod) - m_triPodDimms->posBottomPodTractorConnector; Vec3 moveTop = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posTopPod);// - m_triPodDimms->posTopPodTractorConnector; Vec3 moveBottom = m_vehicle->getVehicleController()->getFrontJointPoint() + (m_triPodDimms->posBottomPod);// - m_triPodDimms->posBottomPodTractorConnector; /*Vec3 moveTop = Vec3(actorTopPos.x, actorTopPos.y, actorTopPos.z) - m_vehicle->getVehicleController()->getBackJointPoint(); Vec3 moveBottom = Vec3(actorBottomPos.x, actorBottomPos.y, actorBottomPos.z) - m_vehicle->getVehicleController()->getBackJointPoint();*/ /*m_actorTop->setGlobalPosition(m_actorTop->getGlobalPosition() + NxVec3(moveTop)); m_actorBottom->setGlobalPosition(m_actorBottom->getGlobalPosition() + NxVec3(moveBottom));*/ m_actorTop->setGlobalPosition(NxVec3(newPosTop)); m_actorBottom->setGlobalPosition(NxVec3(newPosBottom)); NxRevoluteJointDesc revDescTop; revDescTop.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescTop.actor[1] = m_actorTop; revDescTop.localNormal[0] = NxVec3(0, 1, 0); revDescTop.localNormal[1] = NxVec3(0, 1, 0); revDescTop.limit.high.value = highLimit; revDescTop.limit.low.value = lowLimit; revDescTop.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescTop.setGlobalAnchor(NxVec3(moveTop)); //Reference point that the axis passes through. revDescTop.projectionMode = NX_JPM_POINT_MINDIST; revDescTop.projectionDistance = 0.1f; revDescTop.motor = *m_jointMotorTop; revDescTop.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointTop = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescTop); Vec3 leftPos = Vec3(0, 0, m_triPodDimms->width/2); Mat temp; m_actorTop->getGlobalPose().getColumnMajor44((NxF32*)&temp); temp._41 = 0; temp._42 = 0; temp._43 = 0; D3DXVec3TransformCoord(&leftPos, &leftPos, &temp); NxRevoluteJointDesc revDescBottom; revDescBottom.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom.actor[1] = m_actorBottom; revDescBottom.localNormal[0] = NxVec3(0, 1, 0); revDescBottom.localNormal[1] = NxVec3(0, 1, 0); revDescBottom.limit.high.value = highLimit; revDescBottom.limit.low.value = lowLimit; revDescBottom.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescBottom.setGlobalAnchor(NxVec3(moveBottom + leftPos)); //Reference point that the axis passes through. revDescBottom.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom.projectionDistance = 0.1f; revDescBottom.motor = *m_jointMotorBottom; revDescBottom.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomLeft = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom); NxRevoluteJointDesc revDescBottom1; revDescBottom1.actor[0] = m_vehicle->getVehicleController()->getActor(); revDescBottom1.actor[1] = m_actorBottom; revDescBottom1.localNormal[0] = NxVec3(0, 1, 0); revDescBottom1.localNormal[1] = NxVec3(0, 1, 0); revDescBottom1.setGlobalAxis(NxVec3(0, 0, -1)); //The direction of the axis the bodies revolve around. revDescBottom1.setGlobalAnchor(NxVec3(moveBottom - leftPos)); revDescBottom1.limit.high.value = highLimit; revDescBottom1.limit.low.value = lowLimit; revDescBottom1.projectionMode = NX_JPM_POINT_MINDIST; revDescBottom1.projectionDistance = 0.1f; revDescBottom1.motor = *m_jointMotorBottom; revDescBottom1.flags |= NX_RJF_MOTOR_ENABLED | NX_RJF_LIMIT_ENABLED; m_jointBottomRight = (NxRevoluteJoint*)core.dynamics->getScene()->createJoint(revDescBottom1); } lift(); update(); }