| 3469 | } |
| 3470 | |
| 3471 | bool MeshRoad::collideRay( const Point3F &origin, const Point3F &direction, U32 *nodeIdx, Point3F *collisionPnt ) |
| 3472 | { |
| 3473 | Point3F p0 = origin; |
| 3474 | Point3F p1 = origin + direction * 2000.0f; |
| 3475 | |
| 3476 | // If the line segment does not collide with the MeshRoad's world box, |
| 3477 | // it definitely does not collide with any part of the river. |
| 3478 | if ( !getWorldBox().collideLine( p0, p1 ) ) |
| 3479 | return false; |
| 3480 | |
| 3481 | if ( mSlices.size() < 2 ) |
| 3482 | return false; |
| 3483 | |
| 3484 | MathUtils::Quad quad; |
| 3485 | MathUtils::Ray ray; |
| 3486 | F32 t; |
| 3487 | |
| 3488 | // Check each road segment (formed by a pair of slices) for collision |
| 3489 | // with the line segment. |
| 3490 | for ( U32 i = 0; i < mSlices.size() - 1; i++ ) |
| 3491 | { |
| 3492 | const MeshRoadSlice &slice0 = mSlices[i]; |
| 3493 | const MeshRoadSlice &slice1 = mSlices[i+1]; |
| 3494 | |
| 3495 | // For simplicities sake we will only test for collision between the |
| 3496 | // line segment and the Top face of the river segment. |
| 3497 | |
| 3498 | // Clockwise starting with the leftmost/closest point. |
| 3499 | quad.p00 = slice0.p0; |
| 3500 | quad.p01 = slice1.p0; |
| 3501 | quad.p11 = slice1.p2; |
| 3502 | quad.p10 = slice0.p2; |
| 3503 | |
| 3504 | ray.origin = origin; |
| 3505 | ray.direction = direction; |
| 3506 | |
| 3507 | if ( MathUtils::mRayQuadCollide( quad, ray, NULL, &t ) ) |
| 3508 | { |
| 3509 | if ( nodeIdx ) |
| 3510 | *nodeIdx = slice0.parentNodeIdx; |
| 3511 | if ( collisionPnt ) |
| 3512 | *collisionPnt = ray.origin + ray.direction * t; |
| 3513 | return true; |
| 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | return false; |
| 3518 | } |
| 3519 | |
| 3520 | void MeshRoad::regenerate() |
| 3521 | { |
nothing calls this directly
no test coverage detected