Archived

This topic is now archived and is closed to further replies.

easyBob

Neural Nets, Genetic Algorithms, and thrust vectoring spaceships...

Recommended Posts

Thats the idea, of course. Im still in the middle of developing how the ships fly around. And thats the problem. 1 ship is going to chase the other, but the camera needs to follow the one that is doing the chasing. what i have so far is 2 ship (nicely modeled in milkshape by yours truely). the camera is above and in back of the chaser ship, and you know in opengl, the camera does not move, so the ship can''t move. how do i get the correct rotation and translation on the other ship compared to the chaser ship? I have tryed alot of different things, and i plan on trying more, but, a little help cant hurt. Thanks.

Share this post


Link to post
Share on other sites
OpenGL has the camera fixed at the origin (0,0,0). If you need your camera at any other location, you can''t. Instead, you have to move the world :-)
To move the world, simply make your GL_MODELVIEW matrix contain the inverse translation of your camera. So if your camera is at 1,2,3
then you would call:
  
glMatrixMode (GL_MODELVIEW);
glTranslatef (-1, -2, -3);


The same goes for rotation.

Share this post


Link to post
Share on other sites
I think Kippesoep was right about not being able to move the camera, But translating the whole world in the oppersite direction is equivalent(like he said).

I call gluLookAt each frame with the camera position. You can also choose a target. The up_vector referes to the vector which points out of the top of the camera.

Look at the OpenGL Redbook (proggramming guide) for a great explaination of viewing and camering. I belive there is an online version.



void mainloop()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); //important
gluLookAt(cam_pos_x,cam_pos_y,cam_pos_z,
cam_target_x,cam_target_y,cam_target_z,
up_vector_x,up_vector_x,up_vector_y);

drawstuff();

//SwapBuffers()
//or glutSwapBuffers
}

Share this post


Link to post
Share on other sites
Ahh...thanks for all your ideas. I used quadernions and got it working. The reson being,

glRotate (Pitch,1,0,0);
glRotate(Yaw,0,1,0);
glRotate(Roll,0,0,1);

will not work together. But thanks alot.

take it easy,
Bob

Share this post


Link to post
Share on other sites