View Full Version : left right up down...

Phoenix

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????

tfpsly

10-15-2003, 11:06 PM

Use the X, Y, Z vectors of your obj_space ==> world_space rotation matrix.

Phoenix

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.

Phoenix

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];

normaliz(mv_x);

normaliz(mv_y);

normaliz(mv_z);

---------------------

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

glutWireSphere(0.03, 8.0, 8.0);

.....

/////keyboard function///////////

.....

case GLUT_KEY_RIGHT :

{

l1.position[0] += mv_x[0];

l1.position[1] += mv_x[1];

l1.position[2] += mv_x[2];

}

virtualchetan

10-16-2003, 04:23 AM

Hi,

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

knackered

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.

Phoenix

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".

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