• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

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

YodaTheCoder

First Person Games - Camera help!

12 posts in this topic

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
0

Share this post


Link to post
Share on other sites
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
0

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
0

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
0

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
0

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
0

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
0

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.
0

Share this post


Link to post
Share on other sites
gluLookAt isnt an OpenGL function, rather its a utility function that generally makes it easier to move the world and make it look directly at a specific location.

For a 1st person shooter, you dont want to have to calculate the specific location that the camera is to look at when you move around. gluLookAt internally calls glTranslatef and glRotatef, and needs to be in the same area of the code anyway.
0

Share this post


Link to post
Share on other sites
Okay, want to bore yourselves in my pathetic code? Here it is (compiled perfectly with MSVC6.0) NOTE: There are some includes and variables that are declared and not used yet; theyre for later.

#include
#include
#include
#include
#include
#include "main.h"

bool forward; //Movement bool''s
bool backward;
bool turnleft;
bool turnright;
bool strafeleft;
bool straferight;

float FBpos=0.0; //front back position
float LRpos=0.0; //left right position

//Function Declarations
void keysDown(unsigned char key, int x, int y);
void keysUp(unsigned char key, int x, int y);
void renderScene(void);
int moveFB(int direction);
int moveLR(float angle);


int main(int argc, char **argv){
glutInit(&argc, argv);
glutInitWindowPosition(100,100);
glutInitWindowSize(550,550);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
glutCreateWindow("<-Hello world!->");
glutFullScreen();
glutReshapeFunc(changeSize);
glutDisplayFunc(renderScene);
glutKeyboardUpFunc(keysUp);
glutKeyboardFunc(keysDown);
glutIdleFunc(renderScene);

glutMainLoop();
return 0;
}

//Keyboard - Keydown Function
void keysDown(unsigned char key, int x, int y){
switch(key){
case ''w'': forward=1; break;
case ''s'': backward=1; break;
case ''a'': turnleft=1; break;
case ''d'': turnright=1; break;


case 27: exit(1); break;
default: break;
}
cout<}

//Keyboard - Keyup Function
void keysUp(unsigned char key, int x, int y){
switch(key){
case ''w'': forward=0; break;
case ''s'': backward=0; break;
case ''a'': turnleft=0; break;
case ''d'': turnright=0; break;

default: break;
}
cout<}

//Terrain Function
void renderScene(void){
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

if(forward){
FBpos+=0.1;
moveFB(1);
}
if(backward){
FBpos-=0.1;
moveFB(-1);
}
if(turnleft){
LRpos-=0.01;
moveLR(LRpos);
}
if(turnright){
LRpos+=0.01;
moveLR(LRpos);
}

//DRAW THE FLOOR
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(GREEN);
glVertex3f( 2.5f,-0.5f,-2.5f);
glColor3f(RED);
glVertex3f( 2.5f,-0.5f, 7.5f);
glColor3f(BLUE);
glVertex3f(-2.5f,-0.5f, 7.5f);
glColor3f(WHITE);
glVertex3f(-2.5f,-0.5f,-2.5f);
glEnd();
glPopMatrix();

//DRAW THE CEILING
glPushMatrix();
glBegin(GL_POLYGON);
glColor3f(BLUE);
glVertex3f( 20.5f, 5.5f,-20.5f);
glColor3f(BLUE);
glVertex3f( 20.5f, 5.5f, 70.5f);
glColor3f(TEAL);
glVertex3f(-20.5f, 5.5f, 70.5f);
glColor3f(TEAL);
glVertex3f(-20.5f, 5.5f,-20.5f);
glEnd();
glPopMatrix();


glutSwapBuffers();
}


NOW IN another file, main.h, I have the following:

#include
#include

#define WHITE 1.0f, 1.0f, 1.0f
#define TEAL 0.0f, 1.0f, 1.0f
#define BLUE 0.0f, 0.0f, 1.0f
#define RED 1.0f, 0.0f, 0.0f
#define GREEN 0.0f, 1.0f, 0.0f
#define BLACK 0.0f, 0.0f, 0.0f

static float angle=0.0,ratio;
static float x=0.0f,y=0.0f,z=0.0f;
static float lx=0.0f,ly=0.0f,lz=-1.0f;

int moveFB(int direction){ //''1'' if forward ''-1'' if backwards
x += direction*(lx)*0.1;
z += direction*(lz)*0.1;
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);
return 0;
}
int moveLR(float angle){
lx = sin(angle);
lz = -cos(angle);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);
return 0;
}


void changeSize(int w, int h) {

if(h == 0)
h = 1;

float ratio = 1.0* w / h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glViewport(0, 0, w, h);

gluPerspective(45,ratio,1,1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}



Look newbie-ish? Ya, thought so... Compile/run it, it looks okay! (now all I need to learn is texture mapping).. which im on right now =)

~Jesse
0

Share this post


Link to post
Share on other sites
By the way, the movement controls are


w = forward
s = bakcwards
a = turn left
d = turn right



Ill eventually use the arrow keys for strafing..

~Jesse
0

Share this post


Link to post
Share on other sites