Advertisement
Tataklim

Untitled

May 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.33 KB | None | 0 0
  1.  
  2. #define _CRT_SECURE_NO_DEPRECATE
  3. #include <time.h>
  4. #include <vector>
  5.  
  6. #include <cstdlib>
  7. #include <cstdio>
  8. #include <iostream>
  9. #include <glew.h>
  10. #include <vector>
  11. #include <cmath>
  12. #include <ctime>
  13. #include "SOIL.h"
  14. #include <glfw3.h>
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <math.h>
  18. #include <iostream>
  19. #include <string>
  20. #include<Windows.h>
  21.  
  22. #define SCREEN_WIDTH 1000
  23. #define SCREEN_HEIGHT 1000
  24. #define PC_MODE 16
  25. #define CONSOLE_MODE 0
  26.  
  27. #define MAXRAD 4
  28. #define MINRAD 1
  29. #define MAXHEIGHT 7
  30. #define MINHEIGHT 2
  31. #define MAXFREQ_X 40
  32. #define MINFREQ_X 3
  33. #define ANGLE 2
  34. #define DLIGHT 0.5
  35. #define TWINKIE_SPEED 20
  36.  
  37. const double M_PI = 3.14;
  38.  
  39. //Режим текстуры и анимации
  40. bool modT = false, modM=false;
  41.  
  42.  
  43. //Параметры для анимации
  44. float t, twinkie_steps = 100, dt = 5 / twinkie_steps;
  45.  
  46. typedef struct {
  47. GLfloat x, y, z;
  48. } point;
  49.  
  50. //Координаты основной фигуры
  51.  
  52. std::vector<point> base_center;
  53. std::vector<std::vector<point>> base_side;
  54.  
  55.  
  56. //Координаты фигур для анимации (третью пока не реализовала)
  57. // Для каждой фигуры нужно каким-то образов изменить один параметр, чтобы он был отличен от основной фигуры,
  58. // У первой - rx и ry меняются местами
  59. // У второй - изменений высоты в 2 раза
  60. // Для третье можно сделать изменение наклона
  61.  
  62. std::vector<point> tw1_center; // Координаты центров на каждом этаже
  63. std::vector<std::vector<point>> tw1_side; // Координаты боковых точек для каждого этажа vector[i][j] - j-ая координата на i-ом этаже
  64.  
  65. std::vector<point> tw2_center;
  66. std::vector<std::vector<point>> tw2_side;
  67.  
  68. std::vector<point> tw3_center;
  69. std::vector<std::vector<point>> tw3_side;
  70.  
  71.  
  72. GLint MOVE_X = 0;
  73. GLint MOVE_Y = 0;
  74. GLint MOVE_Z = 0;
  75.  
  76. GLint ROTATE_X = 0;
  77. GLint ROTATE_Y = 0;
  78. GLint ROTATE_Z = 0;
  79.  
  80. GLboolean global_ambient = false;
  81. GLboolean two_side = true;
  82. GLboolean local_viewer = true;
  83.  
  84. GLboolean IS_FILL = true;
  85.  
  86. GLfloat Amount = 10;
  87.  
  88. GLfloat mSize = 1.0f;
  89.  
  90. //Количество уровней
  91. GLint floors = 7;
  92.  
  93.  
  94. //Для понимания того, какая стадия в анимации
  95. int check = 1;
  96.  
  97. //--------Координаты фигуры
  98. // В отрисовке фигуры она переворачивается, пыталась сделать, чтобы было по-человечески, но забила и просто работаю с тем, что есть
  99. float xDown = 0;
  100. float yDown = 0;
  101. float xUp = 30;
  102. float yUp = 30;
  103. float height = 200; // Высота
  104. float rx = 50; // Радиус по х
  105. float ry = 100; // Радиус по у
  106.  
  107. GLuint textureID;
  108.  
  109. GLFWwindow* WINDOW;
  110.  
  111. // Прототипы функций
  112. void save();
  113. void load();
  114. void makeLight();
  115. void tweenking();
  116. void CreateTwilFig1();
  117. void CreateTwilFig2();
  118. void CreateTwilFig3();
  119. void CreateBasicFig();
  120. void display();
  121.  
  122. void save()
  123. {
  124. FILE *file;
  125. file = fopen("data.txt", "w");
  126. fprintf(file, "%f\n", xDown);
  127. fprintf(file, "%f\n", yDown);
  128. fprintf(file, "%f\n", xUp);
  129. fprintf(file, "%f\n", yUp);
  130. fprintf(file, "%f\n", height);
  131. fprintf(file, "%f\n", rx);
  132. fprintf(file, "%f\n", ry);
  133. fprintf(file, "%f\n", Amount);
  134. fprintf(file, "%f\n", mSize);
  135. fprintf(file, "%i\n", floors);
  136.  
  137. fprintf(file, "%i\n", MOVE_X);
  138. fprintf(file, "%i\n", MOVE_Y);
  139. fprintf(file, "%i\n", MOVE_Z);
  140.  
  141. fprintf(file, "%i\n", ROTATE_X);
  142. fprintf(file, "%i\n", ROTATE_Y);
  143. fprintf(file, "%i\n", ROTATE_Z);
  144.  
  145. fprintf(file, "%i\n", IS_FILL ? 1 : 0);
  146. fclose(file);
  147.  
  148. printf("-> current state saved\n");
  149. }
  150.  
  151. void load()
  152. {
  153. FILE *file;
  154. file = fopen("data.txt", "r");
  155.  
  156. if (!file) {
  157. printf("-> failed to load!\n");
  158. return;
  159. }
  160.  
  161. int temp;
  162.  
  163. fscanf(file, "%f\n", &xDown);
  164. fscanf(file, "%f\n", &yDown);
  165. fscanf(file, "%f\n", &xUp);
  166. fscanf(file, "%f\n", &yUp);
  167. fscanf(file, "%f\n", &height);
  168. fscanf(file, "%f\n", &rx);
  169. fscanf(file, "%f\n", &ry);
  170. fscanf(file, "%f\n", &Amount);
  171. fscanf(file, "%f\n", &mSize);
  172. fscanf(file, "%i\n", &floors);
  173.  
  174. fscanf(file, "%i\n", &MOVE_X);
  175. fscanf(file, "%i\n", &MOVE_Y);
  176. fscanf(file, "%i\n", &MOVE_Z);
  177.  
  178. fscanf(file, "%i\n", &ROTATE_X);
  179. fscanf(file, "%i\n", &ROTATE_Y);
  180. fscanf(file, "%i\n", &ROTATE_Z);
  181.  
  182. fscanf(file, "%i\n", &temp);
  183.  
  184.  
  185. fclose(file);
  186.  
  187. if (temp == 1) {
  188. IS_FILL = true;
  189. }
  190. else
  191. {
  192. IS_FILL = false;
  193. }
  194.  
  195. printf("-> previous state loaded\n");
  196. }
  197.  
  198. void key(GLFWwindow * window, int key, int scancode, int action, int mods)
  199. {
  200. if (action == GLFW_PRESS || action == GLFW_REPEAT) {
  201. switch (key) {
  202. case GLFW_KEY_ESCAPE:
  203. glfwSetWindowShouldClose(window, GLFW_TRUE);
  204. break;
  205. case GLFW_KEY_UP:
  206. MOVE_Y += 30;
  207. break;
  208. case GLFW_KEY_DOWN:
  209. MOVE_Y -= 30;
  210. break;
  211. case GLFW_KEY_LEFT:
  212. MOVE_X -= 30;
  213. break;
  214. case GLFW_KEY_RIGHT:
  215. MOVE_X += 30;
  216. break;
  217. case GLFW_KEY_3:
  218. MOVE_Z += 100;
  219. break;
  220. case GLFW_KEY_4:
  221. MOVE_Z -= 100;
  222. break;
  223. case GLFW_KEY_W:
  224. ROTATE_X += 5;
  225. break;
  226. case GLFW_KEY_S:
  227. ROTATE_X -= 5;
  228. break;
  229. case GLFW_KEY_A:
  230. ROTATE_Y += 5;
  231. break;
  232. case GLFW_KEY_D:
  233. ROTATE_Y -= 5;
  234. break;
  235. case GLFW_KEY_5:
  236. ROTATE_Z += 5;
  237. break;
  238. case GLFW_KEY_6:
  239. ROTATE_Z -= 5;
  240. break;
  241. case GLFW_KEY_F:
  242. IS_FILL = !IS_FILL;
  243. break;
  244. case GLFW_KEY_1:
  245. mSize += 0.3f;
  246. break;
  247. case GLFW_KEY_2:
  248. mSize -= 0.3f;
  249. break;
  250.  
  251. case GLFW_KEY_T:
  252. modT = !modT;
  253. break;
  254.  
  255. //Разбиение
  256. case GLFW_KEY_Z:
  257. Amount += 1;
  258. break;
  259. case GLFW_KEY_X:
  260. Amount -= 1;
  261. break;
  262.  
  263. //Анимация
  264. case GLFW_KEY_DELETE:
  265. modM = true;
  266. tweenking();
  267. break;
  268.  
  269. //Изменение количество этажей
  270. case GLFW_KEY_PAGE_UP:
  271. floors++;
  272. break;
  273. case GLFW_KEY_PAGE_DOWN:
  274. floors--;
  275. break;
  276.  
  277. //Сохранение состояния
  278. case GLFW_KEY_O:
  279. save();
  280. break;
  281. case GLFW_KEY_P:
  282. load();
  283. break;
  284. }
  285. }
  286. }
  287.  
  288. void makeLight() {
  289. float light0_diffuse[] = { 0.8f, 0.8f, 0.8f };
  290. float light0_position[] = { -390, 290, 300, 1.0 };
  291. float light0_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
  292. float light0_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
  293. float ambient[] = { 0.5f, 0.2f, 0.2f, 1.0f };
  294. float default_amb[] = { 0.2f, 0.2f, 0.2f, 1.0f };
  295. glEnable(GL_NORMALIZE);
  296. glEnable(GL_LIGHTING);
  297. glEnable(GL_LIGHT0);
  298. if (global_ambient)
  299. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
  300. else
  301. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, default_amb);
  302. if (two_side)
  303. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
  304. else
  305. glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
  306. if (local_viewer)
  307. glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE);
  308. else
  309. glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
  310.  
  311. glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  312. glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  313. glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
  314. glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  315. }
  316.  
  317. void tweenking()
  318. {
  319. int i, j, speed;
  320. int k = 0;
  321. printf("tweenking: h=%d\n", k);
  322. for (t = 0, speed = 0; speed <= TWINKIE_SPEED; t += dt, speed++) {
  323. for (i = 0; i < floors + 1; i += 1) {
  324. for (j = 0; j < Amount; j += 1) {
  325.  
  326. base_side[i][j].x = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].x + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].x + 3 * t*t*(1 - t)*tw1_side[i][j].x + t * t*t*tw2_side[i][j].x;
  327. base_side[i][j].y = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].y + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].y + 3 * t*t*(1 - t)*tw1_side[i][j].y + t * t*t*tw2_side[i][j].y;
  328. base_side[i][j].z = (1 - t)*(1 - t)*(1 - t)*base_side[i][j].z + 3 * t*(1 - t)*(1 - t)*tw3_side[i][j].z + 3 * t*t*(1 - t)*tw1_side[i][j].z + t * t*t*tw2_side[i][j].z;
  329. }
  330.  
  331.  
  332. base_center[i].x = (1 - t)*(1 - t)*(1 - t)*base_center[i].x + 3 * t*(1 - t)*(1 - t)*tw3_center[i].x + 3 * t*t*(1 - t)*tw1_center[i].x + t * t*t*tw2_center[i].x;
  333. base_center[i].y = (1 - t)*(1 - t)*(1 - t)*base_center[i].y + 3 * t*(1 - t)*(1 - t)*tw3_center[i].y + 3 * t*t*(1 - t)*tw1_center[i].y + t * t*t*tw2_center[i].y;
  334. base_center[i].z = (1 - t)*(1 - t)*(1 - t)*base_center[i].z + 3 * t*(1 - t)*(1 - t)*tw3_center[i].z + 3 * t*t*(1 - t)*tw1_center[i].z + t * t*t*tw2_center[i].z;
  335.  
  336. }
  337. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  338. display();
  339. glfwSwapBuffers(WINDOW);
  340. Sleep(20);
  341. }
  342. modM = false;
  343. //CreateTwilFig();
  344. }
  345.  
  346.  
  347. void DrawFig(
  348. std::vector<std::vector<point>>& cyl_side,
  349. std::vector<point>& cyl_center)
  350. {
  351. glBindTexture(GL_TEXTURE_2D, textureID);
  352. glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  353.  
  354. GLint j, i;
  355.  
  356. for (j = 0; j < Amount - 1; j++) {
  357. for (i = 0; i < floors; i++) {
  358. glColor3f(1, 1, 0);
  359. glBegin(GL_TRIANGLES);
  360. glVertex3f(cyl_side[i][j].x, cyl_side[i][j].y, cyl_side[i][j].z);
  361. glVertex3f(cyl_center[i].x, cyl_center[i].y, cyl_center[i].z);
  362. glVertex3f(cyl_side[i][j + 1].x, cyl_side[i][j + 1].y, cyl_side[i][j + 1].z);
  363. glEnd();
  364. }
  365. glColor3f(1, 1, 0);
  366. glBegin(GL_TRIANGLES);
  367. glVertex3f(cyl_side[0][j].x, cyl_side[0][j].y, cyl_side[0][j].z);
  368. glVertex3f(cyl_center[floors].x, cyl_center[floors].y, cyl_center[floors].z);
  369. glVertex3f(cyl_side[0][j + 1].x, cyl_side[0][j + 1].y, cyl_side[0][j + 1].z);
  370. glEnd();
  371. }
  372.  
  373. glColor3f(1, 1, 0);
  374. glBegin(GL_TRIANGLES);
  375. glVertex3f(cyl_side[0][j].x, cyl_side[0][j].y, cyl_side[0][j].z);
  376. glVertex3f(cyl_center[floors].x, cyl_center[floors].y, cyl_center[floors].z);
  377. glVertex3f(cyl_side[0][0].x, cyl_side[0][0].y, cyl_side[0][0].z);
  378. glEnd();
  379.  
  380. for (i = 0; i < floors; i++) {
  381. glColor3f(1, 1, 0);
  382. glBegin(GL_TRIANGLES);
  383. glVertex3f(cyl_side[i][Amount - 1].x, cyl_side[i][Amount - 1].y, cyl_side[i][Amount - 1].z);
  384. glVertex3f(cyl_center[i].x, cyl_center[i].y, cyl_center[i].z);
  385. glVertex3f(cyl_side[i][0].x, cyl_side[i][0].y, cyl_side[i][0].z);
  386. glEnd();
  387. }
  388.  
  389. }
  390.  
  391.  
  392. void CreateTwilFig1() {
  393. glBindTexture(GL_TEXTURE_2D, textureID);
  394.  
  395. if (Amount < 3) Amount = 3;
  396. const float step = float(2 * M_PI) / Amount;
  397.  
  398. float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
  399. float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
  400. float xCenterUpTemp = 0;
  401. float yCenterUpTemp = 0;
  402.  
  403. float angle = 0;
  404.  
  405. float hh = height;
  406.  
  407. GLint i = 1, j;
  408.  
  409. tw1_center.resize(floors + 2);
  410.  
  411. tw1_side.resize(floors + 2);
  412.  
  413. for (i = 0; i < floors + 2; i++) tw1_side[i].resize(Amount + 1);
  414.  
  415. glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  416.  
  417. for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
  418. dx1 = ry * cosf(angle);
  419. dy1 = rx * sinf(angle);
  420. for (GLint i = 0; i < floors; i++) {
  421. dx1temp = (dx1 / floors) * (floors - i);
  422. dy1temp = (dy1 / floors) * (floors - i);
  423. xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
  424. yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
  425.  
  426. tw1_side[i][j].x = dx1temp + xCenterUpTemp;
  427. tw1_side[i][j].y = dy1temp + yCenterUpTemp;
  428. tw1_side[i][j].z = hh - (hh / floors) * i;
  429.  
  430. tw1_center[i].x = xCenterUpTemp;
  431. tw1_center[i].y = yCenterUpTemp;
  432. tw1_center[i].z = hh - (hh / floors) * i;
  433. }
  434. }
  435. tw1_center[floors].x = xUp;
  436. tw1_center[floors].y = yUp;
  437. tw1_center[floors].z = 0;
  438. }
  439.  
  440. void CreateTwilFig3() {
  441. glBindTexture(GL_TEXTURE_2D, textureID);
  442.  
  443. if (Amount < 3) Amount = 3;
  444. const float step = float(2 * M_PI) / Amount;
  445.  
  446. float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
  447. float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
  448. float xCenterUpTemp = 0;
  449. float yCenterUpTemp = 0;
  450.  
  451. float xUpT = 0;
  452. float yUpT = 0;
  453.  
  454. float angle = 0;
  455.  
  456. float hh = 2*height;
  457. xUpT = -xUp;
  458. yUpT = -yUp;
  459.  
  460. GLint i = 1, j;
  461.  
  462. tw3_center.resize(floors + 2);
  463.  
  464. tw3_side.resize(floors + 2);
  465.  
  466. for (i = 0; i < floors + 2; i++) tw3_side[i].resize(Amount + 1);
  467.  
  468. glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  469.  
  470. for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
  471. dx1 = rx * cosf(angle);
  472. dy1 = ry * sinf(angle);
  473. for (GLint i = 0; i < floors; i++) {
  474. dx1temp = (dx1 / floors) * (floors - i);
  475. dy1temp = (dy1 / floors) * (floors - i);
  476. xCenterUpTemp = -(xUpT / floors) * (floors - i) + xUpT;
  477. yCenterUpTemp = -(yUpT / floors) * (floors - i) + yUpT;
  478.  
  479. tw3_side[i][j].x = dx1temp + xCenterUpTemp;
  480. tw3_side[i][j].y = dy1temp + yCenterUpTemp;
  481. tw3_side[i][j].z = hh - (hh / floors) * i;
  482.  
  483. tw3_center[i].x = xCenterUpTemp;
  484. tw3_center[i].y = yCenterUpTemp;
  485. tw3_center[i].z = hh - (hh / floors) * i;
  486. }
  487. }
  488. tw3_center[floors].x = xUpT;
  489. tw3_center[floors].y = yUpT;
  490. tw3_center[floors].z = 0;
  491. }
  492.  
  493. void CreateTwilFig2() {
  494. glBindTexture(GL_TEXTURE_2D, textureID);
  495.  
  496. if (Amount < 3) Amount = 3;
  497. const float step = float(2 * M_PI) / Amount;
  498.  
  499. float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
  500. float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
  501. float xCenterUpTemp = 0;
  502. float yCenterUpTemp = 0;
  503.  
  504. float angle = 0;
  505.  
  506. float hh;
  507.  
  508. if (check == -1) {
  509. hh = height;
  510. }
  511. else {
  512. hh = height + 0.5;
  513. }
  514.  
  515. GLint i = 1, j;
  516.  
  517. tw2_center.resize(floors + 2);
  518.  
  519. tw2_side.resize(floors + 2);
  520.  
  521. for (i = 0; i < floors + 2; i++) tw2_side[i].resize(Amount + 1);
  522.  
  523. glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  524.  
  525. for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
  526. dx1 = rx * cosf(angle);
  527. dy1 = ry * sinf(angle);
  528. for (GLint i = 0; i < floors; i++) {
  529. dx1temp = (dx1 / floors) * (floors - i);
  530. dy1temp = (dy1 / floors) * (floors - i);
  531. xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
  532. yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
  533.  
  534. tw2_side[i][j].x = dx1temp + xCenterUpTemp;
  535. tw2_side[i][j].y = dy1temp + yCenterUpTemp;
  536. tw2_side[i][j].z = hh - (hh / floors) * i;
  537.  
  538. tw2_center[i].x = xCenterUpTemp;
  539. tw2_center[i].y = yCenterUpTemp;
  540. tw2_center[i].z = hh - (hh / floors) * i;
  541. }
  542. }
  543. tw2_center[floors].x = xUp;
  544. tw2_center[floors].y = yUp;
  545. tw2_center[floors].z = 0;
  546. }
  547.  
  548. void CreateBasicFig() {
  549. glBindTexture(GL_TEXTURE_2D, textureID);
  550.  
  551. if (Amount < 3) Amount = 3;
  552. const float step = float(2 * M_PI) / Amount;
  553.  
  554.  
  555.  
  556. float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
  557. float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
  558. float xCenterUpTemp = 0;
  559. float yCenterUpTemp = 0;
  560.  
  561. int hh = height;
  562.  
  563. if (check == 1) {
  564. hh = height;
  565. }
  566. else {
  567. //hh = height * 2;
  568. hh = height;
  569. }
  570.  
  571. float angle = 0;
  572.  
  573. GLint i = 1, j;
  574.  
  575. base_center.resize(floors + 2);
  576.  
  577. base_side.resize(floors + 2);
  578.  
  579. for (i = 0; i < floors + 2; i++) base_side[i].resize(Amount + 1);
  580.  
  581. glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  582.  
  583. for (float angle = 0, j = 0; angle <= float(2 * M_PI); j++, angle += step) {
  584. dx1 = rx * cosf(angle);
  585. dy1 = ry * sinf(angle);
  586. for (GLint i = 0; i < floors; i++) {
  587. dx1temp = (dx1 / floors) * (floors - i);
  588. dx2temp = (dx2 / floors) * (floors - i);
  589. dy1temp = (dy1 / floors) * (floors - i);
  590. dy2temp = (dy2 / floors) * (floors - i);
  591. xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
  592. yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
  593.  
  594. base_side[i][j].x = dx1temp + xCenterUpTemp;
  595. base_side[i][j].y = dy1temp + yCenterUpTemp;
  596. base_side[i][j].z = hh - (hh / floors) * i;
  597.  
  598. base_center[i].x = xCenterUpTemp;
  599. base_center[i].y = yCenterUpTemp;
  600. base_center[i].z = hh - (hh / floors) * i;
  601. }
  602. }
  603.  
  604. base_center[floors].x = xUp;
  605. base_center[floors].y = yUp;
  606. base_center[floors].z = 0;
  607.  
  608.  
  609. }
  610.  
  611. void display()
  612. {
  613. int width, height;
  614.  
  615. glfwGetFramebufferSize(WINDOW, &width, &height);
  616.  
  617. if (!modM) {
  618. CreateTwilFig1();
  619. CreateTwilFig2();
  620. CreateTwilFig3();
  621. }
  622.  
  623.  
  624. //Подключение текстуры
  625.  
  626. //Static cube
  627.  
  628. glViewport(0, 0, width / 2, height / 2);
  629. glEnable(GL_DEPTH_TEST);
  630.  
  631. glMatrixMode(GL_PROJECTION);
  632. glLoadIdentity();
  633. glOrtho(-width, width, -height, height, -1000, 1000);
  634. glMatrixMode(GL_MODELVIEW);
  635. glLoadIdentity();
  636.  
  637. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  638. glMatrixMode(GL_MODELVIEW);
  639. glLoadIdentity();
  640.  
  641.  
  642.  
  643. //projection Ozy Вверху слева
  644.  
  645. glViewport(0, height / 2 + 1, width / 2 + 1, height / 2);
  646. glEnable(GL_DEPTH_TEST);
  647.  
  648. glMatrixMode(GL_PROJECTION);
  649. glLoadIdentity();
  650. glOrtho(-width, width, -height, height, -1000, 1000);
  651. glRotatef(90, 1, 0, 0);
  652. glMatrixMode(GL_MODELVIEW);
  653. glLoadIdentity();
  654.  
  655. glTranslatef(-250, -250, 500);
  656. glTranslatef(MOVE_X + 350, MOVE_Y + 350, MOVE_Z - 500);
  657. glScaled(mSize, mSize, mSize);
  658. glRotatef(ROTATE_X, 1, 0, 0);
  659. glRotatef(ROTATE_Y, 0, 1, 0);
  660. glRotatef(ROTATE_Z, 0, 0, 1);
  661.  
  662. if (modM) {
  663. DrawFig(base_side, base_center);
  664. }
  665. else {
  666. CreateBasicFig();
  667. DrawFig(base_side, base_center);
  668. }
  669.  
  670. //projection Oxy Вверху справа
  671.  
  672. glViewport(width / 2 + 1, height / 2 + 1, width / 2, height / 2);
  673. glEnable(GL_DEPTH_TEST);
  674.  
  675. glMatrixMode(GL_PROJECTION);
  676. glLoadIdentity();
  677. glOrtho(-width, width, -height, height, -1000, 1000);
  678. glMatrixMode(GL_MODELVIEW);
  679. glLoadIdentity();
  680.  
  681. glTranslatef(MOVE_X, MOVE_Y, MOVE_Z - 500);
  682. glScaled(mSize, mSize, mSize);
  683. glRotatef(ROTATE_X, 1, 0, 0);
  684. glRotatef(ROTATE_Y, 0, 1, 0);
  685. glRotatef(ROTATE_Z, 0, 0, 1);
  686.  
  687.  
  688. if (modM) {
  689. DrawFig(base_side, base_center);
  690. }
  691. else {
  692. CreateBasicFig();
  693. DrawFig(base_side, base_center);
  694. }
  695.  
  696.  
  697. //projection Oxz Внизу справа
  698.  
  699. glViewport(width / 2 + 1, 0, width / 2, height / 2);
  700. glEnable(GL_DEPTH_TEST);
  701.  
  702. glMatrixMode(GL_PROJECTION);
  703. glLoadIdentity();
  704. glOrtho(-width, width, -height, height, -1000, 1000);
  705. glRotatef(90, 0, 1, 0);
  706. glMatrixMode(GL_MODELVIEW);
  707. glLoadIdentity();
  708.  
  709. glTranslatef(-200, -200, 500);
  710. glTranslatef(MOVE_X + 350, MOVE_Y + 350, MOVE_Z - 500);
  711. glScaled(mSize, mSize, mSize);
  712. glRotatef(ROTATE_X, 1, 0, 0);
  713. glRotatef(ROTATE_Y, 0, 1, 0);
  714. glRotatef(ROTATE_Z, 0, 0, 1);
  715.  
  716.  
  717. if (modM) {
  718. DrawFig(base_side, base_center);
  719. }
  720. else {
  721. CreateBasicFig();
  722. DrawFig(base_side, base_center);
  723. }
  724.  
  725. //DrawFigure2();
  726. //DrawNewFigure();
  727. }
  728.  
  729. int main()
  730. {
  731. if (!glfwInit())
  732. exit(1);
  733.  
  734. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  735. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
  736.  
  737. GLFWwindow * window = glfwCreateWindow(800, 600, "Laba", NULL, NULL);
  738. WINDOW = window;
  739. if (!window)
  740. {
  741. glfwTerminate();
  742. exit(1);
  743. }
  744.  
  745. glfwMakeContextCurrent(window);
  746. glfwSetKeyCallback(window, key);
  747.  
  748. //СВЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕЕТА
  749. //makeLight();
  750.  
  751. int w = 512, h = 512;
  752. unsigned char* image = SOIL_load_image("./met.bmp", &w, &h, 0, SOIL_LOAD_RGB);
  753. glGenTextures(1, &textureID);
  754. glBindTexture(GL_TEXTURE_2D, textureID);
  755.  
  756. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  757. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  758. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  759. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  760. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
  761. SOIL_free_image_data(image);
  762. glBindTexture(GL_TEXTURE_2D, 0);
  763.  
  764.  
  765. while (!glfwWindowShouldClose(window)) {
  766.  
  767. if (modT) {
  768. glEnable(GL_TEXTURE_2D);
  769. }
  770. else {
  771. glDisable(GL_TEXTURE_2D);
  772. }
  773. display(); //рисует
  774. glfwSwapBuffers(window); //Меняет буферы
  775. glfwPollEvents(); //Слушает нажатия
  776. }
  777. glfwDestroyWindow(window);
  778. glfwTerminate();
  779.  
  780. return 0;
  781. }
  782.  
  783. //void DrawFigure() {
  784. // glBindTexture(GL_TEXTURE_2D, textureID);
  785. //
  786. // if (Amount < 3) Amount = 3;
  787. // const float step = float(2 * M_PI) / Amount;
  788. //
  789. // float dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
  790. // float dx1temp = 0, dy1temp = 0, dx2temp = 0, dy2temp = 0;
  791. // float xCenterUpTemp = 0;
  792. // float yCenterUpTemp = 0;
  793. //
  794. // float angle = 0;
  795. //
  796. // float len = hight / 2;
  797. //
  798. // GLint i = 1;
  799. //
  800. // glPolygonMode(GL_FRONT_AND_BACK, IS_FILL ? GL_FILL : GL_LINE);
  801. //
  802. // for (float angle = 0; angle <= float(2 * M_PI); angle += step) {
  803. // dx1 = rx * cosf(angle);
  804. // dy1 = ry * sinf(angle);
  805. // dx2 = rx * cosf(angle + step);
  806. // dy2 = ry * sinf(angle + step);
  807. //
  808. // for (GLint i = 0; i < floors; i++) {
  809. // dx1temp = (dx1 / floors) * (floors - i);
  810. // dx2temp = (dx2 / floors) * (floors - i);
  811. // dy1temp = (dy1 / floors) * (floors - i);
  812. // dy2temp = (dy2 / floors) * (floors - i);
  813. // xCenterUpTemp = -(xUp / floors) * (floors - i) + xUp;
  814. // yCenterUpTemp = -(yUp / floors) * (floors - i) + yUp;
  815. //
  816. //
  817. //
  818. // glColor3d(0, 1, 0);
  819. // glBegin(GL_TRIANGLES);
  820. // glVertex3f(xCenterUpTemp, yCenterUpTemp, len - hight / floors * i);
  821. // glVertex3f(dx1temp + xCenterUpTemp, dy1temp + yCenterUpTemp, len - hight / floors * i);
  822. // glVertex3f(dx2temp + xCenterUpTemp, dy2temp + yCenterUpTemp, len - hight / floors * i);
  823. // glEnd();
  824. // }
  825. // glColor3d(1, 1, 1);
  826. // glBegin(GL_TRIANGLES);
  827. // glVertex3f(xUp, yUp, -len);
  828. // glVertex3f(dx1 + xDown, dy1 + yDown, len);
  829. // glVertex3f(dx2 + xDown, dy2 + yDown, len);
  830. // glEnd();
  831. //
  832. // //glBegin(GL_TRIANGLES);// Основание
  833. // //glVertex3f(xDown, yDown, len);
  834. // //glVertex3f(dx1 + xDown, dy1 + yDown, len);
  835. // //glVertex3f(dx2 + xDown, dy2 + yDown, len);
  836. // //glEnd();
  837. //
  838. // }
  839. //
  840. //
  841. //
  842. // //printf("cone_renewed: s_j=%d\n", floors);
  843. // //glDisable(GL_TEXTURE_2D);
  844. //
  845. //
  846. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement