Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 3
- c
- 1337 150 350 10
- 322
- b
- 322 200 800 0
- 1337 0 322
- c
- 1488 250 500 100
- 322
- stdafx
- // stdafx.h : include file for standard system include files,
- // or project specific include files that are used frequently, but
- // are changed infrequently
- //
- #pragma once
- #include "targetver.h"
- #define _CRT_SECURE_NO_WARNINGS
- //if print is lagging switch this
- //#include <stdio.h>
- #include <iostream>
- #include <vector>
- #include <tchar.h>
- #include <stdlib.h>
- #define _USE_MATH_DEFINES
- #include <cmath>
- #include <math.h>
- #include <ctime>
- #include <time.h>
- #include <Windows.h>
- #include <string>
- #define GLEW_STATIC
- #include <GL\glew.h>
- #include <GLFW\glfw3.h>
- typedef struct { float x, y; } coord;
- #include "body.h"
- #include "cell.h"
- #include "map.h"
- #include "node.h"
- #include "dll.h"
- #define SCREEN_WIDTH 1000
- #define SCREEN_HEIGHT 1000
- #define ROOF_HEIGHT 950
- #define FLOOR_HEIGHT 50
- #define SPLIT_X 10
- #define SPLIT_Y 10
- #define G_CONST 9.781665
- #define MAXRANDID 99999
- #define REVD(COORD_Y) ((SPLIT_Y - 1) - (COORD_Y))
- node.h
- #pragma once
- class node
- {
- public:
- int id;
- char type;
- int listpos;
- int mass;
- float velo, accel;
- bool halt;
- node *next_node;
- node *prev_node;
- node *cp_left_node, *cp_center_node, *cp_right_node;
- int cp_left_id, cp_center_id, cp_right_id;
- coord init;
- coord curr;
- void set_list_param(char type, int id, int listpos, float pos_x, float pos_y, int mass);
- void set_cp_ids(int left, int center, int right);
- void set_cp_ids(int center);
- void draw_body();
- void draw_ropes();
- void fall(float t);
- node *get_next_by_type(char type);
- node *get_prev_by_type(char type);
- coord get_cp_left_pos();
- coord get_cp_center_pos();
- coord get_cp_right_pos();
- node(int id);
- ~node();
- private:
- int size_x, size_y, size_border, size_rope;
- coord cp_left_pos, cp_center_pos, cp_right_pos; //connection points
- };
- node.cpp
- #include "stdafx.h"
- using namespace std;
- node::node(int x)
- {
- id = x;
- next_node = NULL;
- prev_node = NULL;
- halt = false;
- }
- node::~node()
- {
- }
- void node::set_list_param(char type, int id, int listpos, float pos_x, float pos_y, int mass) {
- this->init.x = pos_x;
- this->init.y = pos_y;
- this->curr.x = pos_x;
- this->curr.y = pos_y;
- this->type = type;
- this->id = id;
- this->listpos = listpos;
- this->mass = mass;
- this->size_x = 100;
- this->size_y = 100;
- this->size_border = 5;
- this->size_rope = 3;
- this->velo = 0;
- this->accel = (-1)*G_CONST;
- this->halt = false;
- }
- void node::set_cp_ids(int left, int center, int right) {
- this->cp_left_id = left;
- this->cp_center_id = center;
- this->cp_right_id = right;
- }
- void node::set_cp_ids(int center) {
- this->cp_center_id = center;
- }
- node* node::get_next_by_type(char type) {
- node *tmp = this;
- tmp = tmp->next_node;
- while (tmp != NULL) {
- if (tmp->type == type) {
- return tmp;
- }
- tmp = tmp->next_node;
- }
- return NULL;
- }
- node* node::get_prev_by_type(char type) {
- node *tmp = this;
- tmp = tmp->prev_node;
- while (tmp != NULL) {
- if (tmp->type == type) {
- return tmp;
- }
- tmp = tmp->prev_node;
- }
- return NULL;
- }
- coord node::get_cp_left_pos() {
- coord retval;
- retval.x = this->curr.x - this->size_x / 2;
- retval.y = this->curr.y;
- this->cp_left_pos.x = retval.x;
- this->cp_left_pos.y = retval.y;
- return retval;
- }
- coord node::get_cp_center_pos() {
- if ('b' == this->type) {
- cp_center_pos = curr;
- return this->curr;
- }
- coord retval;
- retval.x = this->curr.x;
- retval.y = this->curr.y + this->size_y / 2;
- this->cp_center_pos.x = retval.x;
- this->cp_center_pos.y = retval.y;
- return retval;
- }
- coord node::get_cp_right_pos() {
- coord retval;
- retval.x = this->curr.x + this->size_x / 2;
- retval.y = this->curr.y;
- this->cp_right_pos.x = retval.x;
- this->cp_right_pos.y = retval.y;
- return retval;
- }
- void draw_line(float from_x, float from_y, float to_x, float to_y) {
- glBegin(GL_LINES);
- glVertex2f(from_x, from_y);
- glVertex2f(to_x, to_y);
- glEnd();
- }
- void draw_line(coord from, coord to) {
- glBegin(GL_LINES);
- glVertex2f(from.x, from.y);
- glVertex2f(to.x, to.y);
- glEnd();
- }
- void node::draw_body() {
- float center_x = this->curr.x;
- float center_y = this->curr.y;
- int size_x = this->size_x;
- int size_y = this->size_y;
- int rad = size_x / 2;
- int border = this->size_border;
- if ('c' == this->type) {
- coord lb, lt, rt, rb;
- lb.x = center_x - size_x / 2;
- lb.y = center_y - size_y / 2;
- lt.x = center_x - size_x / 2;
- lt.y = center_y + size_y / 2;
- rt.x = center_x + size_x / 2;
- rt.y = center_y + size_y / 2;
- rb.x = center_x + size_x / 2;
- rb.y = center_y - size_y / 2;
- //outer black
- glBegin(GL_POLYGON);
- glColor3f(0, 0, 0);
- glVertex2f(lb.x, lb.y);
- glVertex2f(lt.x, lt.y);
- glVertex2f(rt.x, rt.y);
- glVertex2f(rb.x, rb.y);
- glEnd();
- //inner white
- glBegin(GL_POLYGON);
- glColor3f(1, 1, 1);
- glVertex2f(lb.x + border, lb.y + border);
- glVertex2f(lt.x + border, lt.y - border);
- glVertex2f(rt.x - border, rt.y - border);
- glVertex2f(rb.x - border, rb.y + border);
- glEnd();
- }
- if ('b' == this->type) {
- GLfloat phi = 0, theta = 0;
- //outer black
- glBegin(GL_POLYGON);
- glColor3f(0, 0, 0);
- for (phi = 0; phi < 2 * M_PI; phi += 0.1) {
- glVertex2f(center_x + rad*cos(phi), center_y + rad*sin(phi));
- }
- glEnd();
- //inner white
- glBegin(GL_POLYGON);
- glColor3f(1, 1, 1);
- for (phi = 0; phi < 2 * M_PI; phi += 0.1) {
- glVertex2f(center_x + (rad - border)*cos(phi), center_y + (rad - border)*sin(phi));
- }
- glEnd();
- }
- }
- void node::draw_ropes() {
- node *next = this->next_node;
- if (NULL == next) {
- return;
- }
- glLineWidth((GLfloat)this->size_rope);
- glColor3f(0, 0, 0);
- //block's central connection point
- if ('b' == this->type) {
- if (0 == this->cp_center_id) {
- coord this_block_cp_center = this->get_cp_center_pos();
- draw_line(this_block_cp_center.x, this_block_cp_center.y, this_block_cp_center.x, ROOF_HEIGHT);
- }
- else {
- coord next_cargo_cp = this->next_node->get_cp_center_pos();
- draw_line(this->get_cp_center_pos(), next_cargo_cp);
- }
- }
- if ('c' == this->type && 'b' == next->type) {
- coord this_cargo_cp = this->get_cp_center_pos();
- coord next_block_cp_left = next->get_cp_left_pos();
- draw_line(this_cargo_cp, next_block_cp_left);
- }
- if ('b' == this->type && 'b' == next->type) {
- coord this_block_cp_right = this->get_cp_right_pos();
- coord next_block_cp_left = next->get_cp_left_pos();
- draw_line(this_block_cp_right, next_block_cp_left);
- }
- if ('b' == this->type && 'c' == next->type) {
- coord this_block_cp_right = this->get_cp_right_pos();
- coord next_cargo_cp = next->get_cp_center_pos();
- draw_line(this_block_cp_right, next_cargo_cp);
- }
- }
- void node::fall(float t) {
- if (0 != this->mass) {
- float a, v, y0;
- float top_limit = (float)ROOF_HEIGHT;
- node *next_cargo = get_next_by_type(this->type);
- node *prev_cargo = get_prev_by_type(this->type);
- if ('c' == this->type) {
- if (NULL != this->next_node) {
- top_limit = this->next_node->curr.y - this->next_node->size_y / 2;
- }
- if (NULL != this->prev_node) {
- top_limit = this->prev_node->curr.y - this->prev_node->size_y / 2;
- }
- }
- if (NULL == prev_cargo && NULL != next_cargo) {
- a = G_CONST *(next_cargo->mass - this->mass) / (next_cargo->mass + this->mass);
- v = this->velo;
- y0 = this->curr.y;
- next_cargo->accel = -a;
- if (FLOOR_HEIGHT <= this->curr.y - this->size_y / 2 && top_limit >= this->curr.y + this->size_y / 2) {
- this->curr.x = this->curr.x;
- this->curr.y = y0 + v*t + (a*t*t) / 2;
- }
- else {
- this->halt = true;
- }
- return;
- }
- /*if (NULL != prev_cargo && NULL == next_cargo) {
- if (FLOOR_HEIGHT <= this->curr.y - this->size_y / 2 && top_limit >= this->curr.y + this->size_y / 2) {
- this->curr.x = this->curr.x;
- this->curr.y = this->curr.y + this->velo*t + (this->accel*t*t) / 2;
- }
- else {
- this->halt = true;
- }
- return;
- }*/
- if (FLOOR_HEIGHT <= this->curr.y - this->size_y / 2 && top_limit >= this->curr.y + this->size_y / 2) {
- this->curr.x = this->curr.x;
- this->curr.y = this->curr.y + this->velo*t + (this->accel*t*t) / 2;
- }
- else {
- this->halt = true;
- }
- }
- }
- dll.h
- class dll {
- public:
- bool phys_enabled;
- void append_front(int id);
- void append_back(int id);
- void destroy_list();
- int get_length();
- node* get_front();
- node* get_back();
- node* get_by_id(int id);
- node* get_by_pos(int pos);
- void display_forward();
- void display_backward();
- void display_objects();
- void draw_objects();
- void draw_ropes();
- void set_connection_points();
- void enable_fall(float time);
- void check_movement();
- dll() { front = NULL; back = NULL; length = 0; phys_enabled = false; }
- ~dll() { destroy_list(); }
- private:
- int length;
- node *front;
- node *back;
- };
- dll.cpp
- #include "stdafx.h"
- using namespace std;
- void dll::append_front(int x) {
- node *n = new node(x);
- if (front == NULL) {
- front = n;
- back = n;
- }
- else {
- front->prev_node = n;
- n->next_node = front;
- front = n;
- }
- this->length++;
- printf("fornt appended\n");
- }
- void dll::append_back(int x) {
- node *n = new node(x);
- if (back == NULL) {
- front = n;
- back = n;
- }
- else {
- back->next_node = n;
- n->prev_node = back;
- back = n;
- }
- this->length++;
- printf("back appended\n");
- }
- int dll::get_length() {
- return this->length;
- }
- node* dll::get_front() {
- return this->front;
- }
- node* dll::get_back() {
- return this->back;
- }
- node* dll::get_by_id(int id) {
- node *tmp = front;
- node *retval;
- while (tmp != NULL) {
- if (id == tmp->id) {
- retval = tmp;
- return retval;
- }
- tmp = tmp->next_node;
- }
- return NULL;
- }
- node* dll::get_by_pos(int pos) {
- node *tmp = front;
- node *retval;
- int i = 0;
- while (tmp != NULL) {
- if (i == pos) {
- retval = tmp;
- return retval;
- }
- i++;
- tmp = tmp->next_node;
- }
- return NULL;
- }
- void dll::display_forward() {
- node *tmp = front;
- printf("\n\nnodes(%d) in forward order:\n", this->length);
- while (tmp != NULL) {
- printf("%d ", tmp->id);
- tmp = tmp->next_node;
- }
- printf("\n");
- }
- void dll::display_backward() {
- node *tmp = back;
- printf("\n\nnodes(%d) in reverse order:\n", this->length);
- while (tmp != NULL) {
- printf("%d ", tmp->id);
- tmp = tmp->prev_node;
- }
- printf("\n");
- }
- void dll::display_objects() {
- node *tmp = front;
- printf("\n\nobjects(%d) in forward order:\n", this->length);
- while (NULL != tmp) {
- printf("(id:%d", tmp->id);
- if ('c' == tmp->type)
- printf("C, ");
- if ('b' == tmp->type)
- printf("B, ");
- printf("listpos:%d, mass:%d) ", tmp->listpos, tmp->mass);
- tmp = tmp->next_node;
- }
- printf("\n");
- }
- void dll::draw_objects() {
- node *tmp = front;
- while (NULL != tmp) {
- tmp->draw_body();
- tmp = tmp->next_node;
- }
- }
- void dll::draw_ropes() {
- node *tmp = front;
- int i;
- for (i = 0; i < this->length; i++) {
- tmp->draw_ropes();
- tmp = tmp->next_node;
- }
- }
- void dll::destroy_list() {
- node *T = back;
- while (T != NULL) {
- node *T2 = T;
- T = T->prev_node;
- delete T2;
- }
- front = NULL;
- back = NULL;
- }
- void dll::enable_fall(float t) {
- if (this->phys_enabled) {
- node *tmp = front;
- while (NULL != tmp) {
- tmp->fall(t);
- tmp = tmp->next_node;
- }
- }
- }
- void dll::check_movement() {
- node *tmp = front;
- while (NULL != tmp) {
- if (tmp->halt)
- this->phys_enabled = false;
- tmp = tmp->next_node;
- }
- }
- void dll::set_connection_points() {
- node *tmp = front;
- while (NULL != tmp) {
- if ('c' == tmp->type) {
- int cp_center_id = tmp->cp_center_id;
- tmp->cp_center_node = this->get_by_id(cp_center_id);
- }
- if ('b' == tmp->type) {
- tmp->cp_left_node = this->get_by_id(tmp->cp_left_id);
- tmp->cp_center_node = this->get_by_id(tmp->cp_center_id);
- tmp->cp_right_node = this->get_by_id(tmp->cp_right_id);
- }
- tmp = tmp->next_node;
- }
- }
- glfw30
- // glfw_30.cpp : Defines the entry point for the console application.
- // http://www.glfw.org/docs/latest/quick.html
- #include "stdafx.h"
- #include <GLAux.h>
- #pragma comment(lib,"glaux.lib")
- using namespace std;
- GLdouble A, B, C, D;
- float t = 0;
- int mouse_curr_x, mouse_curr_y;
- class cell;
- class map;
- class node;
- class dll;
- map *m;
- dll *list;
- int count_command(string command, char type) {
- int i, comm_len = command.length();
- int retval = 0;
- if ('e' == type) {
- for (i = 0; i < comm_len; i++) {
- if ('b' == command[i] || 'c' == command[i]) {
- retval++;
- }
- }
- return retval;
- }
- for (i = 0; i < comm_len; i++) {
- if (type == command[i]) {
- retval++;
- }
- }
- return retval;
- }
- int count_further(string command, int curr_pos) {
- int i, j, num_of_same_chars;
- int seq_end_pos;
- char curr_sym = command[curr_pos];
- if (curr_pos < command.length()) {
- num_of_same_chars = 1;
- seq_end_pos = curr_pos;
- for (i = curr_pos; i < command.length(); i++) {
- if (curr_sym == command[i] && curr_sym == command[i + 1]) {
- num_of_same_chars++;
- seq_end_pos = i;
- }
- if (curr_sym == command[i] && curr_sym != command[i + 1]) {
- seq_end_pos = i + 1;
- break;
- }
- }
- return seq_end_pos;
- }
- else {
- printf("\ncount_further incorrect input!\n");
- return -1;
- }
- }
- bool lookup_next_sym(string command, int curr_pos) {
- int i;
- char curr_sym = command[curr_pos];
- char opposite;
- if ('b' == curr_sym) opposite = 'c';
- if ('c' == curr_sym) opposite = 'b';
- for (i = curr_pos; i < command.length(); i++) {
- if (command[i] == curr_sym) continue;
- if (command[i] == opposite) break;
- }
- int last_pos_of_curr_sym = i - 1;
- return true;
- }
- char nearest_next_sym(string command, int curr_pos) {
- char curr_sym = command[curr_pos];
- int seq_len = count_further(command, curr_pos);
- if (curr_pos + seq_len < command.length()) {
- return command[curr_pos + seq_len];
- }
- else
- {
- return 'x';
- }
- }
- GLuint texture[1];
- void load_textures()
- {
- AUX_RGBImageRec *texture1;
- texture1 = auxDIBImageLoadA("tex_snoop.bmp");
- glGenTextures(1, &texture[0]);
- glBindTexture(GL_TEXTURE_2D, texture[0]);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- }
- void draw_constraints(int h) {
- glLineWidth(2.0);
- glColor3f(0, 0, 0);
- int i, n = 15;
- float di = SCREEN_WIDTH / n;
- if (h > SCREEN_HEIGHT / 2) {
- glBegin(GL_POLYGON);
- glColor3f(1, 1, 1);
- glVertex2f(0, h);
- glVertex2f(0, SCREEN_HEIGHT);
- glVertex2f(SCREEN_WIDTH, SCREEN_HEIGHT);
- glVertex2f(SCREEN_WIDTH, h);
- glEnd();
- for (i = 0; i < SCREEN_WIDTH; i += (int)di) {
- glBegin(GL_LINES);
- glColor3f(0,0,0);
- glVertex2f(i, h);
- glVertex2f(i + di, h + di);
- glEnd();
- }
- }
- else {
- glBegin(GL_POLYGON);
- glColor3f(1, 1, 1);
- glVertex2f(0, -h);
- glVertex2f(0, h);
- glVertex2f(SCREEN_WIDTH, h);
- glVertex2f(SCREEN_WIDTH, -h);
- glEnd();
- for (i = 0; i < SCREEN_WIDTH; i += (int)di) {
- glBegin(GL_LINES);
- glColor3f(0,0,0);
- glVertex2f(i, h);
- glVertex2f(i - di, h - di);
- glEnd();
- }
- }
- glBegin(GL_LINES);
- glColor3f(0,0,0);
- glVertex2f(0, h);
- glVertex2f(SCREEN_WIDTH, h);
- glEnd();
- }
- static void cursor_callback(GLFWwindow* window, double x, double y)
- {
- mouse_curr_x = (int)x;
- mouse_curr_y = (int)y;
- int tmpx = (int)(x / (SCREEN_WIDTH / SPLIT_X));
- int tmpy = (int)(y / (SCREEN_HEIGHT / SPLIT_Y));
- //printf("%d\t%d\t%c\n", (int)x, (int)y, m->get_cell_type(tmpx, tmpy));
- m->dispell_map();
- //m->highlight_cell(tmpx, tmpy);
- }
- static void mouse_callback(GLFWwindow* window, int button, int action, int mods)
- {
- int tmpx = (int)(mouse_curr_x / (SCREEN_WIDTH / SPLIT_X));
- int tmpy = (int)(mouse_curr_y / (SCREEN_HEIGHT / SPLIT_Y));
- if (button == GLFW_MOUSE_BUTTON_RIGHT)
- {
- if (action == GLFW_PRESS) {
- printf("%d\t%d\t%c\n", (int)mouse_curr_x, (int)mouse_curr_y, m->get_cell_type(tmpx, tmpy));
- }
- if (action == GLFW_RELEASE) glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
- }
- if (button == GLFW_MOUSE_BUTTON_LEFT)
- {
- if (action == GLFW_PRESS) {
- printf("M: %d\t%d\t%c(before click)\n", mouse_curr_x, mouse_curr_y, m->get_cell_type(tmpx, tmpy));
- if ('e' == m->get_cell_type(tmpx, tmpy)) {
- m->erase_cell(tmpx, tmpy);
- m->set_cell(1, tmpx, tmpy, 'b');
- return;
- }
- if ('b' == m->get_cell_type(tmpx, tmpy)) {
- m->erase_cell(tmpx, tmpy);
- m->set_cell(1, tmpx, tmpy, 'c');
- return;
- }
- if ('c' == m->get_cell_type(tmpx, tmpy)) {
- m->erase_cell(tmpx, tmpy);
- m->set_cell(1, tmpx, tmpy, 'e');
- return;
- }
- }
- }
- }
- static void resize_callback(GLFWwindow* window, int width, int height)
- {
- // windowWidth = width;
- // windowHeight = height;
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, (GLdouble)width, 0.0, (GLdouble)height, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- A = width / 4.0;
- B = 0.0;
- C = D = height / 2.0;
- //printf("Reshape occured\n");
- }
- static void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
- {
- if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
- glfwSetWindowShouldClose(window, GL_TRUE);
- if (GLFW_KEY_S == key && action == GLFW_PRESS) {
- m->validate_map();
- }
- if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) {
- if (!list->phys_enabled) {
- list->phys_enabled = true;
- }
- else {
- list->phys_enabled = false;
- }
- }
- }
- static void error_callback(int error, const char* description)
- {
- fputs(description, stderr);
- }
- int main(int argc, _TCHAR* argv[])
- {
- if (!glfwInit()) {
- printf("glfwInit failed\n");
- return -1;
- }
- glfwSetErrorCallback(error_callback);
- GLFWwindow* window;
- // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
- // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);
- window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Anthony's Porject", NULL, NULL);
- if (window == NULL) {
- printf("glfwOpenWindow failed.\n");
- glfwTerminate();
- return -2;
- }
- int i, attrib;
- attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MAJOR);
- attrib = glfwGetWindowAttrib(window, GLFW_CONTEXT_VERSION_MINOR);
- attrib = glfwGetWindowAttrib(window, GLFW_OPENGL_PROFILE);
- glfwMakeContextCurrent(window);
- glfwSetKeyCallback(window, keyboard_callback);
- glfwSetFramebufferSizeCallback(window, resize_callback);
- glfwSetMouseButtonCallback(window, mouse_callback);
- glfwSetCursorPosCallback(window, cursor_callback);
- resize_callback(window, SCREEN_WIDTH, SCREEN_HEIGHT);
- srand(time(NULL));
- FILE *fp;
- fp = fopen("scheme.txt", "r");
- if (NULL == fp) {
- printf("cannot open file\n");
- }
- list = new dll();
- m = new map();
- m->set_map(SPLIT_X, SPLIT_Y);
- printf("reading scheme\n");
- int num;
- fscanf(fp, "%d", &num);
- for (i = 0; i < num; i++) {
- char el_type[6];
- printf("type:");
- fscanf(fp, "%s", el_type);
- if (0 == strcmp(el_type, "stop"))
- break;
- node *curr_node;
- int pos_x, pos_y, mass;
- int body_name, conn_left_name, conn_right_name, conn_center_name;
- if (0 == strcmp(el_type, "block") || 0 == strcmp(el_type, "b")) {
- printf("name pos_x pos_y mass:");
- fscanf(fp, "%d%d%d%d", &body_name, &pos_x, &pos_y, &mass);
- printf("connection: L C R:");
- fscanf(fp, "%d%d%d", &conn_left_name, &conn_center_name, &conn_right_name);
- list->append_back(body_name);
- curr_node = list->get_by_id(body_name);
- curr_node->set_list_param('b', body_name, i, pos_x, pos_y, mass);
- curr_node->set_cp_ids(conn_left_name, conn_center_name, conn_right_name);
- printf("block:%d[x:%d y:%d m:%d CL:%d CC:%d CR:%d]\n\n", body_name, pos_x, pos_y, mass, conn_left_name, conn_right_name, conn_right_name);
- }
- if (0 == strcmp(el_type, "cargo") || 0 == strcmp(el_type, "c")) {
- printf("name pos_x pos_y mass:");
- fscanf(fp, "%d%d%d%d", &body_name, &pos_x, &pos_y, &mass);
- printf("connection: T B:");
- fscanf(fp, "%d", &conn_center_name);
- list->append_back(body_name);
- curr_node = list->get_by_id(body_name);
- curr_node->set_list_param('c', body_name, i, pos_x, pos_y, mass);
- curr_node->set_cp_ids(conn_center_name);
- printf("cargo:%d[x:%d y:%d m:%d CC:%d]\n\n", body_name, pos_x, pos_y, mass, conn_center_name);
- }
- }
- fclose(fp);
- printf("file has been closed\n");
- list->set_connection_points();
- list->phys_enabled = false;
- list->display_objects();
- int ps = 1;
- node *nn = list->get_by_pos(ps);
- int tidsean = nn->next_node->id;
- printf("next to listpos=%d is:%d\n", ps, tidsean);
- /*
- int id, id2;
- char c_type = 'c', b_type = 'b', e_type = 'e';
- int b_pos_x, b_pos_y, c_pos_x, c_pos_y, c_n, b_n;
- c_n = b_n = 0;
- c_pos_x = 0;
- c_pos_y = 6;
- b_pos_x = 0;
- b_pos_y = 3;
- char prev_sym = '0', curr_sym, next_sym;
- int body_num, block_num, cargo_num;
- int seq_start_pos, seq_end_pos, len_of_seq;
- int x;
- //command = "b^bc^b^cc";
- //command = "cbb(cc)bc";
- body_num = count_command(command, 'e');
- cargo_num = count_command(command, c_type);
- block_num = count_command(command, b_type);
- printf("bodies:%d cargos:%d blocks:%d\n", body_num, cargo_num, block_num);
- for (i = 0; i < command.length(); i++) {
- if (i > 0)
- prev_sym = command[i - 1];
- curr_sym = command[i];
- next_sym = command[i + 1];
- seq_start_pos = i;
- seq_end_pos = count_further(command, seq_start_pos);
- len_of_seq = seq_end_pos - seq_start_pos;
- char nearest_sym = command[seq_start_pos + len_of_seq];
- printf("[%d_%d]%c:%d .%c\n", seq_start_pos, seq_end_pos, curr_sym, len_of_seq, nearest_sym);
- //i = seq_end_pos-1;
- if ('b' == curr_sym && len_of_seq > 1) {
- printf(" b.. ");
- if ('(' == nearest_sym || '^' == nearest_sym) {
- len_of_seq -= 1;
- }
- for (j = 0; j < len_of_seq; j++) {
- id = 100 + rand() % MAXRANDID;
- if (0 == j % 2) {
- m->set_cell(id, b_pos_x++, b_pos_y, b_type);
- }
- else {
- m->set_cell(id, b_pos_x++, b_pos_y + 1, b_type);
- }
- }
- i = i + j - 1;
- continue;
- }
- if ('b' == curr_sym && '(' == next_sym) {
- m->set_cell(1, b_pos_x, b_pos_y, b_type);
- int num_of_cargos = 2;
- //int num_of_cargos = count_further(command, i + 2);
- printf(" b(str[%d]=%c(n:%d)) ", i + 2, command[i + 2], num_of_cargos);
- for (j = 0; j < num_of_cargos; j++) {
- id = 100 + rand() % MAXRANDID;
- m->set_cell(id, b_pos_x, c_pos_y++, c_type);
- }
- b_pos_x++;
- c_pos_x++;
- i = i + num_of_cargos;
- }
- //if ('b' == curr_sym && '^' == next_sym) {
- // id = 100 + rand() % MAXRANDID;
- // m->set_cell(id, b_pos_x++, b_pos_y, b_type);
- // int tmp_seq_start = i;
- // int tmp_seq_end = count_further(command, tmp_seq_start, next_sym);
- //
- // int tmp_b_pos_y = b_pos_y;
- // for (j = 0; j < tmp_seq_end; j++) {
- // tmp_b_pos_y++;
- // }
- // id = 100 + rand() % MAXRANDID;
- // m->set_cell(id, b_pos_x++, tmp_b_pos_y, b_type);
- // i = tmp_seq_end;
- // continue;
- // }
- if ('c' == curr_sym && len_of_seq > 1 && len_of_seq <= 3) {
- for (j = 0; j < len_of_seq; j++) {
- id = 100 + rand() % MAXRANDID;
- m->set_cell(id, c_pos_x, c_pos_y + j, c_type);
- }
- i = i + len_of_seq - 1;
- continue;
- }
- }
- */
- printf("\n");
- /*
- for (i = 0; i < command.length(); i++) {
- // 1 = cargo, 2 = block
- id = 100 + rand() % MAXRANDID;
- id2 = 100 + rand() % MAXRANDID;
- if ('c' == command[i]) {
- m->set_cell(id, c_pos_x++, c_pos_y, c_type); //======
- c.set(id, c_n, 1, 10, 50 + 70 * i, 150);
- list->append_back(c_n, c);
- c_n++;
- printf(" c ");
- continue;
- }
- if ('b' == command[i] && 'b' == command[i+1]) {
- m->set_cell(id, b_pos_x++, b_pos_y, b_type); //======
- b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
- list->append_back(b_n, b);
- b_n++;
- m->set_cell(id2, b_pos_x++, b_pos_y - 1, b_type);
- b.set(id2, b_n, 2, 0, 50 + 70 * (i + 1), 200);
- list->append_back(b_n, b);
- b_n++;
- i += 1;
- printf(" bb ");
- continue;
- }
- if ('b' == command[i] && '(' == command[i+1] && 'c' == command[i+2]) {
- m->set_cell(id, b_pos_x, b_pos_y, b_type); //======
- b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
- list->append_back(b_n, b);
- b_n++;
- m->set_cell(id2, b_pos_x, c_pos_y - 2, c_type);
- b_pos_x++;
- b.set(id2, c_n, 1, 10, 50 + 70 * i, 150);
- list->append_back(c_n, b);
- c_n++;
- i += 2;
- printf(" b(c ");
- continue;
- }
- if ('b' == command[i]) {
- m->set_cell(id, b_pos_x++, b_pos_y, b_type); //======
- b.set(id, b_n, 2, 0, 50 + 70 * i, 300);
- list->append_back(b_n, b);
- b_n++;
- printf(" b ");
- continue;
- }
- }
- list->display_forward();
- list->display_objects();
- */
- //load_textures();
- //glEnable(GL_TEXTURE_2D);
- while (!glfwWindowShouldClose(window))
- {
- glClearColor(0.6, 0.6, 0.6, 1);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- draw_constraints(ROOF_HEIGHT);
- draw_constraints(FLOOR_HEIGHT);
- if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) {
- m->print_map();
- }
- //m->draw_map();
- list->draw_objects();
- list->draw_ropes();
- list->check_movement();
- list->enable_fall(t);
- if (list->phys_enabled) {
- t += 0.0002;
- }
- glfwSwapBuffers(window);
- glfwPollEvents();
- //glfwWaitEvents();
- }
- glfwDestroyWindow(window);
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement