1st person 3d movement

hey… im making a 1st person quake-like game… and here is the rendering code so far

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 6.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(-0.8f, 0.0f, 2.0f);
glScalef(0.1f, 0.1f, 0.1f);
gun.Render();
glLoadIdentity();
glTranslatef(0.0f, -1.4f, 0.0f);
lev.Render();

how would i make the camera move around with the arrow keys… thanks

just make the arrow keys change the 1st and 3rd values in gltraslatef() i think

Hi there!

You have to do more than “just change the view values according to the arrow keys”.

Think about where the camera source point will end if your character is near a wall and you want to perfrom a full rotation…

‘Ask Midnight’ at www.flipcode.com has a good description about using third-person-cameras…maybe it helps!

regards, christoph

thats exactly what i mean… i can go forwards and backwards but how do i rotate after i go forward? here’s what i have so far

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 6.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(-0.8f, 0.0f, 2.0f);
glRotatef(turnrot, 0.0f, 1.0f, 0.0f);
glScalef(0.1f, 0.1f, 0.1f);
gun.Render();
glLoadIdentity();
glTranslatef(0.0f, -1.4f, z);
lev.Render();
if (keys[VK_UP])
{
z+=0.3f;
}
if (keys[VK_DOWN])
{
z-=0.3f;
}

i didnt understand that tut… it is hard to understand without any code… thanks anyway…

First if you have some kind of structure to your program, it will make it easy to follow later on. As understand that openGL works in reverse of how one would think rotation and translation should effect an object.

keyboard();// we do keyboard stuff here.
{

if (key == up_arrow) z++;

}

display();// we draw things here!
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); // Start with a clean matrix… note I am not sure why you call it more then once in your program… maybe part of your problem.
glMatrixMode(GL_MODELVIEW); We are ready to draw.

// Move our view, replaces glulookat

glRotatef(WrotateX, 1.0f, 0.0f, 0.0f); // look right/left
glRotatef(WrotateY, 0.0f, 1.0f, 0.0f); // look up/down
glRotatef(WrotateZ, 0.0f, 0.0f, 1.0f); // rotate view, may need to use.
glTranslatef( 0,0, Worldz); // move on the z-axis

// now draw objects
glPushMatrix(); // save the matrix, we only want to effect this object with the follow commands.

glTranslate(…);// move object to its location.
glRotate(…);// rotate object

draw_object()

glPopMatrix(); // repeat this code for each object you want to draw.

glutSwapBuffers();
}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0.0f, 1.0f, -1.0f, 0.0f, 1.0f, 6.0f, 0.0f, 1.0f, 0.0f);
glTranslatef(-0.8f, 0.0f, 2.0f);
glRotatef(turnrot, 0.0f, 1.0f, 0.0f);
glScalef(0.1f, 0.1f, 0.1f);
gun.Render();
glLoadIdentity();
glTranslatef(0.0f, -1.4f, z);
lev.Render();
if (keys[VK_UP])
{
z+=0.3f;
}
if (keys[VK_DOWN])
{
z-=0.3f;
}

i didnt understand that tut… it is hard to understand without any code… thanks anyway…[/b]<HR></BLOCKQUOTE>

[This message has been edited by nexusone (edited 08-28-2002).]

im not drawing an object… im in 1st person

I have implemented a camera system. It works very nicely.

You can get it from http://cheo.resnet.wayne.edu/miguel/downloads/Terrain.zip

It is a project that is not complete, but it will show a camera system works…
Some people use Quaternions… I personally dont like them…

Hope this helps…

p.s. To move around in the world, you need to press esc to enter game mode, and to stop the game mode, press esc again…

All you need is a point P and a matrix M.P is the point at which you’re standing and M is a rotation matrix which represents your orientation.
Now initially P=(0,0,0) and M=I where I is of course the identity matrix.If you want to move you change P and if you want to rotate you change M.Lets look at rotation first…All you have to do in order to turn is to create the correct rotation matrix and multiply it M by it.Matrices for rotations about each axis can be found in the red book(some place towards the end) and of course at many sites on the net.Just be careful because OpenGL uses a left-handed system and you way wonder why the matrix you found rotates about the y-axis in the opposite direction.Anyway once you create the matrix(let’s call it R) you have to multiply M by it so that M=MR.
Translating by a vector V is a little trickier.I assume you want a translation along the Z-axis to move you in the direction you’re looking at.To achieve that you have to multiply V by M first.So V=V
M.This is because the initial vector V is in world coordinates but you need to move in camera or eye coordinates.If you don’t know what these terms mean look’em up on google for info on the various transformations that are done to vertices by opengl.Ok,once you have the vector by wich you want to translate(move) in eye coords. you add it to P,so P=P+V and that’s it.Now setting up the camera is as simple as:

glLoadIdentity();
glTranslatefv(P); /* translate to the correct place/*
glRotatefv(M); /* orient the player */

There are other ways to do it like RUV viewing systems(which is more or less the same thing) ,quaternions etc. etc. and at some point you’ll want to use the mouse which might complicate things a bit but this should get you started.Good luck.

[This message has been edited by zen (edited 08-28-2002).]

What? In 1st person, you don’t need objects to look at like (people, things, wall’s, etc).

Even in first person, you also still need to keep track of where you are also.

Originally posted by colinisinhere:
im not drawing an object… im in 1st person