# 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.

## 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.shapes.pushBack(&boxDesc);
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 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 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!

1. 1
2. 2
3. 3
4. 4
Rutin
22
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632933
• Total Posts
3009298
• ### Who's Online (See full list)

There are no registered users currently online

×