Cube Rotation Around x and y NOT z axis

Started by
14 comments, last by Palidine 17 years, 10 months ago
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
Advertisement
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
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.
enum Bool { True, False, FileNotFound };
Palidine: Yes I realize that, but what should I do to avoid this?
hplus0603: tried quatrnions and yawpitchroll with no luck...
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
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?
Rotate it around the z instead of the y, it looks like, when you did the x-rotation you rotated the axis.
A wiseman once said nothing, but no one was there to hear it.
Same effect with Z rotation.
I just create Rotation with YawPitchRoll function(matrix or quaternion)
and than multiply by the matrix.
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]
Try rotating it around the z then x, it might turn out to be x then y.
A wiseman once said nothing, but no one was there to hear it.

This topic is closed to new replies.

Advertisement