Advertisement
Ladies_Man

added class cell. still works

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