Ich arbeite mit OpenGL und ich möchte einen Würfel mit glutmotionfunc ziehen. Ich habe überhaupt nicht abgeschlossen, ich weiß nicht, wie ich meine Ansichten konfigurieren soll und ich weiß nicht, was los ist.Ziehen von Objekten mit der Maus mit 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;
}