Skip to main content
gamedev.net
🔒 Locked

Skybox

Started by Mybowlcut Mar 21, 2009 at 3:03 AM 2 replies 1k views
Original Post
Mybowlcut
Mybowlcut
Hey. I'm trying to do an assignment where a skybox (cube) is drawn around the player. Wherever the player moves, the skybox moves with them, so that it is at an infinite distance from them. Here is the code (excavator = player - don't ask):
void RendererOpenGL::Render(Excavator bigExcavator) // this does the drawing
{	
	float ExcavatorX = bigExcavator.getLocationX();
	float ExcavatorZ = bigExcavator.getLocationZ();
	float angleAroundY = bigExcavator.getZAngleInDegrees();

	float turretAngle = bigExcavator.getTurretAngle();
	float upperArmAngle = bigExcavator.getUpperArmAngle();
	float lowerArmAngle = bigExcavator.getLowerArmAngle();
	
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // clear buffers from last frame
	glLoadIdentity(); // clear coordinate transformation - (0,0,0) is the screen centre

	glPushMatrix();
	
	// Transformation for keyboard input
	glRotatef(-angleAroundY, 0.0, 1.0, 0.0);
	glTranslatef(-ExcavatorX, -1.0, -ExcavatorZ);
	
	// DRAW THE SKYBOX	
	renderBox(2, m_mySkybox[0], m_mySkybox[1], m_mySkybox[2], m_mySkybox[3], m_mySkybox[4]);

	//Clear the depth buffer
	glClear(GL_DEPTH_BUFFER_BIT);

	glPopMatrix();

	// Draw the ground
	glColor3f(0,1,0);
	float planeSize = 100;
	glBegin(GL_QUADS);
	  glVertex3f(planeSize,0,planeSize);
	  glVertex3f(planeSize,0,-planeSize);
	  glVertex3f(-planeSize,0,-planeSize);
	  glVertex3f(-planeSize,0,planeSize);
	glEnd();	

	
	SwapBuffers(hDC);
}

It doesn't work as it's supposed to. The player can walk through the box, ie they can leave the skybox. I'm curious as to what I'm doing wrong... Cheers.

razorjack
razorjack
What matrix mode have you set?

Try to set matrix mode GL_MODELVIEW
and change glTranslatef( 0.0, -1.0, 0.0);

It should leave the box always at the position of the camera.
My spacesim project blog:http://www.simerge.com/
Mybowlcut
Mybowlcut
Hey razorjack, I tried what you said but it didn't affect it. Turns out the skybox was getting drawn too early... :s

knighty
knighty
Perhaps You should issue the translation before the rotation (before drawing the sky-box).
Edit: is the translation necessary?

BTW:
- Why are you pushing an identity matrix :)
- You are clearing the z buffer two times. You can just disable depth test while drawing the sky-box.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.