📄 oasismass.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 : oasisMass.cpp
* DESCRIPTION : A mass object
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
#include "oasisMass.h"
#include "oasisPhysics.h"
#include "oasisConvert.h"
#include "oasisPhysicsCommon.h"
#include "OgreMatrix3.h"
namespace Oasis {
mass::mass( ) {
/// Set some defaults
parent = NULL;
odeMass = new dMass( );
setSphere( 0.01, 0.01 );
}
mass::~mass( ) {
if ( odeMass ) {
delete odeMass;
odeMass = NULL;
}
}
void mass::setBox( real newDensity, real newLength,
real newHeight, real newDepth ) {
dMassSetBox( odeMass, newDensity, newLength, newHeight, newDepth );
length = newLength;
height = newHeight;
depth = newDepth;
density = newDensity;
radius = 0;
type = MT_BOX;
_reAssignToParent( );
}
void mass::setSphere( real newDensity, real newRadius ) {
dMassSetSphere( odeMass, newDensity, newRadius );
radius = newRadius;
density = newDensity;
length = 0;
height = 0;
depth = 0;
type = MT_SPHERE;
_reAssignToParent( );
}
void mass::setCCylinder( real newDensity,
real newRadius,
real newLength ) {
dMassSetCappedCylinder( odeMass, newDensity, 3, newRadius, newLength );
radius = newRadius;
length = newLength;
density = newDensity;
height = 0;
depth = 0;
type = MT_CCYLINDER;
_reAssignToParent( );
}
void mass::setCylinder( real newDensity,
real newRadius,
real newLength ) {
dMassSetCylinder( odeMass, newDensity, 3, newRadius, newLength );
radius = newRadius;
length = newLength;
density = newDensity;
height = 0;
depth = 0;
type = MT_CYLINDER;
_reAssignToParent( );
}
const mass::MassType mass::getType( void ) const {
return type;
}
const real mass::getDensity( void ) const {
return density;
}
const real mass::getLength( void ) const {
return length;
}
const real mass::getHeight( void ) const {
return height;
}
const real mass::getDepth( void ) const {
return depth;
}
const real mass::getRadius( void ) const {
return radius;
}
void mass::copyParameters( const mass *otherMass ) {
switch ( otherMass->getType( ) ) {
case MT_BOX:
setBox( otherMass->getDensity( ),
otherMass->getLength( ),
otherMass->getHeight( ),
otherMass->getDepth( ) );
break;
case MT_SPHERE:
setSphere( otherMass->getDensity( ),
otherMass->getRadius( ) );
break;
case MT_CCYLINDER:
setCCylinder( otherMass->getDensity( ),
otherMass->getLength( ),
otherMass->getRadius( ) );
break;
case MT_CYLINDER:
setCylinder( otherMass->getDensity( ),
otherMass->getLength( ),
otherMass->getRadius( ) );
break;
};
}
void mass::setODEBodyParent( dBody *newParent ) {
parent = newParent;
_reAssignToParent( );
}
void mass::_reAssignToParent( void ) {
if ( parent ) {
parent->setMass( odeMass );
dMatrix3 mat3;
dQtoR( parent->getQuaternion( ), mat3 );
dMassRotate( odeMass, mat3 );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -