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

base/LineSegPathRep

Go to the documentation of this file.
00001 /****************************************************************************
00002   Copyright (C)2002 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: LineSegPathRep 1029 2004-02-11 20:45:54Z jungd $
00019   $Revision: 1.3 $
00020   $Date: 2004-02-11 15:45:54 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _BASE_LINESEGPATHREP_
00026 #define _BASE_LINESEGPATHREP_
00027 
00028 #include <base/PathRep>
00029 #include <base/Math>
00030 
00031 
00032 namespace base {
00033 
00034 
00035 /// Concrete path representation as a line segment
00036 class LineSegPathRep : public PathRep
00037 {
00038 public:
00039   LineSegPathRep() 
00040     : flags(ConstPos | ConstOrient) {}
00041   LineSegPathRep(const Point3& sp, const Orient& so, const Point3& ep, const Orient& eo)
00042     : sp(sp), so(so), ep(ep), eo(eo), flags(None)
00043   {
00044     if (sp == ep) flags |= ConstPos;
00045     if (so == eo) flags |= ConstOrient;
00046   }
00047 
00048   virtual Object& clone() const
00049     { return *NewObj LineSegPathRep(sp, so, ep, eo); }
00050 
00051   virtual String className() const { return String("LineSegPathRep"); }
00052 
00053   /// get cartesian position at s:[0..1]
00054   virtual Point3 position(Real s) const
00055   {
00056     if (flags & ConstPos)
00057       return sp;
00058     else {
00059       Math::bound(s,0.0,1.0);
00060       return sp+(s*(ep-sp));
00061     }
00062   }
00063 
00064   /// get orientation at s:[0..1]
00065   virtual Orient orientation(Real s) const
00066   {
00067     if (flags & ConstOrient)
00068       return so;
00069     else
00070       return Orient::interpolate(so, eo, s);
00071   }
00072 
00073 
00074   /// translate the path position by t
00075   virtual void translate(const Vector3& t)
00076   { sp += t; ep += t; }
00077 
00078   /// rotate the path orientation by r
00079   virtual void rotate(const Quat4& r)
00080   {
00081     r.rotatePoint(sp);
00082     r.rotatePoint(ep);
00083     Quat4 sq(so.getQuat4()); 
00084     Quat4 eq(eo.getQuat4());
00085     so = r*sq;
00086     eo = r*eq;
00087   }
00088 
00089 
00090   /// transform the path by m
00091   virtual void transform(const Matrix4& m)
00092   {
00093     Point4 sp4(sp);
00094     sp4 = m*sp4;
00095     sp = Point3(sp4.x,sp4.y,sp4.z);
00096 
00097     Point4 ep4(ep);
00098     ep4 = m*ep4;
00099     ep = Point3(ep4.x,ep4.y,ep4.z);
00100     
00101     Quat4 r;
00102     r.setRotation(m);
00103     Quat4 sq(so.getQuat4());
00104     Quat4 eq(eo.getQuat4());
00105     so = r*sq;
00106     eo = r*eq;
00107   }
00108 
00109 
00110   virtual void scalePosition(Real s)
00111   {
00112     sp *= s;
00113     ep *= s;
00114   }
00115 
00116 
00117   virtual void serialize(Serializer& s) 
00118   { 
00119     s(flags,"flags");
00120     s(sp,"startPoint");
00121     s(so,"startOrient");
00122     s(ep,"endPoint");
00123     s(eo,"endOrient");
00124   }
00125 
00126 protected:
00127   Point3 sp; ///< start pos
00128   Orient so; ///< start orient
00129   Point3 ep; ///< end pos
00130   Orient eo; ///< end orient
00131 
00132   enum Flags { None=0, ConstPos=1, ConstOrient=2 };
00133   Int flags;
00134 };
00135 
00136 
00137 } // base
00138 
00139 #endif

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