Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1.  
  2. #include <windows.h>
  3. #include <GLFW/glfw3.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <math.h>
  8. #include <GL/glu.h>
  9. #include <vector>
  10. void print(float[]);
  11. using namespace std;
  12. class level{
  13. public:
  14. vector<double> point;
  15. vector<vector<double>> points;
  16. level(double h){
  17. point.reserve(3);
  18. points.reserve(100);
  19. double x, y,phi,r1 = 4*sqrt(h),r2 = 2 * sqrt(h);
  20. phi = 0;
  21. while (phi < 6.2){
  22. x = r1*cos(phi);
  23. y = r2*sin(phi);
  24. point.emplace_back(x);
  25. point.emplace_back(y);
  26. point.emplace_back(h);
  27. points.emplace_back(point);
  28. }
  29. }
  30. };
  31. double xpos, ypos;
  32. // 24 вариант
  33.  
  34. static void error_callback(int error, const char* description)
  35. {
  36. fputs(description, stderr);
  37. }
  38. static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
  39. {
  40. if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  41. glfwSetWindowShouldClose(window, GL_TRUE);
  42. }
  43. void make3per() {
  44. glMatrixMode(GL_PROJECTION);
  45. glLoadIdentity();
  46. double M[] = {
  47. 1 , 0 , 0 , 0 ,
  48. 0 , 1 , 0 , 0 ,
  49. 0 , 0 , -1.5 , 0 ,
  50. 0 , 0 , -0.9, 3
  51. };
  52. double phi = -0.2;
  53. double M1[] = {
  54. cos(-phi) , 0 , sin(-phi) , 0,
  55. 0 , 1 , 0 , 0,
  56. -sin(-phi), 0 , cos(-phi) , 0,
  57. 0 , 0 , 0, 1
  58. };
  59.  
  60. double M3[] = {
  61. 1 , 0 , 0 , 0,
  62. 0 , cos(phi) , sin(phi) , 0,
  63. 0 , -sin(phi) , cos(phi) , 0,
  64. 0 , 0 , 0, 1
  65. };
  66. glLoadMatrixd(M);
  67. glMultMatrixd(M1);
  68. glMultMatrixd(M3);
  69. }
  70.  
  71.  
  72.  
  73. int main(void)
  74. {
  75. double xCenter = 0.f, yCenter = 0.f, zCenter = 0.0f, scale = 1.f;
  76. int rAngle = 0, dAngle = 0;
  77. double h = 0;
  78.  
  79. //грани
  80. float front[] = { 0.f ,1.f ,1.f,
  81. 0.f,0.f,0.f,
  82. 0.5f,0.f,0.f,
  83. 0.5f,0.5f,0.f,
  84. 0.f,0.5f,0.f
  85. };
  86. float back[] = { 0.f ,0.5f ,1.f,
  87. 0.f,0.f,0.5f,
  88. 0.5f,0.f,0.5f,
  89. 0.5f,0.5f,0.5f,
  90. 0.f,0.5f,0.5f
  91. };
  92. float down[] = { 1.f ,0.5f, 0.f,
  93. 0.f,0.f,0.f,
  94. 0.5f,0.f,0.f,
  95. 0.5f,0.f,0.5f,
  96. 0.f,0.f,0.5f
  97. };
  98. float top[] = { 1.f ,1.f ,0.f,
  99. 0.f,0.5f,0.f,
  100. 0.5f,0.5f,0.f,
  101. 0.5f,0.5f,0.5f,
  102. 0.f,0.5f,0.5f
  103. };
  104. float lleft[] = { 0.f,1.f,0.5f,
  105. 0.f,0.f,0.f,
  106. 0.f,0.f,0.5f,
  107. 0.f,0.5f,0.5f,
  108. 0.f,0.5f,0.f
  109. };
  110. float rright[] = { 0.5f,1.f,0.f,
  111. 0.5f,0.f,0.f,
  112. 0.5f,0.f,0.5f,
  113. 0.5f,0.5f,0.5f,
  114. 0.5f,0.5f,0.f
  115. };
  116. vector<level> l;
  117. for (int i = 0; i < 30; i++){
  118. level a(h);
  119. l[i] = a;
  120. h += 0.1;
  121. }
  122. GLFWwindow* window;
  123. glfwSetErrorCallback(error_callback);
  124. if (!glfwInit()) {
  125. exit(EXIT_FAILURE);
  126. }
  127. window = glfwCreateWindow(800, 800, "Laba2", NULL, NULL);
  128. if (!window) {
  129. glfwTerminate();
  130. }
  131. glfwMakeContextCurrent(window);
  132. glfwSetKeyCallback(window, key_callback);
  133.  
  134. int width, height;
  135. double ratio;
  136. make3per();
  137. glfwGetFramebufferSize(window, &width, &height);
  138. ratio = width / height;
  139. glViewport(0, 0, width, height);
  140. glMatrixMode(GL_MODELVIEW_MATRIX);
  141. glEnable(GL_DEPTH_TEST);
  142. while (!glfwWindowShouldClose(window))
  143. {
  144. glfwGetCursorPos(window, &xpos, &ypos);
  145. glClearColor(0, 0, 0, 0);
  146. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  147. /*for (int i = 0; i < 30; i++) {
  148. level a = l[i];
  149. for(int j = 0 ; j < l[i].points.size() - 1 ; j++){
  150. glBegin(GL_LINES);
  151. vector<double> p1 = l[i].points[j];
  152. vector<double> p2 = l[i].points[j + 1];
  153. p1.reserve(3);
  154. p2.reserve(3);
  155. glColor3d(1, 0, 0);
  156. glVertex3d(p1[0], p1[1], p1[2]);
  157. glVertex3d(p2[0], p2[1], p2[2]);
  158. glEnd();
  159. }
  160.  
  161. }*/
  162. //отрисовка граней
  163. /*print(back);
  164. print(front);
  165. print(lleft);
  166. print(rright);
  167. print(down);
  168. print(top);*/
  169. glfwSwapBuffers(window);
  170. glfwPollEvents();
  171. }
  172. glfwTerminate();
  173. exit(EXIT_SUCCESS);
  174. }
  175.  
  176. void print(float plane[]) {
  177. glBegin(GL_QUADS);
  178. glVertex3d(plane[3], plane[4], plane[5]);
  179. glColor3f(plane[0] + xpos / 300, plane[1] - xpos / 200, plane[2] + ypos / 900);
  180. glVertex3d(plane[6], plane[7], plane[8]);
  181. glColor3f(plane[0] - xpos / 900, plane[1] - xpos / 700, plane[2] - ypos / 900);
  182. glVertex3d(plane[9], plane[10], plane[11]);
  183. glColor3f(plane[0] + xpos / 900, plane[1] + xpos / 300, plane[2] - ypos / 600);
  184. glVertex3d(plane[12], plane[13], plane[14]);
  185. glColor3f(plane[0] - xpos / 800, plane[1] + xpos / 900, plane[2] + ypos / 900);
  186. glEnd();
  187. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement