Ladies_Man

phys_move, deliver_motion OLD

Dec 24th, 2015
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. void node::phys_move(float t) {
  2.  
  3.     if (0 != this->mass && false == this->halt_move) {
  4.         float a, v, y0;
  5.         float all_mass;
  6.         float bot_limit = (float)FLOOR_HEIGHT;
  7.         float top_limit = (float)ROOF_HEIGHT;
  8.         node *next_cargo = this->get_next_by_type('c');
  9.         node *prev_cargo = this->get_prev_by_type('c');
  10.         node *next_block = this->get_next_by_type('b');
  11.         node *prev_block = this->get_prev_by_type('b');
  12.  
  13.         if ('c' == this->type) {
  14.             if (NULL != this->next_node)
  15.                 top_limit = this->next_node->curr.y - this->next_node->size_y / 2;
  16.             if (NULL != this->prev_node)
  17.                 top_limit = this->prev_node->curr.y - this->prev_node->size_y / 2;
  18.         }
  19.  
  20.         if (NULL == prev_cargo && ((NULL != next_cargo) || (NULL != prev_block))) {
  21.  
  22.             all_mass = next_cargo->mass;
  23.             node *curr = this;
  24.             for (int i = 0; i < this->cargos_amount - this->listpos; i++) {
  25.                 node *tmp = curr->next_node;
  26.                 if ('c' == tmp->type) {
  27.                     all_mass += tmp->mass;
  28.                     i++;
  29.                 }
  30.             }
  31.  
  32.            
  33.            
  34.             a = this->accel;//G_CONST *(all_mass - this->mass) / (all_mass + this->mass);
  35.             printf("a=%f\n", a);
  36.             v = this->velo;
  37.             y0 = this->curr.y;
  38.            
  39.             this->accel = a;
  40.             this->velo = v;
  41.             this->curr.y = y0;
  42.            
  43.             this->deliver_motion_to_list();
  44.            
  45.         }
  46.  
  47.         if (bot_limit <= this->curr.y - this->size_y / 2 && top_limit >= this->curr.y + this->size_y / 2) {
  48.  
  49.             this->curr.x = this->curr.x;
  50.  
  51.             this->curr.y = this->curr.y + this->velo*t + (this->accel*t*t) / 2;
  52.  
  53.         }
  54.         else {
  55.             this->halt_move = true;
  56.         }
  57.        
  58.  
  59.     }
  60.  
  61. }
  62.  
  63. void node::deliver_motion_to_list() {
  64.  
  65.     float accel = this->accel;
  66.     node *curr = this->next_node;
  67.  
  68.     int i = 0;
  69.     while (NULL != curr) {
  70.        
  71.         if ('c' == curr->type) {
  72.             int his_blocks_id = curr->cp_center_id;
  73.             node *his_block = this->get_by_id(his_blocks_id);
  74.  
  75.             if (NULL != his_block) {
  76.  
  77.                 if (his_block->cp_center_id == curr->id) {
  78.                     //this cargo is hanging on block
  79.                     //curr->accel = -accel / 2;
  80.                     curr->deliver_motion_by_id(curr->cp_center_id);
  81.                 } else {
  82.                     //its twined
  83.                     //its also the last cargo
  84.                     curr->accel = -accel;
  85.                 }
  86.  
  87.             } else {
  88.                 printf("[node::deliver_motion_to_list]: couldnt find block[id:%d] for cargo[id:%d]\n", his_blocks_id, curr->id);
  89.             }
  90.         }
  91.  
  92.         if ('b' == curr->type) {
  93.             if (0 != curr->cp_center_id && -1 != curr->cp_center_id) {
  94.                 curr->accel = -accel / 2;
  95.                 curr->deliver_motion_by_id(curr->cp_center_id);
  96.             }
  97.             i++;
  98.         }
  99.         curr = curr->next_node;
  100.     }
  101.  
  102. }
Add Comment
Please, Sign In to add comment