2010-09-18 35 views
0

因此,我正在完成一項家庭作業,並且設法創建了我的天空盒並且它看起來正確,唯一的問題是我的相機在天空盒之外。在我的天空盒內獲取相機

我試過命令gluLookAt的思想也許會把我的注意力集中到盒子裏,但它沒有奏效。這是我現在的代碼。如果有人可以讓我知道我在做什麼錯了,將不勝感激:

gluLookAt(
     0,0,0, 
     0,0,0 
     0,1,0); 
glPushMatrix(); 
//load identity matrix 
glLoadIdentity(); 

//update x, y and z rotation directions 
glRotatef(currentRotation[1], 1.0, 0.0, 0.0); //x rotation 
glRotatef(currentRotation[2], 0.0, 1.0, 0.0); //y rotation 
glRotatef(currentRotation[3], 0.0, 0.0, 1.0); //z rotation 
/* 
//update scale of display 
glScalef(currentScaling[1], 
    currentScaling[2], 
    currentScaling[3]);*/ 

//translate the image 
glTranslatef(currentTranslation[1], 
    currentTranslation[2], 
    currentTranslation[3]); 

    /* Clear buffers */ 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glEnable(GL_TEXTURE_2D); // Enable texturing from now on 


    //front quadrant 
    glBindTexture(GL_TEXTURE_2D,frontTextureId); // select which texture to use 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(1.0 ,0.0); glVertex3f(-0.5, 0.5, 0.5); 
    glTexCoord2f(0.0 ,0.0); glVertex3f(0.5, 0.5, 0.5); 
    glTexCoord2f(0.0 ,1.0); glVertex3f(0.5, 0.5, -0.5); 
    glTexCoord2f(1.0 ,1.0); glVertex3f(-0.5, 0.5, -0.5); 
    glEnd(); 

//left quadrant 
    glBindTexture(GL_TEXTURE_2D, leftTextureId); 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5); 
    glTexCoord2f(1.0, 1.0); glVertex3f(-0.5, -0.5, -0.5); 
    glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, -0.5, 0.5); 
    glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.5, 0.5); 
    glEnd(); 

    //back quadrant 
    glBindTexture(GL_TEXTURE_2D, backTextureId); 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(1.0, 1.0); glVertex3f(0.5, -0.5, -0.5); 
    glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, 0.5); 
    glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5); 
    glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5); 
    glEnd(); 

    //right quadrant 
    glBindTexture(GL_TEXTURE_2D, rightTextureId); 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5); 
    glTexCoord2f(1.0, 0.0); glVertex3f(0.5, 0.5, 0.5); 
    glTexCoord2f(0.0, 0.0); glVertex3f(0.5, -0.5, 0.5); 
    glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, -0.5); 
    glEnd(); 

    //up quadrant 
    glBindTexture(GL_TEXTURE_2D, upTextureId); 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5); 
    glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, 0.5, 0.5); 
    glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0.5); 
    glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, 0.5); 
    glEnd(); 

    //down quadrant 
    glBindTexture(GL_TEXTURE_2D, downTextureId); 
    glBegin(GL_QUADS); 
    glColor3f(1.0, 1.0, 1.0); 
    glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, -0.5); 
    glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5); 
    glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5); 
    glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, -0.5); 
    glEnd(); 

謝謝你的任何幫助,您可以提供!

回答

0

幾個問題一目瞭然:gluLookAt參數:前三個是相機位置,後三個是相機目標 - 不應該是相同的,相機必須有有效的方向向量。接下來,你的天空盒只有1.0個單位 - 讓它更大。使用一個常數而不是0.5,這樣你就可以在一個地方控制它。

0

那麼你確實有一個glTranslate()電話在那裏,所以除非你通過它零,這可能是爲什麼你不在框中。

1

我覺得你的問題是在glulookat

嘗試用這個值

gluLookAt(0.0, 0.0 , 2.0 , 
      0.0, 0.0, 0.0, 
      0.0, 1.0, 0.0);