tango2009
asked on
Opengl skybox
I am creating a skybox for my game. I have drawn a simple cube that will surround the game level. The question I have though is how to I draw the box so that it will keep its distance from the camera. This is so the player will not be able to walk through the background.
I have just drawn a very simple cube. Will this be sufficient.
void skybox(void)
{
glNormal3f( 0.0f, 0.0f, 0.5f);
glVertex3f(-300.0f, -300.0f, 300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
// Back Face
glNormal3f( 0.0f, 0.0f,-0.5f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
// Top Face
glNormal3f( 0.0f, 0.5f, 0.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
// Bottom Face
glNormal3f( 0.0f,-0.5f, 0.0f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
glVertex3f(-300.0f, -300.0f, 300.0f);
// Right Face
glNormal3f( 0.5f, 0.0f, 0.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
// Left Face
glNormal3f(-0.5f, 0.0f, 0.0f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f(-300.0f, -300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
}
I have just drawn a very simple cube. Will this be sufficient.
void skybox(void)
{
glNormal3f( 0.0f, 0.0f, 0.5f);
glVertex3f(-300.0f, -300.0f, 300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
// Back Face
glNormal3f( 0.0f, 0.0f,-0.5f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
// Top Face
glNormal3f( 0.0f, 0.5f, 0.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
// Bottom Face
glNormal3f( 0.0f,-0.5f, 0.0f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
glVertex3f(-300.0f, -300.0f, 300.0f);
// Right Face
glNormal3f( 0.5f, 0.0f, 0.0f);
glVertex3f( 300.0f, -300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, -300.0f);
glVertex3f( 300.0f, 300.0f, 300.0f);
glVertex3f( 300.0f, -300.0f, 300.0f);
// Left Face
glNormal3f(-0.5f, 0.0f, 0.0f);
glVertex3f(-300.0f, -300.0f, -300.0f);
glVertex3f(-300.0f, -300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, 300.0f);
glVertex3f(-300.0f, 300.0f, -300.0f);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you only considering the view rotation part , then you dont need to reposition the skybox, as you are already at the center anyhow...