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

📄 oasiscamerasystem.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    : oasisCameraSystem.cpp

 * DESCRIPTION : Camera system

 * AUTHOR      : Zephie Greyvenstein

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



#include "oasisCameraSystem.h"

#include "oasisGraphicsSystem.h"

#include "oasisConvert.h"

#include "oasisException.h"

#include "oasisObject.h"

#include "oasisConfiguration.h"

#include "oasisSoundSystem.h"



#include "OgreCamera.h"

#include "OgreProfiler.h"

#include "OgreAnimation.h"

#include "OgreAnimationState.h"

#include "OgreSceneManager.h"

#include "OgreAnimationTrack.h"

#include "OgreKeyFrame.h"



namespace Oasis {

  

  template< > cameraSystem *singleton< cameraSystem >::singletonPtr = 0;



  cameraSystem::cameraSystem( ) : system( "Camera" ) {

    // Grab the camera handle

    camera = graphicsSystem::get( ).getCamera( );

    // Default to fixed yaw axis

    setFixedYawAxis( true );

    // We are not a sound listener    

    listener = false;   

  }

  

  cameraSystem::~cameraSystem( ) {   

    // Forget the camera handle

    camera = NULL;  

  }

  

  cameraSystem &cameraSystem::get( void ) {

    return singleton< cameraSystem >::get( );

  }

  

  cameraSystem *cameraSystem::getPtr( void ) {

    return singleton< cameraSystem >::getPtr( );

  }



  void cameraSystem::reset( void ) {

    setPosition( vector3::ZERO ); 

    setDirection( vector3::UNITZ );

  }

  

  void cameraSystem::update( real time ) {

   

  }



  void cameraSystem::setSoundListener( bool isListener ) {

    listener = isListener;

  }



  void cameraSystem::setDirection( real x, real y, real z ) {

    setDirection( vector3( x, y, z ) );

  }



  void cameraSystem::setDirection( const vector3 &newDirection ) {

    camera->setDirection( convert::toOgreVector3( newDirection ) ); 

    orientation = convert::parseQuaternion( camera->getOrientation( ) );   

    _updateSoundListener( );

  }



  void cameraSystem::lookAt( const object *target ) {

    lookAt( target->getPosition( ) );

  }



  void cameraSystem::lookAt( real x, real y, real z ) {

    lookAt( vector3( x, y, z ) );

  }



  void cameraSystem::lookAt( const vector3 &target ) {

    camera->lookAt( convert::toOgreVector3( target ) );

    orientation = convert::parseQuaternion( camera->getOrientation( ) );   

    _updateSoundListener( );

  }



  void cameraSystem::roll( real degrees ) {

    camera->roll( degrees );

    orientation = convert::parseQuaternion( camera->getOrientation( ) );   

    _updateSoundListener( );

  }

  

  void cameraSystem::yaw( real degrees ) {

    camera->yaw( degrees );

    orientation = convert::parseQuaternion( camera->getOrientation( ) );   

    _updateSoundListener( );

  }

  

  void cameraSystem::pitch( real degrees ) {

    camera->pitch( degrees );

    orientation = convert::parseQuaternion( camera->getOrientation( ) );   

    _updateSoundListener( );

  }



  void cameraSystem::setFixedYawAxis( bool newState, const vector3 &axis ) {

    camera->setFixedYawAxis( newState, convert::toOgreVector3( axis ) );

  }



  void cameraSystem::_updateSoundListener( void ) {

    if ( !listener ) {

      return;

    }    



    // Up

    Ogre::Vector3 up = camera->getDerivedOrientation( ) * 

      Ogre::Vector3::UNIT_Y;

      

    soundSystem::get( ).

      setListenerPosition( position,

         convert::parseVector3( camera->getDirection( ) ),

         convert::parseVector3( up ) );  

  }

  

  void cameraSystem::_updatePosition( void ) {    

    camera->setPosition( convert::toOgreVector3( position ) );

    _updateSoundListener( );

  }

  

  void cameraSystem::_updateOrientation( void ) {  

    camera->setOrientation( convert::toOgreQuaternion( orientation ) );

    _updateSoundListener( );

  }



}

⌨️ 快捷键说明

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