Sign in to follow this  
ex9

Cube Rotation Around x and y NOT z axis

Recommended Posts

Hi My Cube Step 1: start .......up............. .left..center..right.. .....down............. Step 2: x axis rotation 90 deg .......back............ .left..up..right....... .....center............. Step 3: y axis rotation 90 deg "ERROR" it starts rotate around Z axis! ........right.......... ..back...up....center... ........left........... !My wish is to have!: Step 3: .......back............. .down....left..up....... .....center............. How to avoid this phenomena? (I'm using DX) THX

Share this post


Link to post
Share on other sites
are you meaning to rotate about the object's local axis or an axis parallel with the world axis? I believe you'd get what you're seeing if you're rotating about local axis.

-me

Share this post


Link to post
Share on other sites
You want Tait-Bryan coordinates, where you rotate in the next step around the NEW axis, not the original axis. You probably also want to google "Gimball lock."

To represent orientations (rotations) I recommend using quaternions, or possibly rotation matrices, not Euler angles. In D3DX, there are rotation functions to set up heading/pitch/roll, which might also help you.

Share this post


Link to post
Share on other sites
There are many coordinate spaces going on here.

Let P be the current object-position. (P*(0,0,0) maps to the object position)
Let C be the object-description.
Let O be the current object-orientation. (O*C rotates the object C to the current orientation of the object)

Let "`" (backtick) be the "inverse operator".

Let R be a rotation.

What you appear to be doing is, taking:
P*O*C
(the object C rotated by the orientation O, then moved by the translation P)

and rotating it like:
P*O*R*O`*P`*P*O*C

(translate it back and unrotate it by it's current orientation, then apply your rotation, then reorient it and move it back to it's current location).

ie, you are rotating it in "object local orientation and coordinates".

What you want to do is rotate it relative to your world orientation:
P*R*P`*P*O*C

This may or may not be a wise thing to want to do, but it is what you said you wanted to do. :)

Another way of looking at it...

Suppose every object has 3 components.

(Model, Orientation and Position)

When you rotate the model, you have to decide which way you want to rotate it. Given a rotation R, you can set it's components to any of the following:

Model, R*Orientation, Position
Model, Orientation*R, Position
Model, Orientation, R*Position
Model, Orientation, Position*R
Model, R*Orientation, R*Position
Model, R*Orientation, Position*R
Model, Orientation*R, R*Position
Model, Orientation*R, Position*R

or you could even change the model:

R*Model, Orientation, Position

but I would advise against that.

And then you can invert your rotation on some components, you can rotate both the model and the position, you can...

All of these cause "rotation like behaviour". Some of them are far more insane than others. :)

In this scheme, the difference between rotating in world and object local orientation is the difference between:
Model, R*Orientation, Position
Model, Orientation*R, Position

Share this post


Link to post
Share on other sites
WOW! It looks like You know what You writing
Sadly I don't know exactly what I'm reading...
Can You help me convert P*R*P`*P*O*C to fit my DX needs?

Share this post


Link to post
Share on other sites
Same effect with Z rotation.
I just create Rotation with YawPitchRoll function(matrix or quaternion)
and than multiply by the matrix.

Share this post


Link to post
Share on other sites
Sorry mate -- I know 3D math, not 3D APIs.

From the one's I've seen coworkers play with, you end up producing a transformation matrix for the position of each object. It is possible to extract a translation and rotation matrix from these transformation matrixes, at least using math -- and probably using the 3D engine's API.

So, I'd advise:
1> Find out how to get the transformation matrix for your object.
2> Find out how to extract the translation and rotation components of this matrix.
3> Find out how to invert and apply the position component seperately.

Currently, your object's transformation matrix (T) is:
T:=P*O
you want to change it to:
P*R*P`*T = P*R*P`*P*O = P*R*O

How your API deals with transformation matrixes is something I have no clue about. :)

[Edited by - NotAYakk on June 7, 2006 4:53:11 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by ex9
I tried tried and tired... NOTHING
One thing that's not entirely clear from your post is whether the 'steps' you mention are steps within a function or algorithm that are applied 'all at once' as far as the user is concerned, or 'user interface' steps, that is, the user says, 'Hm, I think I'll rotate 90 degrees about the world x axis", then looks at the results and says, "Now I think I'll rotate 45 degrees about the world y axis".

If it's the latter, then what you want is for rotations to be about the specified world axis, regardless of what previous rotations have been applied. To do this you need to maintain your matrix from frame to frame rather than reconstructing it from scratch each time. Then, apply the appropriate world rotation matrix (on the right for DX) to update the orientation. You also may need to orthogonalize occasionally (I can't remember if DX has a function for this), or just use the DX quaternion class and normalization function.

Share this post


Link to post
Share on other sites
Something i did in the past before i moved to quaternions...

may be hacky:

1) rotate about one axis
2) multiply an object vector by a matrix created by the above
3) rotate object about the vector result of 2

the hackyness led me to moving to quaternions. not sure if i ever got that system to work right in all cases.

As an aside it seems to me that the core of your problem here is that you don't understand basic linear algebra. The easiest thing might be to stop coding for a week and learn: matrices, vectors, quaternions and the basic math surrounding each. After that, the problem you are facing will be intuitive to solve. Right now you're trying to just "get the code right" when you don't understand the math; you're just stabbing around in the dark and getting frustrated.

-me

Share this post


Link to post
Share on other sites
I have done already version with RotateAxis but I was hoping
for something much more elegant...
You are right I'm not good at math but in this case I'm
really suprised by the lack of the nice clean solution...

thx

Share this post


Link to post
Share on other sites
Quote:
Original post by ex9
I have done already version with RotateAxis but I was hoping
for something much more elegant...
You are right I'm not good at math but in this case I'm
really suprised by the lack of the nice clean solution...
I'm still curious; to quote my previous post:
Quote:
One thing that's not entirely clear from your post is whether the 'steps' you mention are steps within a function or algorithm that are applied 'all at once' as far as the user is concerned, or 'user interface' steps, that is, the user says, 'Hm, I think I'll rotate 90 degrees about the world x axis", then looks at the results and says, "Now I think I'll rotate 45 degrees about the world y axis".
Which of these behaviors is it that you're looking for?

(If you've already made it clear and I'm just missing it, never mind.)

Share this post


Link to post
Share on other sites
Quote:
Original post by ex9
I'm really suprised by the lack of the nice clean solution...


Quaternions offer a clean solution. Maintaining a matrix of the object's rotation is also a clean solution.

I think you are conflating "clean" with "something i already understand". It's not going to seem clean if you don't understand the math.

-me

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