MercuryODE.h

Go to the documentation of this file.
00001 #ifndef _MercuryODE_H
00002 #define _MercuryODE_H
00003 
00004 #include <ode/ode.h>
00005 #include "MercuryINI.h"
00006 #include "MercuryObject.h"
00007 
00008 class MercuryODEWorld;
00009 
00011 class MercuryODEObject : public MercuryObject
00012 {
00013 public:
00014     MercuryODEObject();
00015     virtual ~MercuryODEObject();
00016 
00018     virtual bool Collide( MercuryODEObject * pHit, dContact & pContact, MercuryODEWorld * pWorld ) = 0;
00019 
00021     dMass               m_oAccumulatedMass;
00023     dBodyID             m_oBody;
00025     dSpaceID            m_oSpace;
00026 
00027     PSElement GetParameter( const MString & sName ) { return m_mParameters[sName]; }
00028     void SetParameter( const MString & sName, const PSElement & pSet ) { m_mParameters[sName] = pSet; }
00029 
00031     virtual void PreCycleUpdate( const float dTime ) { }
00032     CLASS_RTTI( MercuryODEObject, MercuryObject );
00033 
00034     virtual void RemoveODE();
00035 
00036     MercuryODEWorld *   m_pWorld;
00037 protected:
00038     bool m_wasActive;
00039 private:
00040     std::map< MString, PSElement > m_mParameters;
00041 };
00042 
00044 class MercuryODEObjectLoadable : public MercuryODEObject
00045 {
00046 public:
00047     MercuryODEObjectLoadable()
00048         :MercuryODEObject()
00049     { }
00050     MercuryODEObjectLoadable( const MString & sName )
00051         :MercuryODEObject()
00052     {
00053         SetName(sName);
00054     }
00055 
00056     virtual ~MercuryODEObjectLoadable();
00057     virtual void Update( const float dTime );
00058     virtual void RemoveODE();
00059 
00060     virtual bool Collide( MercuryODEObject * pHit, dContact & pContact, MercuryODEWorld * pCollide )  { return true; }
00061 
00063     virtual bool LoadFromINI( MercuryINI & pINI, const MString & sShapeName, const dWorldID &oWorld );
00064 
00066     bool                m_bBodied;
00067 
00068     MercuryPoint        m_pPrePosition;
00069     MercuryPoint        m_pPreRotation;
00070 
00071     MVector< dGeomID > m_vAllGeoms;
00072     MVector< dGeomID > m_vAllTransforms;
00073 
00074     dSpaceID            m_oWorldSpace;
00075     CLASS_RTTI( MercuryODEObjectLoadable, MercuryODEObject );
00076 
00077     MVector< MercuryObject * > m_vMercuryShapes;
00078 
00079 protected:
00080     dWorldID            m_oParentWorld;
00081 private:
00082 
00084     struct InternalTrimesh
00085     {
00086         //XXX: We HAVE to define this here, otherwise we get an
00087         //internal compiler error in VC6
00088         ~InternalTrimesh()
00089         {
00090             dGeomTriMeshDataDestroy( m_oTriData );
00091             delete [] m_aVerts;
00092             delete [] m_aIndices;
00093         }
00094 
00096         dTriMeshDataID      m_oTriData;
00097 
00099         dVector3        *   m_aVerts;
00100         int                 m_iVertexCount;
00101 
00103         int             *   m_aIndices;
00104         int                 m_iIndexCount;
00105     };
00106 
00108     MVector< InternalTrimesh * > m_vTrimeshes;
00109 };
00110 
00112 
00128 class MercuryODEWorld : public MercuryObject
00129 {
00130 public:
00131     MercuryODEWorld();
00132     virtual ~MercuryODEWorld();
00133 
00134     virtual void Init();
00135 
00137     bool LoadFromINI( MercuryINI & pINI, const MString & sWorldName );
00138 
00140     void AddToWorld( MercuryODEObject * toAdd );
00141 
00143     MercuryODEObject * GenAndAddToWorld( MercuryINI & pINI, const MString & sItemName, const MString & sItemType, const MString & sClass, bool bBodied, const MercuryPoint & pInitialPosition );
00144 
00146     virtual bool RemoveObject( MercuryObject * object, bool bAllowDelete = true );
00147 
00149     MercuryODEObject * GetODEObjectByName( const MString & name ) { return m_mObjects[name]; }
00150 
00152     dSpaceID GetWorldSpaceID() { return m_oSpace; }
00153 
00155     dWorldID GetWorldID() { return m_oWorld; }
00156 
00157     virtual void Update( const float fDeltaTime );
00158 
00160     void SetGravity( const float fGravity );
00161 
00162     CLASS_RTTI( MercuryODEWorld, MercuryObject );
00163 
00164     MHash<MercuryODEObject *> & GetAllObjectMap() { return m_mObjects; }
00165 
00167     dJointGroupID       m_oJointGroup;
00168 protected:
00170     MHash< MercuryODEObject * > m_mObjects;
00171 
00173     dWorldID            m_oWorld;
00174 
00176     dSpaceID            m_oSpace;
00177 
00179     dGeomID             m_oGround;
00180 
00182     friend void nearCallback (void *data, dGeomID o1, dGeomID o2);
00183 };
00184 
00185 //NOTE: This type of self-registering screen system is almost an
00186 //exact rip-off of the one in Rage (for StepMania). The following
00187 //few lines are (c) MIT 2001-2005 Chris Danford, Glenn Maynard
00188 typedef MercuryODEObjectLoadable* (*NewODEObjectFunction)(const MString& sClassName);
00189 void RegisterODEType( const MString& sClassName, NewODEObjectFunction pfn );
00190 
00191 #include "MercuryObjectFactory.h"
00192 
00193 #define REGISTER_ODE_OBJECT_CLASS( className ) \
00194     static MercuryODEObjectLoadable* CreateODE##className( const MString &sName ) \
00195     { MercuryODEObjectLoadable *pRet = new className( sName ); return pRet; } \
00196     struct RegisterODE##className { \
00197         RegisterODE##className() { RegisterODEType( #className,CreateODE##className); } \
00198     }; \
00199     static RegisterODE##className register_ODE##className; \
00200     REGISTER_OBJECT_TYPE( className );
00201 
00202 extern std::map< MString, NewODEObjectFunction >  *ToMakeODEs;
00203 
00204 //End of Rage-based registering system.
00205 
00206 
00207 #endif
00208 
00209 /* 
00210  * Copyright (c) 2005-2006, Charles Lohr
00211  * All rights reserved.
00212  *
00213  * Redistribution and use in source and binary forms, with or
00214  * without modification, are permitted provided that the following
00215  * conditions are met:
00216  *  -   Redistributions of source code must retain the above
00217  *      copyright notice, this list of conditions and the following disclaimer.
00218  *  -   Redistributions in binary form must reproduce the above copyright
00219  *      notice, this list of conditions and the following disclaimer in
00220  *      the documentation and/or other materials provided with the distribution.
00221  *  -   Neither the name of the Mercury Engine nor the names of its
00222  *      contributors may be used to endorse or promote products derived from
00223  *      this software without specific prior written permission.
00224  *
00225  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00226  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00227  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00228  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
00229  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00230  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00231  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00232  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00233  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00234  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00235  */

Hosted by SourceForge.net Logo