Raycast a single triangle of the height-field
| 321 | |
| 322 | // Raycast a single triangle of the height-field |
| 323 | bool HeightField::raycastTriangle(const Ray& ray, const Vector3& p1, const Vector3& p2, const Vector3& p3, uint32 shapeId, |
| 324 | Collider* collider, RaycastInfo& raycastInfo, decimal& smallestHitFraction, |
| 325 | TriangleRaycastSide testSide, MemoryAllocator& allocator) const { |
| 326 | |
| 327 | // Generate the first triangle for the current grid rectangle |
| 328 | Vector3 triangleVertices[3] = {p1, p2, p3}; |
| 329 | |
| 330 | // Create a triangle collision shape |
| 331 | TriangleShape triangleShape(triangleVertices, shapeId, mTriangleHalfEdgeStructure, allocator); |
| 332 | triangleShape.setRaycastTestType(testSide); |
| 333 | |
| 334 | #ifdef IS_RP3D_PROFILING_ENABLED |
| 335 | |
| 336 | |
| 337 | // Set the profiler to the triangle shape |
| 338 | triangleShape.setProfiler(mProfiler); |
| 339 | |
| 340 | #endif |
| 341 | |
| 342 | // Ray casting test against the collision shape |
| 343 | RaycastInfo triangleRaycastInfo; |
| 344 | bool isTriangleHit = triangleShape.raycast(ray, triangleRaycastInfo, collider, allocator); |
| 345 | |
| 346 | // If the ray hit the collision shape |
| 347 | if (isTriangleHit && triangleRaycastInfo.hitFraction <= smallestHitFraction) { |
| 348 | |
| 349 | assert(triangleRaycastInfo.hitFraction >= decimal(0.0)); |
| 350 | |
| 351 | raycastInfo.body = triangleRaycastInfo.body; |
| 352 | raycastInfo.collider = triangleRaycastInfo.collider; |
| 353 | raycastInfo.hitFraction = triangleRaycastInfo.hitFraction; |
| 354 | raycastInfo.worldPoint = triangleRaycastInfo.worldPoint; |
| 355 | raycastInfo.worldNormal = triangleRaycastInfo.worldNormal; |
| 356 | raycastInfo.triangleIndex = -1; |
| 357 | |
| 358 | smallestHitFraction = triangleRaycastInfo.hitFraction; |
| 359 | |
| 360 | return true; |
| 361 | } |
| 362 | |
| 363 | return false; |
| 364 | } |
| 365 | |
| 366 | // Compute the first grid cell of the heightfield intersected by a ray. |
| 367 | /// This method returns true if the ray hit the AABB of the height field and false otherwise |
nothing calls this directly
no test coverage detected