Jump to content

  • Log In with Google      Sign In   
  • Create Account


Correct Positive Rotation Directions

  • You cannot reply to this topic
2 replies to this topic

#1 Stephany   Members   -  Reputation: 124

Like
0Likes
Like

Posted Yesterday, 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, Yesterday, 02:03 PM.


Sponsor:

#2 Stephany   Members   -  Reputation: 124

Like
0Likes
Like

Posted Today, 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!



#3 L. Spiro   Crossbones+   -  Reputation: 12300

Like
0Likes
Like

Posted Today, 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.

 

 

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


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums





PARTNERS