Jump to content
  • Advertisement

Archived

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

YodaTheCoder

First Person Games - Camera help!

This topic is 6142 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Please! Could someone (even pseudo code) tell me the basic idea behind a first person program? Something simple; One that you can walk around on the Z plane. Do you move the camera? The whole world? And how? If someone could explain gluLookAt, that''d be great! ~Jesse

Share this post


Link to post
Share on other sites
Advertisement
Dont bother with gluLookAt, just use glTranslatef and glRotatef to move and rotate the "camera". I say "camera" because there is no real camera in OpenGL, the viewpoint is always at 0,0,0 facing in the same direction, you just move the world around the camera instead. It's really quite simple

For moving around, poll the keys you wish to use for moving/turning... if turning, increment/decrement an angle variable, and if moving forward/backward, use sine/cosine to work out how much to move the camera along the x & y axis, and increment a location vector with the values.

For instance:
if (Key_state[DI_UPARROW]) {
camera.origin[0] += (float)sin(camera.angle / 180 * PI) * MOVE_SPEED;
camera.origin[2] -= (float)cos(camera.angle / 180 * PI) * MOVE_SPEED;
}

In that code, Key_state is an array that holds the state of each key, whether its pressed (value of 1) or not (0).

Edited by - Maximus on October 20, 2001 3:43:36 AM

Share this post


Link to post
Share on other sites
I think I understand what you said (partly). Where would the glRotatef and Translate go?

it looks like it would be something like

glRotatef(camera.angle, camera.x, camera.y, camera.z);

(If that''s even the right syntax)... But, where do I put it? A quick example is all I need... Thank you sir!

~Jesse

Share this post


Link to post
Share on other sites
Opps... should have included a bit of that in my first post

When you start rendering your scene, before you draw the world but after setting up OGL to render, first rotate and then translate, for example:

glRotatef(camera.angles,0,1,0);
glTranslatef(-camera.origin[0],-camera.origin[1],-camera.origin[2]);

Im using the negative of the cameras origin (location) because we are moving the world backward instead of the camera, so the world moves backwards when the camera "moves" forward.

After doing that, you can proceed to draw your game worlds static geometry.

When moving onto the non-static items in the world, you make use of the matrix stack. Drawing non-static items can be done like so:

glPushMatrix();
glRotatef(); // set the rotating of the item
glTranslatef(); // set the location in the world
DrawNonStaticItem(); // draw item
glPopMatrix();


Hope this post has a bit more info

Share this post


Link to post
Share on other sites
Just to let you know... If you plan on coding a first person shooter, and are having trouble with the rotation and translation, there is very little hope that you will be able to code a BSP/PVS. Although BSPs arent very hard to code, the PVS is very difficult to code and even harder to understand. But that is from my own experiences. I still think you should go ahead with your program though. Even if you dont write the best FPS in the world, or even finish, you will learn alot.

easyBob

Share this post


Link to post
Share on other sites
RRkk... I know enough about where to put the functions like rotate and translate, but do youy think it would be wiser to move the whole world or the camera? Lets say I want something like Doom, UT, quake, you know... (im not going to get that good, but I''ll try =)

wouldnt I just do something like

if(user presses the up arrow){
camera position on z axis += 1;
}

or something?

bah, and I know I use gluLookAt, but I dont get the parameters in that either... bah!!!

~Jesse

Share this post


Link to post
Share on other sites
Also, could someone tell me (newbie question?) the smartest way to make a floor? I was thinking of texture mapping, but I don''t know how yet... That smart? No?

I think I am just an anxious newbie..
Could someone help? =)

~Jesse

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why dont you just move the camera?

Share this post


Link to post
Share on other sites
There is no camera. Your only choice is to move the world. This is often abstracted into a "camera" though, much like maximus described above.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!