ODESimulator.h

Go to the documentation of this file.
00001 /*************************************************************************
00002 *                                                                       *
00003 * Open Physics Abstraction Layer                                        *
00004 * Copyright (C) 2004-2005                                               *
00005 * Alan Fischer  alan.fischer@gmail.com                                  *
00006 * Andres Reinot  andres@reinot.com                                      *
00007 * Tyler Streeter  tylerstreeter@gmail.com                               *
00008 * All rights reserved.                                                  *
00009 * Web: opal.sourceforge.net                                             *
00010 *                                                                       *
00011 * This library is free software; you can redistribute it and/or         *
00012 * modify it under the terms of EITHER:                                  *
00013 *   (1) The GNU Lesser General Public License as published by the Free  *
00014 *       Software Foundation; either version 2.1 of the License, or (at  *
00015 *       your option) any later version. The text of the GNU Lesser      *
00016 *       General Public License is included with this library in the     *
00017 *       file license-LGPL.txt.                                          *
00018 *   (2) The BSD-style license that is included with this library in     *
00019 *       the file license-BSD.txt.                                       *
00020 *                                                                       *
00021 * This library is distributed in the hope that it will be useful,       *
00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00024 * license-LGPL.txt and license-BSD.txt for more details.                *
00025 *                                                                       *
00026 *************************************************************************/
00027 
00028 #ifndef OPAL_ODE_SIMULATOR_H
00029 #define OPAL_ODE_SIMULATOR_H
00030 
00031 // project headers
00032 #include "../Defines.h"
00033 #include "../Simulator.h"
00034 #include "../AccelerationSensor.h"
00035 #include "../InclineSensor.h"
00036 #include "../RaycastSensor.h"
00037 #include "../VolumeSensor.h"
00038 #include "ODESolid.h"
00039 #include "ODEJoint.h"
00040 #include "ODESpace.h"
00041 
00042 // system headers
00043 #include <ode/ode.h>
00044 #include <vector>
00045 
00046 namespace opal
00047 {
00049     class ODESimulator : public Simulator
00050     {
00051         public:
00053             enum SolverType
00054             {
00057                 SOLVER_WORLDSTEP,
00058 
00061                 SOLVER_QUICKSTEP };
00062 
00064             ODESimulator( );
00065 
00067             void initData( SimulatorData data );
00068 
00069             virtual ~ODESimulator();
00070 
00071             virtual void OPAL_CALL destroy();
00072 
00073             virtual void OPAL_CALL setMaxCorrectingVel( real vel );
00074 
00075             // SOLIDS
00076 
00077             virtual Solid* OPAL_CALL createSolid();
00078 
00079             // JOINTS
00080 
00081             virtual Joint* OPAL_CALL createJoint();
00082 
00083             // MOTORS
00084 
00085             // No ODE-specific Motor implementations at this time.
00086 
00087             // SENSORS
00088 
00089             // No ODE-specific Sensor implementations at this time.
00090 
00091             // SPACES
00092 
00093             virtual Space* OPAL_CALL createSpace();
00094 
00095             virtual void OPAL_CALL setGravity( const Vec3r& gravity );
00096 
00097             virtual Vec3r OPAL_CALL getGravity() const;
00098 
00099             virtual void OPAL_CALL setSolverAccuracy( SolverAccuracyLevel level );
00100 
00101             virtual dWorldID OPAL_CALL internal_getWorldID() const;
00102 
00103             virtual dSpaceID OPAL_CALL internal_getSpaceID() const;
00104 
00105             virtual dJointGroupID OPAL_CALL internal_getJointGroupID() const;
00106 
00107             virtual std::vector<RaycastResult> & OPAL_CALL internal_fireRay(
00108                 const Rayr& r, real length, const Solid* attachedSolid,
00109                 unsigned int rayContactGroup );
00110 
00111             virtual const VolumeQueryResult& OPAL_CALL internal_queryVolume(
00112                 const Solid* volume, const Solid* attachedSolid );
00113 
00115 
00118             void internal_addRaycastResult( Solid* solid,
00119                     const Point3r& intersection, const Vec3r& normal, real depth );
00120 
00122             void internal_addCollidedSolid( Solid* solid );
00123 
00125             virtual unsigned int OPAL_CALL internal_getRayContactGroup();
00126 
00127         protected:
00128             virtual void stepPhysics();
00129 
00131             dWorldID mWorldID;
00132 
00134             dSpaceID mRootSpaceID;
00135 
00137             dJointGroupID mContactJointGroupID;
00138 
00140             SolverType mSolverType;
00141 
00143             long int mCollisionCount;
00144 
00147             VolumeQueryResult mVolumeQueryResult;
00148 
00153             const Solid* mSensorSolid;
00154 
00157             unsigned int mRayContactGroup;
00158 
00160             std::vector<RaycastResult> mRaycastResults;
00161     };
00162 
00164     namespace ode_hidden
00165     {
00166         // These function don't use the OPAL_CALL calling convention
00167         // because they are functors passed to ODE, which expects a different
00168         // calling convention.
00169 
00171         void internal_collisionCallback( void* data, dGeomID o0, dGeomID o1 );
00172 
00176         Joint* internal_getCommonJoint( dBodyID body0, dBodyID body1 );
00177 
00180         void internal_volumeCollisionCallback( void* data, dGeomID o0,
00181                         dGeomID o1 );
00182 
00185         void internal_raycastCollisionCallback( void* data, dGeomID o0,
00186                         dGeomID o1 );
00187 
00188         //helper function for collision callback
00189         //void createOneSidedContact(dJointID contactJoint,
00190         //      dBodyID movingObject, dBodyID staticObject, dVector3 pos);
00191     }
00192 }
00193 
00194 #endif

Generated on Tue May 16 17:49:51 2006 for OPAL by  doxygen 1.4.6-NO