2013-03-02 49 views
2

我的問題是我在Xcode中有一個項目,我必須使用OpenGL來創建兩個原子,其中一個原子位於窗口的中心,另一個原子圍繞第一個原子旋轉。我的問題是,似乎沒有深度。旋轉的原子永遠不會穿過另一個。在Xcode中使用OpenGL的深度

我有這樣的代碼:

#include <GLUT/glut.h> 
#include <OpenGL/gl.h> 
#include <OpenGL/glu.h> 

const int W_WIDTH = 500; 
const int W_HEIGHT = 500; 
GLfloat Rot = 0; 

void Display(void) { 
    glEnable(GL_DEPTH_TEST); 
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
    glMatrixMode(GL_MODELVIEW); // Se activa la matriz del modelador 
    glLoadIdentity(); //Se pone a "0" realmente al 1 

    // Boramos la pantalla 
    glOrtho(-500.0f, 500.0f, -500.0f, 500.0f, -500.0f, 500.0f); 

    //glPushMatrix(); 
    glTranslatef(0.0f, 0.0f, -100.0f); // Se traslada todo al -100 

    // Red Nucleus 
    glColor3f(255, 0, 0); 
    glutSolidSphere(12.0f, 20, 20); // Se dibuja una esfera 


    glPushMatrix(); 
    // First Electron Orbit 
    // Se hace un push copiamos la traslacion de -100 a la Pila 
    // Save viewing transformation 
    // Rotate by angle of revolution 
    //Sumamos a la translacion -100 una rotacion = -100 + rotacion 

    glRotatef(Rot, 0.0f, 1.0f, 0.0f); 
    // Translate out from origin to orbit distance 
    glTranslatef(90.0f, 0.0f, 0.0f); //Sumamos a la -100 + rotacion una nueva traslacion = -100 + rotacion + 90 
    glColor3f(0, 00, 100); 
    glutSolidSphere(8.0f, 20, 20); // Draw the electron 
    // Se recupera la matriz de la pila quie era -100 
    /* Se dibujan los siguiente electrone.*/ 

    glPopMatrix(); 

    /* 
     glPushMatrix(); 
     glColor3f(0, 00, 100); 
     glRotatef(fAngulo, 0.0f, 1.0f, 0.0f); 
     glTranslatef(-90.0f, 0.0f, 0.0f); 
     glutSolidSphere(6.0f, 20, 20); 
     fAngulo = fAngulo + 0.03; 
     glPopMatrix(); 
    */ 

    glutSwapBuffers();// Se limpian los buffers 
    glFlush(); 
} 

void idle(void) { 
    Rot += 0.01; 
    if(Rot > 360.0f) 
     Rot = 0.0f; 
    glutPostRedisplay(); 
} 



int main(int argc, char **argv) { 

    glutInit(&argc, argv); 
    //Inicializa la ventana en una determinada posicion 
    glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE); // Nombre de la ventana 
    glutInitWindowPosition(0, 0); 
    //Inicializa el tamano de la funcion 
    glutInitWindowSize (W_WIDTH, W_HEIGHT); //Inicaliza el modeo de display, RGBA y Doble buffer 

    glutCreateWindow("Ventana"); 

    glutDisplayFunc(Display); 
    glutIdleFunc(idle); 

    glutMainLoop(); 
    return 0; 
} 

回答

3
glutInitDisplayMode (GLUT_RGBA | GLUT_DOUBLE); 

你是如何做深度測試沒有深度緩衝規劃?在OR列車的後面拍了一個GLUT_DEPTH