00001 /************************************************************************/ 00002 /* This file is part of openMask(c) INRIA, CNRS, Universite de Rennes 1 */ 00003 /* 1993-2002, thereinafter the Software */ 00004 /* */ 00005 /* The Software has been developped within the Siames Project. */ 00006 /* INRIA, the University of Rennes 1 and CNRS jointly hold intellectual */ 00007 /* property rights */ 00008 /* */ 00009 /* The Software has been registered with the Agence pour la Protection */ 00010 /* des Programmes (APP) under registration number */ 00011 /* IDDN.FR.001.510008.00.S.P.2001.000.41200 */ 00012 /* */ 00013 /* This file may be distributed under the terms of the Q Public License */ 00014 /* version 1.0 as defined by Trolltech AS of Norway and appearing in */ 00015 /* the file LICENSE.QPL included in the packaging of this file. */ 00016 /* */ 00017 /* Licensees holding valid specific licenses issued by INRIA, CNRS or */ 00018 /* Universite Rennes 1 for the software may use this file in */ 00019 /* acordance with that specific license */ 00020 /************************************************************************/ 00021 #include "OMKCameraBaseExtension.h" 00022 #include "OMKOgreVis.h" 00023 #include "OMKParametersAccessor.inl" 00024 //----------------------------------------------------------------------------- 00025 using namespace OMK ; 00026 using namespace Vis ; 00027 //----------------------------------------------------------------------------- 00028 REGISTER_EXTENSION_FACTORY( CameraBaseExtension, "CameraBase" ) ; 00029 //----------------------------------------------------------------------------- 00030 CameraBaseExtension::CameraBaseExtension( 00031 OMK::ExtensibleSimulatedObject *owner, 00032 const Name &id, 00033 bool registerExtension ) 00034 : ExtensionT< ExtensibleSimulatedObject >( owner, id, registerExtension ), 00035 _vis( 0 ), 00036 _viewportNumber( 0 ), 00037 _camera( 0 ), 00038 _camBase( 0 ), 00039 _usePreCompute( false ) 00040 { 00041 std::string attributeName( "CameraBase" ) ; 00042 ConfigurationParameterDescriptor *node( 0 ) ; 00043 if( ParametersAccessor::get( 00044 owner->getObjectDescriptor().getExtensionsParameters(), 00045 id.getString(), 00046 node ) ) 00047 { 00048 ParametersAccessor::get( node, "AttributeId", attributeName ) ; 00049 ParametersAccessor::get( node, "ViewportNumber", _viewportNumber ) ; 00050 ParametersAccessor::get( node, "usePreCompute", _usePreCompute ) ; 00051 } 00052 _camBase = new AttributeT< Type::Transform >( Name( attributeName ), 00053 Type::Transform() ) ; 00054 owner->addAttribute( *_camBase, true ) ; 00055 00056 // get visualisation 00057 _vis = dynamic_cast< OgreVis * >( owner ) ; 00058 if( _vis == 0 ) 00059 { 00060 OMFATALERROR( "Can't get associated visualisation object. Is extension placed in a visu?" ) ; 00061 } 00062 } 00063 //----------------------------------------------------------------------------- 00064 CameraBaseExtension::~CameraBaseExtension() 00065 { 00066 delete _camBase ; 00067 } 00068 //----------------------------------------------------------------------------- 00069 void CameraBaseExtension::retreiveCamera() 00070 { 00071 _camera = _vis->touchRoot().getAutoCreatedWindow()-> 00072 getViewport( _viewportNumber )->getCamera() ; 00073 } 00074 //----------------------------------------------------------------------------- 00075 void CameraBaseExtension::computeParameters() 00076 { 00077 if( _camera == 0 ) 00078 { // now, Ogre is set up and we can access to camera 00079 retreiveCamera() ; 00080 } 00081 const Ogre::Vector3 &ogreCamPos( _camera->getWorldPosition() ) ; 00082 const Ogre::Quaternion &ogreCamQuat( _camera->getWorldOrientation() ) ; 00083 const Type::Transform camBase( 00084 Wm4::Vector3f( ogreCamPos.x, ogreCamPos.y, ogreCamPos.z ), 00085 Wm4::Quaternionf( ogreCamQuat.w, ogreCamQuat.x, ogreCamQuat.y, ogreCamQuat.z ) ) ; 00086 _camBase->set( camBase ) ; 00087 } 00088 //----------------------------------------------------------------------------- 00089 void CameraBaseExtension::preComputeParameters() 00090 { 00091 if( _usePreCompute ) 00092 { 00093 computeParameters() ; 00094 } 00095 } 00096 //----------------------------------------------------------------------------- 00097 void CameraBaseExtension::postComputeParameters() 00098 { 00099 if( !_usePreCompute ) 00100 { 00101 computeParameters() ; 00102 } 00103 }
Documentation generated on Mon Jun 9 11:45:55 2008 |
Generated with doxygen by Dimitri van Heesch , 1997-2007 |