📄 oasisvisible.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 : oasisVisible.cpp
* DESCRIPTION : The visible component
* AUTHOR : Zephie Greyvenstein
*****************************************************************************/
#include "oasisVisible.h"
#include "oasisGraphicsSystem.h"
#include "oasisConvert.h"
#include "oasisEntity.h"
// Include Ogre stuff
#include "OgreSceneNode.h"
#include "OgreSceneManager.h"
namespace Oasis {
visible::visible( ) {
node = NULL;
usedEntity = NULL;
absScale = vector3::UNITSCALE;
}
visible::~visible( ) {
removeAndDestroyEntity( );
if ( node ) {
graphicsSystem::get( ).getSceneManager( )->getRootSceneNode( )->
removeChild( node->getName( ) );
graphicsSystem::get( ).getSceneManager( )->
destroySceneNode( node->getName( ) );
}
}
void visible::scale( real x, real y, real z ) {
scale( vector3( x, y, z ) );
}
void visible::scale( const vector3 &newScale ) {
_createNode( );
node->scale( convert::toOgreVector3( newScale ) );
absScale = convert::parseVector3( node->getScale( ) );
}
void visible::setScale( real x, real y, real z ) {
setScale( vector3( x, y, z ) );
}
void visible::setScale( const vector3 &newScale ) {
_createNode( );
node->setScale( convert::toOgreVector3( newScale ));
absScale = convert::parseVector3( node->getScale( ) );
}
const vector3 &visible::getScale( void ) const {
return absScale;
}
entity *visible::setEntity( const string &entityToUse ) {
// If there is no graphics system, error
if ( !graphicsSystem::getPtr( ) ) {
oasisError( exception::ET_INTERNAL_ERROR,
"To include entities in visibles, start the graphics system",
"visible::addEntity" );
}
entity *object = graphicsSystem::get( ).
createEntity( graphicsSystem::get( ).getNextUniqueName( ),
entityToUse );
setEntity( object );
return object;
}
void visible::setEntity( entity *entityToUse ) {
if ( !entityToUse ) {
oasisError( exception::ET_NULL_POINTER,
"Entity was null",
"visible::setEntity" );
}
// Make sure we have a node, and no entity is being used
_createNode( );
removeAndDestroyEntity( );
entityToUse->attachToNode( node );
usedEntity = entityToUse;
}
void visible::removeEntity( void ) {
if ( usedEntity ) {
usedEntity->detachFromNode( );
usedEntity = NULL;
}
}
void visible::removeAndDestroyEntity( void ) {
if ( usedEntity ) {
graphicsSystem::get( ).removeEntity( usedEntity );
usedEntity = NULL;
}
}
entity *visible::getEntity( void ) const {
return usedEntity;
}
void visible::_setVisiblePosition( const vector3 &newPosition ) {
if ( node ) {
node->setPosition( convert::toOgreVector3( newPosition ) );
}
}
void visible::_setVisibleOrientation( const quaternion &newOrientation ) {
if ( node ) {
node->setOrientation( convert::toOgreQuaternion( newOrientation ) );
}
}
void visible::_createNode( void ) {
if ( node ) {
return;
}
// If there is no graphics system, error
if ( !graphicsSystem::getPtr( ) ) {
oasisError( exception::ET_INTERNAL_ERROR,
"To include visibles, start the graphics system",
"visible::_createNode" );
}
node = static_cast< Ogre::SceneNode* >( graphicsSystem::get( ).
getSceneManager( )->
getRootSceneNode( )->
createChild( ) );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -