reworked _internal_collision_overlap to be more verbose

This commit is contained in:
Sara 2023-11-01 22:59:48 +01:00
parent 22709234cd
commit 4438070170

View file

@ -62,7 +62,7 @@ int _internal_collision_get_overlap(PhysicsEntity self, PhysicsEntity other, Col
// the shortest distance to solve collision found so far
Vector shortest_escape = InfinityVector;
// the squared length of the shortest escape vector found so far
float shortest_sqrmag = INFINITY;
float shortest_dot = INFINITY;
// the first index of the points on the edge
size_t shortest_escape_edge = 0;
// the number of points in the shape of self
@ -72,20 +72,20 @@ int _internal_collision_get_overlap(PhysicsEntity self, PhysicsEntity other, Col
// the next point on the line
size_t next_index = (point_index + 1) % self_point_count;
// get the two points defining the collision edge
Vector a = shape_get_point_transformed(self.tc->get_shape(self.data), point_index, *self_transform);
Vector b = shape_get_point_transformed(self.tc->get_shape(self.data), next_index, *self_transform);
Vector edge_lhs = shape_get_point_transformed(self.tc->get_shape(self.data), point_index, *self_transform);
Vector edge_rhs = shape_get_point_transformed(self.tc->get_shape(self.data), next_index, *self_transform);
// the direction of the line
Vector normal = vperpendicularf(vsubf(b, a));
Vector normal = vnormalizedf(vperpendicularf(vsubf(edge_rhs, edge_lhs)));
Vector overlap_point;
// the smallest escape vector on this axis
Vector escape = _internal_collision_overlap_on_axis(self, other, vnormalizedf(normal), &overlap_point);
float sqr_mag = vsqrmagnitudef(escape);
if(sqr_mag == 0) {
Vector escape = _internal_collision_overlap_on_axis(self, other, normal, &overlap_point);
float dot = vdotf(vinvf(normal), escape);
if(dot <= 0.0) {
return 0;
}
if(sqr_mag < shortest_sqrmag) {
shortest_sqrmag = sqr_mag;
if(dot <= shortest_dot) {
shortest_dot = dot;
shortest_escape = escape;
shortest_escape_edge = point_index;
}