📄 oasisphysical.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 : oasisPhysical.cpp
* DESCRIPTION : A physical object
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
#include "oasisPhysical.h"
#include "oasisPhysicsSystem.h"
#include "oasisException.h"
namespace Oasis {
physical::physical( ) {
drivingPhysics = NULL;
removeAllCollisionListeners( );
}
physical::~physical( ) {
removeAndDestroyPhysics( );
removeAllCollisionListeners( );
}
void physical::setPosition( const vector3 &newPosition ) {
position = newPosition;
if ( drivingPhysics ) {
drivingPhysics->setPosition( position );
}
_updatePosition( );
}
void physical::setOrientation( const quaternion &newOrientation ) {
orientation = newOrientation;
if ( drivingPhysics ) {
drivingPhysics->setOrientation( orientation );
}
_updateOrientation( );
}
void physical::enablePhysics( bool usePhysics ) {
drivingPhysics->setDynamicsEnabled( usePhysics );
drivingPhysics->setCollisionEnabled( usePhysics );
}
void physical::setPhysics( physics *physicsToUse ) {
if ( !physicsToUse ) {
oasisError( exception::ET_NULL_POINTER,
"Physics was null",
"physical::setPhysics" );
}
removeAndDestroyPhysics( );
drivingPhysics = physicsToUse;
// Backward data
drivingPhysics->setPhysical( this );
}
physics *physical::setPhysics( const string &templateName ) {
// If there is no physics system, error. Perhaps we could start it?
if ( !physicsSystem::getPtr( ) ) {
oasisError( exception::ET_INTERNAL_ERROR,
"To create physics, start the physics system",
"physical::setPhysics" );
}
physics *object = physicsSystem::get( ).
createPhysics( physicsSystem::get( ).getNextUniqueName( ),
templateName );
setPhysics( object );
return object;
}
physics *physical::getPhysics( void ) const {
return drivingPhysics;
}
void physical::removePhysics( void ) {
if ( drivingPhysics ) {
drivingPhysics->setPhysical( NULL );
drivingPhysics = NULL;
}
}
void physical::removeAndDestroyPhysics( void ) {
if ( drivingPhysics ) {
physicsSystem::get( ).removePhysics( drivingPhysics );
drivingPhysics = NULL;
}
}
void physical::addCollisionListener( collisionListener *listener ) {
listeners.insert( listener );
}
void physical::removeCollisionListener( collisionListener *listener ) {
listeners.erase( listener );
}
void physical::removeAllCollisionListeners( void ) {
listeners.clear( );
}
void physical::updatePhysics( const vector3 &newPosition,
const quaternion &newOrientation ) {
position = newPosition;
orientation = newOrientation;
_updatePosition( );
_updateOrientation( );
}
void physical::notifyCollision( collisionListener::CollisionInfo &info ) {
// Notify all collision listeners of the collision
for ( collisionListenerSet::iterator it = listeners.begin( );
it != listeners.end( ); ++it ) {
( *it )->collided( this, info );
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -