Skip to main content
gamedev.net
🔒 Locked

Rotation Problem

Started by JohnLamock Mar 24, 2006 at 8:21 AM 4 replies 800+ views
Original Post
JohnLamock
JohnLamock
Hi! I'm having a little problem with my rotation function. I'm coding for cellphones, using Mascot Capsule v3, but I think this is a general problem. When I rotate an object, it must be at (0,0,0) position, if not, the rotation will not be correct. So, I rotate the object at starting point and put the old (x,y,z) coordinates back into object coordinate. The problem is that, for instance, the object rotates 180 degrees, the old "Z" position will be now behind the car. The reference is the object, not the world. How can I solve this problem? Any ideia will be helpfull! Thanks! .Sorry about my bad english :)
someusername
someusername
I'm not sure I understand the problem here... :/

Quote:

When I rotate an object, it must be at (0,0,0) position, if not, the rotation will not be correct.

This is true if you want to rotate the car around its own center, and not the world origin.

Quote:

So, I rotate the object at starting point and put the old (x,y,z) coordinates back into object coordinate.

If you can't work with 4x4 matrices, you'll have to do that yourself, indeed.

Quote:

The problem is that, for instance, the object rotates 180 degrees, the old "Z" position will be now behind the car.

What do you mean with "old Z position"? The z-component of the car's center?
If yes, how can it now be behind the car? this shouldn't change.

Quote:

The reference is the object, not the world.

Didn't you want to rotate around its own center, from the start?

edit:
forgot to add the word "around" in the end
(the meaning was completely different without it)

[Edited by - someusername on March 24, 2006 12:13:36 PM]
JohnLamock
JohnLamock
Thanks for your answer! :)

If I try to rotate the object 90 degrees at the point (0,0,10) for example, it will not rotate 90 degrees. It will rotate like if the center point of my rotation is the world origin.

So I move th eobject to the origin, and will rotate properly, but when I move the object to the point (0,0,10) again, it will move to the world (0,10,0). This is because the object is pointing now to this point.

And yes, I'm using 4x4 matrices!

Thank you very much!
someusername
someusername
I see... The object translates with respect to its own local axes, not the global ones. I'm curious how you managed to get this effect by applying only two matrices! :)

The transformation matrix you should apply to the object is T*R, where:
    [ 0  0  0  Pos.x ]T = [ 0  0  0  Pos.y ]    [ 0  0  0  Pos.z ]    [ 0  0  0    1   ]

"Pos" is the desired position of the object in world coordinates, and R is any composition of rotations.

This will first rotate the model, -in its own model space around its pivot-, and then translate it. I believe this is what you want.

If this is what you already do, there must be some problem with your rotation/translation matrices. Post some code if possible.
In the simple case you describe, one can only get two behaviors.
The first -applying "translation"*"rotation"- would result to the object being rotated around its own center and then positioned at the right place.
The other one - "rotation"*"translation"- would result in the object being rotated on an arc around then origin by the desired rotation angle.
I don't know how you managed to get the effect you're describing!

When this problem arises, one has to cancel the current transformation (multiply by the inverse), apply the generic translation matrix (just like T above) and then restore the transformation.
In simple cases, this merely gets down to applying the translation matrix at the other side of the product.

And there is one more issue... The above will work assuming that the matrix-vector products transform as:
[ m11  m12  m13  m14 ] (x)[ m21  m22  m23  m24 ]*(y)[ m31  m32  m33  m34 ] (z)[ m41  m42  m43  m44 ] (w)If the specific API transforms them as              [ m11  m12  m13  m14 ](x  y  z  w )*[ m21  m22  m23  m24 ]              [ m31  m32  m33  m34 ]              [ m41  m42  m43  m44 ]


You'll have to transpose the entire transformation before applying it.
JohnLamock
JohnLamock
Quote:

The other one - "rotation"*"translation"- would result in the object being rotated on an arc around then origin by the desired rotation angle.
I don't know how you managed to get the effect you're describing!


This is what i was trying to explain :)

I was doing rot*trans, now i'm doing trans*rot and it is acting like a normal object :)

Thank you very much!
Sorry for my bad problem explanation attempt! :P

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.