This commit is contained in:
vaner 2024-10-22 22:13:40 +02:00 committed by GitHub
commit f997c8fd5d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -228,23 +228,37 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEv
}
}
//test the lines now
//Testing transition lines
int closest = -1;
float closest_d = 1e20;
for (int i = 0; i < transition_lines.size(); i++) {
Vector2 s[2] = {
transition_lines[i].from,
transition_lines[i].to
};
Vector2 cpoint = Geometry2D::get_closest_point_to_segment(mb->get_position(), s);
float d = cpoint.distance_to(mb->get_position());
if (d > transition_lines[i].width) {
continue;
}
if (d < closest_d) {
closest = i;
closest_d = d;
for (int i = 0; i < transition_lines.size(); i++) {
Vector2 from = transition_lines[i].from;
Vector2 to = transition_lines[i].to;
Vector2 midpoint = (from + to) / 2.0;
// Calculate distance to the midpoint
float d_midpoint = midpoint.distance_to(mb->get_position());
// Check if the click is within the clickable area of the line
Vector2 click_pos = mb->get_position();
Vector2 line_vec = to - from;
float line_length = line_vec.length();
Vector2 line_dir = line_vec / line_length;
Vector2 to_click = click_pos - from;
float projection = line_dir.dot(to_click);
if (projection >= 0 && projection <= line_length) {
Vector2 closest_point = from + line_dir * projection;
float d_line = closest_point.distance_to(click_pos);
if (d_line <= transition_lines[i].width) {
// Prioritize based on distance to midpoint
if (d_midpoint < closest_d) {
closest = i;
closest_d = d_midpoint;
}
}
}
}