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; }
void Simulation::buildModelRobot(int indexRobot, int indexScene, int indexTeam) { //Veiculo descricao //Body Descricao NxActor* robotActor = Simulation::getActorRobot(indexScene, indexRobot); //NxBounds3 bodyBounds; //robotShapes[0]->getWorldBounds(bodyBounds); NxVehicleDesc vehicleDesc; vehicleDesc.position = NxVec3(robotActor->getGlobalPosition()); float mass = 5.; vehicleDesc.mass = mass;//robotActor->getMass(); //PLUGIN TAH COM PROBLEMA XML ERRADO //vehicleDesc.motorForce = 70000; //vehicleDesc.maxVelocity = 300.f; //vehicleDesc.cameraDistance = 8.0f; vehicleDesc.centerOfMass.set(NxVec3(0,0,0));//robotActor->getCMassLocalPosition()); //vehicleDesc.differentialRatio = 3.42f; //vehicleDesc.transmissionEfficiency vehicleDesc.actor = robotActor; vehicleDesc.actor->setMaxAngularVelocity(6.2); vehicleDesc.actor->setMass(mass); //TODO: LEVANTAR DAMPING float t = vehicleDesc.actor->getLinearDamping(); float b = vehicleDesc.actor->getAngularDamping(); //vehicleDesc.actor->setAngularDamping(0.5); //vehicleDesc.actor->setLinearDamping(0.5); //TODO: LEVANTAR CMASS E INERTIA TENSOR //vehicleDesc.actor->setCMassOffsetGlobalPosition(NxVec3(0, 0, 0)); NxMat33 inertiaTensor = NxMat33(NxVec3(1294.4362, 3.14502, -66.954), NxVec3(3.14502, 1094.42351, -0.24279), NxVec3(-66.954, -0.24279, 1754.80511)); vehicleDesc.actor->setCMassOffsetLocalPose( NxMat34( inertiaTensor, NxVec3(0,0,0) ) ); //TODO: Diagonalizar inertiaTensor e passar para setMassSpaceInertiaTensor vehicleDesc.actor->setMassSpaceInertiaTensor(/*vehicleDesc.actor->getMassSpaceInertiaTensor()*1000.*/NxVec3(1764.3, 1284.9, 1094.4) ); //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 = Simulation::getNumberWheels(indexScene, indexRobot); NxWheelDesc* wheelDesc = new NxWheelDesc[numberWheels]; for(NxU32 i=0; i<numberWheels; i++) { //NxActor* wheelModel = Simulation::getActorWheel(indexScene,indexRobot,i); //NxActorDesc wheelActorDesc; //wheelModel->saveToDesc(wheelActorDesc); //Simulation::gScenes[0]->releaseActor(*wheelModel); NxActor* actorWheel = Simulation::getActorWheel(indexScene,indexRobot,i);//wheelModel;//Simulation::gScenes[0]->createActor(wheelActorDesc); //NxShape*const* wheelShapes = actorWheel->getShapes(); //NxBounds3 wheelBounds; //wheelShapes[0]->getWorldBounds(wheelBounds); //Para exportar modelo da roda do 3ds Max // NxWhee //wheelDesc[i] //robot1Shapes[0]->isConvexMesh()->getConvexMesh().saveToDesc(convexMesh); //NxWheelShape* wheelShape = (NxWheelShape*)wheel; //NxTriangleMeshDesc meshDesc = *((NxTriangleMeshDesc*)(mesh->userData)); //robot1Shapes[0]->isWheel()-> //wheelDesc[i].wheelApproximation = 10; wheelDesc[i].wheelOrientation = actorWheel->getGlobalOrientation(); wheelDesc[i].position.set(actorWheel->getGlobalPosition()-robotActor->getGlobalPosition()); //wheelDesc[i].position.z = 0; wheelDesc[i].id = i; wheelDesc[i].wheelRadius = 27.6; //wheelDesc[i].wheelWidth = 100; wheelDesc[i].wheelSuspension = 0; wheelDesc[i].springRestitution = 0; wheelDesc[i].springDamping = 0; wheelDesc[i].springBias = 0.0f; wheelDesc[i].maxBrakeForce = 100; wheelDesc[i].frictionToFront = 0.1f;//0.1f; //TODO: CONFIGURAR PARÂMETRO wheelDesc[i].frictionToSide = 0;//0.02f; //TODO: CONFIGURAR PARÂMETRO wheelDesc[i].inverseWheelMass = 0.1; //TODO: CONFIGURAR PARÂMETRO //Angulo das Rodas (Omni) NxVec3 wheelPosRel = actorWheel->getGlobalPosition() - robotActor->getGlobalPosition(); wheelDesc[i].angWheelRelRobot = NxMath::atan2( wheelPosRel.y, wheelPosRel.x ); vehicleDesc.robotWheels.pushBack(&wheelDesc[i]); Simulation::gScenes[indexScene]->scene->releaseActor(*actorWheel); //NxU32 flags = NX_WF_BUILD_LOWER_HALF; wheelDesc[i].wheelFlags = NX_WF_ACCELERATED | NX_WF_AFFECTED_BY_HANDBRAKE | NX_WF_USE_WHEELSHAPE | NX_WF_BUILD_LOWER_HALF;// |/*NX_WF_STEERABLE_INPUT |*/ flags; } //NxBall* teste = Simulation::gScenes[indexScene]->ball; //Criar robot, vehicle base NxRobot* robot = (NxRobot*)NxRobot::createVehicle(Simulation::gScenes[indexScene], &vehicleDesc); if(robot) { robot->setId(indexRobot); robot->setIdTeam(indexTeam); robot->indexScene = indexScene; //Dribbler and Kicker for(int i=0; i<robotActor->getNbShapes(); i++) { NxShape*const* robotShapes = robotActor->getShapes(); const char* shapeName = robotShapes[i]->getName(); if(shapeName) { char* dribblerName = new char[10];//"Driblador\0" dribblerName[9] = 0; memcpy(dribblerName, shapeName, strlen(dribblerName)); char* kickerName = new char[9];//"Chutador\0" kickerName[8] = 0; memcpy(kickerName, shapeName, strlen(kickerName)); if(strcmp(dribblerName, "Driblador") == 0) { robot->dribbler->dribblerShapes.push_back(robotShapes[i]); } else if(strcmp(kickerName, "Chutador") == 0) { robot->kicker->kickerShapeDesc = Simulation::copyShapeDesc(robotShapes[i]); robotActor->releaseShape(*(robotShapes[i])); } delete dribblerName; delete kickerName; } } //Initial Pose robot->setInitialPose(robotActor->getGlobalPose()); robotActor->putToSleep(); //Mudar pose do robo //NxQuat q; //q. //q.fromAngleAxis(180.0f, NxVec3(0.0f, 1.0f, 0.0f)); //robot->getActor()->setGlobalPose(pose); //Release no actor importado do 3ds Max //gScenes[0]->releaseActor(*robotActor); string label; string plabel = "Robo"; stringstream out; out << indexRobot; out << "-"; out << indexTeam; //out << "-"; //out << indexScene; 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; } }