Read the position Actor in PhysX

894 views Asked by At

I have a question about PhysX SDK 2.8.1

I'm an actor:

NxActorDesc actorDesc;
NxBodyDesc bodyDesc;
NxSphereShapeDesc sphereDesc;
sphereDesc.radius = 1.5f;
actorDesc.shapes.pushBack(&sphereDesc);
actorDesc.body = &bodyDesc;
actorDesc.density = 10;
actorDesc.globalPose.t = NxVec3(0.0f, 25.0f, 0.0f);
NxActor *dynamicActor = gsc->createActor(actorDesc);

I want the console print out the current position of the actor. How to do it? This below doesn't work:

for (int i = 0; i <= 10; i++) {
    //Step PhysX simulation  
    if (gsc)
        StepPhysX(); 
    NxMat34 pose = dynamicActor->getGlobalPose();
    cout <<pose.t << endl;
}

Specifically depends on my reading the position Y.

1

There are 1 answers

0
James0124 On

std::cout can't take an NxVec3 (which your post.t is).

If you want to print out the global position of your dynamicActor,
you need to print out X, Y, Z components of your NxVec3 variable separately.

NxVec3 trans = dynamicActor->getGlobalPose().t;  // or you could use "dynamicActor->getGlobalPosition()"

std::cout << trans.x << ", " << trans.y << ", " << trans.z << std::endl;