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

📄 oasisjoints.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    : oasisJoints.cpp

 * DESCRIPTION : Define the different joints

 * AUTHOR      : Zephie Greyvenstein

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



#include "oasisJoints.h"

#include "oasisPhysicsCommon.h"



namespace Oasis {

  

  ballJoint::ballJoint( const dWorld *worldParent,

      physics *first,

      physics *second ) : joint( JT_BALL ) {

    odeJoint = new dBallJoint( worldParent->id( ) );

    setBodies( first, second );

  }



  ballJoint::~ballJoint( ) {

    

  }



  void ballJoint::setAnchorPosition( const vector3 &origin ) {

    dBallJoint *ball = static_cast< dBallJoint* >( odeJoint );

    

    ball->setAnchor( origin.x, origin.y, origin.z );

    anchor = origin;

  }



  sliderJoint::sliderJoint( const dWorld *worldParent,

          physics *first,

          physics *second ) : joint( JT_SLIDER ) {

    odeJoint = new dSliderJoint( worldParent->id( ) );

    setBodies( first, second );

  }

  

  sliderJoint::~sliderJoint( ) {

    

  }

  

  void sliderJoint::setAxes( const vector3 &primary,

           const vector3 &secondary ) {

    dSliderJoint *slider = static_cast< dSliderJoint* >( odeJoint );

    

    slider->setAxis( primary.x, primary.y, primary.z );

    axes.first = primary;

  }



  void sliderJoint::setParameter( JointParam param, real value ) {

    dSliderJoint *slider = static_cast< dSliderJoint* >( odeJoint );



    slider->setParam( _mapToODEParam( param ), value );

  }



  const real sliderJoint::getParameter( JointParam param ) {

    dSliderJoint *slider = static_cast< dSliderJoint* >( odeJoint );

    

    return ( real )slider->getParam( _mapToODEParam( param ) );

  }



  hingeJoint::hingeJoint( const dWorld *worldParent,

        physics *first,

        physics *second ) : joint( JT_HINGE ) {

    odeJoint = new dHingeJoint( worldParent->id( ) );

    setBodies( first, second );

  }



  hingeJoint::~hingeJoint( ) {

    

  }

  

  void hingeJoint::setAnchorPosition( const vector3 &origin ) {

    dHingeJoint *hinge = static_cast< dHingeJoint* >( odeJoint );



    hinge->setAnchor( origin.x, origin.y, origin.z );

    anchor = origin;

  }



  void hingeJoint::setAxes( const vector3 &primary,

          const vector3 &secondary ) {

    dHingeJoint *hinge = static_cast< dHingeJoint* >( odeJoint );



    hinge->setAxis( primary.x, primary.y, primary.z );

    axes.first = primary;

  }



  void hingeJoint::setParameter( JointParam param, real value ) {

    dHingeJoint *hinge = static_cast< dHingeJoint* >( odeJoint );



    hinge->setParam( _mapToODEParam( param ), value );

  }



  const real hingeJoint::getParameter( JointParam param ) {

    dHingeJoint *hinge = static_cast< dHingeJoint* >( odeJoint );

    

    return ( real )hinge->getParam( _mapToODEParam( param ) );

  }



  const real hingeJoint::getAxisAngle( JointAxis axis ) const {

     dHingeJoint *hinge = static_cast< dHingeJoint* >( odeJoint );

     

     return ( real )hinge->getAngle( );

  }



  hinge2Joint::hinge2Joint( const dWorld *worldParent,

          physics *first,

          physics *second ) : joint( JT_HINGE2 ) {

    odeJoint = new dHinge2Joint( worldParent->id( ) );

    setBodies( first, second );

  }

  

  hinge2Joint::~hinge2Joint( ) {

    

  }

  

  void hinge2Joint::setAnchorPosition( const vector3 &origin ) {

    dHinge2Joint *hinge2 = static_cast< dHinge2Joint* >( odeJoint );



    hinge2->setAnchor( origin.x, origin.y, origin.z );

    anchor = origin;

  }



  void hinge2Joint::setAxes( const vector3 &primary,

           const vector3 &secondary ) {

    dHinge2Joint *hinge2 = static_cast< dHinge2Joint* >( odeJoint );



    hinge2->setAxis1( primary.x, primary.y, primary.z );

    hinge2->setAxis2( secondary.x, secondary.y, secondary.z );

  

    axes.first = primary;

    axes.second = secondary;

  }



  void hinge2Joint::setParameter( JointParam param, real value ) {

    dHinge2Joint *hinge2 = static_cast< dHinge2Joint* >( odeJoint );

   

    hinge2->setParam( _mapToODEParam( param ), value );

  }



  const real hinge2Joint::getParameter( JointParam param ) {

    dHinge2Joint *hinge2 = static_cast< dHinge2Joint* >( odeJoint );

    

    return ( real )hinge2->getParam( _mapToODEParam( param ) );

  }



  const real hinge2Joint::getAxisAngle( JointAxis axis ) const {

    dHinge2Joint *hinge2 = static_cast< dHinge2Joint* >( odeJoint );

     

     return ( real )hinge2->getAngle1( );

  }



  universalJoint::universalJoint( const dWorld *worldParent,

          physics *first,

          physics *second ) : joint( JT_UNIVERSAL ) {

    odeJoint = new dUniversalJoint( worldParent->id( ) );

    setBodies( first, second );

  }

  

  universalJoint::~universalJoint( ) {

    

  }

  

  void universalJoint::setAnchorPosition( const vector3 &origin ) {

    dUniversalJoint *uni = static_cast< dUniversalJoint* >( odeJoint );



    uni->setAnchor( origin.x, origin.y, origin.z );

    anchor = origin;

  }



  void universalJoint::setAxes( const vector3 &primary,

        const vector3 &secondary ) {

    dUniversalJoint *uni = static_cast< dUniversalJoint* >( odeJoint );



    uni->setAxis1( primary.x, primary.y, primary.z );

    uni->setAxis2( secondary.x, secondary.y, secondary.z );

    axes.first = primary;

    axes.second = secondary;

  }



  void universalJoint::setParameter( JointParam param, real value ) {

    dUniversalJoint *uni = static_cast< dUniversalJoint* >( odeJoint );



    uni->setParam( _mapToODEParam( param ), value );

  }



  const real universalJoint::getParameter( JointParam param ) {

    dUniversalJoint *uni = static_cast< dUniversalJoint* >( odeJoint );

    

    return ( real )uni->getParam( _mapToODEParam( param ) );

  }

}

⌨️ 快捷键说明

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