Jump to content
  • Advertisement
Sign in to follow this  

PhysX: Rotate a box

This topic is 2968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Everyone! This is my first post, I hope you can help me.

I'm working with PhysX and I need to rotate a Box (in the game, it's a wall).

We create the box this way:

// Descripción de la caja.
NxBoxShapeDesc boxDesc;
boxDesc.dimensions.set(dim.x, dim.y, dim.z);
boxDesc.localPose.t = NxVec3(0.0f,0.0f,0.0f);//(pos.x, pos.y, pos.z);

NxActorDesc actorDesc;
actorDesc.globalPose.t = NxVec3(pos.x, pos.y,pos.z);//(0.0f,0.0f,0.0f);

//This is because it's a kinematic wall
NxBodyDesc bodyDesc;
bodyDesc.mass = 100.0f;
bodyDesc.massSpaceInertia = NxVec3(1.0f, 1.0f, 1.0f);

The thing is I need to rotate the box in Y axis (30 degrees, for example) and I don't know what code do I need to write and where.

Thank you!

Share this post

Link to post
Share on other sites
When you say you need to rotate the box, I assume that you mean you want to set it's initial rotation! (The physics simulation would compute its movement/rotation/whatever once you start simulating.) Is this correct? If so, then you can do this via the *Pose variables you assign to the shape and to the actor during initialization. You have set boxDesc.localPose.t and actorDesc.globalPose.t. There are also *Pose.M, where M (I think) represents the rotation matrix. You must set the M to get the box to be initially rotated. (I believe there are also helper functions, such as *Pose.rotate*() to help you build M without having to set it directly.

Note that the *localPose stuff in the shapes is used to build up the collision shapes of the rigid body, while the *globalPose stuff in the actor itself orients that body. The idea here is, perhaps you have some shape that resembles multiple boxes, or perhaps boxes and other shapes, which you want to move together. You could use the *localPose of each shape to put them together relative to each other, as you want them to remain for the entire simulation. If, on the other hand, your actor is simply box-shaped, then you'd probably want to leave *localPose as is, without touching M, and just do your initial rotation within actorDesc.globalPose.M. An easier way to think about this, maybe, is that *globalPose represents the initial position/orientation of an arbitrary rigid body object in the world, then *localPose defines the fixed rigid shape of that object.

I hope that helps!

Share this post

Link to post
Share on other sites
The boxes are invisibles walls. The game it's a beat'em up and we use them to lock the avatar until it's defeat all the enemies.

I'm going to try again. Thank you!

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!