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

physics/SpatialTransform.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2003 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: SpatialTransform.cpp 1031 2004-02-11 20:46:36Z jungd $
00019   $Revision: 1.1 $
00020   $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #include <physics/SpatialTransform>
00026 
00027 
00028 using physics::SpatialTransform;
00029 
00030 using base::Point3;
00031 using base::Orient;
00032 using base::Transform;
00033 
00034 using physics::Spatial;
00035 
00036 
00037 
00038 SpatialTransform::SpatialTransform()
00039 {
00040 }
00041 
00042 SpatialTransform::SpatialTransform(const base::Transform& childTransform)
00043   : t(childTransform), tinv(inverse(childTransform))
00044 {
00045 }
00046 
00047 SpatialTransform::SpatialTransform(ref<Spatial> child, const base::Transform& childTransform)
00048   : t(childTransform), tinv(inverse(childTransform)), child(child)
00049 {
00050 }
00051 
00052 SpatialTransform::SpatialTransform(ref<Spatial> child, ref<Spatial> transformedRelativeTo)
00053   : child(child)
00054 {
00055   if (child) 
00056     t = transformedRelativeTo->getConfiguration() * inverse(child->getConfiguration());
00057   else
00058     t = transformedRelativeTo->getConfiguration();
00059   tinv = inverse(t);
00060 }
00061 
00062 SpatialTransform::SpatialTransform(const String& name)
00063   : Spatial(name)
00064 {
00065 }
00066 
00067 SpatialTransform::SpatialTransform(const SpatialTransform& st)
00068  : Spatial(st), t(st.t), tinv(st.tinv), child(st.child)
00069 {
00070 }
00071 
00072 
00073 SpatialTransform::~SpatialTransform()
00074 {
00075 }
00076 
00077 
00078 SpatialTransform& SpatialTransform::operator=(const SpatialTransform& st)
00079 {
00080   t = st.t;
00081   tinv = st.tinv;
00082   child = st.child;
00083   setName(st.getName());
00084   return *this;
00085 } 
00086 
00087  
00088 
00089 
00090 void SpatialTransform::setConfiguration(const base::Transform& configuration)
00091 {
00092   if (child) child->setConfiguration( configuration*t );
00093 }
00094 
00095 
00096 base::Transform SpatialTransform::getConfiguration() const
00097 {
00098   if (child)
00099     return child->getConfiguration()*tinv;
00100   return Transform();
00101 }
00102 
00103 
00104 void SpatialTransform::setPosition(const Point3& pos)
00105 {
00106   setConfiguration( Transform(pos, getOrientation()) );
00107 }
00108  
00109  
00110 Point3 SpatialTransform::getPosition() const
00111 {
00112   return getConfiguration().getTranslation();
00113 }
00114  
00115  
00116 void SpatialTransform::setOrientation(const Orient& orient)
00117 {
00118   setConfiguration( Transform(getPosition(), orient) );
00119 }
00120  
00121  
00122 Orient SpatialTransform::getOrientation() const
00123 {
00124   return getConfiguration().getRotation();
00125 }
00126 
00127 
00128 void SpatialTransform::setTransform(const base::Transform& transform)
00129 {
00130   t = transform;
00131   tinv = inverse(t);
00132 }
00133 
00134 
00135 base::Transform SpatialTransform::getTransform() const
00136 {
00137   return t;
00138 }
00139 
00140 
00141 void SpatialTransform::setChild(ref<Spatial> child)
00142 {
00143   this->child = child;
00144 }
00145 
00146 
00147 ref<Spatial> SpatialTransform::getChild() const 
00148 {
00149   return child; 
00150 }
00151 
00152 

Generated on Thu Jul 29 15:56:30 2004 for OpenSim by doxygen 1.3.6