⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oasisphysics.h

📁 使用stl技术,(还没看,是听说的)
💻 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    : oasisPhysics.h

 * DESCRIPTION : Physics instance

 * AUTHOR      : Zephie Greyvenstein

 *****************************************************************************/



/// Avoid double inclusion

#ifndef __PHYSICS_H__

#define __PHYSICS_H__



/// Include common stuff

#include "oasisCommon.h"

/// Include the rest of the needed oasis stuff

#include "oasisPoolable.h"

#include "oasisVector3.h"

#include "oasisIterators.h"



/// Foward declare ode stuff

class dBody;

struct dxGeom;



namespace Oasis {

  /// Physics object based on a template

  class _oasisExport physics : public poolable {

    /// Physics system needs access to private functions

    friend class physicsSystem;

    /// Physicals need to be able to set our position and orientation

    friend class physical;

    /// Joints need access to the ODE body

    friend class joint;

  public: 

    /// Inifinte friction

    static const real infiniteFriction;

   

    /// Constructor

    physics( );

    /// Destructor

    virtual ~physics( );

  

    /// List of collision proxies

    typedef std::list< proxy* > proxyList;

    /// Iterator for collision proxies

    typedef vectorIterator< proxyList > proxyIterator;



    /// Force a proxy update

    void updateProxies( void );



    /// Set the enabled status of the dynamics

    void setDynamicsEnabled( bool newState, bool newReenable = true );

    /// Get the status of the reenable flag

    const bool getDynamicsReenabled( void ) const;

    /// Get the status of dynamics

    const bool getDynamicsEnabled( void ) const;



    /// Set the enabled status of collision

    void setCollisionEnabled( bool newState );

    /// Get the status of collision

    const bool getCollisionEnabled( void ) const;

   

    /// Get the mass for this physics

    mass *getMass( void ) const;

       

    /// Add a box proxy

    boxProxy *addBoxProxy( real width, real height, real depth );

    /// Add a sphere proxy

    sphereProxy *addSphereProxy( real radius );

    /// Add a capped cylinder proxy

    ccylinderProxy *addCCylinderProxy( real radius, real length );    



    /// Remove a proxy

    void removeProxy( uint8 index );

    /// Remove a proxy

    void removeProxy( proxy *oldProxy );



    /// Remove all proxies from the physics

    void removeAllProxies( void );



    /// Get the collision proxy iterator

    proxyIterator getProxyIterator( void );



    /// Set the softness

    void setSoftness( const real newSoftness );

    /// Get the softness

    const real getSoftness( void ) const;



    /// Set the friction

    void setFriction( const real newFriction );   

    /// Get the friction

    const real getFriction( void ) const;



    /// Set whether to use gravity

    void setGravity( bool newState );

    /// Get gravity usage

    const bool getGravity( void ) const;



    /// Set the bounciness

    void setBounce( const real coEff, const real velThresh );

    /// Get the bounce co-efficient

    const real getBounceCoEff( void ) const;

    /// Get the bounce velocity threshold

    const real getBounceVelThreshold( void ) const;    



    /// Set the linear velocity

    void setLinearVelocity( real x, real y, real z );

    /// Set the linear velocity

    void setLinearVelocity( const vector3 &velocity );

    /// Get the linear velocity

    const vector3 &getLinearVelocity( void ) const;



    /// Set the angular velocity

    void setAngularVelocity( real x, real y, real z );

    /// Set the angular velocity

    void setAngularVelocity( const vector3 &velocity );

    /// Get the angular velocity

    const vector3 &getAngularVelocity( void ) const;



    /// Add a force to the object

    void addForce( real x, real y, real z, 

		   real rx = 0, real ry = 0, real rz = 0 );

    /// Add a force in world space

    void addForceWorld( real x, real y, real z, real rx, real ry, real rz );   

    /// Add a force to the object

    void addForce( const vector3 &force, 

		   const vector3 &position = vector3::ZERO );

    /// Add a force in world space

    void addForceWorld( const vector3 &force, const vector3 &worldPos );

  

    /// Add torque to the object

    void addTorque( real x, real y, real z );

    /// Add torque in world space

    void addTorqueWorld( real x, real y, real z );

    /// Add torque to the object

    void addTorque( const vector3 &torque );

    /// Add torque in world space

    void addTorqueWorld( const vector3 &torque );



  protected:

    /// The physics body

    dBody *body;



     /// The mass for this physical

    mass *usedMass;

    /// Collision proxies attached to this physical

    proxyList proxies;



    /// Enabled state of dynamics

    bool dynamicsEnabled;

    /// Auto-renable dynamics

    bool reenableDynamics;

    /// Enabled state of collision

    bool collisionEnabled;

    /// Gravity usage

    bool useGravity;

    /// Disable time counter

    real disableTimer;

    /// Softness of physics

    real softness;

    /// Friction of physics

    real friction;

    /// Bounce co-efficient restitution

    real bounceCoeffRest;

    /// Bounce velocity threshold

    real bounceVelThreshold;

    /// The physical object this physics might be driving

    physical *drivingPhysical;



    /// Set position for this object

    void setPosition( const vector3 &newPosition );

    /// Set orientation for this object

    void setOrientation( const quaternion &newOrientation );

    /// Set the physical object to control

    void setPhysical( physical *newPhysical );



    /// Get the ODE body for this physics

    dBody *getODEBody( void ) const;

    

    /// Sets up the sound for a specific template

    void setup( resource *parent );



    /// Clear the physics, ready for repooling

    void clear( void );

   

    /// Update this physics

    void updateDynamics( real time ); 

    /// Do proper collision test between this and another physics

    void testCollision( physics *other, dxGeom *one, dxGeom *two );

  };

};



#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -