Solved

Opengl skybox

Posted on 2011-03-12
3
1,395 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

728 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

14 Experts available now in Live!

Get 1:1 Help Now