@@ -4397,31 +4397,38 @@ void PhysicsPrivate::UpdateRayIntersections(EntityComponentManager &_ecm)
43974397 return ;
43984398 }
43994399
4400+ // Go through each entity that has a RaycastData components, trace the
4401+ // rays and store the results
44004402 _ecm.Each <components::RaycastData,
44014403 components::Pose>(
44024404 [&](const Entity &_entity,
44034405 components::RaycastData *_raycastData,
44044406 components::Pose */*_pose*/) -> bool
44054407 {
4408+ // Retrieve the rays from the RaycastData component
44064409 if (!_raycastData->Data ().needsRaycast )
44074410 return true ;
44084411 _raycastData->Data ().needsRaycast = false ;
44094412
44104413 const auto &rays = _raycastData->Data ().rays ;
44114414
4415+ // Clear the previous results
44124416 auto &results = _raycastData->Data ().results ;
44134417 results.clear ();
44144418 results.reserve (rays.size ());
44154419
4420+ // Get the entity's world pose
44164421 const auto &entityWorldPose = worldPose (_entity, _ecm);
44174422
44184423 for (const auto &ray : rays)
44194424 {
4425+ // Convert ray to world frame
44204426 const math::Vector3d rayStart = entityWorldPose.Pos () +
44214427 entityWorldPose.Rot ().RotateVector (ray.start );
44224428 const math::Vector3d rayEnd = entityWorldPose.Pos () +
44234429 entityWorldPose.Rot ().RotateVector (ray.end );
44244430
4431+ // Perform ray intersection
44254432 auto rayIntersection =
44264433 worldRayIntersectionFeature->GetRayIntersectionFromLastStep (
44274434 math::eigen3::convert (rayStart),
@@ -4434,6 +4441,7 @@ void PhysicsPrivate::UpdateRayIntersections(EntityComponentManager &_ecm)
44344441 results.emplace_back ();
44354442 auto &result = results.back ();
44364443
4444+ // Convert result to entity frame and store
44374445 const math::Vector3d intersectionPoint =
44384446 math::eigen3::convert (rayIntersectionResult.point );
44394447 result.point = entityWorldPose.Rot ().RotateVectorReverse (
0 commit comments