Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

ModelAnimator.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id:  $
00022 */
00023 
00024 
00025 #include "Teddy/Behaviour/ModelAnimator.h"
00026 #include "Teddy/Behaviour/ModelController.h"
00027 using namespace Teddy::Maths;
00028 using namespace Teddy::Models;
00029 
00030 
00031 namespace Teddy     {
00032 namespace Behaviour {
00033 
00034 
00036 ModelAnimator::ModelAnimator(
00037     Model         *m,
00038     DoubleVector  tick_translation,
00039     double        up,
00040     double        right,
00041     double        view
00042 )
00043 :
00044 model              ( m     ),
00045 controller         ( NULL  ),
00046 tick_translation   ( tick_translation ),
00047 tick_rotation_up   ( up    ),
00048 tick_rotation_right( right ),
00049 tick_rotation_view ( view  )
00050 {
00051 }
00052 
00053 
00054 /*virtual*/ ModelAnimator::~ModelAnimator(){
00055     if( controller!=NULL ){
00056         controller->setAnimator( NULL );
00057     }
00058 }
00059 
00060 
00061 void ModelAnimator::setController( ModelController *controller ){
00062     this->controller = controller;
00063 }
00064 
00065 
00066 ModelController *ModelAnimator::getController(){
00067     return this->controller;
00068 }
00069 
00070 
00071 void ModelAnimator::setTickTranslation( DoubleVector tick_translation ){
00072     this->tick_translation = tick_translation;
00073 }
00074 
00075 
00076 float ModelAnimator::getSpeed(){
00077     return tick_translation.magnitude();
00078 }
00079 
00080 
00081 void ModelAnimator::setTickRotation( double up, double right, double view ){
00082     tick_rotation_up    = up;
00083     tick_rotation_right = right;
00084     tick_rotation_view  = view;
00085 }
00086 
00087 
00088 /*virtual*/ void ModelAnimator::tick(){
00089     if( controller != NULL ){
00090         controller->tick();
00091     }
00092     if( model != NULL ){
00093         model->translate( tick_translation    );
00094         model->heading  ( tick_rotation_up    );
00095         model->pitch    ( tick_rotation_right );
00096         model->roll     ( tick_rotation_view  );
00097     }
00098 }
00099 
00100 
00101 Model *ModelAnimator::getModel(){
00102     return this->model;
00103 }
00104 
00105 
00106 void ModelAnimator::setModel( Model *model ){
00107     this->model = model;
00108 }
00109 
00110 
00111 };  //  namespace Behaviour
00112 };  //  namespace Teddy
00113