Advertisement
Kojima0502

mouse_move2

Jan 25th, 2014
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #define GLUT_LEFT_BUTTON0
  2. #define GLUT_MIDDLE_BUTTON1
  3. #define GLUT_RIGHT_BUTTON2
  4. #define GLUT_DOWN0
  5. #define GLUT_UP1
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <GLUT/glut.h>
  9. float shiftX,shiftY;
  10. float mouseX,mouseY;
  11. void display(void)
  12. {
  13.    
  14.     glClear(GL_COLOR_BUFFER_BIT);
  15.     glTranslatef(shiftX,shiftY,0);
  16.     glColor3d(0.0, 0.0, 0.0);//色
  17.     glBegin(GL_LINE_LOOP);
  18.     glVertex2d(-0.1f, -0.1f);//位置
  19.     glVertex2d(0.1f, -0.1f);//位置
  20.     glVertex2d(0.1f, 0.1f);//位置
  21.     glVertex2d(-0.1f, 0.1f);//位置
  22.    
  23.     glEnd();
  24.     glFlush();
  25.    
  26. }
  27.  
  28. void keyboard(unsigned char key, int x, int y)
  29. {
  30.     switch (key) {
  31.         case 'q':
  32.         case 'Q':
  33.         case '\033':  /* '\033' は ESC の ASCII コード */
  34.             exit(0);
  35.         default:
  36.             break;
  37.     }
  38. }
  39.  
  40. void resize(int w, int h)
  41. {
  42.    
  43. }
  44.  
  45.  
  46.  
  47. void mouse(int btn, int state, int x, int y){
  48.     if(state == GLUT_DOWN){
  49.         mouseX = x;
  50.         mouseY = y;
  51.     }
  52.     else if(btn==GLUT_MIDDLE_BUTTON){
  53.         shiftX += 0.01f*(x - mouseX);
  54.         shiftY -= 0.01f*(y - mouseY);
  55.         display();
  56.     }
  57. }
  58.  
  59. void init(void)
  60.  
  61.     {
  62.         glClearColor(1.0, 1.0, 1.0, 0.0);
  63.    
  64. }
  65.  
  66. int main(int argc, char *argv[])
  67. {
  68.     glutInitWindowPosition(100, 100);//ウィンドウの位置
  69.     glutInitWindowSize(600, 600);//ウィンドウの幅と大きさ
  70.     glutInit(&argc, argv);
  71.     glutInitDisplayMode(GLUT_RGBA);
  72.     glutCreateWindow(argv[0]);
  73.     glutDisplayFunc(display);
  74.     glutKeyboardFunc(keyboard);
  75.     glutMouseFunc(mouse);
  76. //motionfunc
  77.     init();
  78.     glutMainLoop();
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement