• Create Account

## Correct Positive Rotation Directions

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #1Stephany  Members

166
Like
0Likes
Like

Posted 27 July 2014 - 01:54 PM

I'm having some trouble understanding the "correct" direction to rotate in 3D for a positive angle on each axis. Some of this may come down to convention (?), and if so, I suppose I'm asking for opinions rather than facts.

In my game world, Y=up, Z=forward, and X=right. I'm in the middle of writing some matrix-rotation functions that use sin()/cos() to spin their vectors around each specific axis (such as RotateX(float angle), etc). I'm currently relying on DirectX (using D3DXQuaternionRotationAxis() on an ID-quaternion with specific hardcoded axes, then examining the result) to determine which way to spin a positive angle around each axis. This is what I've extracted from that:

Positive rotation of 90 degrees on each axis: (rotation concept for a car in parenthesis, for mental image)

X-axis: changes Z+ to Y- (car goes down hill, forward)

Y-axis: changes Z+ to X+ (car goes around a turn to the right)

Z-axis: changes X+ to Y- (car rolls, facing driver-side toward the ground)

For some reason, the X and Y axis rotations "feel right" to me, but the Z axis feels backwards. The Y rotation feels clockwise (?) while Z feels counter-clockwise (I guess the concept of clockwise is a 2D notion?). Is it just me? Is there a reason this axis rotates in that specific direction? Is this the logical way math plays out when working with quaternions, or was it a decision made by Microsoft? Judging by my own quaternion math (which is still in its infancy), I would say it just works out that way, but I can't really rely on it being accurate at the moment.

I'm asking this question in the Graphics forum because that's what my math library will be used for. The proper math angles don't concern me as much as what will work best when rotating 3D objects. In the end, these may both be the same, but I'm not in the place to know yet.

Thanks a bunch for any advice.

Edited by Stephany, 27 July 2014 - 02:03 PM.

### #2Stephany  Members

166
Like
0Likes
Like

Posted 28 July 2014 - 07:27 PM

Another note to add is that, when writing the functions to rotate on the X and Z axes, I seem to have to negate the scaler angle sent to cos() and sin() for the rotation to match a normal axis rotation. Is this normal, or am I simply doing everything else backwards?

Thanks for any help!

### #3L. Spiro  Members

24827
Like
0Likes
Like

Posted 28 July 2014 - 09:59 PM

car rolls, facing driver-side toward the ground

That’s about as ambiguous as you can get.
“Which way should it rotate?”
“So the driver’s side goes to the ground before the passenger’s side.”
“Okay, so…which way should it rotate?”
The driver’s side in what country? America? England? In other words, do they drive on the right side of the road or the wrong left side of the road?  Is the car imported?

I am going to assume this is what you want:

An airplane rotating around positive Z will lift its left wing and lower its right wing (and if physics ensue it will veer off to the right).

This is a standard left-handed coordinate system.

Direct3D claims to default to left-handed coordinate systems, yet their functions such as D3DXMatrixRotationYawPitchRoll() are right-handed.

Likewise, D3DXQuaternionRotationAxis() rotates clockwise around each axis as if you were looking from a positive value along the axis towards the origin, which is basically a long-winded way of saying it is right-handed.  If you start at X = 1 and look towards X = 0, a clockwise rotation would be as you described—tilting the car forward.  Do the same with Y and you get the same result as you described.  With Z you get the opposite of what I described (left wing down).

This applies to D3DXMatrixRotationZ() as well.

All of the above assumes a left-handed coordinate system in which X goes away from you to the right, Y goes away from you up, and Z goes away from you forward.

So you will have to make your own functions or invert the Z axis when you pass it to those types of functions.

Left-handed matrix-rotation functions are readily available online.  I have never searched but no doubt there are some for quaternions as well.

L. Spiro

Edited by L. Spiro, 28 July 2014 - 11:19 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.