2016-04-10 12 views
0

OpenGLで作業していて、glutmotionfuncでキューブをドラッグしたいと思います。私はまったく完了しなかった、私はどのように私のビューを構成するのか分からず、何が間違っているのか分からない。glutWireCube()でマウスでオブジェクトをドラッグする

#include <GL/gl.h> 
    #include <GL/glut.h> 


    double rotate_y=0; 
    double rotate_x=0; 
    double rotate_z=0; 

    GLfloat X = 0.0f; 
    GLfloat Y = 0.0f; 
    GLfloat Z = 0.0f; 
    GLfloat scale = 1.0f; 


    float ancho=800; 
    float alto=600; 
    int perspectiva = 0; 
    float rx, ry; 

    void motion(int x, int y) // this is my motion function 
    // called when a mouse is in motion with a button down 
    { 
     printf("YYYMotion call back: %d, %d)\n", x, y); 
     rx = x; 
     ry = alto - y; 
    } 

    void display() 
    { 
     // Borrar pantalla y Z-buffer 
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 

     // Resetear transformaciones 
     glLoadIdentity(); 


     gluLookAt(1.0, 2.0, 50.0, //eye (x,y,z) 
     0.0, 0.0, 0.0,   //at(x,y,z) 
     0.0, 1.0, 0.0);   //up (x,y,z) 
     glScalef(scale, scale, scale); 
     glTranslatef((rx/ancho), (1-(ry/alto)), 0); 

     glFlush(); 
     glutSwapBuffers(); 

    } 
    void menu(int valor) 
    { 
     switch(valor) 
     { 
     case 1: 
      glutWireTorus(0.5,2.0,20,20); 
      break; 
     case 2: 
      glutWireTeapot(1.0); 
      break; 
     case 3: 
      glutWireSphere(0.8,50,50); 
      break; 
     case 4: 
      glutWireCube(1.0f); 
      break; 
     case 5: 
      glutWireIcosahedron(); 
      break; 
     case 6: 
      glutWireOctahedron(); 
      break; 
     case 7: 
      glutWireTetrahedron(); 
      break; 
     case 8: 
      glutWireCone(0.5,1,5,5); 
      break; 
     case 9: 
      exit(1); 
      break; 

    } 
} 
    void menu_opciones(void) 
{ 
    glutCreateMenu(menu); 
    glutAddMenuEntry("Torus",1); 
    glutAddMenuEntry("Tetera",2); 
    glutAddMenuEntry("Esfera",3); 
    glutAddMenuEntry("Cubo",4); 
    glutAddMenuEntry("Icosaedro",5); 
    glutAddMenuEntry("Octaedro",6); 
    glutAddMenuEntry("Tetraedro",7); 
    glutAddMenuEntry("Cono",8); 
    glutAddMenuEntry("Salir",9); 
    glutAttachMenu(GLUT_RIGHT_BUTTON); 
} 

void init() 
{ 
    glClearColor(0,0,0,0); 
    // Habilitar la prueba de profundidad de Z-buffer 
    glEnable(GL_DEPTH_TEST); 
    ancho = 800; 
    alto = 600; 
} 

void reshape(int w, int h) 
{ 
    glViewport(0, 0, w,h); 
    glMatrixMode(GL_PROJECTION); 
    menu_opciones(); 
    glLoadIdentity(); 


    //gluPerspective(80.0f, (GLfloat)w/(GLfloat)h, 0.2f, 30.0f); 

    //glOrtho(-2,2, -2, 2, 1, 10); 
    //glOrtho(-2, 2, -2, 2, -2, 2); 
    glFrustum (-1.0, 1.0, -1.0, 1.0, 2.5, 50.0); 
    glMatrixMode(GL_MODELVIEW); 


} 







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

    // Inicializar los parámetros GLUT y de usuario proceso 
    glutInit(&argc,argv); 

    // Solicitar ventana con color real y doble buffer con Z-buffer 
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize (800, 600); 
    glutInitWindowSize(ancho, alto); 
    // Crear ventana 
    glutCreateWindow(""); 
    init(); 
    // Funciones de retrollamada 
    glutDisplayFunc(display); 
    glutReshapeFunc(reshape); 
    glutMotionFunc(motion); 
    //glutKeyboardFunc(keyboard); 
    //glutSpecialFunc(specialKeys); 

    // Pasar el control de eventos a GLUT 
    glutMainLoop(); 

    // Regresar al sistema operativo 
    return 0; 

} 

答えて

0

ここで実際に物を描いていますか?何かがありません:

void display() 
{ 
    // Borrar pantalla y Z-buffer 
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 

    // Resetear transformaciones 
    glLoadIdentity(); 


    gluLookAt(1.0, 2.0, 50.0, //eye (x,y,z) 
    0.0, 0.0, 0.0,   //at(x,y,z) 
    0.0, 1.0, 0.0);   //up (x,y,z) 
    glScalef(scale, scale, scale); 
    glTranslatef((rx/ancho), (1-(ry/alto)), 0); 

/* where are things actually drawn? <<<<<<<<<<<<<<<<< */ 

    glFlush(); 
    glutSwapBuffers(); 

} 

OpenGLはシーングラフではなく、描画APIです。 OpenGLの描画関数を呼び出すと、点、線、または三角形がフレームバッファに描画されます。一人一人ずつ自分でOpenGLでは「シーンにモデルを追加する」というようなことはありません。あなたの描画コードの息子は、何かを見るために何かを描く必要があります。あなたのシーンで何かが変わった場合は、すべてを再描画する必要があります。

関連する問題