Solved

Opengl skybox

Posted on 2011-03-12
3
1,405 Views
Last Modified: 2012-05-11
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);


}
0
Comment
Question by:tango2009
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 250 total points
ID: 35133317
The trick is to draw the skydome BEFORE any camera transformation is made.
So you set your projection ,  and view matrix to identity, then set a view matrix taking into the account ONLY the rotation of the camera.
Now draw he sky,
Now set the projection and view matrix as usual and draw the scene.

The way I set the view matrix for the sky is take your regular view matrix (LookAt of some sort for example) then clear the translation part of the matrix (usually 41,42,43 elements of the matrix) and use this as the view matrix.
0
 
LVL 3

Assisted Solution

by:xelous
xelous earned 250 total points
ID: 35400409
Sunny (above) is correct, however, you also need to translate the skybox so that it is centred over your camera position each time you render the frame.

There's a rather good tutorial on here: http://www.morrowland.com/apron/tut_gl.php
0
 
LVL 8

Expert Comment

by:SunnyDark
ID: 35407383
If you only considering the view rotation part , then you dont need to reposition the skybox, as you are already at the center anyhow...
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
This is about my first experience with programming Arduino.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now