Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include <Windows.h>
  2. #include <gl/GL.h>
  3. #include <gl/GLU.h>
  4. #include <gl/glut.h>
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. #define WIDTH 640
  10. #define HEIGHT 480
  11.  
  12. // starting camera position
  13. GLfloat     eyeX=0.0;
  14. GLfloat     eyeY=0.0;
  15. GLfloat     eyeZ=2.0;
  16. GLfloat     centerX=0.0;
  17. GLfloat     centerY=0.0;
  18. GLfloat     centerZ=0.0;
  19. GLfloat     upX=0.0;
  20. GLfloat     upY=1.0;
  21. GLfloat     upZ=0.0;
  22.  
  23. // aspect ratio
  24. GLdouble aspectRatio=WIDTH/HEIGHT;
  25. GLdouble worldx = 2.0*aspectRatio;
  26. GLdouble worldy = 2.0;
  27.  
  28. // Zoom factor to allow the camera to 'zoom in' and 'zoom out'
  29. GLfloat zoomFactor = 1.0;        
  30.  
  31. // user defined functions
  32. void MyInit();
  33. void Draw();
  34. //void ChangeSize(GLsizei w, GLsizei h);
  35. //void SpecialKeys(int key, int x, int y);
  36. //void MyKeyboard(unsigned char theKey, int x, int y);
  37. //void myTimerFunction(int value);
  38.  
  39. // Main function
  40. int main(int argc, char **argv)
  41. {
  42.     glutInit(&argc, argv);
  43.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  44.     glutInitWindowSize(WIDTH, 480);
  45.     glutInitWindowPosition(100, 100);
  46.     glutCreateWindow("Malignant Tumor Growth Model");
  47.     glutDisplayFunc(Draw);                           // DisplayFunc callback is Draw                           
  48.     //glutReshapeFunc(ChangeSize);                   // ReshapeFunc callback is ChangeSize
  49.     //glutSpecialFunc(SpecialKeys);                    // SpecialFunc callback is SpecialKeys
  50.     //glutKeyboardFunc(MyKeyboard);                    // KeyboardFunc callback is Keyboard
  51.     glViewport(0, 0, 640, 480);
  52.     //glutTimerFunc(1,myTimerFunction,0);              // TimerFunc callback is myTimerFunction
  53.    
  54.     MyInit();
  55.    
  56.     glutMainLoop();
  57.    
  58.     return 0;
  59. }
  60.  
  61. void MyInit()
  62. {
  63.     glMatrixMode(GL_PROJECTION); // set the view volume shape
  64.     glLoadIdentity();
  65.     glOrtho(-worldx, worldx, -worldy, worldy, 0.1, 200);
  66.    
  67.     glMatrixMode(GL_MODELVIEW); // position and aim the camera
  68.     glLoadIdentity();
  69.     gluLookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ); // original view point
  70.    
  71.     glClearColor(1.0f, 0.5f, 0.5f, 0.0f);  
  72.  
  73.     GLfloat mat_ambient[] = {0.0, 0.5, 0.8, 1.0 };   // object material settings
  74.     GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0 };
  75.     GLfloat mat_shininess[] = {50.0};
  76.     GLfloat light_position0[] = {-1.0, 1.0, -2.0, 0.0 };  // light position
  77.     GLfloat light_position1[] = {1.0, -1, -2.0, 0.0 };
  78.     GLfloat light_position2[] = {1.0, -1.0, 2.0, 0.0 };
  79.     GLfloat light_position3[] = {-1.0, -1.0, 2.0, 0.0 };
  80.  
  81.     GLfloat model_ambient[] = {0.5, 0.5, 0.5, 1.0 };    // lighting
  82.  
  83.     glClearColor(0.0, 0.0, 0.0, 0.0);
  84.    
  85.     // set lighting and material of the objects
  86.     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  87.     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  88.     glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  89.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, model_ambient);
  90.  
  91.     // set light 0
  92.     glEnable(GL_LIGHTING);
  93.     glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
  94.     glEnable(GL_LIGHT0);
  95.    
  96.     // set light 1
  97.     glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
  98.     glEnable(GL_LIGHT1);
  99.    
  100.     // set light 2
  101.     glLightfv(GL_LIGHT2, GL_POSITION, light_position2);
  102.     glEnable(GL_LIGHT2);
  103.    
  104.     // set light 3
  105.     glLightfv(GL_LIGHT3, GL_POSITION, light_position3);
  106.     glEnable(GL_LIGHT3);
  107.    
  108.    
  109.     glEnable(GL_DEPTH_TEST);
  110. }  
  111.  
  112. // The purpose of this function is to draw the objects to the screen
  113. void Draw()
  114. {
  115.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);                         // clear the screen
  116.  
  117.     glPushMatrix();
  118.     glTranslated(-0.5, 0, 0);
  119.     glutSolidTeapot(0.5);
  120.     glPopMatrix();     
  121.  
  122.     // draw cone at (1.65, 0, 0)
  123.     glPushMatrix();
  124.     glTranslated(1.65, 0,0.0); 
  125.     glutSolidCone(0.5, 1.5, 10, 8);  
  126.     glPopMatrix();     
  127.  
  128.     glPopMatrix();                                                              // restore the matrix state
  129.     glutSwapBuffers();
  130. }
Add Comment
Please, Sign In to add comment