本文整理汇总了C++中NxActor::getGlobalPose方法的典型用法代码示例。如果您正苦于以下问题:C++ NxActor::getGlobalPose方法的具体用法?C++ NxActor::getGlobalPose怎么用?C++ NxActor::getGlobalPose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NxActor
的用法示例。
在下文中一共展示了NxActor::getGlobalPose方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle
virtual bool handle( const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa)
{
osgViewer::Viewer *viewer=dynamic_cast<osgViewer::Viewer*>(&aa);
if(!viewer) return false;
switch(ea.getEventType())
{
case osgGA::GUIEventAdapter::FRAME:
{
//printf("Time %f\n",ea.getTime());
gMyPhysX.simulate(1.0f/60.0f);
int nbActors = gMyPhysX.getScene()->getNbActors();
NxActor** actors = gMyPhysX.getScene()->getActors();
//int userdateNum = 0;
while(nbActors--)
{
NxActor* actor = *actors++;
if(!actor->userData) continue;
osg::MatrixTransform *mt = static_cast<osg::MatrixTransform*>(actor->userData);
if (mt)
{
float glmat[16];
actor->getGlobalPose().getColumnMajor44(glmat);//得到角色的世界位置
osg::Matrix mat;
mat.set(glmat);
mt->setMatrix(mat);
//userdateNum+=1;
//printf("userdateNum = %d\n",userdateNum);
}
}
return false;
}
case(osgGA::GUIEventAdapter::KEYDOWN):
{
if(ea.getKey()=='w'||ea.getKey()=='W')
{
CreateCubeFromEye(2,viewer->getCamera());
}
return false;
}
default:
return false;
}
}
示例2: PhysUpdate
void PhysUpdate ( void )
{
int iObject = 1;
// Render all the actors in the scene
int nbActors = gScene->getNbActors();
NxActor** actors = gScene->getActors();
while (nbActors--)
{
NxActor* actor = *actors++;
// Get an OpenGL transform (float[16]) from a Novodex shape’s global pose
// (NxMat34)
NxShape* shape = NULL;
NxMat34 pose = actor->getGlobalPose();
NxMat33 orient = pose.M;
NxVec3 pos = pose.t;
float glmat[16]; // 4x4 column major OpenGL matrix
orient.getColumnMajorStride4(&(glmat[0]));
pos.get(&(glmat[12]));
// clear the elements we don't need:
glmat[3] = glmat[7] = glmat[11] = 0.0f;
glmat[15] = 1.0f;
{
sPhysObject* pPhys = ( sPhysObject* ) actor->userData;
if ( pPhys )
{
SetWorldMatrix ( pPhys->iID, ( D3DXMATRIX* ) &glmat );
sObject* pObject = dbGetObject ( pPhys->iID );
pObject->position.vecPosition = D3DXVECTOR3 ( glmat [ 12 ], glmat [ 13 ], glmat [ 14 ] );
}
}
}
}
示例3: render
void render()
{
static Timer t;
if(gScene && !gPauseSimulation) //start the simulation
{
gTouchedTris.clear();
gScene->simulate(t.elapsed_time());
//printf("%f\n",t.elapsed_time());
t.reset();
gScene->flushStream();
/*ASYNC: in here we can do computations which depend only on the old
state of the scene "actors". Writing to the scene is not allowed.
Write calls in here are skipped.
*/
gScene->fetchResults(NX_RIGID_BODY_FINISHED,true);
}
// Clear buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor4f(0.0,1.0,1.0,1.0);
DrawSkyBox(5000.0f);
//drawPlane(2000.0);
//Render all actors
int nbActors = gScene->getNbActors();
NxActor** actors = gScene->getActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if(!actor->userData) continue;
// Render actor
glPushMatrix();
float glMat[16];
actor->getGlobalPose().getColumnMajor44(glMat);
glMultMatrixf(glMat);
NxVec3 color = static_cast<UserData*>(actor->userData)->color;
glColor4f(color.x,color.y,color.z,1.0f);
glutSolidCube((static_cast<UserData*>(actor->userData)->size)*2.0f);
glPopMatrix();
}
RenderTerrain();
}
示例4: render
void Part::render()
{
assert(act && "partrender: physics equivalent invalid");
glPushMatrix();
float glMat[16];
NxActor* actor;
actor=act;
if(NULL==actor) return;
actor->getGlobalPose().getColumnMajor44(glMat);
glMultMatrixf(glMat);
if(actor->userData!=NULL && gRenderUserData) {
glPushMatrix();
((GraphicsObject*)actor->userData)->render();
glPopMatrix();
}
else {
//render according to shape descriptions in actor
for(unsigned s=0; s < actor->getNbShapes(); s++) {
NxShape *shape = actor->getShapes()[s];
glPushMatrix();
shape->getLocalPose().getColumnMajor44(glMat);
glMultMatrixf(glMat);
//render shapes
if(shape->getFlag(NX_TRIGGER_ENABLE)) {
//do nothing, triggers are not to be rendered and have different userdata
}
else if(shape->userData!=NULL) {
((GraphicsObject*)shape->userData)->render();
}
else {
NxShapeType type=shape->getType();
if(NX_SHAPE_BOX==type) {
NxBoxShape *sh=(NxBoxShape *)shape;
NxVec3 dim=sh->getDimensions();
BoxGraphicsObject g(dim.x,dim.z,dim.y); //wrond dimensions
g.render();
}
else if(NX_SHAPE_CAPSULE==type) {
NxCapsuleShape *sh=(NxCapsuleShape *)shape;
float radius=sh->getRadius();
float height=sh->getHeight();
CapsuleGraphicsObject g(radius,height);
g.render();
}
else if(NX_SHAPE_SPHERE==type) {
NxSphereShape *sh=(NxSphereShape *)shape;
float radius=sh->getRadius();
SphereGraphicsObject g(radius);
g.render();
}
else {
//render a default sphere if shape type unknown
SphereGraphicsObject sg(1);
sg.render();
}
}
glPopMatrix();
}
}
glPopMatrix();
}
示例5: glutDisplay
//.........这里部分代码省略.........
glPushMatrix();
glColor3d(0.0, 0.0, 1.0);
glRasterPos3d(GL_WIN_SIZE_X/2-60, GL_WIN_SIZE_Y/2+20, 0.0);
drawBitmapString(GLUT_BITMAP_HELVETICA_18,"GAME OVER");
glPopMatrix();
glPushMatrix();
glColor3d(1.0, 1.0, 0.0);
glRasterPos3d(GL_WIN_SIZE_X/2-65, GL_WIN_SIZE_Y/2, 0.0);
drawBitmapString(GLUT_BITMAP_HELVETICA_18,gametime);
glPopMatrix();
glPushMatrix();
glColor3d(1.0, 0.0, 0.0);
glRasterPos3d(GL_WIN_SIZE_X/2-90, GL_WIN_SIZE_Y/2-20, 0.0);
drawBitmapString(GLUT_BITMAP_HELVETICA_18,"Push 'r' -> RESTART");
glPopMatrix();
printf("GAME OVER\ntime -> %f\n",(double)(t2 - t1) / CLOCKS_PER_SEC);
break;
case 2: // ゲーム中の画面
glEnable(GL_DEPTH_TEST);
// アクターの描画
int nbActors = gScene->getNbActors();
NxActor** actors = gScene->getActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if(!actor->userData) continue;
glPushMatrix();
glEnable(GL_LIGHTING);
float glMat[16];
actor->getGlobalPose().getColumnMajor44(glMat);
glMultMatrixf(glMat);
myData* mydata = (myData*)actor->userData;
int shape = mydata->shape;
int color = mydata->color;
switch(shape){
case 1:
glColor4f(0.0f,0.0f,1.0f,1.0f);
if(mydata->houkou==0){
link(pole[0], pole[4]);
}
else if(mydata->houkou==1){
tlink(3000.0,2000.0,6000.0,-3000.0,2000.0,6000.0);
tlink(-3000.0,2000.0,4000.0,-3000.0,2000.0,6000.0);
}
else if(mydata->houkou==2){
ylink(3000.0,2000.0,4000.0,-3000.0,2000.0,4000.0);
ylink(3000.0,2000.0,6000.0,-3000.0,2000.0,6000.0);
}
else if(mydata->houkou==3){ // パネル
glColor4f(0.0f,1.0f,1.0f,1.0f);
cuboid(mydata->width*2,mydata->length*2, mydata->height*2);
}
else if(mydata->houkou==4){
}
break;
case 2:
if(mydata->ball == 1){
glColor4f(1.0f,0.0f,0.0f,1.0f); // ボールの色
glutSolidSphere(mydata->size,15,15);
}
else if(mydata->ball == 0){
示例6: ICreateController
void plPXPhysicalControllerCore::ICreateController(const hsPoint3& pos)
{
NxScene* scene = plSimulationMgr::GetInstance()->GetScene(fWorldKey);
NxCapsuleControllerDesc desc;
desc.position.x = pos.fX;
desc.position.y = pos.fY;
desc.position.z = pos.fZ;
desc.upDirection = NX_Z;
desc.slopeLimit = kSLOPELIMIT;
desc.skinWidth = kPhysxSkinWidth;
desc.stepOffset = STEP_OFFSET;
desc.callback = &gMyReport;
desc.userData = this;
desc.radius = fRadius;
desc.height = fHeight;
desc.interactionFlag = NXIF_INTERACTION_EXCLUDE;
//desc.interactionFlag = NXIF_INTERACTION_INCLUDE;
fController = (NxCapsuleController*)gControllerMgr.createController(scene, desc);
// Change the avatars shape groups. The avatar doesn't actually use these when
// it's determining collision, but if you're standing still and an object runs
// into you, it'll pass through without this.
NxActor* actor = fController->getActor();
NxShape* shape = actor->getShapes()[0];
shape->setGroup(plSimDefs::kGroupAvatar);
// need to create the non-bouncing object that can be used to trigger things while the avatar is doing behaviors.
NxActorDesc actorDesc;
NxCapsuleShapeDesc capDesc;
capDesc.radius = fRadius;
capDesc.height = fHeight;
capDesc.group = plSimDefs::kGroupAvatar;
actorDesc.shapes.pushBack(&capDesc);
capDesc.materialIndex= plSimulationMgr::GetInstance()->GetMaterialIdx(scene, 0.0,0.0);
actorDesc.globalPose=actor->getGlobalPose();
NxBodyDesc bodyDesc;
bodyDesc.mass = kAvatarMass;
actorDesc.body = &bodyDesc;
bodyDesc.flags = NX_BF_KINEMATIC;
bodyDesc.flags |=NX_BF_DISABLE_GRAVITY ;
actorDesc.name = "AvatarTriggerKinematicGuy";
fSeeking=false;
try
{
fKinematicActor = scene->createActor(actorDesc);
}
catch (...)
{
hsAssert(false, "Actor creation crashed");
}
// set the matrix to be the same as the controller's actor... that should orient it to be the same
//fKinematicActor->setGlobalPose(actor->getGlobalPose());
// the proxy for the debug display
//hsAssert(!fProxyGen, "Already have proxy gen, double read?");
hsColorRGBA physColor;
float opac = 1.0f;
// local avatar is light purple and transparent
physColor.Set(.2f, .1f, .2f, 1.f);
opac = 0.8f;
/*
// the avatar proxy doesn't seem to work... not sure why?
fProxyGen = new plPhysicalProxy(hsColorRGBA().Set(0,0,0,1.f), physColor, opac);
fProxyGen->Init(this);
*/
}
示例7: RenderCallback
static void RenderCallback()
{
/*
static DWORD PreviousTime = 0;
DWORD CurrentTime = getTime();
DWORD ElapsedTime = CurrentTime - PreviousTime;
PreviousTime = CurrentTime;
*/
// Physics code
if(!gPause)
{
NxU32 i;
//this is an example of allowing two scenes to run in parallell if the implementation supports it:
for(i=0;i<2;i++)
{
if(gScenes[i])
{
gScenes[i]->simulate(1.0f/60.0f); //Note: a real application would compute and pass the elapsed time here.
gScenes[i]->flushStream();
}
}
for(i=0;i<2;i++)
{
if(gScenes[i])
{
gScenes[i]->fetchResults(NX_RIGID_BODY_FINISHED, true);
}
}
}
// ~Physics code
// Clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Setup camera
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (float)glutGet(GLUT_WINDOW_WIDTH)/(float)glutGet(GLUT_WINDOW_HEIGHT), 1.0f, 10000.0f);
gluLookAt(Eye.x, Eye.y, Eye.z, Eye.x + Dir.x, Eye.y + Dir.y, Eye.z + Dir.z, 0.0f, 1.0f, 0.0f);
// Keep physics & graphics in sync
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
for(NxU32 i=0;i<2;i++)
{
int nbActors = gScenes[i]->getNbActors();
NxActor** actors = gScenes[i]->getActors();
while(nbActors--)
{
NxActor* actor = *actors++;
glPushMatrix();
float glmat[16];
actor->getGlobalPose().getColumnMajor44(glmat);
glMultMatrixf(glmat);
if(i==0) glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
else glColor4f(0.5f, 0.5f, 0.5f, 1.0f);
glutSolidCube(float(int(actor->userData))*2.0f);
glPopMatrix();
// Handle shadows
if(gShadows)
{
glPushMatrix();
const static float ShadowMat[]={ 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 };
glMultMatrixf(ShadowMat);
glMultMatrixf(glmat);
glDisable(GL_LIGHTING);
glColor4f(0.3f, 0.2f, 0.3f, 1.0f);
glutSolidCube(float(int(actor->userData))*2.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_LIGHTING);
glPopMatrix();
}
}
}
#ifdef __PPCGEKKO__
char buf[256];
sprintf(buf,
"\nPress the keys 1,2,+,-, and b to create various things.\nThe object will appear in randomly in one of two scenes.\n"
"\nUse the arrow keys to move around."
"\nPress a to pause the simulation.\n" );
GLFontRenderer::setScreenResolution(glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT));
GLFontRenderer::setColor(0.9f, 1.0f, 0.0f, 1.0f);
GLFontRenderer::print(0.01, 0.9, 0.036, buf, false, 11, true);
#endif
glutSwapBuffers();
}
示例8: Tick
void FPxSceneMain::Tick( FLOAT DeltaTime )
{
pxguard(FPxSceneMain::Tick);
if( mScene )
{
//mCharManager->updateControllers();
//
// Kinematic actors move unreal actors
//
/*NxActor** actors = mScene->getActors();
int nbActors = mScene->getNbActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if( actor->userData && actor->isDynamic() && actor->readBodyFlag( NX_BF_KINEMATIC ) )
{
AActor* aptr = (AActor*)actor->userData;
// update location and rotation
FCheckResult Hit(1.0f);
NxMat34 m = actor->getGlobalPose();
aptr->GetLevel()->MoveActor( aptr, FVector(0,0,0), ToRotator(m.M), Hit );
aptr->GetLevel()->FarMoveActor( aptr, ToFVS(m.t), 0, 1 );
}
}*/
//
// Unreal actors move kinematic actors
//
/*NxActor** actors = mScene->getActors();
int nbActors = mScene->getNbActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if( actor->userData && actor->isDynamic() && actor->readBodyFlag( NX_BF_KINEMATIC ) )
{
AActor* aptr = (AActor*)actor->userData;
// update location and rotation
NxMat34 m = ToMat34(aptr->Rotation,aptr->Location);
actor->setGlobalPose(m);
}
}*/
//
// Dynamic actors move unreal actors
//
NxActor** actors = mScene->getActors();
int nbActors = mScene->getNbActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if( actor->userData && actor->isDynamic() && !actor->readBodyFlag( NX_BF_KINEMATIC ) )
{
AActor* aptr = (AActor*)actor->userData;
// update location and rotation
FCheckResult Hit(1.0f);
NxMat34 m = actor->getGlobalPose();
aptr->GetLevel()->FarMoveActor( aptr, ToFVS(m.t) );
aptr->GetLevel()->MoveActor( aptr, FVector(0,0,0), ToRotator(m.M), Hit );
}
}
//
// TODO: optimize timing
//
// Minimum acceptable framerate is 5fps
if( DeltaTime > 0.2f )
{
DeltaTime = 0.2f;
}
mTime += DeltaTime;
while( /*!mSimulating &&*/ mTime >= PX_TIMESTEP )
{
mTime -= PX_TIMESTEP;
mScene->simulate(PX_TIMESTEP);
mScene->flushStream();
mScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
//mSimulating = true;
}
//renderScene();
/*if( mSimulating && mScene->checkResults(NX_RIGID_BODY_FINISHED, false) )
{
mScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
mSimulating = false;
//modifyScene(DeltaTime);
}*/
// get debug info
//.........这里部分代码省略.........
示例9: RenderCallback
static void RenderCallback()
{
if(pScene == NULL) {
#ifdef _DEBUG
std::cout << "pScene == NULL" << std::endl;
#endif //_DEBUG
return;
}
// Start simulation
if (isSimulate) {
pScene->simulate(1.0f/60.0f);
}
// Clear buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
// Setup projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0f, (float)glutGet(GLUT_WINDOW_WIDTH)/(float)glutGet(GLUT_WINDOW_HEIGHT), 1.0f, 10000.0f);
gluLookAt(gEye.x, gEye.y, gEye.z, gEye.x + gDir.x, gEye.y + gDir.y, gEye.z + gDir.z, 0.0f, 1.0f, 0.0f);
// Setup modelview matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// Render all actors
int nbActors = pScene->getNbActors();
NxActor** actors = pScene->getActors();
while(nbActors--)
{
NxActor* actor = *actors++;
if(actor->userData == NULL) {
// draw grid
glBegin(GL_LINES);
int y = 0;
for(int i=-100; i<=100; ++i) {
glVertex3f(i*10,y,-1000);
glVertex3f(i*10,y,1000);
glVertex3f(1000,y,i*10);
glVertex3f(-1000,y,i*10);
}
glEnd();
}
// Render actor
glPushMatrix();
float glMat[16];
actor->getGlobalPose().getColumnMajor44(glMat);
glMultMatrixf(glMat);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glutSolidCube(size_t(actor->userData)*10.0f);
glPopMatrix();
// Render shadow
glPushMatrix();
const static float shadowMat[]= { 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 };
glMultMatrixf(shadowMat);
glMultMatrixf(glMat);
glDisable(GL_LIGHTING);
glColor4f(0.1f, 0.2f, 0.3f, 1.0f);
glutSolidCube(size_t(actor->userData)*10.0f);
glEnable(GL_LIGHTING);
glPopMatrix();
}
// Fetch simulation results
if(isSimulate) {
pScene->flushStream();
pScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
}
glutSwapBuffers();
}
示例10: cloneRobot
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();
//.........这里部分代码省略.........
示例11: buildModelRobot
//.........这里部分代码省略.........
// 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;
}
}
示例12: Render
bool GraphicsClass::Render(float rotation)
{
D3DXMATRIX viewMatrix, projectionMatrix, worldMatrix;
n_scene->simulate(1.0f/60.0f);
// Clear buffers
// Cornflower blue #6495ED :)
//m_D3D->BeginScene(100.0f/255.0f, 149.0f/255.0f, 237.0f/255.0f, 1.0f);
m_D3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
// move it from here!!
// this calculates the ViewMatrix!
m_Camera->Render();
m_Camera->GetViewMatrix(viewMatrix);
m_D3D->GetWorldMatrix(worldMatrix);
m_D3D->GetProjectionMatrix(projectionMatrix);
D3DXMATRIX world_modification;
/*
for(int i = 0; i < m_Models.size(); i++){
world_modification = m_Models[i]->GetWorldTransformationMatrix();
m_Models[i]->Render(m_D3D->GetDeviceContext());
result = m_baseShader->Render(m_D3D->GetDeviceContext(), m_Models[i]->GetIndexCount(), \
worldMatrix * world_modification, viewMatrix, projectionMatrix, m_Models[i]->GetTexture(), m_light->GetDirection(),
m_light->GetDiffuseColor());
if(!result)
{
return false;
}
}
*/
int nb_Actors = n_scene->getNbActors();
NxActor** actors = n_scene->getActors();
while(nb_Actors--)
{
NxActor* actor = *actors++;
if(!actor->userData) continue;
// render current actor
unsigned int model_id = (unsigned int)actor->userData - 1;
NxMat34 w_matrx = actor->getGlobalPose();
w_matrx.getColumnMajor44(world_modification);
m_Models[model_id]->Render(m_D3D->GetDeviceContext());
m_baseShader->Render(m_D3D->GetDeviceContext(), m_Models[model_id]->GetIndexCount(), \
worldMatrix * world_modification, viewMatrix, projectionMatrix, m_Models[model_id]->GetTexture(), m_light->GetDirection(),
m_light->GetDiffuseColor());
}
m_D3D->EndScene();
n_scene->flushStream();
n_scene->fetchResults(NX_RIGID_BODY_FINISHED, true);
return true;
}
示例13: render
void render()
{
static Timer t;
if(!gMyPhysX.isPaused())
{
for (NxU32 i = 0; i < gKinematicActors.size(); i++)
{
NxActor* actor = gKinematicActors[i].actor;
NxVec3 pos = actor->getGlobalPosition();
pos += gKinematicActors[i].vel * 1.f/60.f;
actor->moveGlobalPosition(pos);
}
}
gMyPhysX.simulate(t.elapsed_time());
t.reset();
// Clear buffers
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor4f(0.5,0.9,0.5,1.0);
DrawSkyBox(SKYEXTENTS);
drawPlane(SKYEXTENTS);
// Keep physics & graphics in sync
for (NxU32 pass = 0; pass < 2; pass++) {
int nbActors = gMyPhysX.getScene()->getNbActors();
NxActor** actors = gMyPhysX.getScene()->getActors();
actors += nbActors;
while(nbActors--)
{
NxActor* actor = *--actors;
float size;
bool isTrigger = false;
bool isKinematic = actor->isDynamic() && actor->readBodyFlag(NX_BF_KINEMATIC);
NxVec3 color;
NxF32 alpha = 1;
if (actor->isDynamic()) {
if (actor->readBodyFlag(NX_BF_KINEMATIC)) {
color.set(1,0,0);
} else {
color.set(0,1,0);
}
} else {
color.set(0.2f,0.2f,0.2f);
}
if (*(int *)(&actor->userData) < 0)
{
NxI32 triggerNumber = -(*(NxI32 *)(&actor->userData));
NxI32 triggerIndex = triggerNumber - 1;
// This is our trigger
isTrigger = true;
size = 10.0f;
color.z = gNbTouchedBodies[triggerIndex] > 0.5f ? 1.0f:0.0f;
alpha = 0.5f;
if (pass == 0)
continue;
}
else
{
// This is a normal object
size = float(*(int *)(&actor->userData));
if (pass == 1)
continue;
}
float glmat[16];
glPushMatrix();
actor->getGlobalPose().getColumnMajor44(glmat);
glMultMatrixf(glmat);
glColor4f(color.x, color.y, color.z, 1.0f);
glutSolidCube(size*2.0f);
glPopMatrix();
// Handle shadows
if( !isTrigger)
{
glPushMatrix();
const static float ShadowMat[]={ 1,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,1 };
glMultMatrixf(ShadowMat);
glMultMatrixf(glmat);
glDisable(GL_LIGHTING);
glColor4f(0.1f, 0.2f, 0.3f, 1.0f);
glutSolidCube(size*2.0f);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glEnable(GL_LIGHTING);
glPopMatrix();
}
}
}
}