View Full Version : Using transformation matrices

Say I use the following code:

glMatrixMode(GL_MODELVIEW_MATRIX);

glLoadIdentity();

glMultMatrix(Rot1);

glMultMatrix(Rot2);

...

When the modelview matrix is multiplicated by Rot1 it results in a new coordinate system,right?So when Rot2 gets mutilplied the retation that is performed is done according to the new coord. system that was produced by modelview*rot1.So assuming that the z axis points into the screen if rot2 was a matrix for rotation around the z-axis it would produce an effect like 'rolling' the camera no matter what kind of rotation matrix rot1 was,right?Or would the rotation occur according to the initial coordinate system's z-axis?

WhatEver

05-01-2001, 01:52 PM

Yes. Everything is relative to the last rotation. So if you rotate around the z axis 90deg 4 times, you would end up with the same coordinate system as you started with.

Pretty cool stuff.

I thought so.So I'm using a matrix to strore camera roation.This matrix(let's call it C) is initialy equal to the identity matrix.I have a bunch of functions cam_rot_x() y and z that just compose a suitable martix and mutiply it to C.Afterwards I use glLoadMatrix to load C into the modelview matrix.Yet after a few rotaions I notice taht the camera doesn't rotate around it's world axes but around a coord. sytem identical to the initial one(the world's cs)translated to the camera's position,i.e using cam_rot_z doesn't roll the camera unless you're in the initial camera state(haven't done any other rotations excepth of course .around the z axis).Can anone explain that?

I just solved the problem and, as always it turned out to be someting quite simple which you already knew to begin with.I just had to multiply the matrices in reverse order.e.g. if I wanted transformation r1 first and then r2 I the camera matrix would have been r1*c and r2*r1*c respectively.That's all.I allready considered that when multiplying the rotation matrix with the translation matrix but not between rot. matrices.

For another matter though.Say I wanna translate by (0,0,5) in camera roations,that is make 5 steps forward.How dod I do that considering that I specify camera position in world coordinates.I should find a way to map camera coordinates into world coordinates.Do I do that by multiplying the camera-space translation vector([0,0,5]) by the inverse camera matrix?If not then how?

You can forget my last question as well.I just did it by multipliyng the camera space translation vector by the inverse of the camera's rotation matrix.And the cool part is that because it's a rotation matrix it's inverse and transpose are identical so I don't even have to calculate the inverse.Thanx to anyone who posted in this and my previous two topics about the camera model.

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.