Advertisement

How to walk around in a simple room?

Started by January 08, 2001 10:58 AM
6 comments, last by Kevinst 23 years, 10 months ago
Hi, I have written (in 10 seconds lol) a simple room (it looks like a cube, but i am inside, lol), now i want to walk around in it, but i dont know how. What code must i fill in to be able to move forward, back, left, right?? I''ve seen the Lesson 10 in the OpenGl Tutorial, but I cant see and cant understand how it was made, and then it loads a 3d world, not i, my little 3d world is in the program. So PLEASE can you give my a simple example how to walk around in my room (of course only the code for walking through the room) PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE PLEASE!!! I really need it. Thanks Cya Kevin
Code no, since it is already there and all you have to do is cut and paste the freaking stuff.

Next,

put a translate statement at the top of your draw function and then pass in the parameters left, right, forward, back, and put this in as the x and z values of the translate statement. No I will not put code, nor spend time on the rotations since the code is all there anyways.
Advertisement
If you can''t figure this out on your own, and even by reading tutorial 10, then you probably don''t understand the math fundamentals needed for 3d coding. I suggest you start studying.
Hi all

Hay Kevinst, Don’t give on the coding, 3D math can be a pain in the *** at the start but when you get a hang of it, it is quite easy. Studying 3D Math will pay off.

Good Luck

3DG
Hey Kevinst, what you ask isn''t so hard. When you draw opbjects in opengl, you must first translate ''back away'' from the monitor screen, and deeper into the scene. (using glTranslatef) What you could do, (like Tbach said) though it is very simple, and you wouldn''t be able to turn, just strafe, is use variables for the values in glTranslatef(), then use the keys to modify the values of the variable. Nothing worth jumping up and down about, but still, I think it might work how you want it to. Thats how I was able to create ''movement'' in my first program, and don''t pay attention to those idiots, who replied to your post earlier, your new at this, and so am I. If you have anymore questions EMAIL me at galwyn@hotmail.com

wolfman8k and Tbach - LIGHTEN UP A BIT !!! Everyone starts out as a newbie, completely inept, and almost incapable of even thinking in the terms of openGL. But as they code they gain the ability, to think the way they need to. Until then, leave this guy alone. Just because you know more, doesn''t mean you have to trash talk him, when he asks for your help.

The Kid
I don''t know what the future holds, but I know who holds the future.
The Kid,
All they said was to study the maths part.
Like they all said before it is all there ready to cut and paste...




  if (keys[VK_RIGHT])							// Is The Right Arrow Being Pressed?{	yrot -= 1.5f;							// Rotate The Scene To The Left}if (keys[VK_LEFT])							// Is The Left Arrow Being Pressed?{	yrot += 1.5f;							// Rotate The Scene To The Right	}if (keys[VK_UP])							// Is The Up Arrow Being Pressed?{	xpos -= (float)sin(yrot*piover180) * 0.05f;			// Move On The X-Plane Based On Player Direction	zpos -= (float)cos(yrot*piover180) * 0.05f;			// Move On The Z-Plane Based On Player Direction	if (walkbiasangle >= 359.0f)					// Is walkbiasangle>=359?	{		walkbiasangle = 0.0f;					// Make walkbiasangle Equal 0	}	else								// Otherwise	{		 walkbiasangle+= 10;					// If walkbiasangle < 359 Increase It By 10	}	walkbias = (float)sin(walkbiasangle * piover180)/20.0f;		// Causes The Player To Bounce}if (keys[VK_DOWN])							// Is The Down Arrow Being Pressed?{	xpos += (float)sin(yrot*piover180) * 0.05f;			// Move On The X-Plane Based On Player Direction	zpos += (float)cos(yrot*piover180) * 0.05f;			// Move On The Z-Plane Based On Player Direction	if (walkbiasangle <= 1.0f)					// Is walkbiasangle<=1?	{		walkbiasangle = 359.0f;					// Make walkbiasangle Equal 359	}	else								// Otherwise	{		walkbiasangle-= 10;					// If walkbiasangle > 1 Decrease It By 10	}	walkbias = (float)sin(walkbiasangle * piover180)/20.0f;		// Causes The Player To Bounce}  


that goes in the WinMain

  int DrawGLScene(GLvoid)									// Here''s Where We Do All The Drawing{	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer	glLoadIdentity();									// Reset The View	GLfloat x_m, y_m, z_m, u_m, v_m;	GLfloat xtrans = -xpos;	GLfloat ztrans = -zpos;	GLfloat ytrans = -walkbias-0.25f;	GLfloat sceneroty = 360.0f - yrot;	int numtriangles;	glRotatef(lookupdown,1.0f,0,0);	glRotatef(sceneroty,0,1.0f,0);		glTranslatef(xtrans, ytrans, ztrans);					// Process Each Triangle	for (int loop_m = 0; loop_m < numtriangles; loop_m++)	{		glBegin(GL_TRIANGLES);			glVertex3f(-1.0f,-1.0f,0.0f);			glVertex3f(1.0f,1.0f,0.0f);			glVertex3f(-1.0f,1.0f,0.0f);		glEnd();	}	return TRUE;										// Everything Went OK}  


that goes in the glDrawScene




that will draw a triangle... Put more code in the draw parts...
don''t forget to include the math.h
Advertisement
this question has been asked so many times in this forum. Do a search on your topic before you post. You''ll come up with SO much info. Particularly so in this case. Try it!
Hi to you and everyone.

I''m a bit of a newbie myself, and I don''t profess to be a god at opengl or anything, but i''ve found that using the gluLookAt() function to be much better at moving around. This way you dont have to position your objects relative to the person, but relative to a common point. Then you can just move the camera around with gluLookAt().

I''m at work so I don''t know the syntax off the top of my head but it is something like:

gluLookAt(current x position, current y position, current z position, x position that you''re looking at, ypos you''re looking at, zpos you''re looking at, x position of up vector, y position of up vector, z position of up vector);

I''ll probably be shot at by all of the experienced coders for writing it out like that, so here is the actual syntax which I just looked up:

void gluLookAt(
GLdouble eyeX,
GLdouble eyeY,
GLdouble eyeZ,
GLdouble centerX,
GLdouble centerY,
GLdouble centerZ,
GLdouble upX,
GLdouble upY,
GLdouble upZ)

Parameters

eyeX, eyeY, eyeZ
Specifies the position of the eye point.
centerX, centerY, centerZ
Specifies the position of the reference point.
upX, upY, upZ
Specifies the direction of the up-vector.


So the ''eye'' set of variables is where you are, the ''center'' variables is where you''re looking and the ''up'' variables is a vector pointing straight up (otherwise you could be upside down, half way to the right etc, because OpenGL doesn''t know how you oreinted your objects).

I hope this helps you in someway, and good luck with the coding

This topic is closed to new replies.

Advertisement