Original Post
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):
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.
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.