SHARE
TWEET

Untitled

a guest Feb 27th, 2020 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int     eyeX = 0, eyeY = 15, eyeZ = 60,
  2.         lookAtX = 0, lookAtY = 0, lookAtZ = -20,
  3.         upX = 0, upY = 1,  upZ = 0;
  4.  
  5. int speed = 1;
  6. int refreshmil = 250;
  7.  
  8. void timer(int value){
  9.     glutPostRedisplay();
  10.     glutTimerFunc(refreshmil, timer, 0);
  11. }
  12.  
  13. void setCamera(int eyeX, int eyeY, int eyeZ, int lookAtX, int lookAtY, int lookAtZ, int upX, int upY, int upZ){
  14.     gluLookAt(eyeX, eyeY, eyeZ, lookAtX, lookAtY, lookAtZ, upX, upY, upZ);
  15. }
  16.  
  17. void init()
  18. {
  19.     GLfloat light_amb[] = { 1, 1, 1, 0 };
  20.     glEnable(GL_DEPTH_TEST);
  21.     glShadeModel(GL_SMOOTH);
  22.     glLightfv(GL_LIGHT0, GL_AMBIENT, light_amb);
  23.     glEnable(GL_LIGHTING);
  24.     glEnable(GL_LIGHT0);
  25.     glShadeModel(GL_SMOOTH);
  26.     glEnable(GL_COLOR_MATERIAL);
  27.     glEnable(GL_BLEND);
  28.     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  29. }
  30.  
  31. void moveCamera(unsigned char key, int x, int y) {
  32.     switch (key) {
  33.         case 119: //W move camera forward
  34.             lookAtZ--;
  35.             eyeZ--;
  36.             break;
  37.         case 115: //S move camera back
  38.             lookAtZ++;
  39.             eyeZ++;
  40.             break;
  41.         case 97: //A move camera left
  42.             lookAtX--;
  43.             eyeX--;
  44.             break;
  45.         case 100: //D move camera right
  46.             lookAtX++;
  47.             eyeX++;
  48.             break;
  49.         case 113: //Q move camera down
  50.             lookAtY--;
  51.             eyeY--;
  52.             break;
  53.         case 101: //E move camera up
  54.             lookAtY++;
  55.             eyeY++;
  56.             break;
  57.         case 122: //tilt up
  58.             lookAtY++;
  59.             break;
  60.         case 120: //tilt down
  61.             lookAtY--;
  62.             break;
  63.         case 99:
  64.             lookAtX--;
  65.             break; //tilt left
  66.         case 118:
  67.             lookAtX++;
  68.             break; //tilt right
  69.         case 32: //press space bar to exit program
  70.             exit(0);
  71.             break;
  72.     }
  73. }
  74.  
  75. int rotateVal = 0;
  76.  
  77. void display()
  78. {
  79.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  80.     glLineWidth(1.0);
  81.     glClearColor(0.678, 0.847, 0.902, 0);
  82.     glLoadIdentity();
  83.     glutKeyboardFunc(moveCamera);
  84.    
  85.     setCamera(eyeX, eyeY, eyeZ, lookAtX, lookAtY, lookAtZ, upX, upY, upZ);
  86.    
  87.     glFlush();
  88. }
  89.  
  90. void reshape(int w, int h)
  91. {
  92.     glViewport(0, 0, (GLsizei)w, (GLsizei) h);
  93.     glMatrixMode(GL_PROJECTION);
  94.     glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 400.0);
  95.     glMatrixMode(GL_MODELVIEW);
  96. }
  97.  
  98. int main(int argc, char** argv)
  99. {
  100.     glutInit(&argc, argv);
  101.     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  102.     glutInitWindowSize(900, 700);
  103.     glutInitWindowPosition(100, 100);
  104.     glutCreateWindow("blank");
  105.    
  106.  
  107.     init();
  108.    
  109.     glMatrixMode(GL_MODELVIEW);
  110.     glLoadIdentity();
  111.     glColor3f(0, 1, 0);
  112.     glutDisplayFunc(display);
  113.    
  114.     glutReshapeFunc(reshape);
  115.     glutTimerFunc(10, timer, 0);
  116.     // glutFullScreen();
  117.     glutMainLoop();
  118.     return 0;
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top