[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Opengl skybox

Posted on 2011-03-12
3
Medium Priority
?
1,454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
SunnyDark earned 1000 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Simple Linear Regression
Suggested Courses

656 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