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/Materials/Material.h" 00026 #include "Teddy/Models/Model.h" 00027 #include "Teddy/PhysicalComponents/Projection.h" 00028 #include "Teddy/Scenes/Camera.h" 00029 #include "Teddy/SysSupport/StdMaths.h" 00030 #include "Teddy/SysSupport/StdSDL.h" 00031 #include "Teddy/SysSupport/StdIO.h" 00032 using namespace Teddy::Graphics; 00033 using namespace Teddy::Materials; 00034 using namespace Teddy::Maths; 00035 using namespace Teddy::Scenes; 00036 00037 00038 namespace Teddy { 00039 namespace Models { 00040 00041 00042 Quaternion &Model::getAttitude(){ 00043 return attitude; 00044 } 00045 00046 /*virtual*/ void Model::setPosition( const double x, const double y, const double z ){ 00047 position.v[0] = x; 00048 position.v[1] = y; 00049 position.v[2] = z; 00050 } 00051 00052 00054 TVector<double> Model::getPosition() const { 00055 return position; 00056 } 00057 00058 00060 /*virtual*/ void Model::setPosition( const TVector<double> &v ){ 00061 position = v; 00062 } 00063 00064 00065 void Model::translate( const TVector<double> &v ){ 00066 position += v; 00067 } 00068 00069 00078 double Model::distanceTo( const Model &other ) const { 00079 return position.distance( other.position ); 00080 } 00081 00082 00088 double Model::distanceTo( const TVector<double> &pos ) const { 00089 return position.distance( pos ); 00090 } 00091 00092 00097 TVector<double> Model::vectorTo( const Model &other ) const { 00098 return other.position - position; 00099 } 00100 00101 00106 void Model::copyAttitude( const Model &other ){ 00107 attitude = other.attitude; 00108 } 00109 00110 00111 void Model::transform( const Matrix &m ){ 00112 attitude *= m; 00113 } 00114 00115 00122 void Model::roll( const double radians ){ 00123 attitude.rotate( attitude.getViewAxis(), radians ); 00124 } 00125 00126 00133 void Model::pitch( const double radians ){ 00134 attitude.rotate( attitude.getRightAxis(), radians ); 00135 } 00136 00137 00144 void Model::heading( const double radians ){ 00145 attitude.rotate( attitude.getUpAxis(), radians ); 00146 } 00147 00148 00156 void Model::foward( const double len ){ 00157 translate( attitude.getViewAxis() * len ); 00158 } 00159 00160 00169 /*void Model::translate( const double x, const double y, const double z ){ 00170 translate( Vector(x,y,z) ); 00171 }*/ 00172 00173 00174 }; // namespace Models 00175 }; // namespace Teddy 00176