Archived

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

Moving backwards makes the cube disappear

This topic is 5588 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

For some reason hitting the down arrow makes the cube disappear, and once it disappears it doesn''t ever reappear. I was thinking that it was outside of the viewing volume, err the frustrum thing, but even when I hit the up arrow it doesn''t come back I can sidestep to the left and right, and I can move forward, but going backwards makes the cube disappear Here is the keyboard routine (I am modifying NeHe''s code from lesson 1)
				if (keys[VK_ESCAPE]) // Was ESC Pressed?

				{

					done=TRUE; // ESC Signalled A Quit

				}
				if (keys[VK_LEFT])
				{
					SideStep += -.1;
				}
				if (keys[VK_RIGHT])
				{
					SideStep += .1;
				}
				if (keys[VK_UP])
				{
					BackNForth += -.1;
				}
				if(keys[VK_DOWN])
				{
					BackNForth += .1;
				}
 
And here is the drawscene routine that actually draws the cube and the plane that represents the ''floor''
int DrawGLScene(GLvoid) // Here''s Where We Do All The Drawing

{
	glClearColor(0.0f, 1.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
	glLoadIdentity();

	gluLookAt(SideStep, 0.0f, BackNForth,  SideStep, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); //sidestep = 0, backnfort = 25

	glBegin(GL_POLYGON);		//The cube

	glColor3f(1.0f, 0.0f, 0.0f);

	glVertex3f(0.0f, 0.5f, -1.0f);
	glVertex3f(0.0f, 1.5f, -1.0f);
	glVertex3f(1.0f, 1.5f, -1.0f);
	glVertex3f(1.0f, 0.5f, -1.0f);
	glVertex3f(0.0f, 0.5f, -1.0f);

	glVertex3f(0.0f, 0.5f, -3.0f);
	glVertex3f(0.0f, 1.5f, -3.0f);
	glVertex3f(1.0f, 1.5f, -3.0f);
	glVertex3f(1.0f, 0.5f, -3.0f);
	glVertex3f(0.0f, 0.5f, -3.0f);

	glVertex3f(0.0f, 1.5f, -3.0f);
	glVertex3f(0.0f, 1.5f, -1.0);
	glVertex3f(1.0f, 1.5f, -1.0f);
	glVertex3f(1.0f, 1.5f, -3.0f);
	glVertex3f(0.0f, 1.5f, -3.0f);
	glEnd();

SwapBuffers(hDC);

	glBegin(GL_POLYGON);	//The bottom plane, the floor

	glColor3f(0.0f, 1.0f, 0.0f);
		glVertex3f(-30, 0.0f, 30);
		glVertex3f(30, 0.0f, 30);
		glVertex3f(30, 0.0f, -30);
		glVertex3f(-30, 0.0f, -30);
		glEnd();
		SwapBuffers(hDC); 
//I swap the buffers after each glEnd() call, is this needed?



/*
dont'' need this, this is from previous experiments
	glVertex3f(0.0f, 0.0f, -1.0f);

	glVertex3f(0.0f, 1.0f, -1.0f);

	glVertex3f(1.0f, 1.0f, -1.0f);

	glVertex3f(1.0f, 0.0f, -1.0f);

	glVertex3f(0.0f, 0.0f, -1.0f);

	glVertex3f(0.0f, 0.0f, -3.0f);

	glVertex3f(0.0f, 1.0f, -3.0f);

	glVertex3f(1.0f, 1.0f, -3.0f);

	glVertex3f(1.0f, 0.0f, -3.0f);

	glVertex3f(0.0f, 0.0f, -3.0f);

	glEnd();
	*/

	return TRUE; // Everything Went OK

}
 
I really am not sure what I am doing wrong because all of the movements work except for moving backwards. Also I swap the buffers after each glend() call, is that necessary?

Share this post


Link to post
Share on other sites
quote:
Original post by Shadow1234567890


I really am not sure what I am doing wrong because all of the movements work except for moving backwards.
Also I swap the buffers after each glend() call, is that necessary?



first you don't have to swap the buffers more than once per frame. and if you do that then you are missing the whole point of using double buffering...

i think you are moving fast enough for the polygon to disapear.
try changing the max distance in gluPerspective()

[edit] spelling

[edited by - daher on August 27, 2002 5:26:51 PM]

Share this post


Link to post
Share on other sites
Yeppers, your far clipping plane is what is making the cube disappear, consider moving the far clipping plane farther into 3D world space (I set mine at a length of 8000 units in most of my simple demos, just to be safe. ).

Also, switch buffers ONCE per frame, that wouldn''t cause your problem, it just means you''re wasting needless time.

Trent(ShiningKnight)
trent@voxelsoft.com
The Official Site of All True Programmers

Share this post


Link to post
Share on other sites
Okay, for one it isn't moving fast enough for the cube to disappear, two if it was the clipping plane that was causing the cube to disappear wouldn't the cube reappear if I moved closer to it? The cube disappears and then never reappears no matter how close I move to it.

Also how to you set the clipping plane. glFrustrum or something like that?


What do you mean ''Someday become a programmer?'' I'm a programmer right now!

edit

what are good values for the glfrustum/gluperspective functions



[edited by - Shadow1234567890 on August 27, 2002 10:40:08 PM]

Share this post


Link to post
Share on other sites
Okay for some reason I still haven''t been able to make the cube stay in the scene when I hit the down arrow. Instead of actually moving backwards the cube simply disappears. I have fiddled with the gluPerspective and that doesn''t do a thing.

Share this post


Link to post
Share on other sites
gluLookAt(SideStep, 0.0f, BackNForth, SideStep, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f); //sidestep = 0, backnfort = 25

...

if (keys[VK_ESCAPE]) // Was ESC Pressed?

{

done=TRUE; // ESC Signalled A Quit

}
if (keys[VK_LEFT])
{
SideStep += -.1;
}
if (keys[VK_RIGHT])
{
SideStep += .1;
}
if (keys[VK_UP])
{
BackNForth += -.1;
}
if(keys[VK_DOWN])
{
BackNForth += .1;
}

...
If the left arrow key is pressed then the gluLookAt() function moves -.1 to the left, if it is moved up then the gluLookAt() function moves closer to the origin. I dont'' see how any of that is incorrect

Share this post


Link to post
Share on other sites