mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 18:03:56 -04:00
fix sphere-sphere collisions for moving spheres
This commit is contained in:
parent
aa92d0c62e
commit
20197b6767
@ -312,11 +312,9 @@ test_intersection_from_sphere(const CollisionEntry &entry) const {
|
|||||||
DCAST_INTO_R(sphere, entry.get_from(), 0);
|
DCAST_INTO_R(sphere, entry.get_from(), 0);
|
||||||
|
|
||||||
CPT(TransformState) wrt_space = entry.get_wrt_space();
|
CPT(TransformState) wrt_space = entry.get_wrt_space();
|
||||||
CPT(TransformState) wrt_prev_space = entry.get_wrt_prev_space();
|
|
||||||
|
|
||||||
const LMatrix4f &wrt_mat = wrt_space->get_mat();
|
const LMatrix4f &wrt_mat = wrt_space->get_mat();
|
||||||
|
|
||||||
LPoint3f from_a = sphere->get_center() * wrt_prev_space->get_mat();
|
|
||||||
LPoint3f from_b = sphere->get_center() * wrt_mat;
|
LPoint3f from_b = sphere->get_center() * wrt_mat;
|
||||||
|
|
||||||
LPoint3f into_center(get_center());
|
LPoint3f into_center(get_center());
|
||||||
@ -331,7 +329,15 @@ test_intersection_from_sphere(const CollisionEntry &entry) const {
|
|||||||
LPoint3f contact_point(into_intersection_point);
|
LPoint3f contact_point(into_intersection_point);
|
||||||
float actual_t = 0.0f;
|
float actual_t = 0.0f;
|
||||||
|
|
||||||
if (from_a != from_b) {
|
LVector3f vec = from_b - into_center;
|
||||||
|
float dist2 = dot(vec, vec);
|
||||||
|
if (dist2 > (into_radius + from_radius) * (into_radius + from_radius)) {
|
||||||
|
// No intersection with the current position. Check the delta
|
||||||
|
// from the previous frame.
|
||||||
|
CPT(TransformState) wrt_prev_space = entry.get_wrt_prev_space();
|
||||||
|
LPoint3f from_a = sphere->get_center() * wrt_prev_space->get_mat();
|
||||||
|
|
||||||
|
if (!from_a.almost_equal(from_b)) {
|
||||||
LVector3f from_direction = from_b - from_a;
|
LVector3f from_direction = from_b - from_a;
|
||||||
if (!intersects_line(t1, t2, from_a, from_direction, from_radius)) {
|
if (!intersects_line(t1, t2, from_a, from_direction, from_radius)) {
|
||||||
// No intersection.
|
// No intersection.
|
||||||
@ -357,17 +363,10 @@ test_intersection_from_sphere(const CollisionEntry &entry) const {
|
|||||||
// sphere or beyond it. The first intersection point is at t1.
|
// sphere or beyond it. The first intersection point is at t1.
|
||||||
into_intersection_point = from_a + t1 * from_direction;
|
into_intersection_point = from_a + t1 * from_direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LVector3f vec = from_a - into_center;
|
// No delta, therefore no intersection.
|
||||||
float dist2 = dot(vec, vec);
|
|
||||||
if (dist2 > (into_radius + from_radius) * (into_radius + from_radius)) {
|
|
||||||
// No intersection.
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
into_intersection_point = from_a;
|
|
||||||
t1 = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (collide_cat.is_debug()) {
|
if (collide_cat.is_debug()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user