View Full Version : Help! How do you handle multiple world/local objects?

This is my problem, I have a world, and I have 6 objects in the world.

Those 6 objects can be independent of each other, and all have 6DOF.

Now, my draw loop is:

..

{

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glPushMatrix();

setup_camera_matrix();

translate_camera_matrix();

glPushMatrix();

for(i=0;i<6;i++)

{

glPushMatrix();

move_plane(i); //sets up matrix rotation

glTranslate(pos[i].x,pos[i].y,pos[i].[z]);

glPopMatrix();

)

..

Now, what I wanted to happen is have each of those planes move within the world, but they seem to be moving in a very strange way, like if I am moving 1 plane forward and pointed up, it moves it in the wrong direction, like it is moving only via local, and not in theworld axis.

I tried doing this in another order, but it still fails!!

Any pointers on what I am doing wrong? The program works fine with 1 plane, and I can move it like a FPS, but when I have multiple objects, it screws up! HELP!!

Elixer

01-13-2001, 02:40 PM

Well, the order does matter in which you rotate & translate.

If I am reading you right, you have a world loaded, then the first pushmatrix saves the world matrix (which is the identity), the 2nd push saves the camera matrix, which I *think* is correct, then you enter the loop with a push (which saves camera matrix) you then do the rotation, and then translate. then pop..pop..pop..

I think you need to have the translate first, then the rotation matrix, since then it translates via the camera matrix, then rotates. (so that means translate along world first, then do rotations).

Then again, I haven't gotten that far yet, since I am redoing my matrix stuff as well, and I am sure I will run into this problem. http://www.opengl.org/discussion_boards/ubb/smile.gif

I do try this, and still no work right.

Maybe my matrix code bad? Can someone with working matrix code for 6dof help please, post code?

Michael Steinberg

01-14-2001, 12:03 PM

Why would you push an identity matrix?

Anyway, for cameras, you're moving first to its position, then rotating it. Because matrices have to be done other way around, the posting is correct at that point.

Did you use glMatrixMode( GL_MODELVIEW )?

Also, you can leave out that glPushMatrix before the loop.

Can you post the codes for the setup_camera and translate_camera?

Nigel

01-15-2001, 04:23 AM

All translations and rotations are relative, so the reference frame is fixed to the body of the plane. in your case, a translation first and then a rotation is probably the right sequence.

If you have 6DOF, you should have the euler (!) xyz rotationmatrix or something similar for translations:

X_body-fixed = A_psi*A_theta*A_phi * X_inertial

with X_ vectors and A_ are 3x3 matrices

if you don't know what I'm talking about right now, find a mechanics book or send me an email

greets Nigel

The setup_camera_matrix() uses quanterions & uses input from uzer. Code is to big to post.

translate_camera_matrix() just does:

Quat.getDirectionVector( dirX, dirY, dirZ );

(so dirX,dirY, dirZ - m[2],m[6],m[10])

and then for movement:

camX += dirX * tBy;

camY += dirY * tBy;

camZ += dirZ * tBy;

camX,camY,camZ = m[12],m[13],m[14].

then calls glmultmatrixf...

the extra push is there to be extra safe. http://www.opengl.org/discussion_boards/ubb/smile.gif

I forgot to say I am uzing glMatrixMode( GL_MODELVIEW ).

I also got sent code and was told to try this:

x = camMat[0] * camDir[0] + camMat[4] * camDir[1] + camMat[8] * camDir[2];

y = camMat[1] * camDir[0] + camMat[5] * camDir[1] + camMat[9] * camDir[2];

z = camMat[2] * camDir[0] + camMat[6] * camDir[1] + camMat[10] * camDir[2];

//len=x*x+y*y+z*z;

camDir[0] = x;

camDir[1] = y;

camDir[2] = z;

//Now you run the user interface again and add or sub the CamDir vector to the CamPos vector.

//All that's left now is to modity the camMat to fit the new translation.

camMat[12] = camPos[0];

camMat[13] = camPos[1];

camMat[14] = camPos[2];

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

This no work.. is correct I don't thinks so.

I post wrong topic sorry. should be here:

i forgot this also:

if((*game::keyboard)[DIK_UP]) camPos+=camDir;

if((*game::keyboard)[DIK_DOWN]) camPos-=camDir;

Again, I try and this no work either.

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