Advertisement
xerpi

Untitled

Apr 21st, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include <gl/gl.h>
  2. #include <gl/glut.h>
  3. #include <stdio.h>
  4.  
  5.  
  6. float alpha, beta, theta;
  7. int x0, y0;
  8. void display(void) {
  9.     glClear(GL_COLOR_BUFFER_BIT);
  10.     glMatrixMode(GL_PROJECTION);
  11.     glLoadIdentity();
  12.     gluPerspective(20.0f, 1.0f, 1.0f, 10.0f);
  13.     glMatrixMode(GL_MODELVIEW);
  14.     glLoadIdentity();
  15.     gluLookAt(0.0f, 0.0f, 5.0f,
  16.     0.0f, 0.0f, 0.0f,
  17.     0.0f, 1.0f, 0.0f);
  18.     glRotatef(alpha, 1.0f, 0.0f, 0.0f);
  19.     glRotatef(beta, 0.0f, 1.0f, 0.0f);
  20.     glRotatef(theta, 0.0f, 0.0f, 1.0f);
  21.     glutWireCube(0.5);
  22.     glFlush();
  23.     glutSwapBuffers();
  24. }
  25.  
  26. void update() {
  27.     theta = theta + 1;
  28.     glutPostRedisplay();
  29. }
  30.  
  31. void onMouse(int button, int state, int x, int y) {
  32.     if ( (button == GLUT_LEFT_BUTTON) & (state == GLUT_DOWN) ) {
  33.         x0 = x; y0 = y;
  34.     }
  35. }
  36. void onMotion(int x, int y) {
  37.     alpha = (alpha + (y - y0));
  38.     beta = (beta + (x - x0));
  39.     x0 = x; y0 = y;
  40.     glutPostRedisplay();
  41. }
  42. int main(void) {
  43.     theta = 0;
  44.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  45.     glutInitWindowSize(400, 400);
  46.     glutInitWindowPosition(100, 100);
  47.     glutCreateWindow("Ejemplo de menus");
  48.     glutDisplayFunc(display);
  49.     glutIdleFunc(update);
  50.     glutMouseFunc(onMouse);
  51.     glutMotionFunc(onMotion);
  52.     glutMainLoop();
  53.     return 1;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement