Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <GL/glew.h>
  2. #include <GLFW/glfw3.h>
  3. #include <OpenGL/gl.h>
  4. #include <OpenGl/glu.h>
  5. #include <GLUT/glut.h>
  6. #include <iostream>
  7. #define _USE_MATH_DEFINES
  8. #include <math.h>
  9. #include <stdio.h>
  10. GLfloat xRotated, yRotated, zRotated;
  11. GLdouble radius = .3;
  12. GLfloat xPos = 0;
  13. GLfloat yPos = 0;
  14. GLfloat zPos = 0;
  15. GLfloat vertices[11][3] = {{-1,-1,0},{-.8,-.8,0},{-.6,-.6,0},{-.4,-.4,0},{-.2,-.2,0},{0,0,0},{.2,.2,0},{.4,.4,0},{.6,.6,0},{.8,.8,0}, {1,1,0}};
  16. int test[4] = {1,2,3,4};
  17. void display(void);
  18. void reshape(int x, int y);
  19. void idle(void)
  20. {
  21. //xRotated += 0.3;
  22. // yRotated += 0.3;
  23. zRotated += 0.3;
  24. display();
  25. }
  26. int main (int argc, char **argv)
  27. {
  28. glutInit(&argc, argv);
  29. glutInitWindowSize(350,350);
  30. glutCreateWindow("Solid Sphere");
  31. xRotated = yRotated = zRotated = 30.0;
  32. xRotated=43;
  33. yRotated=350;
  34. glutDisplayFunc(display);
  35. glutReshapeFunc(reshape);
  36. glutIdleFunc(idle);
  37. glutMainLoop();
  38. return 0;
  39. }
  40. void myWireSphere(float r, int nParal, int nMerid){
  41. float x,y,z,i,j;
  42. for (j=0;j<3.14159; j+=3.14159/(nParal+1)){
  43. glBegin(GL_LINE_LOOP);
  44. y=(float) (r*cos(j));
  45. for(i=0; i<2*3.14159; i+=3.1415960){
  46. x=(float) (r*cos(i)*sin(j));
  47. z=(float) (r*sin(i)*sin(j));
  48. glVertex3f(x,y,z);
  49. }
  50. glEnd();
  51. }
  52.  
  53. for(j=0; j<3.14159; j+=3.14159/nMerid){
  54. glBegin(GL_LINE_LOOP);
  55. for(i=0; i<2*3.14159; i+=3.14159/60){
  56. x=(float) (r*sin(i)*cos(j));
  57. y=(float) (r*cos(i));
  58. z=(float) (r*sin(j)*sin(i));
  59. glVertex3f(x,y,z);
  60. }
  61. glEnd();
  62. }
  63. }
  64.  
  65. void display(void)
  66. {
  67. glMatrixMode(GL_MODELVIEW);
  68. // clear the drawing buffer.
  69. glClear(GL_COLOR_BUFFER_BIT);
  70. // clear the identity matrix.
  71. glLoadIdentity();
  72. // traslate the draw by z = -4.0
  73. // Note this when you decrease z like -8.0 the drawing will looks far , or smaller.
  74. glTranslatef(0.0,0.0,-5.0);
  75. // Red color used to draw.
  76. glColor3f(0.9, 0.3, 0.2);
  77. // changing in transformation matrix.
  78. // rotation about X axis
  79. //Translates sphere to given coordinates
  80. // glTranslatef(xPos, yPos, zPos);
  81. // glRotatef(xRotated,1.0,0.0,0.0);
  82. // rotation about Y axis
  83. // glRotatef(yRotated,0.0,1.0,0.0);
  84. // rotation about Z axis
  85. //glRotatef(zRotated,0.0,1.0,1.0);
  86. // scaling transfomation
  87. glScalef(1.0,1.0,1.0);
  88. glTranslatef(vertices[0][0], vertices[0][1], vertices[0][2]);
  89. myWireSphere(radius,25,25);
  90. //glutWireSphere(radius,25,25)
  91. for (int i = 1; i < sizeof(vertices)/sizeof(vertices[0]); i++) {
  92. glTranslatef(vertices[i][0] - vertices[i-1][0], vertices[i][1] - vertices[i-1][1], vertices[i][2] - vertices[i-1][2]);
  93. myWireSphere(radius,25,25);
  94. }
  95. // Flush buffers to screen
  96. glFlush();
  97. // sawp buffers called because we are using double buffering
  98. // glutSwapBuffers();
  99. }
  100. void reshape(int x, int y)
  101. {
  102. if (y == 0 || x == 0) return;
  103. glMatrixMode(GL_PROJECTION);
  104. glLoadIdentity();
  105. gluPerspective(39.0,(GLdouble)x/(GLdouble)y,0.6,21.0);
  106. glMatrixMode(GL_MODELVIEW);
  107. glViewport(0,0,x,y); //Use the whole window for rendering
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement