// project a point from the position and the delta_v. Useful for working with lines / segments
const b2Vec2 point_b {aerolite_pos + delta_v};
float slope{}, distance{};
b2Vec2 intersect_point {};
// arrow: calculate the angle of attack respect to the screen's center
const auto theta {atan2Normalized(aerolite_pos.y - screen_center.y, aerolite_pos.x - screen_center.x)};
// asign an incoming direction so we can position the arrow
if (theta >= b2_pi / 6.ftop_right && theta < 5.f * b2_pi / 6.ftop_left) {
// TOP
aerolite->arrow_->incoming_direction_ = Direction::Top;
slope = (point_b.y - aerolite_pos.y) / (point_b.x - aerolite_pos.x);
const auto y_intersect = aerolite_pos.y - (slope * aerolite_pos.x);
intersect_point.Set(-y_intersect / slope, b2_screen_size_.y);
} else if (theta >= 5.f * b2_pi / 6.ftop_left && theta < 7.f * b2_pi / 6.fbottom_left) {
// LEFT
aerolite->arrow_->incoming_direction_ = Direction::Left;
slope = (point_b.y - aerolite_pos.y) / (point_b.x - aerolite_pos.x);
intersect_point.Set(0.f, aerolite_pos.y - (slope * aerolite_pos.x));
} else if (theta >= 7.f * b2_pi / 6.fbottom_left && theta < 11.f * b2_pi / 6.fbottom_right) {
// BOTTOM
aerolite->arrow_->incoming_direction_ = Direction::Bottom;
slope = (point_b.y - aerolite_pos.y) / (point_b.x - aerolite_pos.x);
const auto y_intersect = aerolite_pos.y - (slope * aerolite_pos.x);
intersect_point.Set(-y_intersect / slope , 0.f);
} else {
// RIGHT
aerolite->arrow_->incoming_direction_ = Direction::Right;
slope = (point_b.y - aerolite_pos.y) / (point_b.x - aerolite_pos.x + b2_screen_size_.x);
intersect_point.Set(b2_screen_size_.x, aerolite_pos.y - (slope * (aerolite_pos.x + b2_screen_size_.x)));
}
// distance from spawn point to intersect point
distance = b2Distance(aerolite_pos, intersect_point);
// calculate the time for the aerolite to enter the screen
aerolite->arrow_->time_to_enter_ = distance / delta_v.Length();