📄 oasisphysicssystem.h
字号:
/******************************************************************************
* This source file is part of Bad Camel Gaming
* Copyright (C) 2003 Zephie Greyvenstein
* See Readme.html for acknowledgements
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
/******************************************************************************
* FILENAME : oasisPhysicsSystem.h
* DESCRIPTION : The physics engine
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
/// Avoid double inclusion
#ifndef __PHYSICSSYSTEM_H__
#define __PHYSICSSYSTEM_H__
/// Include common stuff
#include "oasisCommon.h"
/// Include the rest of the needed oasis stuff
#include "oasisConfiguration.h"
#include "oasisResourceManager.h"
#include "oasisSystem.h"
#include "oasisPool.h"
#include "oasisFrameListener.h"
#include "oasisVector3.h"
#include "oasisJoint.h"
#include "oasisSingleton.h"
/// Foward declare ode stuff
struct dWorld;
struct dJointGroup;
class dSpace;
struct dxGeom;
namespace Oasis {
/** Physics and collision engine
@remarks
The physic system loads in and keeps handles on all physic templates
defined in scripts. Physics instances are then create from these
templates using the helper functions found in this class.
*/
class _oasisExport physicsSystem : public resourceManager,
public system,
public pool,
public frameListener,
public singleton< physicsSystem > {
/// Physics objects need information about ODE
friend class physics;
/// Physics resource needs to get information about ODE
friend class physicsResource;
public:
/// Constructor
physicsSystem( );
/// Destructor
virtual ~physicsSystem( );
/// Get singleton
static physicsSystem &get( void );
/// Get singleton pointer
static physicsSystem *getPtr( void );
/// Reset this system
void reset( void );
/// Update this system
void update( real time );
/// Get a physics template for further editing
physicsResource *getPhysicsTemplate( const string &name );
/// Create a new physic template and add it to the system
physicsResource *createPhysicsTemplate( const string &name );
/** Create a new physics object from a template
@remarks
You create physics objects via this function so that the physic system
can keep track of all physic objects in the system
*/
physics *createPhysics( const string &physicsName,
const string &templateName );
/// Remove a physics object from the system
void removePhysics( physics *oldPhysics );
/// Remove a physics object from the system
void removePhysics( const string &physicsName );
/// Get physics by name
physics *getPhysics( const string &physicsName );
/// Create a new joint
joint *createJoint( joint::JointType type,
const string &name,
physics *first,
physics *second );
/// Retrieve a joint
joint *getJoint( const string &name );
/// Remove a joint
void removeJoint( const string &name );
/// Remove all joints
void removeAllJoints( void );
/// Set the global gravity
void setGravity( real x, real y, real z );
/// Set the global gravity
void setGravity( const vector3 &newGravity );
/// Get the global gravity
const vector3 &getGravity( void ) const;
/// Set the step size for the simulations
void setStepSize( const real newSize );
/// Get the step size
const real getStepSize( void ) const;
/// Set the global error reduction
void setERP( const real newERP );
/// Get the global error reduction
const real getERP( void ) const;
/// Set the global constraint force mixing
void setCFM( const real newCFM );
/// Get the global constraint force mixing
const real getCFM( void ) const;
#if PHYSICS_SPACE_HASH == 1
/** Set the cell limits for hash space
@remarks
Note: This will only be available if oasis was compiled to support
hash spaces
*/
void setSpaceLimits( uint16 min, uint16 max );
#endif
private:
/// The ode world
dWorld *odeWorld;
/// The ode contact group
dJointGroup *odeContactGroup;
/// The ode space
dSpace *odeSpace;
/// Global gravity
vector3 gravity;
/// Simulation step size
real stepSize;
/// Left over time from steps
real timeLeftOver;
/// Stepfast switch count
uint16 stepfastSwitch;
/// A map of joints ... this should be a hash_map
typedef std::map< string, joint* > jointMap;
/// All the joints in the system
jointMap joints;
/// Creates a new sound template as a resource
resource *createResource( const string &name );
/// Creates a new sound as a poolable
poolable *_createPoolable( void );
/// Get the ODE world object
const dWorld *getODEWorld( void ) const;
/// Get the ODE contact joint group
const dJointGroup *getODEContactJointGroup( void ) const;
/// Get the ODE space
const dSpace *getODESpace( void ) const;
/// Tests collsions within the system
static void _doCollision( void *data, dxGeom *one, dxGeom *two );
/// Parse a sound file
void _parseFile( Ogre::DataChunk &chunk );
/// Parse attributes for the sound file
void _parseAttribute( const Ogre::String &line, physicsResource *file );
/// Listener event for frame started
bool frameStarted( real time );
};
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -