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/ODECollisionModel>
00026
00027 #include <physics/Shape>
00028 #include <physics/Box>
00029 #include <physics/Sphere>
00030 #include <physics/Cylinder>
00031 #include <physics/Polyhedron>
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include <base/Dimension3>
00041
00042 #include <osg/Node>
00043 #include <osg/Group>
00044 #include <osg/Transform>
00045 #include <osg/StateSet>
00046 #include <osg/Material>
00047 #include <osg/Vec4>
00048 #include <osg/PolygonMode>
00049
00050
00051 using physics::ODECollisionModel;
00052 using physics::Shape;
00053 using physics::Box;
00054 using physics::Sphere;
00055 using physics::Cylinder;
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 using base::Dimension3;
00066 using base::Matrix3;
00067 using base::transpose;
00068 using base::cross;
00069 using base::reflist;
00070 using base::dynamic_cast_ref;
00071
00072
00073 using osg::Vec4;
00074 using osg::StateSet;
00075
00076
00077 ODECollisionModel::ODECollisionModel(ref<const Shape> shape)
00078 : shape(shape)
00079 {
00080 create(shape);
00081 }
00082
00083
00084 ODECollisionModel::ODECollisionModel(const ODECollisionModel& cm)
00085 : shape(cm.shape)
00086 {
00087 create(shape);
00088 }
00089
00090
00091 ODECollisionModel::~ODECollisionModel()
00092 {
00093 dGeomDestroy(geomID);
00094 }
00095
00096
00097 void ODECollisionModel::create(ref<const Shape> shape)
00098 {
00099 if (instanceof(*shape, const Box)) {
00100 ref<const Box> box = dynamic_cast_ref<const Box>(shape);
00101 Dimension3 dim = box->dimensions();
00102 geomID = dCreateBox(0, dim.x, dim.y, dim.z);
00103 }
00104 else if (instanceof(*shape, const Sphere)) {
00105 ref<const Sphere> sphere = dynamic_cast_ref<const Sphere>(shape);
00106 geomID = dCreateSphere(0, sphere->radius());
00107 }
00108 else if (instanceof(*shape, const Cylinder)) {
00109 ref<const Cylinder> cylinder = dynamic_cast_ref<const Cylinder>(shape);
00110 geomID = dCreateCCylinder(0, cylinder->radius(), cylinder->height());
00111 }
00112 else {
00113 Logln("Unsupported Shape: " << shape->className() << ", using bounding sphere for collision region");
00114 Real radius = (shape->getBoundingSphere()).radius();
00115 geomID = dCreateSphere(0, radius);
00116 }
00117 }
00118
00119
00120
00121 osg::Node* ODECollisionModel::createOSGVisual(Visual::Attributes visualAttributes) const
00122 {
00123
00124 return new osg::Node();
00125 }
00126