How to make and object move with the world. OpenGL
Today I was working on a flight simulator. I have added a bunch of features. Here are the keys:
Up arrow : foreward
Left Arrow : left
Right Arrow : right
Down Arrow : back
A : tilt left
S : tilt right
Q : move up
W : move down
Page Up : tilt up
Page Down tilt down
It works really nicely but the problem is I want the camera to move with the airplane so that the airplane is 5 units out in front of the camera at all times. How do I do that?
it would help to know what api ur using.
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
life is unfair, take advantage of it.
UNMB2 - if the link doesn''t work, try clicking it
quote:Original post by thuned
it would help to know what api ur using.
You mean you didnt read the topic of this thread?
It clearly says "OpenGL"
Does anybody know how to move the camera with the object with object being a little bit ahead of the camera. Also how do minipulate one object, ie rotate or translate, while I the other object doesn''t move.
um wouldnt you just use the input from they keyboard when u are tilting or turning and apply that to the camera also?
A = airplanes position
D = direction airplane is looking
gluLookAt( A.x - D.x*zoom, A.y - D.y*zoom, A.z - D.z*zoom, A.x, A.y, A.z, 0,1,0 );
http://members.xoom.com/myBollux
D = direction airplane is looking
gluLookAt( A.x - D.x*zoom, A.y - D.y*zoom, A.z - D.z*zoom, A.x, A.y, A.z, 0,1,0 );
http://members.xoom.com/myBollux
Yes I knw your supposed to apply this camera movement when the object moves but how do I do that. Also does anyone know how to move just one object but make the other object still.
Well, I assume that you have the matrix of the viewpoint loaded into memory for this. But you can do something like this:
glPushMatrix();
glLoadIdentity();
glTranslatef(0, 0, -5);
DrawPlane();
glPopMatrix();
That will draw the airplane 5 units in front of you. If it doesn''t work, then you are probably doing things differently than me.
glPushMatrix();
glLoadIdentity();
glTranslatef(0, 0, -5);
DrawPlane();
glPopMatrix();
That will draw the airplane 5 units in front of you. If it doesn''t work, then you are probably doing things differently than me.
I know that draw the plane five unuts ahead of me. Here parts of my code:
GLfloat zpos; // Z position
-----------------------------
glTranslatef(0.0f,0.0f,zpos);
-----------------------------
if (keys[VK_UP])
{
zpos-=1.0f;
}
That moves the ariplane one unit a head of the camera if you press space bar. How would I make both the camera and the plane move one unit ahead if I press the space bar? I have been trying eveything. Also lets say I have a run way. I if I were to press the spacebar the runway would move one unit with the plane. How do I get just the plane to move.
GLfloat zpos; // Z position
-----------------------------
glTranslatef(0.0f,0.0f,zpos);
-----------------------------
if (keys[VK_UP])
{
zpos-=1.0f;
}
That moves the ariplane one unit a head of the camera if you press space bar. How would I make both the camera and the plane move one unit ahead if I press the space bar? I have been trying eveything. Also lets say I have a run way. I if I were to press the spacebar the runway would move one unit with the plane. How do I get just the plane to move.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement