Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void node::phys_move(float t) {
- if (0 != this->mass && false == this->halt_move) {
- float a, v, y0;
- float all_mass;
- float bot_limit = (float)FLOOR_HEIGHT;
- float top_limit = (float)ROOF_HEIGHT;
- node *next_cargo = this->get_next_by_type('c');
- node *prev_cargo = this->get_prev_by_type('c');
- node *next_block = this->get_next_by_type('b');
- node *prev_block = this->get_prev_by_type('b');
- 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) || (NULL != prev_block))) {
- all_mass = next_cargo->mass;
- node *curr = this;
- for (int i = 0; i < this->cargos_amount - this->listpos; i++) {
- node *tmp = curr->next_node;
- if ('c' == tmp->type) {
- all_mass += tmp->mass;
- i++;
- }
- }
- a = this->accel;//G_CONST *(all_mass - this->mass) / (all_mass + this->mass);
- printf("a=%f\n", a);
- v = this->velo;
- y0 = this->curr.y;
- this->accel = a;
- this->velo = v;
- this->curr.y = y0;
- this->deliver_motion_to_list();
- }
- if (bot_limit <= 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_move = true;
- }
- }
- }
- void node::deliver_motion_to_list() {
- float accel = this->accel;
- node *curr = this->next_node;
- int i = 0;
- while (NULL != curr) {
- if ('c' == curr->type) {
- int his_blocks_id = curr->cp_center_id;
- node *his_block = this->get_by_id(his_blocks_id);
- if (NULL != his_block) {
- if (his_block->cp_center_id == curr->id) {
- //this cargo is hanging on block
- //curr->accel = -accel / 2;
- curr->deliver_motion_by_id(curr->cp_center_id);
- } else {
- //its twined
- //its also the last cargo
- curr->accel = -accel;
- }
- } else {
- printf("[node::deliver_motion_to_list]: couldnt find block[id:%d] for cargo[id:%d]\n", his_blocks_id, curr->id);
- }
- }
- if ('b' == curr->type) {
- if (0 != curr->cp_center_id && -1 != curr->cp_center_id) {
- curr->accel = -accel / 2;
- curr->deliver_motion_by_id(curr->cp_center_id);
- }
- i++;
- }
- curr = curr->next_node;
- }
- }
Add Comment
Please, Sign In to add comment