00001 /* **-*-c++-*-************************************************************** 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: SpatialGroup 1031 2004-02-11 20:46:36Z jungd $ 00019 $Revision: 1.2 $ 00020 $Date: 2004-02-11 15:46:36 -0500 (Wed, 11 Feb 2004) $ 00021 $Author: jungd $ 00022 00023 ****************************************************************************/ 00024 00025 #ifndef _PHYSICS_SPATIALGROUP_ 00026 #define _PHYSICS_SPATIALGROUP_ 00027 00028 #include <physics/physics> 00029 00030 #include <base/ReferencedObject> 00031 #include <base/Named> 00032 #include <physics/Spatial> 00033 00034 #include <base/reflist> 00035 #include <physics/Body> 00036 00037 00038 namespace physics { 00039 00040 /// A collection of spatial entities 00041 class SpatialGroup : public Spatial 00042 { 00043 public: 00044 SpatialGroup(); 00045 SpatialGroup(const String& name); 00046 SpatialGroup(const SpatialGroup& bg); 00047 virtual ~SpatialGroup(); 00048 00049 virtual String className() const { return String("SpatialGroup"); } 00050 00051 00052 virtual SpatialGroup& operator=(const SpatialGroup& sg); 00053 00054 virtual void setImplicitConfiguration(ref<Spatial> spatial); 00055 virtual void setExplicitConfiguration(const base::Transform& configuration); 00056 00057 virtual void setPosition(const Point3& pos); 00058 virtual Point3 getPosition() const; 00059 virtual void setOrientation(const Orient& orient); 00060 virtual Orient getOrientation() const; 00061 virtual void setConfiguration(const base::Transform& configuration); 00062 00063 virtual void add(ref<Spatial> spatial); 00064 virtual void remove(ref<Spatial> spatial); 00065 virtual void clear(); 00066 00067 typedef base::reflist<Spatial> SpatialList; 00068 typedef SpatialList::iterator iterator; 00069 typedef SpatialList::const_iterator const_iterator; 00070 00071 iterator begin() { return spatials.begin(); } 00072 iterator end() { return spatials.end(); } 00073 const_iterator begin() const { return spatials.begin(); } 00074 const_iterator end() const { return spatials.end(); } 00075 00076 virtual void updateGroupPositionOrientation(const Point3& pos, const Orient& orient); 00077 virtual void updateGroupConfiguration(const base::Transform& configuration); 00078 00079 protected: 00080 SpatialList spatials; 00081 00082 private: 00083 bool implicit; ///< if true, the configuration of this group is implicit (i.e. it is that of spatial) 00084 00085 ref<Spatial> spatial; ///< if implicit, the configuration of this group is the same configuration of this spatial 00086 00087 Point3 position; ///< if explicit, origin of this group (i.e. its position) 00088 Orient orient; ///< if explicit, orientation of this group 00089 00090 friend std::ostream& operator<<(std::ostream& out, const SpatialGroup& sg); 00091 }; 00092 00093 00094 inline std::ostream& operator<<(std::ostream& out, const SpatialGroup& sg) // Output 00095 { 00096 SpatialGroup::SpatialList::const_iterator s = sg.spatials.begin(); 00097 SpatialGroup::SpatialList::const_iterator end = sg.spatials.end(); 00098 while (s != end) { 00099 out << *(*s); 00100 s++; 00101 } 00102 return out; 00103 } 00104 00105 00106 } // physics 00107 00108 #endif