Advertisement
Ladies_Man

tmp pre2nd stage

Oct 28th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.03 KB | None | 0 0
  1.  
  2. // glfw_30.cpp : Defines the entry point for the console application.
  3. //  http://www.glfw.org/docs/latest/quick.html
  4.  
  5. #include "stdafx.h"
  6. #include <time.h>
  7. #define _USE_MATH_DEFINES
  8. #include <cmath>
  9. #include <stdio.h>
  10. #include <iostream>
  11. #include <string>
  12.  
  13. #include <GLAux.h>
  14. #pragma comment(lib,"glaux.lib")
  15.  
  16.  
  17. #define SCREEN_WIDTH 1000
  18. #define SCREEN_HEIGHT 1000
  19. #define SPLIT_X 10
  20. #define SPLIT_Y 10
  21. #define G_CONST 9.78
  22.  
  23. #define REVD(X) ((SPLIT_Y) - (X))
  24.  
  25. using namespace std;
  26.  
  27. float t;
  28.  
  29. GLdouble A, B, C, D;
  30.  
  31. float delta_pos(float velocity, float acceleration);
  32.  
  33. class map;
  34. class body;
  35. class block;
  36. class cargo;
  37. class pendulum;
  38.  
  39.  
  40.  
  41.  
  42. typedef struct {
  43.     int x, y;
  44. } coord;
  45.  
  46. typedef struct {
  47.     coord botleft, topleft, topright, botright;
  48.     int type;
  49. } cell;
  50.  
  51. class map {
  52. public:
  53.    
  54.  
  55.     void set_map(int, int);
  56.     void clean_map();
  57.     void draw_net();
  58.     void draw_obj();
  59.     void print_map();
  60.  
  61.     void set_cell(int, int, int);
  62.  
  63. private:
  64.     int map_size_y;
  65.     int map_size_x;
  66.  
  67.     cell **map_arr;
  68.     int cell_size_x;
  69.     int cell_size_y;
  70. };
  71.  
  72. void map::set_map(int rows, int cols) {
  73.     this->map_size_y = rows;
  74.     this->map_size_x = cols;
  75.  
  76.     this->cell_size_x = (int)(SCREEN_WIDTH / SPLIT_X);
  77.     this->cell_size_y = (int)(SCREEN_HEIGHT / SPLIT_Y);
  78.  
  79.     this->map_arr = (cell **)malloc(this->map_size_y * sizeof(cell *));
  80.     // a[0]
  81.     // a[1]
  82.     // a[2]
  83.     // a[3]
  84.  
  85.     int i, j;
  86.     for (i = 0; i < this->map_size_y; i++) {
  87.         this->map_arr[i] = (cell *)malloc(this->map_size_x * sizeof(cell)); // a[0][0] a[0][1] a[0][2] a[0][3]
  88.     }
  89.  
  90.     for (i = 0; i < this->map_size_y; i++) {
  91.         for (j = 0; j < this->map_size_x; j++) {
  92.             this->map_arr[i][j].type = 0;
  93.         }
  94.     }
  95. }
  96.  
  97. void map::clean_map() {
  98.     for (int i = 0; i < this->map_size_y; i++) {
  99.         delete[] this->map_arr[i];
  100.     }
  101.     delete[] this->map_arr;
  102. }
  103.  
  104. void map::draw_net() {
  105.     int i, j;
  106.  
  107.     for (i = 0; i < SCREEN_WIDTH; i += SCREEN_WIDTH / this->map_size_x) {
  108.         glColor3f(1, 1, 1);
  109.         for (j = 0; j < SCREEN_HEIGHT; j += SCREEN_HEIGHT / this->map_size_y) {
  110.             glBegin(GL_LINES);
  111.             glVertex2f(i, 0);
  112.             glVertex2f(i, SCREEN_HEIGHT);
  113.             glEnd();
  114.  
  115.             glBegin(GL_LINES);
  116.             glVertex2f(0, j);
  117.             glVertex2f(SCREEN_WIDTH, j);
  118.             glEnd();
  119.         }
  120.     }
  121. }
  122.  
  123. void map::draw_obj() {
  124.     int i, j;
  125.  
  126.     for (j = 0; j < this->map_size_y; j++) {
  127.         for (i = 0; i < this->map_size_x; i++) {
  128.             if (0 != map_arr[i][j].type) {
  129.                 if (1 == map_arr[i][j].type) {
  130.                     glColor3f(1, 0, 0);
  131.                 }
  132.                 if (2 == map_arr[i][j].type) {
  133.                     glColor3f(0, 0, 1);
  134.                 }
  135.  
  136.                 glBegin(GL_POLYGON);
  137.                 glTexCoord2f(0.0f, 0.0f);
  138.                 glVertex2f(map_arr[i][j].botleft.x, map_arr[i][j].botleft.y);
  139.                 glTexCoord2f(0.0f, 1.0f);
  140.                 glVertex2f(map_arr[i][j].topleft.x, map_arr[i][j].topleft.y);
  141.                 glTexCoord2f(1.0f, 1.0f);
  142.                 glVertex2f(map_arr[i][j].topright.x, map_arr[i][j].topright.y);
  143.                 glTexCoord2f(1.0f, 0.0f);
  144.                 glVertex2f(map_arr[i][j].botright.x, map_arr[i][j].botright.y);
  145.                 glEnd();
  146.             }
  147.         }
  148.     }
  149. }
  150.  
  151. void map::print_map() {
  152.     int i, j;
  153.  
  154.     printf("\ncurrent map:\n");
  155.     for (j = 0; j < this->map_size_y; j++) {
  156.         for (i = 0; i < this->map_size_x; i++) {
  157.             if (0 == this->map_arr[i][j].type) {
  158.                 printf("- ");
  159.             }
  160.             if (1 == this->map_arr[i][j].type) {
  161.                 printf("C ");
  162.             }
  163.             if (2 == this->map_arr[i][j].type) {
  164.                 printf("B ");
  165.             }
  166.         }
  167.         printf("\n");
  168.     }
  169.  
  170. }
  171.  
  172. void map::set_cell(int x, int y, int type) {
  173.     this->map_arr[x][REVD(y)].type = type;
  174.  
  175.     this->map_arr[x][REVD(y)].botleft.x = (int)(x * this->cell_size_x);// -this->cell_size_x / 2);
  176.     this->map_arr[x][REVD(y)].botleft.y = (int)(y * this->cell_size_y);// + this->cell_size_y / 2);
  177.  
  178.     this->map_arr[x][REVD(y)].topleft.x = (int)(x * this->cell_size_x);// - this->cell_size_x / 2);
  179.     this->map_arr[x][REVD(y)].topleft.y = (int)(y * this->cell_size_y + this->cell_size_y);
  180.  
  181.     this->map_arr[x][REVD(y)].topright.x = (int)(x * this->cell_size_x + this->cell_size_x);
  182.     this->map_arr[x][REVD(y)].topright.y = (int)(y * this->cell_size_y + this->cell_size_y);
  183.  
  184.     this->map_arr[x][REVD(y)].botright.x = (int)(x * this->cell_size_x + this->cell_size_x);
  185.     this->map_arr[x][REVD(y)].botright.y = (int)(y * this->cell_size_y);// + this->cell_size_y / 2);
  186. }
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193. class body {
  194. public:
  195.     char *name;
  196.     int type, num, mass;    // 1 - cargo, 2 - block
  197.     body *up;
  198.     body *down;
  199.     body *right;
  200.     body *left;
  201.  
  202.     void set(int, int, int, float, float);
  203.     void draw();
  204.  
  205. private:
  206.     float curr_x, curr_y;
  207.     float init_x, init_y;
  208.     float center_x, center_y;
  209.     int h, w;
  210.  
  211.  
  212. };
  213.  
  214. void body::set(int num, int type, int mass, float pos_x, float pos_y) {
  215.     this->init_x = pos_x;
  216.     this->init_y = pos_y;
  217.  
  218.     this->curr_x = pos_x;
  219.     this->curr_y = pos_y;
  220.  
  221.     this->type = type;
  222.     this->num = num;
  223.     this->mass = mass;
  224.  
  225.     this->up = NULL;
  226.     this->down = NULL;
  227.     this->right = NULL;
  228.     this->left = NULL;
  229.  
  230.     this->h = 20;
  231.     this->w = 20;
  232. }
  233.  
  234. void body::draw() {
  235.     float pos_x = this->curr_x;
  236.     float pos_y = this->curr_y;
  237.     // 1 = cargo, 2 = block
  238.  
  239.     glBegin(GL_POLYGON);
  240.         if (1 == this->type) glColor3f(1, 0, 0);
  241.         if (2 == this->type) glColor3f(0, 0, 1);
  242.         glVertex2i(pos_x, pos_y);
  243.         glVertex2i(pos_x + this->w, pos_y);
  244.         glVertex2i(pos_x + this->w, pos_y + this->h);
  245.         glVertex2i(pos_x, pos_y + this->h);
  246.     glEnd();
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253. float delta_pos(float velocity, float acceleration);
  254.  
  255.  
  256.  
  257. class block {
  258. public:
  259.     char *name;
  260.     int mass;
  261.  
  262.     void grav();
  263.     void init();
  264.  
  265.     block(float pos_x, float pos_y) {
  266.         this->init_x = pos_x;
  267.         this->init_y = pos_y;
  268.  
  269.         this->curr_x = pos_x;
  270.         this->curr_y = pos_y;
  271.  
  272.         this->visibility = true;
  273.     }
  274.  
  275. private:
  276.     float init_x, init_y;
  277.     float curr_x, curr_y;
  278.     bool visibility;
  279.  
  280.     void draw(float pos_x, float pos_y);
  281. };
  282.  
  283. void block::draw(float pos_x, float pos_y) {
  284.     glBegin(GL_POLYGON);
  285.     glColor3f(1, 0, 0);
  286.     glVertex2i(pos_x, pos_y);
  287.     glVertex2i(pos_x + 20, pos_y);
  288.     glVertex2i(pos_x + 20, pos_y + 20);
  289.     glVertex2i(pos_x, pos_y + 20);
  290.     glEnd();
  291. }
  292.  
  293. void block::grav() {
  294.     if (this->curr_y > 0) {
  295.  
  296.         float pos_x = this->curr_x + delta_pos(0, 0);
  297.         float pos_y = this->curr_y - delta_pos(-2, G_CONST);
  298.  
  299.         this->curr_x = pos_x;
  300.         this->curr_y = pos_y;
  301.  
  302.     }
  303.     else {
  304.         this->curr_y = 0;
  305.         this->visibility = false;
  306.     }
  307.  
  308.     this->draw(this->curr_x, this->curr_y);
  309.  
  310.     printf("x:%f, y:%f\n", this->curr_x, this->curr_y);
  311. }
  312.  
  313. void block::init() {
  314.     float pos_x = this->init_x;
  315.     float pos_y = this->init_y;
  316.  
  317.     this->draw(pos_x, pos_y);
  318. }
  319.  
  320.  
  321. float delta_pos(float velocity, float acceleration) {
  322.     //s = s0 + v*t + (a*t^2)/2
  323.     float delta = velocity * t + (acceleration * t * t) / 2;
  324.     printf("delta=%f\n", delta);
  325.  
  326.     t += 0.0001;
  327.  
  328.     return delta;
  329. }
  330.  
  331.  
  332.  
  333.  
  334. class cargo {
  335. public:
  336.     char *name;
  337.     int ord_num;
  338.     int mass;
  339.     int move_direction;
  340.     block* left_block;
  341.     block* right_block;
  342.     cargo* above_cargo;
  343.     cargo* below_cargo;
  344.  
  345.     void grav(bool);
  346.     void init();
  347.     void add_right_block(block*);
  348.     void add_left_block(block*);
  349.     void add_above_cargo(cargo*);
  350.     void add_below_cargo(cargo*);
  351.  
  352.     cargo(int n, float pos_x, float pos_y) {
  353.         this->ord_num = n;
  354.  
  355.         this->init_x = pos_x;
  356.         this->init_y = pos_y;
  357.  
  358.         this->curr_x = pos_x;
  359.         this->curr_y = pos_y;
  360.  
  361.         this->velo_x = 0;
  362.         this->velo_y = 0;
  363.  
  364.         if (this->velo_y == 0) {
  365.             this->move_direction = -1;
  366.         }
  367.     }
  368.  
  369. private:
  370.     float init_x, init_y;
  371.     float curr_x, curr_y;
  372.     float velo_x, velo_y;
  373.  
  374.     void draw(float, float);
  375. };
  376.  
  377. void cargo::draw(float pos_x, float pos_y) {
  378.     glBegin(GL_POLYGON);
  379.     glColor3f(0, 1, 0);
  380.     glVertex2i(pos_x, pos_y);
  381.     glVertex2i(pos_x + 25, pos_y);
  382.     glVertex2i(pos_x + 25, pos_y + 25);
  383.     glVertex2i(pos_x, pos_y + 25);
  384.     glEnd();
  385. }
  386.  
  387. void cargo::grav(bool fall) {
  388.     if (fall) {
  389.  
  390.         float pos_y;
  391.  
  392.         if (this->curr_y <= 0) {
  393.  
  394.             this->curr_y = 0;
  395.  
  396.             this->velo_y = sqrt(2 * G_CONST * this->init_y) * 0.8;
  397.  
  398.             this->move_direction = 1;
  399.  
  400.         }
  401.  
  402.         if (this->curr_y >= 0) {
  403.  
  404.             if (this->move_direction < 0) {
  405.  
  406.                 float pos_y = (G_CONST * t * t) / 2;
  407.                 this->curr_y -= pos_y;
  408.  
  409.             }
  410.  
  411.             if (this->move_direction > 0) {
  412.  
  413.                 float pos_y = this->velo_y * t - (G_CONST * t * t) / 2;
  414.                 this->curr_y += pos_y;
  415.  
  416.             }
  417.  
  418.         }
  419.     }
  420.  
  421.     this->draw(this->curr_x, this->curr_y);
  422.  
  423.     t += 0.001;
  424.  
  425.     printf("x:%f, y:%f, v=%f\n", this->curr_x, this->curr_y, this->velo_y);
  426. }
  427.  
  428. void cargo::init() {
  429.     float pos_x = this->init_x;
  430.     float pos_y = this->init_y;
  431.  
  432.     this->draw(pos_x, pos_y);
  433. }
  434.  
  435.  
  436.  
  437.  
  438.  
  439. struct node
  440. {
  441.     int value;
  442.     body obj;
  443.     node *next_r, *prev_l;
  444.  
  445.     node(int y) { value = y; next_r = prev_l = NULL; }
  446. };
  447.  
  448. class dll {
  449. public:
  450.  
  451.     void append_front(int, body);
  452.     void append_back(int, body);
  453.     node* get_front();
  454.     node* get_back();
  455.     void display_forward();
  456.     void display_backward();
  457.     void display_objects();
  458.     void draw_objects();
  459.     void destroy_list();
  460.  
  461.     dll() { front = NULL; back = NULL; }
  462.     ~dll() { destroy_list(); }
  463.  
  464.  
  465. private:
  466.  
  467.     node *front;
  468.     node *back;
  469.  
  470. };
  471.  
  472. void dll::append_front(int x, body b) {
  473.  
  474.     node *n = new node(x);
  475.  
  476.     n->obj = b;
  477.  
  478.     if (front == NULL) {
  479.         front = n;
  480.         back = n;
  481.     } else {
  482.         front->prev_l = n;
  483.         n->next_r = front;
  484.         front = n;
  485.     }
  486.  
  487.     cout << "fornt appended" << endl;
  488. }
  489.  
  490. void dll::append_back(int x, body b) {
  491.  
  492.     node *n = new node(x);
  493.  
  494.     n->obj = b;
  495.  
  496.     if (back == NULL) {
  497.         front = n;
  498.         back = n;
  499.     } else {
  500.         back->next_r = n;
  501.         n->prev_l = back;
  502.         back = n;
  503.     }
  504.  
  505.     cout << "back appended" << endl;
  506. }
  507.  
  508. node* dll::get_front() {
  509.     return this->front;
  510. }
  511.  
  512. node* dll::get_back() {
  513.     return this->back;
  514. }
  515.  
  516. void dll::display_forward() {
  517.     node *temp = front;
  518.  
  519.     cout << "\n\nnodes in forward order:" << endl;
  520.  
  521.     while (temp != NULL) {
  522.         cout << temp->value << "   ";
  523.         temp = temp->next_r;
  524.     }
  525. }
  526.  
  527. void dll::display_backward() {
  528.     node *temp = back;
  529.  
  530.     cout << "\n\nnodes in reverse order:" << endl;
  531.  
  532.     while (temp != NULL) {
  533.         cout << temp->value << "   ";
  534.         temp = temp->prev_l;
  535.     }
  536. }
  537.  
  538. void dll::display_objects() {
  539.     node *temp = front;
  540.  
  541.     cout << "\n\nobjects in forward order:" << endl;
  542.  
  543.     while (NULL != temp) {
  544.         printf("(%d", temp->value);
  545.         if (1 == temp->obj.type) printf("CG ");
  546.         if (2 == temp->obj.type) printf("BK ");
  547.         printf("[m:%d])   ", temp->obj.mass);
  548.         temp = temp->next_r;
  549.     }
  550. }
  551.  
  552. void dll::draw_objects() {
  553.     node *temp = front;
  554.  
  555.     while (NULL != temp) {
  556.         temp->obj.draw();
  557.         if (temp->obj.down != NULL) temp->obj.down->draw();
  558.         temp = temp->next_r;
  559.     }
  560. }
  561.  
  562. void dll::destroy_list() {
  563.     node *T = back;
  564.  
  565.     while (T != NULL) {
  566.         node *T2 = T;
  567.         T = T->prev_l;
  568.         delete T2;
  569.     }
  570.  
  571.     front = NULL;
  572.     back = NULL;
  573. }
  574.  
  575.  
  576.  
  577.  
  578. void count_position(string command) {
  579.  
  580.     int comm_len = command.length();
  581.  
  582.  
  583. }
  584.  
  585.  
  586.  
  587. GLuint texture[1];
  588.  
  589. void load_textures()
  590. {
  591.  
  592.     AUX_RGBImageRec *texture1;
  593.     texture1 = auxDIBImageLoadA("tex_snoop.bmp");
  594.     glGenTextures(1, &texture[0]);
  595.     glBindTexture(GL_TEXTURE_2D, texture[0]);
  596.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  597.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  598.     glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
  599.  
  600.     glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  601. }
  602.  
  603.  
  604.  
  605. static void cursor_callback(GLFWwindow* window, double x, double y)
  606. {
  607.  
  608. }
  609.  
  610. static void mouse_callback(GLFWwindow* window, int button, int action, int mods)
  611. {
  612.     if (button == GLFW_MOUSE_BUTTON_RIGHT)
  613.     {
  614.         if (action == GLFW_PRESS) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
  615.         if (action == GLFW_RELEASE) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
  616.     }
  617.  
  618.     if (button == GLFW_MOUSE_BUTTON_LEFT)
  619.     {
  620.  
  621.     }
  622. }
  623.  
  624. static void resize_callback(GLFWwindow* window, int width, int height)
  625. {
  626.     //      windowWidth = width;
  627.     //      windowHeight = height;
  628.  
  629.     glViewport(0, 0, width, height);
  630.     glMatrixMode(GL_PROJECTION);
  631.     glLoadIdentity();
  632.     glOrtho(0.0, (GLdouble)width, 0.0, (GLdouble)height, -1, 1);
  633.  
  634.     glMatrixMode(GL_MODELVIEW);
  635.     glLoadIdentity();
  636.  
  637.     A = width / 4.0;
  638.     B = 0.0;
  639.     C = D = height / 2.0;
  640.  
  641.     //printf("Reshape occured\n");
  642. }
  643.  
  644. static void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
  645. {
  646.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  647.         glfwSetWindowShouldClose(window, GL_TRUE);
  648.     //if (GLFW_KEY_T == key && action == GLFW_PRESS) { gravity(); }
  649. }
  650.  
  651. static void error_callback(int error, const char* description)
  652. {
  653.     fputs(description, stderr);
  654. }
  655.  
  656.  
  657.  
  658.  
  659. int main(int argc, _TCHAR* argv[])
  660. {
  661.     if (!glfwInit()) {
  662.         printf("glfwInit failed\n");
  663.         return -1;
  664.     }
  665.  
  666.     glfwSetErrorCallback(error_callback);
  667.  
  668.     GLFWwindow* window;
  669.  
  670.     //      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
  671.     //      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
  672.     //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
  673.     window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Anthony's Porject", NULL, NULL);
  674.     if (window == NULL) {
  675.         printf("glfwOpenWindow failed.\n");
  676.         glfwTerminate();
  677.         return -2;
  678.     }
  679.  
  680.     int i, attrib;
  681.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
  682.     attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
  683.     attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
  684.  
  685.     glfwMakeContextCurrent(window);
  686.  
  687.     glfwSetKeyCallback(window, keyboard_callback);
  688.     glfwSetFramebufferSizeCallback(window, resize_callback);
  689.     glfwSetMouseButtonCallback(window, mouse_callback);
  690.     glfwSetCursorPosCallback(window, cursor_callback);
  691.     resize_callback(window, SCREEN_WIDTH, SCREEN_HEIGHT);
  692.  
  693.  
  694.     dll *list = new dll();
  695.     body c, b;
  696.     int b_pos_x, b_pos_y, b_pos_y_low, c_pos_x, c_pos_y, c_pos_y_low, b_type, c_type, c_n, b_n;
  697.  
  698.     c_n = b_n = 0;
  699.  
  700.     printf("insert scheme:\n..........\n");
  701.  
  702.     string command;
  703.     back:
  704.     getline(cin, command);
  705.     if (command.length() > 10) {
  706.         printf("must be no longer than 10\n");
  707.         goto back;
  708.     }
  709.  
  710.     count_position(command);
  711.  
  712.  
  713.     map *m = new map();
  714.     m->set_map(SPLIT_X, SPLIT_Y);
  715.  
  716.     c_type = 1;
  717.     b_type = 2;
  718.  
  719.     c_pos_x = 0;
  720.     c_pos_y = 4;
  721.     c_pos_y_low = 2;
  722.  
  723.     b_pos_x = 0;
  724.     b_pos_y = 7;
  725.     b_pos_y_low = 5;
  726.  
  727.     for (i = 0; i < command.length(); i++) {
  728.         // 1 = cargo, 2 = block
  729.         if ('c' == command[i]) {
  730.  
  731.             m->set_cell(c_pos_x++, c_pos_y, c_type); //======
  732.  
  733.             c.set(c_n, 1, 10, 50 + 70 * i, 150);
  734.             list->append_back(c_n, c);
  735.             c_n++;
  736.         }
  737.         if ('b' == command[i] && 'b' == command[i+1]) {
  738.  
  739.             m->set_cell(b_pos_x++, b_pos_y, b_type); //======
  740.  
  741.             b.set(b_n, 2, 0, 50 + 70 * i, 300);
  742.             list->append_back(b_n, b);
  743.             b_n++;
  744.  
  745.  
  746.             m->set_cell(b_pos_x++, b_pos_y - 2, b_type);
  747.  
  748.             b.set(b_n, 2, 0, 50 + 70 * (i + 1), 200);
  749.             list->append_back(b_n, b);
  750.             b_n++;
  751.  
  752.             i += 2;
  753.             /*if ('b' == command[i + 1]) {
  754.  
  755.                 m->set_cell(x_pos++, 5, 2); //======
  756.  
  757.                 b.set(b_n, 2, 0, 50 + 70 * (i + 1), 200);
  758.                 list->append_back(b_n, b);
  759.                 b_n++;
  760.                 i++;
  761.             }
  762.             if ('(' == command[i + 1]) {
  763.                 if ('c' == command[i + 2] && ')' == command[i+3]) {
  764.  
  765.                     m->set_cell(x_pos++, 1, 1); //======
  766.  
  767.                     body extra_c;
  768.                     extra_c.set(c_n, 1, 10, 50 + 70 * i, 100);
  769.                     b.down = &extra_c;
  770.                     c_n++;
  771.                     i += 3;
  772.                 }
  773.             }*/
  774.         }
  775.         if ('b' == command[i] && '(' == command[i+1] && 'c' == command[i+2]) {
  776.  
  777.             m->set_cell(b_pos_x, b_pos_y, b_type); //======
  778.  
  779.             b.set(b_n, 2, 0, 50 + 70 * i, 300);
  780.             list->append_back(b_n, b);
  781.             b_n++;
  782.  
  783.  
  784.             m->set_cell(b_pos_x, c_pos_y - 2, c_type);
  785.             b_pos_x++;
  786.  
  787.             b.set(c_n, 1, 10, 50 + 70 * i, 150);
  788.             list->append_back(c_n, b);
  789.             c_n++;
  790.  
  791.             i += 2;
  792.            
  793.         }
  794.        
  795.         if ('b' == command[i]) {
  796.  
  797.             m->set_cell(b_pos_x++, b_pos_y, b_type); //======
  798.  
  799.             b.set(b_n, 2, 0, 50 + 70 * i, 300);
  800.             list->append_back(b_n, b);
  801.             b_n++;
  802.         }
  803.        
  804.     }
  805.  
  806.     list->display_forward();
  807.     list->display_objects();
  808.  
  809.  
  810.     t = 0;
  811.  
  812.     //load_textures();
  813.     //glEnable(GL_TEXTURE_2D);
  814.  
  815.     while (!glfwWindowShouldClose(window))
  816.     {
  817.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  818.  
  819.         if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
  820.             m->print_map();
  821.         }
  822.         if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS) {
  823.             i -= 5;
  824.         }
  825.  
  826.         m->draw_obj();
  827.         m->draw_net();
  828.        
  829.  
  830.  
  831.         list->draw_objects();
  832.  
  833.  
  834.  
  835.         glfwSwapBuffers(window);
  836.         glfwPollEvents();
  837.         //glfwWaitEvents();
  838.     }
  839.  
  840.     glfwDestroyWindow(window);
  841.     glfwTerminate();
  842.  
  843.     return 0;
  844. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement