NxActor* CreateTrike(const NxVec3& pos) { NxActor* actor = CreateBox(pos + NxVec3(0,0.5,0), NxVec3(2,0.25,0.75), 10); NxTireFunctionDesc lngTFD; lngTFD.extremumSlip = 1.0f; lngTFD.extremumValue = 0.02f; lngTFD.asymptoteSlip = 2.0f; lngTFD.asymptoteValue = 0.01f; lngTFD.stiffnessFactor = 1000000.0f; NxTireFunctionDesc latTFD; latTFD.extremumSlip = 1.0f; latTFD.extremumValue = 0.02f; latTFD.asymptoteSlip = 2.0f; latTFD.asymptoteValue = 0.01f; latTFD.stiffnessFactor = 1000000.0f; NxTireFunctionDesc slipTFD; slipTFD.extremumSlip = 1.0f; slipTFD.extremumValue = 0.02f; slipTFD.asymptoteSlip = 2.0f; slipTFD.asymptoteValue = 0.01f; slipTFD.stiffnessFactor = 100.0f; // Front wheel NxWheelDesc wheelDesc; wheelDesc.wheelApproximation = 10; wheelDesc.wheelRadius = 0.5; wheelDesc.wheelWidth = 0.3; // 0.1 wheelDesc.wheelSuspension = 1.0; wheelDesc.springRestitution = 100; wheelDesc.springDamping = 0.5; wheelDesc.springBias = 0; wheelDesc.maxBrakeForce = 1; wheelDesc.position = NxVec3(2.5,0.5,0); wheelDesc.wheelFlags = NX_WF_USE_WHEELSHAPE | NX_WF_BUILD_LOWER_HALF | NX_WF_ACCELERATED | NX_WF_AFFECTED_BY_HANDBRAKE | NX_WF_STEERABLE_INPUT; wheel1 = AddWheelToActor(actor, &wheelDesc); // Rear left wheel NxWheelDesc wheelDesc2; wheelDesc2.wheelApproximation = 10; wheelDesc2.wheelRadius = 0.5; wheelDesc2.wheelWidth = 0.3; // 0.1 wheelDesc2.wheelSuspension = 1.0; wheelDesc2.springRestitution = 100; wheelDesc2.springDamping = 0.5; wheelDesc2.springBias = 0; wheelDesc2.maxBrakeForce = 1; wheelDesc2.position = NxVec3(-1.5,0.5,-1); wheelDesc2.wheelFlags = NX_WF_USE_WHEELSHAPE | NX_WF_BUILD_LOWER_HALF | NX_WF_ACCELERATED | NX_WF_AFFECTED_BY_HANDBRAKE | NX_WF_STEERABLE_INPUT; wheel2 = AddWheelToActor(actor, &wheelDesc2); // Rear right wheel NxWheelDesc wheelDesc3; wheelDesc3.wheelApproximation = 10; wheelDesc3.wheelRadius = 0.5; wheelDesc3.wheelWidth = 0.3; // 0.1 wheelDesc3.wheelSuspension = 1.0; wheelDesc3.springRestitution = 100; wheelDesc3.springDamping = 0.5; wheelDesc3.springBias = 0; wheelDesc3.maxBrakeForce = 1; wheelDesc3.position = NxVec3(-1.5,0.5,1); wheelDesc3.wheelFlags = NX_WF_USE_WHEELSHAPE | NX_WF_BUILD_LOWER_HALF | NX_WF_ACCELERATED | NX_WF_AFFECTED_BY_HANDBRAKE | NX_WF_STEERABLE_INPUT; wheel3 = AddWheelToActor(actor, &wheelDesc3); // LOWER THE CENTER OF MASS NxVec3 massPos = actor->getCMassLocalPosition(); massPos.y -= 1; actor->setCMassOffsetLocalPosition(massPos); return actor; }
void NxRobot::cloneRobot(int indexNewScene, int indexNewRobot, NxVec3 newPosition, int indexNewTeam) { NxRobot* nxRobotSource = Simulation::gScenes[this->indexScene]->allRobots->getRobotByIdByTeam(this->id, this->idTeam); NxActor* robotActor = Simulation::cloneActor(nxRobotSource->getActor(),indexNewScene); //NxBounds3 bodyBounds; //robotShapes[0]->getWorldBounds(bodyBounds); NxVehicleDesc vehicleDesc; vehicleDesc.position = NxVec3(robotActor->getGlobalPosition()); vehicleDesc.mass = robotActor->getMass(); //vehicleDesc.motorForce = 70000; //vehicleDesc.maxVelocity = 300.f; //vehicleDesc.cameraDistance = 8.0f; vehicleDesc.centerOfMass.set(robotActor->getCMassLocalPosition()); //vehicleDesc.differentialRatio = 3.42f; //vehicleDesc.transmissionEfficiency vehicleDesc.actor = robotActor; //Motor descricao //NxVehicleMotorDesc motorsDesc[4]; //for(NxU32 i=0;i<4;i++) //{ //motorsDesc[i].setToCorvette(); //vehicleDesc.motorsDesc.push_back(&motorsDesc[i]); //} //Roda (Wheel) descricao int numberWheels = nxRobotSource->getNbWheels(); NxWheelDesc* wheelDesc = new NxWheelDesc[numberWheels]; for(NxU32 i=0; i<numberWheels; i++) { //NxActor* wheelModel = Simulation::getActorWheel(indexSourceScene,indexNewRobot,i); //NxActorDesc wheelActorDesc; //wheelModel->saveToDesc(wheelActorDesc); //Simulation::gScenes[0]->releaseActor(*wheelModel); //NxShape*const* wheelShapes = actorWheel->getShapes(); //NxBounds3 wheelBounds; //wheelShapes[0]->getWorldBounds(wheelBounds); const NxWheel* wheel = nxRobotSource->getWheel(i); NxWheelShape* wheelShape = ((NxWheel2*)wheel)->getWheelShape(); //wheelDesc[i].wheelApproximation = 10; wheelDesc[i].wheelOrientation = wheelShape->getGlobalOrientation(); wheelDesc[i].position.set(wheelShape->getGlobalPosition()-robotActor->getGlobalPosition()); //wheelDesc[i].position.z = 0; wheelDesc[i].id = i; wheelDesc[i].wheelFlags = ((NxWheel*)wheel)->getWheelFlags(); wheelDesc[i].wheelRadius = wheel->getRadius(); //wheelDesc[i].wheelWidth = 100; wheelDesc[i].wheelSuspension = wheelShape->getSuspensionTravel(); wheelDesc[i].springRestitution = 0; wheelDesc[i].springDamping = 0; wheelDesc[i].springBias = 0.0f; wheelDesc[i].maxBrakeForce = 100; wheelDesc[i].frictionToFront = 0.1f;//0.1f; wheelDesc[i].frictionToSide = 0;//0.02f;// wheelDesc[i].inverseWheelMass = wheelShape->getInverseWheelMass(); //TODO: CONFIGURAR PARÂMETRO //Angulo das Rodas (Omni) wheelDesc[i].angWheelRelRobot = ((NxWheel2*)wheel)->angWheelRelRobot; vehicleDesc.robotWheels.pushBack(&wheelDesc[i]); } //Criar robot, vehicle base NxRobot* robot = (NxRobot*)NxRobot::createVehicle(Simulation::gScenes[indexNewScene], &vehicleDesc); //NxRobot* robot = (NxRobot*)NxRobot::createVehicle(gScenes[indexSourceScene], &vehicleDesc); robot->setId(indexNewRobot); robot->setIdTeam(indexNewTeam); robot->indexScene = indexNewScene; robot->bodyRadius = nxRobotSource->bodyRadius; //Dribbler and Kicker NxShape*const* robotShapes = robotActor->getShapes(); for(int i=0; i<robotActor->getNbShapes(); i++) { const char* shapeName = robotShapes[i]->getName(); if(shapeName) { char* dribblerName = new char[10];//"Driblador\0" dribblerName[9] = 0; memcpy(dribblerName, shapeName, strlen(dribblerName)); if(strcmp(dribblerName, "Driblador") == 0) { robot->dribbler->dribblerShapes.push_back(robotShapes[i]); } delete dribblerName; } } robot->kicker->kickerShapeDesc = new NxBoxShapeDesc(); NxShapeDesc* shapeDesc = nxRobotSource->kicker->kickerShapeDesc; robot->kicker->kickerShapeDesc->localPose = shapeDesc->localPose; ((NxBoxShapeDesc*)(robot->kicker->kickerShapeDesc))->dimensions = ((NxBoxShapeDesc*)shapeDesc)->dimensions; //Initial Pose robot->setInitialPose(robotActor->getGlobalPose()); robotActor->putToSleep(); //Transladando o robo robot->getActor()->setGlobalPosition(newPosition); string label; string plabel = "Robo"; stringstream out; out << indexNewRobot; out << "-"; out << indexNewTeam; //out << "-"; //out << indexNewScene; label.append(plabel); label.append(out.str()); char* arrayLabel = new char[label.size()+1]; arrayLabel[label.size()]=0; memcpy(arrayLabel, label.c_str(), label.size()); robotActor->setName(arrayLabel); //delete arrayLabel; }