Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matrix local/global rotation

20 views
Skip to first unread message

Dima Zhukov

unread,
Jan 30, 2003, 10:21:00 AM1/30/03
to
Hello,

I need to rotate my camera (say viewplane) around arbitrary point in
space. Viewplane is rotated around local axes (not global ones!).
I have my viewplane stored as column-major 4x4 matrix (three vectors +
origin).
I have the 3x3 rotation matrix the does some rotation.

Given:
Matrix4d M; // vieplane matrix
Matrix4d R // rotational matrix only 3x3 part is used

Just to remind that:

M = M * R; rotation about global axes placed at (0,0,0)
M = R * M; rotation about local axes placed at local CS origin

So to do rotation about global axes placed at arbitrary point P I need
to move global CS to P, rotate and move it backwards:

M = M * (P); // translation
M = M * R // rotation
M = M * (-P) // back translation

So how do I rotate about local axes placed at arbitrary point P - do I
have to move local CS to point P, rotate and move it backwards?

Sharanga Dayananda

unread,
Jan 30, 2003, 2:25:54 PM1/30/03
to
Hi

> I need to rotate my camera (say viewplane) around arbitrary point in
> space. Viewplane is rotated around local axes (not global ones!).
> I have my viewplane stored as column-major 4x4 matrix (three vectors

I have a similar problem, rotating around local axes. I have a 3d object
which needs to rotate around its own axis. I can do it quite cheaply by
remebering the modelview matrix from the previous setting and applying only
relative movements. However, I need the actual coordinates of the object
for collision detection. I know this is a common problem. But I'm stumped.

Searches on google have yielded stuff about Euler angles but nothing solid.

Thanks
Sharanga


Wolfgang Draxinger

unread,
Jan 30, 2003, 5:30:37 PM1/30/03
to

Simplest solution:

Translate the point of rotation to the origin, rotate and translate back.

--
+------------------------------------------------+
| +----------------+ WOLFGANG DRAXINGER |
| | ,-. DARKSTAR | lead programmer |
| |( ) +---------+ wdrax...@darkstargames.de |
| | `-' / GAMES / |
| +----+'''''''' http://www.darkstargames.de |
+------------------------------------------------+

fungus

unread,
Jan 30, 2003, 8:02:03 PM1/30/03
to
Sharanga Dayananda wrote:
> I have a similar problem, rotating around local axes. I have a 3d object
> which needs to rotate around its own axis. I can do it quite cheaply by
> remebering the modelview matrix from the previous setting and applying only
> relative movements. However, I need the actual coordinates of the object
> for collision detection. I know this is a common problem. But I'm stumped.
>

Look at the bottom row of the matrix you're remembering.


--
<\___/>
/ O O \
\_____/ FTB.

Sharanga Dayananda

unread,
Feb 1, 2003, 4:47:09 AM2/1/03
to
Hi

> Simplest solution:
>
> Translate the point of rotation to the origin, rotate and translate back.

I'm already translating to the object's centre to perform the rotation. My
problem is that, I need to do two rotations about the object's z and y axes.
However, the first rotation rotates the object about the frames z axis (
i.e. up and down ) and the second rotation rotates it about the frames y
axis. When a rotation about the z-axis is performed, the object's y-axis
rotates. I want to rotate about this moving y-axis. Unfortunately I don't
seem to be able to perform this.


Sharanga Dayananda

unread,
Feb 1, 2003, 4:48:17 AM2/1/03
to
> Look at the bottom row of the matrix you're remembering.

The bottom row is all zero.

The last column of the matrix contains the screen relative coordinates of
the origin of the object. Using gluUnProject to return absolute values
doesn't seem to be working.


fungus

unread,
Feb 1, 2003, 4:55:04 AM2/1/03
to
Sharanga Dayananda wrote:
>>Look at the bottom row of the matrix you're remembering.
>
>
> The bottom row is all zero.
>
> The last column of the matrix contains...


...or column, depending on your "GetMatrix" code.

> the screen relative coordinates of the origin of the object.
> Using gluUnProject to return absolute values
> doesn't seem to be working.
>

I don't know the details of your program but the
last column should the object's position.

No matter what, you don't need gluUnproject().

fungus

unread,
Feb 1, 2003, 4:56:01 AM2/1/03
to

If you want a rotation in object space then just
multiply the matrices the other way around.

Sharanga Dayananda

unread,
Feb 1, 2003, 7:30:40 AM2/1/03
to
Hi

> I don't know the details of your program but the
> last column should the object's position.
>
> No matter what, you don't need gluUnproject().

I'm talking about the modelview matrix.

I've messed around with the coordinates you mentioned to position sound
sources releative to the camera with OpenAL. Those three coordinates are
relative to the screen. (0, 0, 0 ) is relative to the centre of the screen,
at the near clip plane.

Suppose my far plane is 5000 units away from the near plane. An object which
is near the far clipping plane will have an z coordinate of ~ -4999.

I need world coordinates.

My code for moving my object in the direction it faces is as follows:

( helimatrix is the preserved modelview matrix I use for storing the
helicopter's translated and rotated position ).

X = -HELICOPTER_MOVE_INC;

Y = 0;

Z = 0;

//Pos = MatMul( HeliMatrix, Vector( X, Y, Z ) );

glPushMatrix();

glLoadMatrixd( HeliMatrix );

glTranslatef( X, Y, Z );

glGetDoublev( GL_MODELVIEW_MATRIX, TempMatrix );

X = TempMatrix[12];

Y = TempMatrix[13];

Z = TempMatrix[14];

/*GetOriginalCoordsCustom( TempMatrix, X, Y, Z, a, b, c );

//X = a;

Y = b;

Z = c;*/

cout << "Internal coords" << X << ", " << Y << ", " << Z << endl;

glPopMatrix();

I can use the above principle to move the object. However, I need to perform
collision detection.

Cheers

Sha

Andrew F. Vesper

unread,
Feb 1, 2003, 10:00:43 AM2/1/03
to
Sharanga Dayananda wrote:
>>Look at the bottom row of the matrix you're remembering.
>
>
> The bottom row is all zero.

I hope not. It should be 0,0,0,1.

(Bottom row versus last column depends on how you
write out the matrix.)

> The last column of the matrix contains the screen relative coordinates of
> the origin of the object.

Assuming the matrix you are using is the model-view times the
projection, yes.

> Using gluUnProject to return absolute values
> doesn't seem to be working.

What are you using for screen z?

--
Andy V (OpenGL Alpha Geek)
"In order to make progress, one must leave the door to the unknown ajar."
Richard P. Feynman, quoted by Jagdish Mehra in _The Beat of a Different Drum_.

OpenGL Technical FAQ: http://www.opengl.org/developers/faqs/technical.html

Sharanga Dayananda

unread,
Feb 1, 2003, 10:41:41 AM2/1/03
to
> > The bottom row is all zero.
>
> I hope not. It should be 0,0,0,1.
You're right, but I was just concerned about the x,y and z coordinates.

> Assuming the matrix you are using is the model-view times the
> projection, yes.
>
> > Using gluUnProject to return absolute values
> > doesn't seem to be working.
>
> What are you using for screen z?

z = -z / (Far - Near);


Cheers

Sharanga

Sharanga Dayananda

unread,
Feb 5, 2003, 3:54:38 PM2/5/03
to
> > The last column of the matrix contains the screen relative coordinates
of
> > the origin of the object.
No, this is just the modelview. After applying the transformations, I do a
glGetDoublev( GL_MODELVIEW_MATRIX .. );

However, I use gluLookAt before. This should position the damn thing.


0 new messages