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

📄 oasisphysicsresource.cpp

📁 使用stl技术,(还没看,是听说的)
💻 CPP
字号:
/******************************************************************************

 * 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    : oasisPhysicsResource.cpp

 * DESCRIPTION : Physics resource

 * AUTHOR      : Zephie Greyvenstein

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



#include "oasisPhysicsResource.h"

#include "oasisPhysicsSystem.h"

#include "oasisProxies.h"

#include "oasisPhysics.h"

#include "oasisMass.h"



namespace Oasis {

  

  physicsResource::physicsResource( const string &thisName ) : resource( thisName ) {   

    useGravity = true;;

    softness = 0;

    friction = physics::infiniteFriction;

    bounceCoeffRest = 0;

    bounceVelThreshold = 0;

    usedMass = NULL;

    

    // Set a default minimum mass

    usedMass = new mass( );

    // Clear proxies

    proxies.clear( );

  }

  

  physicsResource::~physicsResource( ) {

    // Delete mass

    if ( usedMass ) {

      delete usedMass;

      usedMass = NULL;

    }



    // Delete all proxies

    removeAllProxies( );

  }



  mass *physicsResource::getMass( void ) const {

    return usedMass;

  }

 

  boxProxy *physicsResource::addBoxProxy( real width, 

            real height,

            real depth ) {

    boxProxy *newProxy = new boxProxy( physicsSystem::get( ).getODESpace( ),

               width, height, depth );

    

    if ( !newProxy ) {

      oasisError( exception::ET_NULL_POINTER,

      "Could not create box proxy",

      "physicsResource::addBoxProxy" );

    }  

    

    proxies.push_back( newProxy );

    return newProxy;

  }



  sphereProxy *physicsResource::addSphereProxy( real radius ) {

    sphereProxy *newProxy = new sphereProxy( physicsSystem::get( ).getODESpace( ),

               radius );



    if ( !newProxy ) {

      oasisError( exception::ET_NULL_POINTER,

      "Could not create sphere proxy",

      "physicsResource::addSphereProxy" );

    }

   

    proxies.push_back( newProxy );

    return newProxy;

  }



  ccylinderProxy *physicsResource::addCCylinderProxy( real radius,

                  real length ) { 

    ccylinderProxy *newProxy = new ccylinderProxy( physicsSystem::get( ).getODESpace( ),

               radius, length );



    if ( !newProxy ) {

      oasisError( exception::ET_NULL_POINTER,

      "Could not create capped cylinder proxy",

      "physicsResource::addCCylinderProxy" );

    }

   

    proxies.push_back( newProxy );

    return newProxy;

  }



  void physicsResource::removeProxy( uint8 index ) {

    if ( index < proxies.size( ) ) {

      // Get the correct element

      proxyList::iterator it = proxies.begin( );

      // Increment

      while ( index-- ) {

  ++it;

      }

            

      delete ( *it );

      proxies.erase( it );

    } else {

      oasisError( exception::ET_ITEM_NOT_FOUND,

      "Index was out of bounds",

      "physics::removeProxy" );

    }

  }



  void physicsResource::removeProxy( proxy *oldProxy ) {

    if ( oldProxy != NULL ) {

      delete oldProxy;

      proxies.remove( oldProxy );

    }

  }



  void physicsResource::removeAllProxies( void ) {

    for ( proxyList::iterator it = proxies.begin( );

    it != proxies.end( ); ++it ) {

      delete ( *it );

    }

    proxies.clear( );

  }



  physicsResource::proxyIterator physicsResource::getProxyIterator( void ) {

    return proxyIterator( proxies.begin( ), proxies.end( ) );

  }



  void physicsResource::setSoftness( const real newSoftness ) {

    softness = newSoftness;

  }

  

  const real physicsResource::getSoftness( void ) const {

    return softness;

  }

  

  void physicsResource::setFriction( const real newFriction ) {    

    friction = newFriction;

  }



  const real physicsResource::getFriction( void ) const {

    return friction;

  }



  void physicsResource::setGravity( bool newState ) {

    useGravity = newState;

  }



  const bool physicsResource::getGravity( void ) const {

    return useGravity;

  }

  

  void physicsResource::setBounce( const real coEff,

           const real velThreshold ) {

    bounceCoeffRest = coEff;

    bounceVelThreshold = velThreshold;

  }



  const real physicsResource::getBounceCoEff( void ) const {

    return bounceCoeffRest;

  }



  const real physicsResource::getBounceVelThreshold( void ) const {

    return bounceVelThreshold;

  }

}

⌨️ 快捷键说明

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