00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <physics/SimpleCollisionCuller>
00026
00027 using physics::SimpleCollisionCuller;
00028
00029 using physics::Collider;
00030 using physics::Collidable;
00031 using physics::CollidableBody;
00032 using physics::CollidableGroup;
00033
00034
00035 void SimpleCollisionCuller::collide(ref<const Collidable> collidable1, ref<const Collidable> collidable2)
00036 {
00037 if (!isCollisionEnabled()) return;
00038
00039 Assert(collidable1);
00040 Assert(collidable2);
00041
00042 if (instanceof(*collidable1, const CollidableBody) && instanceof(*collidable2, const CollidableBody)) {
00043 if (!isCollisionEnabled(collidable1, collidable2)) return;
00044 notifyListeners(collidable1, collidable2);
00045 return;
00046 }
00047
00048 if (instanceof(*collidable1, const CollidableGroup) && instanceof(*collidable2, const CollidableGroup)) {
00049
00050
00051 ref<const CollidableGroup> group1(narrow_ref<const CollidableGroup>(collidable1));
00052 ref<const CollidableGroup> group2(narrow_ref<const CollidableGroup>(collidable2));
00053
00054
00055 if (isCollisionEnabled(collidable1, collidable2)) {
00056 CollidableGroup::const_iterator_const c = group2->const_begin();
00057 CollidableGroup::const_iterator_const end = group2->const_end();
00058 while (c != end) {
00059 collide(group1, *c);
00060 ++c;
00061 }
00062 }
00063
00064
00065 if (group1->isChildIntercollisionEnabled())
00066 collide(group1);
00067
00068 if (group2->isChildIntercollisionEnabled())
00069 collide(group2);
00070
00071 }
00072 else {
00073
00074 if (instanceof(*collidable1, const CollidableBody))
00075 base::swap(collidable1, collidable2);
00076
00077
00078
00079 Assert(instanceof(*collidable1, const CollidableGroup));
00080 Assert(instanceof(*collidable2, const CollidableBody));
00081
00082 ref<const CollidableGroup> group(narrow_ref<const CollidableGroup>(collidable1));
00083 ref<const CollidableBody> body(narrow_ref<const CollidableBody>(collidable2));
00084
00085
00086 if (isCollisionEnabled(collidable1, collidable2)) {
00087 CollidableGroup::const_iterator_const c = group->const_begin();
00088 CollidableGroup::const_iterator_const end = group->const_end();
00089 while (c != end) {
00090 collide(*c, body);
00091 ++c;
00092 }
00093 }
00094
00095 if (group->isChildIntercollisionEnabled())
00096 collide(group);
00097
00098 }
00099
00100 }