View Full Version : How rotate away from 0? HELP!!

My ship only work at 0,0,0. When move from 0,0,0, then all rotations are based off of 0,0,0 instead of new position. Why?

I use quats for rotations, and matrix for everything else, NO openGL transform calls.

So I do

Fpos(pmatrix);

Fquat(matrix);

mult(matrix);

mult(pmatrix);

I try to have position matrix before rotation, but that didn't work either.

I am doing is:

calculate position, then do rotation, then multiply rotation and then position.

so it ends up as:

m=M*R

m=pm*m.

I have tried various orders and can't seem to roate object on its own axis, not the 0,0,0 axis!

HELP!

Michael Steinberg

02-15-2001, 05:14 AM

So you've got your rotation matrix and your translation matrix.

Load the rotational matrix up and then multiply the translation matrix on it.

Yes, I try this.

I try glLoadmatrixf(rotmatrix)

then mmat(posMatrix,rotmatrix,omatrix)

then glmultmatrixf(omatrix)

This makes it only rotate OK at 0,0,0. Anything else, and it no work. so if I move 0,0,-5, and I try to turn ship now, instead of local axis turn, if I keep hold down turn, then object will make a circle. I also try swapping posmatrix and rotmatrix around, but that no work either.

This why I am stuck!!

o-----t

if o is 0,0,0, and I move to t, then try to turn t, it rotates around o. if I stay at o and turn, all is great, and ship turns in the correct direction!

Michael Steinberg

02-15-2001, 10:45 AM

It has to be:

glLoadMatrix( rotation matrix )

glMultMAtrix( translation matrix )

you don't have to premultiply them.

Elixer

02-15-2001, 12:47 PM

You sure Michael ?

I think your supposed to take object coordinates, subtract world coordinates,

(this should get you back to whatever the camera is looking at in your case, 0,0,10 - 0,0,0 = 0,0,-10) So you translate your object by that much, then you do rotation as normal, then you mult the translation back.

Err... I think...

Maybe DFrey can shed some light on this?

DFrey

02-15-2001, 01:15 PM

I think the problem Lost is having may stem from incompatible matrix conventions. Either his matrix code premultiplies a matrix by a transformation matrix (OpenGL postmultiplies), or his matrix code uses row major matricies (OpenGL uses column major). If one is going to mirror the OpenGL matricies within the app (typically a good thing to do for a complex app), you'll only need to use glLoadMatrix after you have used your own matrix/quarternion transformation code.

Michael Steinberg

02-15-2001, 01:50 PM

When you've got the model in model space, you would normally move it to it's world position and then rotate it there. Since matrix operations work the other way around, you have to do it the other way around. I think that is correct. I relate on model transformation, not on camera transformation.

Michael Steinberg

02-15-2001, 01:53 PM

I think I get what you meant. Well, you need to negate all the rotations and translations when using camera "model". If you however move a normal object like a spaceship to its intended world position, you use the unnegated transformations.

Yes, I premultiply matrix. Is that not good?

My matrix a= (position matrix)

1 0 0 x

0 1 0 y

0 0 1 z

0 0 0 1

My matrix b= rotation matrix)

rxx ryx rzx 0

rxy ryy rzy 0

rxz ryz rzz 0

0 0 0 1

so I then do a*b=c

I then do glLoadMatrix(c)

then I do glMultMatrix(a)

This no work as I said.

How convert model in model space to world position? I think all rotation are from 0,0,0 am I right?

Hey Lost,

You need to understand how the OpenGL pipeline works.

Your object coordinates get post-multiplied by the current model view matrix. Meaning:

(X', Y', Z', W') = [current_model_view_matrix] * (X, Y, Z,W)

where X,Y, Z and W are the coordinates of your object and X', Y', Z' and W' are the actual coordinates that get drawn on the screen (this is not entirely true as they get post-multiplied by the projection matrix and etc, but for now we can just ignore that.

So in order to rotate/translate/scale an object, all you have to do is modify the [current_model_view_matrix]. A call to glRotate*, glTranslate* or glScale* will positmultiply the [current_model_view_matrix] by the appropiate transformation matrix. For example,

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix]

or

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix]

or

[current_model_view_matrix] = [current_model_view_matrix] * [scaling_matrix]

so what happens when you call glRoate*() and then glTranslate*()?

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix]

then

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix]

the end result is

[current_model_view_matrix] = [current_model_view_matrix] * [rotation_matrix] * [translation_matrix]

the net effect is that you 1st translate (move) the object to some location and the rotate it. Now rotation in either direction is a rotation about that axis. If you call glRoate(current_angle,1.0,0.0,0.0) you are rotating the object about the x axis. Now if you have translated your object say for 5 units, this will cause your object to move in a circular path with centre (0.0,0.0,0.0) and radius 5.0.

But what you want is:

[current_model_view_matrix] = [current_model_view_matrix] * [translation_matrix] * [rotation_matrix]

In this case you 1st rotate the object and then translate it. Always remember this, matrices always work from right to left.

How do you avoid this? there are to solutions:

If you want to premultiply rotation and then translation

1. Translate your object back to (0.0,0.0,0.0)

2. Rotate it

3. Translate it back to the previous location.

Use post multiply, but reconstruct your [current_view_matrix] everytime you do a transformation. In this case you do ALL the rotations 1st, then ALL the translations and finally all the scales.

Hope this helps,

Rizo

[This message has been edited by Rizo (edited 02-15-2001).]

I think I see my mistake.

In my rotation matrix above, matrix b, it should have the position in it correct?

rxx ryx rzx X

rxy ryy rzy Y

rxz ryz rzz Z

0 0 0 1

and now I should do

glloadmatrixf(matrix b)

glmultmatrixf(matrix a)

correct?

If no, what should rotation matrix look like?

I find mistake. It not with rotation matrix, or how I multiply, it is since I pass wrong matrix to movement routine!!

I get the dir vector from position but should be from rotation. This why I always at 0,0,0 since position matrix always 0!

Sorry friends!

Elixer

02-16-2001, 12:00 PM

I forgot to say that if you use glLoadMatrixf(), then you lose the other transforms/rotations that you did before, unless you kept track of those also.

What I mean is if you have your camera matrix first, then you have your planes/ships whatever, if you use glMultMatrix that will be applied to the camera matrix view, and glLoadMatrixf() will kill the camera matrix view, unless of course you do something like:

glLoadMatrixf(object)

glMultMatrixf(object_transform)

glMultMatrixf(Camera_view)

Draw()

..

The order is important, and it depends on the effect you want to achieve.

Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.