void Grapple::TryRemoveNodes() { std::list<rope_node_t>::reverse_iterator nodeit; int lg; Point2d V; Point2i handPos, contact_point; Double angle; ActiveCharacter().GetHandPosition(handPos); while (rope_nodes.size() > 1) { nodeit = rope_nodes.rbegin(); ++nodeit; V.x = handPos.x - nodeit->pos.x; V.y = handPos.y - nodeit->pos.y; angle = V.ComputeAngle(); lg = static_cast<int>(V.Norm()); if (find_first_contact_point(nodeit->pos, angle, lg, SKIP_DST, contact_point)) break; DetachNode(); } }
bool Grapple::TryAddNode() { uint lg; Point2d V; Point2i contact_point; Double angle, rope_angle; Point2i handPos; ActiveCharacter().GetHandPosition(handPos); // Compute distance between hands and rope fixation point. V.x = handPos.x - m_fixation_point.x; V.y = handPos.y - m_fixation_point.y; angle = V.ComputeAngle(); lg = static_cast<int>(V.Norm()); if (lg < DST_MIN) return false; // Check if the rope collide something if (find_first_contact_point(m_fixation_point, angle, lg, SKIP_DST, contact_point)) { rope_angle = ActiveCharacter().GetRopeAngle() ; // if contact point is the same as position of the last node // (can happen because of jitter applied in find_first_contact_point), // give up adding such node if ( rope_nodes.size() > 0 && rope_nodes.back().pos == contact_point ) return false; // The rope has collided something... // Add a node on the rope and change the fixation point AttachNode(contact_point, rope_angle); return true; } return false; }