Sign in to follow this  
jdub

(PhysX) I have some questions(Still need help)

Recommended Posts

I just started using PhysX for my 2D game. This is a lot more complicated of an API than any I've used in the past so, even with reading the tutorials that come with the SDK I am still slightly confused about a couple things. 1) When I render my actor on screen. I just set it's transform matrix to the corrosponding PhysX Actor's GlobalOrientation matrix. The object just stays at the origin. Even if I set the Global orientation myself.. still nothing happens. 2) What is an actor's GlobalPose? How is it different from Global Orientation? [Edited by - jdub on September 10, 2009 12:41:19 PM]

Share this post


Link to post
Share on other sites
The global orientation is simply the rotation part of the transformation matrix. The global pose includes translation. It is no surprise that the object, at least the center-of-mass position, does not move if you merely apply the orientation. To get it to translate, you need to apply the translation also.

I have a question...when you apply the global orientation, does the object rotate in place at the origin? Is the PhysX value changing? If the PhysX matrix changes but your object doesn't rotate, then I'd say you have a problem with your renderer. If the PhysX matrix doesn't change, then you've set up the PhysX simulation incorrectly.

If you need some background info on physics simulation, which might help work through the meaning behind some of the PhysX API features, then I'd highly recommend the essential math tutorials. You can find a link in the sticky thread at the top of the forum list, the thread that lists physics engines and reference material. Look for "essential math".

Share this post


Link to post
Share on other sites
Well.. I think I set the simulation up because When I change GlobalPose and the later, render an actor on screen with that transform, it shows up where I want it to. However, for some reason I cannot apply forces to actors. Whenever I try to do that the actor doesnt move and just stays in the same place. Here is the code for physics initiallization actor creation (It's in C#. I am using the PhysX.Net wrapper. However the code should be very similar):



private void createPhysics( )
{
core = new Core(); //core is the same as NXPhysicsSDK

SceneDescription sceneDesc = new SceneDescription();
sceneDesc.SimulationType = SimulationType.Hardware;

if (!sceneDesc.IsValid())
throw new Exception();

scene = core.CreateScene( sceneDesc );

core.SetParameter( PhysicsParameter.SkinWidth, 0.01f );

if (!createMaterial())
throw new Exception();

if (!createSquare())
throw new Exception();
}

bool createSquare( )
{
ActorDescription actorDesc = new ActorDescription();

BoxShapeDescription boxDesc = new BoxShapeDescription() ;
boxDesc.Dimensions = new Vector3( 200, 200, 1 );
boxDesc.Material = scene.Materials[1];

if (!boxDesc.IsValid())
{
return false;
}

actorDesc.Shapes.Add( boxDesc );
actorDesc.BodyDescription = null;
actorDesc.Density = 1.0f;
actorDesc.GlobalPose = Matrix.AffineTransformation2D( 1f, Vector2.Zero, 0f, new Vector2( 20, 20 ) );

if (!actorDesc.IsValid())
{
return false;
}

squareActor = scene.CreateActor( actorDesc );

return true;
}

bool createMaterial( )
{
MaterialDescription matDesc = new MaterialDescription();
matDesc.DynamicFriction = 0.5f;
matDesc.Restitution = 0.5f;
matDesc.StaticFriction = 0.5f;
matDesc.Name = "Default Game Material";
if (!matDesc.IsValid())
{
return false;
}

scene.CreateMaterial( matDesc );
return true;
}

Share this post


Link to post
Share on other sites
I think you need to fill in the BodyDescription otherwise the actor will be 'kinematic' which means it does not have any dynamic properties and only really interacts with the collision detection part of the physics engine, for all other purposes the actor will appears to have infinite mass (which also means you cannot apply a force large enough to move such an actor).

Share this post


Link to post
Share on other sites
I got the same problem with you, I just set the actor's global Orientation matrix, nothing happens too. How did you solve this problem finally?
This question is come from integrate PhysX's SampleRaycastCar into Trinigy Vision Engine application(the coordinate systems of these two platforms are difference; PhysX with Y up and Trinigy with Z up)
But, These codes perform good:

NxVec3 pos = getActor()->getGlobalPosition() + NxVec3(0,0,20);
rot.fromAngleAxis(90, NxVec3(1,0,0));
getActor()->setGlobalPosition(pos);
getActor()->setGlobalOrientationQuat(rot);
getActor()->setLinearVelocity(NxVec3(0,0,0));
getActor()->setAngularVelocity(NxVec3(0,0,0));

Quote:
Original post by jdub
I just started using PhysX for my 2D game. This is a lot more complicated of an API than any I've used in the past so, even with reading the tutorials that come with the SDK I am still slightly confused about a couple things.

1) When I render my actor on screen. I just set it's transform matrix to the corrosponding PhysX Actor's GlobalOrientation matrix. The object just stays at the origin. Even if I set the Global orientation myself.. still nothing happens.

2) What is an actor's GlobalPose? How is it different from Global Orientation?


Share this post


Link to post
Share on other sites
Quote:
Original post by cbirkhold
I think you need to fill in the BodyDescription otherwise the actor will be 'kinematic' which means it does not have any dynamic properties and only really interacts with the collision detection part of the physics engine, for all other purposes the actor will appears to have infinite mass (which also means you cannot apply a force large enough to move such an actor).


I agree. If I recall correctly, unless actorDesc.BodyDescription is non-NULL, PhysX will treat the actor as a kinematic actor, which by definition does not respond to forces. So, the code should in this case be:


actorDesc.BodyDescription = &boxDesc;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this