MCPcopy Create free account
hub / github.com/DanielChappuis/reactphysics3d / raycast

Method raycast

src/body/Body.cpp:333–356  ·  view source on GitHub ↗

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 */

Source from the content-addressed store, hash-verified

331* @return True if the ray hit the body and false otherwise
332*/
333bool 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/**

Callers 10

testRaycastMethod · 0.45
testBoxMethod · 0.45
testSphereMethod · 0.45
testCapsuleMethod · 0.45
testConvexMeshMethod · 0.45
testCompoundMethod · 0.45
testConcaveMeshMethod · 0.45
testHeightFieldMethod · 0.45
updateMethod · 0.45
moveBodyWithMouseMethod · 0.45

Calls 3

getIsActiveMethod · 0.45
sizeMethod · 0.45
getColliderMethod · 0.45

Tested by 8

testRaycastMethod · 0.36
testBoxMethod · 0.36
testSphereMethod · 0.36
testCapsuleMethod · 0.36
testConvexMeshMethod · 0.36
testCompoundMethod · 0.36
testConcaveMeshMethod · 0.36
testHeightFieldMethod · 0.36