Solved

Opengl skybox

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to refer to value 8 81
AutoIncrement column based of FK 11 64
what is the best Integrated development environment 2 39
IntelliJ and Eclipse Neon 2 installations 4 38
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.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

733 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