00001 /* **-*-c++-*-************************************************************** 00002 Copyright (C)1996 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: DynamicSpatial 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 #ifndef _PHYSICS_DYNAMICSPATIAL_ 00026 #define _PHYSICS_DYNAMICSPATIAL_ 00027 00028 #include <physics/physics> 00029 00030 #include <physics/Spatial> 00031 00032 00033 namespace physics { 00034 00035 00036 class DynamicSpatial : public Spatial 00037 { 00038 public: 00039 DynamicSpatial() {} 00040 DynamicSpatial(const DynamicSpatial& b) : Spatial(b) { *this = b; } 00041 00042 virtual ~DynamicSpatial() {} 00043 00044 virtual String className() const { return String("DynamicSpatial"); } 00045 00046 virtual DynamicSpatial& operator=(const DynamicSpatial& b) 00047 { 00048 setPosition(b.getSavedPosition()); 00049 setOrientation(b.getSavedOrientation()); 00050 setVelocity(b.getSavedVelocity()); 00051 setAngVelocity(b.getSavedAngVelocity()); 00052 saveState(); 00053 Spatial::operator=(b); 00054 setVelocity(b.getVelocity()); 00055 setAngVelocity(b.getAngVelocity()); 00056 return *this; 00057 } 00058 00059 00060 // Spatial 00061 virtual void setPosition(const Point3& x) = 0; 00062 virtual void setOrientation(const Orient& orient) = 0; 00063 virtual Point3 getPosition() const = 0; 00064 virtual Orient getOrientation() const = 0; 00065 00066 00067 virtual void setVelocity(const Vector3& v) = 0; 00068 virtual void setAngVelocity(const Vector3& w) = 0; 00069 virtual Vector3 getVelocity() const = 0; 00070 virtual Vector3 getAngVelocity() const = 0; 00071 00072 virtual void saveState() = 0; 00073 virtual void restoreState() = 0; 00074 00075 virtual Point3 getSavedPosition() const = 0; 00076 virtual Orient getSavedOrientation() const = 0; 00077 virtual Vector3 getSavedVelocity() const = 0; 00078 virtual Vector3 getSavedAngVelocity() const = 0; 00079 00080 // Utility 00081 virtual Point3 getRelPointPos(const Point3& p) 00082 { 00083 return getConfiguration().transform(p); 00084 } 00085 00086 virtual Vector3 getRelPointVel(const Point3& p) 00087 { 00088 Unimplemented; 00089 } 00090 00091 virtual Point3 getGlobalPointRelPos(const Point3& p) 00092 { 00093 return inverse(getConfiguration()).transform(p); 00094 } 00095 00096 }; 00097 00098 00099 inline std::ostream& operator<<(std::ostream& out, const DynamicSpatial& b) // Output 00100 { 00101 return out << "(x:" << b.getPosition() << ",q:" << b.getOrientation() 00102 << ",v:" << b.getVelocity() << ",w:" << b.getAngVelocity() << ")"; 00103 } 00104 00105 00106 } // physics 00107 00108 #endif