| 497 | #endif |
| 498 | |
| 499 | void Object::Intersect(CollisionBuffer& result, Object* with, const FrameBase& thisPos, const FrameBase& withPos, |
| 500 | int hierLevel) const |
| 501 | { |
| 502 | // typical usage: |
| 503 | // this is object in landscape |
| 504 | // with is vehicle we test on collisions |
| 505 | // with inverse transformation is typically cheap |
| 506 | LODShape* withShape = with->GetShape(); |
| 507 | LODShape* thisShape = this->GetShape(); |
| 508 | if (!withShape || !thisShape) |
| 509 | { |
| 510 | return; |
| 511 | } |
| 512 | // check all possible collisions between components of this and with |
| 513 | // create transformation between with and this |
| 514 | // first of all check object bounding spheres |
| 515 | float dist2 = thisPos.Position().Distance2(withPos.Position()); |
| 516 | float sumRadius2 = Square(this->GetRadius() + with->GetRadius()); |
| 517 | if (dist2 > sumRadius2) |
| 518 | { |
| 519 | return; // no collision possible |
| 520 | } |
| 521 | if (thisShape->GetGeomComponents().Size() <= 0) |
| 522 | { |
| 523 | return; |
| 524 | } |
| 525 | if (withShape->GetGeomComponents().Size() <= 0) |
| 526 | { |
| 527 | return; |
| 528 | } |
| 529 | Shape* withGeom = withShape->GeometryLevel(); |
| 530 | Shape* thisGeom = thisShape->GeometryLevel(); |
| 531 | |
| 532 | if (!withGeom || !thisGeom) |
| 533 | { |
| 534 | return; |
| 535 | } |
| 536 | // make sure both objects have well defined geometry level |
| 537 | // note: we will deanimate it again |
| 538 | const_cast<Object*>(this)->AnimateGeometry(); |
| 539 | const_cast<Object*>(with)->AnimateGeometry(); |
| 540 | |
| 541 | // minMax may be invalid now |
| 542 | thisGeom->RecalculateNormalsAsNeeded(); |
| 543 | withGeom->RecalculateNormalsAsNeeded(); |
| 544 | |
| 545 | #if PERF_ISECT |
| 546 | #endif |
| 547 | |
| 548 | Matrix4Val withToThis = thisPos.GetInvTransform() * withPos; |
| 549 | |
| 550 | // draw min-max box positions |
| 551 | #if DIAG_INTERSECT |
| 552 | if (CHECK_DIAG(DECollision)) |
| 553 | { |
| 554 | // draw bbox of this and with |
| 555 | DiagBBox(thisGeom->MinMax(), thisPos, PackedColor(Color(0, 0, 1, 0.5))); |
| 556 | DiagBBox(withGeom->MinMax(), withPos, PackedColor(Color(0, 1, 0, 0.5))); |
no test coverage detected