Skip to content

Commit 21cc9a8

Browse files
authored
fix bug with ray distance scaling (#2022)
1 parent b6186aa commit 21cc9a8

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/esp/physics/bullet/BulletPhysicsManager.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ RaycastResults BulletPhysicsManager::castRay(const esp::geo::Ray& ray,
491491
hit.normal = Magnum::Vector3{allResults.m_hitNormalWorld[i]};
492492
hit.point = Magnum::Vector3{allResults.m_hitPointWorld[i]};
493493
hit.rayDistance =
494-
(static_cast<double>(allResults.m_hitFractions[i]) * maxDistance) /
495-
rayLength;
494+
(static_cast<double>(allResults.m_hitFractions[i]) * maxDistance);
496495
// default to -1 for "scene collision" if we don't know which object was
497496
// involved
498497
hit.objectId = -1;

tests/test_physics.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,20 @@ def test_raycast():
568568
sim.set_stage_is_collidable(False)
569569
raycast_results = sim.cast_ray(test_ray_1)
570570
assert not raycast_results.has_hits()
571+
sim.set_stage_is_collidable(True)
572+
573+
# test non-unit ray direction
574+
test_ray_1.direction = mn.Vector3(0.5, 0, 0)
575+
raycast_results = sim.cast_ray(test_ray_1)
576+
assert raycast_results.has_hits()
577+
assert len(raycast_results.hits) == 3
578+
assert (
579+
raycast_results.hits[0].point
580+
- (
581+
test_ray_1.origin
582+
+ test_ray_1.direction * raycast_results.hits[0].ray_distance
583+
)
584+
).length() < 0.001
571585

572586

573587
@pytest.mark.skipif(

0 commit comments

Comments
 (0)