Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] - ray distance scaling #2022

Merged
merged 1 commit into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/esp/physics/bullet/BulletPhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,7 @@ RaycastResults BulletPhysicsManager::castRay(const esp::geo::Ray& ray,
hit.normal = Magnum::Vector3{allResults.m_hitNormalWorld[i]};
hit.point = Magnum::Vector3{allResults.m_hitPointWorld[i]};
hit.rayDistance =
(static_cast<double>(allResults.m_hitFractions[i]) * maxDistance) /
rayLength;
(static_cast<double>(allResults.m_hitFractions[i]) * maxDistance);
// default to -1 for "scene collision" if we don't know which object was
// involved
hit.objectId = -1;
Expand Down
14 changes: 14 additions & 0 deletions tests/test_physics.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,20 @@ def test_raycast():
sim.set_stage_is_collidable(False)
raycast_results = sim.cast_ray(test_ray_1)
assert not raycast_results.has_hits()
sim.set_stage_is_collidable(True)

# test non-unit ray direction
test_ray_1.direction = mn.Vector3(0.5, 0, 0)
raycast_results = sim.cast_ray(test_ray_1)
assert raycast_results.has_hits()
assert len(raycast_results.hits) == 3
assert (
raycast_results.hits[0].point
- (
test_ray_1.origin
+ test_ray_1.direction * raycast_results.hits[0].ray_distance
)
).length() < 0.001


@pytest.mark.skipif(
Expand Down