Advertisement
ait-survey

keep rotate

Nov 5th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1.  
  2. #include <GL/freeglut.h>
  3. #include <cstdio>
  4.  
  5. //----------- プロトタイプ宣言 --------------//
  6. void display();
  7. void reshape(int w, int h);
  8. void timer(int value);
  9. void MouseWheel(int wheel_number, int direction, int x, int y);
  10.  
  11.  
  12.  
  13. //------------- OpenGLの初期設定 ------------------//
  14. void GLUT_INIT()
  15. {
  16.         glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH);
  17.         glutInitWindowSize(640,480);
  18.         glutCreateWindow("freeglut MouseWheel");
  19. }
  20.  
  21. void GLUT_CALL_FUNC()
  22. {
  23.         glutDisplayFunc(display);
  24.         glutReshapeFunc(reshape);
  25.         glutMouseWheelFunc ( MouseWheel ) ;//ホイールコールバック
  26.         glutTimerFunc(0,timer,17);
  27. }
  28.  
  29. void MY_INIT()
  30. {
  31.         glClearColor(1.0, 1.0, 1.0, 1.0);
  32.  
  33.         glEnable(GL_DEPTH_TEST);//ZバッファON
  34. }
  35.  
  36.  
  37.  
  38. //--------- GLUTの初期設定 -----------//
  39. void GLUT_INITs(int *argcp, char **argv)
  40. {
  41.         glutInit(argcp,argv);
  42.         GLUT_INIT();
  43.         GLUT_CALL_FUNC();
  44.         MY_INIT();
  45. }
  46.  
  47. //------------- メイン関数 ----------------//
  48. int main(int argc, char **argv)
  49. {
  50.  
  51.         GLUT_INITs(&argc, argv);
  52.         glutMainLoop();
  53.  
  54.         return 0;
  55. }
  56.  
  57.  
  58.  
  59. //------------ ここからコールバック関数 ------------------//
  60. void display()
  61. {
  62.         static int r = 0;
  63.  
  64.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  65.         glColor3f(0,0,1);
  66.         glPushMatrix();
  67.         glRotated(static_cast<double>(r), 0.0, 1.0, 0.0);
  68.         glutWireRhombicDodecahedron();//菱形12面体
  69.         glPopMatrix(); //行列を戻す
  70.         glColor3f(1,1,1);
  71.  
  72.         glutSwapBuffers();
  73.  
  74.         if(++r > 360){r= 0;}
  75. }
  76.  
  77.  
  78. void reshape(int w, int h)
  79. {
  80.         glViewport(0, 0, w, h);
  81.  
  82.         glMatrixMode(GL_PROJECTION);
  83.         glLoadIdentity();
  84.         gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0);
  85.  
  86.         glMatrixMode(GL_MODELVIEW);
  87.         glLoadIdentity();
  88.         gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  89. }
  90.  
  91. void timer(int t)
  92. {
  93.         glutPostRedisplay();
  94.         glutTimerFunc(t,timer,17); //タイマー関数
  95. }
  96.  
  97.  
  98. void MouseWheel(int wheel_number, int direction, int x, int y)
  99. {
  100.         printf("WheelNumber:%d,  direction:%d, at (%d, %d)\n",wheel_number,direction,x,y);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement