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

Drakon

First Person Camera

15 posts in this topic

I''m playing around with OpenGL now, and I thought I''d try to make a simple (VERY simple) first person camera. As far as I can tell, it works to a small extent. (You can only move backwards.) I doubt this is how most of them work, but am I headed in the right direction? NOTE: I put all this in a seperate .cpp and have it connected to the main OpenGL .cpp. #include #include #include #include int Rendering() // also handles moving { static GLfloat ccx = 0.0f; static GLfloat ccy = 0.0f; static GLfloat ccz = 0.0f; static GLfloat cx; static GLfloat cy; static GLfloat cz; WINGDIAPI void APIENTRY glTranslatef (GLfloat x, GLfloat y, GLfloat z); { } if(GetAsyncKeyState( VK_DOWN )) { cz = ccz - 0.5f; ccz = cz; } glTranslatef(cx, cy, cz); glBegin(GL_TRIANGLES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(1.0f,0.0f,0.0f); glVertex3f(1.0f,1.0f,0.0f); glEnd(); return 0; }
0

Share this post


Link to post
Share on other sites
Remember that opengl''s camera is really the eye coordinates, so if there is no camera to move around, you are forced to move the entire world. Here is a snippet of my code from a 3d game I wrote:

int moveLeftandRight(float angle){
lx = sin(angle);
lz = -cos(angle);
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);


return 0;
}

int moveForwardandBackward(int direction){ //''1'' if forward ''-1'' if backwards
x += direction*(lx)*SPEED;
z += direction*(lz)*SPEED;
glLoadIdentity();
gluLookAt(x, y, z,
x + lx, y + ly, z + lz,
0,1,0);
return 0;
}

Then, you can use BOOLs to detect keypresses, like

if(keyLeft){
LRpos-=0.01;
moveLeftandRight(LRpos);

Anyway, its the math that is hard for most people. Hope that helps.
moveLeftandRight(
0

Share this post


Link to post
Share on other sites
Forgot to mention:

the camera coordinates are x,y,z and the view coordinates (the coordinates that you look at) are lx,ly,and lz.


0

Share this post


Link to post
Share on other sites
Ok I figured that stuff out... but how do you turn left instead of move left? Do you need to use glRotatef to do that?

Also: How do you use that key stuff? I tried it and it doesn't seem to work...

Edited by - Drakon on November 26, 2001 6:50:31 PM
0

Share this post


Link to post
Share on other sites
Did you even TRY my code up there? That moveLeftandRight function DOES turn you... sheesh!

try it out, all you need is a few geometrical calls to gluLookAt
0

Share this post


Link to post
Share on other sites
I tried it out but it gave me a few errors so I went back to trying it on my own...

What are cos and sin? They have anything to do with it?
0

Share this post


Link to post
Share on other sites
Woah, if you don't know what cos and sin are then you probably are in Algebra I, right?

That's not bad though, you'll get there, but I'll try to give you the basic stuff.

GO HERE to learn about Trigonometry

Read those tutorials they should help you out. The math isn't terribly difficult.

Just read the first three tutorials, and they'll get you in the right direction. The rest is more advanced stuff, but nothing too difficult. When I took trig, I thought it was pretty easy.

After you read those, you should be able to infer what that snippet of code is actually doing.

Good luck!

EDIT: This is probably real important. The sin and cos functions in the code accept their angles in radians. You may not know what those are, but just think of them as degrees. You'll get used to it.

Edited by - Floppy on November 26, 2001 11:40:31 PM
0

Share this post


Link to post
Share on other sites
Ok, thanks
Yes, ... (*thinks... remembering which algebra I''m in*) Man... I dont even remember what algebra book I''m in, but I think its two... but we haven''t gotten to cos and sin yet...
Its far too late to read that stuff now, but I''ll look at it in the morning.
0

Share this post


Link to post
Share on other sites
Another question... what is angle equal to?

Also: I don't understand whats going on in that tutorial stuff... I have a hard time learning math from tutorials.

Edited by - Drakon on November 27, 2001 9:33:22 AM
0

Share this post


Link to post
Share on other sites
There are three ways to get measurments of a triangle: sine, cosine, and tangent. Each are methodical to SOHCAHTOA, meaning:

sine = opposite over hypotenuse
cosine= adjacent over hypotenuse
tangent = opposite over adjacent

You need to know these because when you turn left, for example, you would decrement a variable ''float angle''. Then, you need to figure out whether the sin, cos, or tangent is needed.

In the case of turning, the most commonly used are the negative cosine and the sine.

gluLookAt takes 9 arguments. The first three are the camera position (x,y,z), which are unaffected when you turn. The ones that are affected are the next three arguments, (lx, ly, lz) which are the look-x, look-y, and look-z. They determine the point where the camera is looking.

So when you move forward, you need to figure out what angle measurement between you and the z axis (and x axis) is so that you can move in the proper direction.

The mathematical (actually, it''s geometrical) way of calculating this properly is in the functions that I gave you.

Set up a system of BOOLs. Like this:

bool turnleft; bool turnright; bool forward; bool backward;

Then, (assuming that you are using GLUT), set up your keyboard up functions and keyboard down functions.


float turnangle;

void main(int argc, char **argv){
...
glutKeyboardUpFunc(KeysUp);
glutKeyboardFunc(KeysDown);
...
glutDisplayFunc(RenderScene);
...
glutMainLoop();
}

void KeysDown(unsigned char key, int x, int y){
switch(key){
case ''a'': turnleft=1; break;
case ''d'': turnright=1; break;
case ''w'': forward=1; break;
case ''s'': backward=1; break;
default: break;
}
}

void KeysUp(unsigned char key, int x, int y){
switch(key){
case ''a'': turnleft=0; break;
case ''d'': turnright=0; break;
case ''w'': forward=0; break;
case ''s'': backward=0; break;
default: break;
}
}

void RenderScene(void){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
...
if(turnleft){
turnangle-=0.01;
moveLeftandRight(angle);
}
if(turnright){
turnangle+=0.01;
moveLeftanfRight(angle);
}
if(forward){
moveForwardandBackward(1);
}
if(backward){
moveForwardandBackward(-1);
}


Get it now? Geometry is the only way you can interpret the angles easily. Because the default setting for translating forward would be along the z axis, you not only need to compenstate your lx,ly,lz coords by translating along the z axis, but also the x axis.

This, my friend, is why geometry is critical.

~Jesse Lawson,
www.proggin.com/tutorials/opengl/index.htm

0

Share this post


Link to post
Share on other sites
I just noticed that you aren''t using GLUT; I thought you would be. The functions are still cooperative, so try them before you deny them.
0

Share this post


Link to post
Share on other sites
??? Huh ???

I have been searching for an answer on how to correctly move after turning, so I tried to use your code Zues_. However, just like all things, it screwed up. I can get it to turn very strangley, but, when I implemented the forward and backward movement code, it would stand still when I hit forward, when I hit back, it would rotate the screen, then when I hit forward again, it just screws up some more, and makes me frustrated. Does anyone have any other answers? Oh, and um, Zues_, you said that sin, and -cos are often used to determine this. Um, how is this? I''ve taken Algebra, but not Trigo yet. SOMEONE HELP ME! If you don''t, then I will have to calculate the additions to X and Z for all three hundred and sixty degrees of movement. Also, if I just add and subtract values from the camera''s X axis view, why does it stop when I reach 180 degrees and 360 degrees?

En taro Adun!
Doom to all who threaten the homeworld!
*Protoss Zealot - Starcraft*
0

Share this post


Link to post
Share on other sites
Do you know what sine, cosine, and tangent are? No?

Hmm... Look them up. To do what you want to do, the way you want to do it, you need to use SOHCAHTOA.

Do you know why?

Well, my examples involved incrementing an angle, right?

SOHCAHTOA was previously explained by me. Im serious, ask your math teacher about it, its hard to explain without visual contact. =)

0

Share this post


Link to post
Share on other sites