Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

physics/ODECollisionModel.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: ODECollisionModel.cpp 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.4 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
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 #include <gfx/Color4>
00034 #include <gfx/Triangle3>
00035 #include <gfx/TriangleContainer>
00036 #include <gfx/TriangleIterator>
00037 #include <gfx/VisualTriangles>
00038 #include <gfx/IndexedPoint3Array>
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 using gfx::Triangle3;
00059 using gfx::Color4;
00060 using gfx::TriangleContainer;
00061 using gfx::TriangleIterator;
00062 using gfx::VisualTriangles;
00063 using gfx::IndexedPoint3Array;
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   // !!! nothing to show for the model for now
00124   return new osg::Node();
00125 }
00126 

Generated on Thu Jul 29 15:56:25 2004 for OpenSim by doxygen 1.3.6