| 557 | |
| 558 | |
| 559 | static int dCollideUserGeomWithGeom (dxGeom *o1, dxGeom *o2, int flags, |
| 560 | dContactGeom *contact, int skip) |
| 561 | { |
| 562 | // this generic collider function is called the first time that a user class |
| 563 | // tries to collide against something. it will find out the correct collider |
| 564 | // function and then set the colliders array so that the correct function is |
| 565 | // called directly the next time around. |
| 566 | |
| 567 | int t1 = o1->type; // note that o1 is a user geom |
| 568 | int t2 = o2->type; // o2 *may* be a user geom |
| 569 | |
| 570 | // find the collider function to use. if o1 does not know how to collide with |
| 571 | // o2, then o2 might know how to collide with o1 (provided that it is a user |
| 572 | // geom). |
| 573 | dColliderFn *fn = user_classes[t1-dFirstUserClass].collider (t2); |
| 574 | int reverse = 0; |
| 575 | if (!fn && t2 >= dFirstUserClass && t2 <= dLastUserClass) { |
| 576 | fn = user_classes[t2-dFirstUserClass].collider (t1); |
| 577 | reverse = 1; |
| 578 | } |
| 579 | |
| 580 | // set the colliders array so that the correct function is called directly |
| 581 | // the next time around. note that fn can be 0 here if no collider was found, |
| 582 | // which means that dCollide() will always return 0 for this case. |
| 583 | colliders[t1][t2].fn = fn; |
| 584 | colliders[t1][t2].reverse = reverse; |
| 585 | colliders[t2][t1].fn = fn; |
| 586 | colliders[t2][t1].reverse = !reverse; |
| 587 | |
| 588 | // now call the collider function indirectly through dCollide(), so that |
| 589 | // contact reversing is properly handled. |
| 590 | return dCollide (o1,o2,flags,contact,skip); |
| 591 | } |
| 592 | |
| 593 | |
| 594 | int dCreateGeomClass (const dGeomClass *c) |