View Full Version : left right up down...

10-15-2003, 09:55 PM
I have to move an object in a scene according to a strange perspective...I move the object with arrow keys, but I want that when I press right the object really moves on the right of the screen and not on the right of the "scene"...how would I obtain this????

10-15-2003, 11:06 PM
Use the X, Y, Z vectors of your obj_space ==> world_space rotation matrix.

10-16-2003, 01:05 AM
I get the modelview matrix, "calculate" the transposed and extract the x,y,z vectors...now the problem is that, when I set unusual coordinate systems, I push the right-arrow-key and the object moves to the left and vice-versa...so the question becomes, how can I obtain the actual RIGHT of the screen???

Nicolas Lelong
10-16-2003, 01:40 AM
IMHO, you'd better calculate the _inverse_ of your modelview matrix (as the transpose is only only a special case inverse) and transform your eye-space RIGHT vector (surely (1,0,0)) by this inverse matrix... that should do the trick.

10-16-2003, 04:04 AM
I tried this...It works for all directions up, down, forward, back, BUT when I press RIGHT the sphere goes ALWAYS left...any ideas?

gluLookAt(1.4, 0.0, -1.2, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

glGetDoublev(GL_MODELVIEW_MATRIX, matrix);
mv_x[0] = matrix[0]; mv_x[1] = matrix[4]; mv_x[2] = matrix[8]; mv_y[0] = matrix[1]; mv_y[1] = matrix[5]; mv_y[2] = matrix[9]; mv_z[0] = matrix[2]; mv_z[1] = matrix[6];
mv_z[2] = matrix[10];

glTranslatef(l1.position[0], l1.position[1], l1.position[2]);
glutWireSphere(0.03, 8.0, 8.0);

/////keyboard function///////////
l1.position[0] += mv_x[0];
l1.position[1] += mv_x[1];
l1.position[2] += mv_x[2];

10-16-2003, 04:23 AM

I think what you need is move in the Camera in Camera Co-ordinates. i.e. basically shifting Camera XYZ and LookAt Point XYZ, in Camera co-ordinates.

- Chetan

10-16-2003, 04:55 AM
"as the transpose is only only a special case inverse"
The special case being that the matrix is orthagonal - which in general it is.

10-17-2003, 12:53 AM
I cannot transform the (1,0,0) with the inverse modelview matrix for the following reason: I could obtain an inverse matrix like this:
(-1 0 0 )
( 0 1 0 )
( 0 0 1 )

as you see the X vector points at the "left" and multiplying (1 0 0) by this matrix will give the wrong result (I wanted ALWAYS right).

So I thought to use the cross product between Y and Z to obtain the X vector I need but the problem is the following one:

imagine you are looking at the negative-Z (and this should happen always, right?), if the Y vector points "up" then doing the cross product Y*Z will give the X pointing at "right", but if the Y is pointing "down" the resulting X will be "left".