Raycast method with feedback information The method returns the closest hit among all the collision shapes of the body * @param ray The ray used to raycast agains the body * @param[out] raycastInfo Structure that contains the result of the raycasting * (valid only if the method returned true) * @return True if the ray hit the body and false otherwise */
| 331 | * @return True if the ray hit the body and false otherwise |
| 332 | */ |
| 333 | bool Body::raycast(const Ray& ray, RaycastInfo& raycastInfo) { |
| 334 | |
| 335 | // If the body is not active, it cannot be hit by rays |
| 336 | if (!mWorld.mBodyComponents.getIsActive(mEntity)) return false; |
| 337 | |
| 338 | bool isHit = false; |
| 339 | Ray rayTemp(ray); |
| 340 | |
| 341 | // For each collider of the body |
| 342 | const Array<Entity>& colliderEntities = mWorld.mBodyComponents.getColliders(mEntity); |
| 343 | const uint32 nbColliderEntities = static_cast<uint32>(colliderEntities.size()); |
| 344 | for (uint32 i=0; i < nbColliderEntities; i++) { |
| 345 | |
| 346 | Collider* collider = mWorld.mCollidersComponents.getCollider(colliderEntities[i]); |
| 347 | |
| 348 | // Test if the ray hits the collider |
| 349 | if (collider->raycast(rayTemp, raycastInfo)) { |
| 350 | rayTemp.maxFraction = raycastInfo.hitFraction; |
| 351 | isHit = true; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | return isHit; |
| 356 | } |
| 357 | |
| 358 | // Compute and return the AABB of the body by merging all colliders AABBs |
| 359 | /** |