|
movable.h00001 /* 00002 Copyright (C) 2000 by Jorrit Tyberghein 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library 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 GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public 00015 License along with this library; if not, write to the Free 00016 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00017 */ 00018 00019 #ifndef __CS_MOVABLE_H__ 00020 #define __CS_MOVABLE_H__ 00021 00022 #include "csutil/typedvec.h" 00023 #include "csutil/nobjvec.h" 00024 #include "iengine/movable.h" 00025 #include "iengine/sector.h" 00026 00027 class csVector3; 00028 class csMatrix3; 00029 class csMovable; 00030 class csMeshWrapper; 00031 00032 CS_DECLARE_TYPED_VECTOR_NODELETE (csMovableListenerVector, iMovableListener); 00033 CS_DECLARE_RESTRICTED_ACCESS_OBJECT_VECTOR (csSectorVector, iSector); 00034 00036 class csMovableSectorList : public csSectorVector 00037 { 00038 private: 00039 csMovable* movable; 00040 00041 public: 00042 SCF_DECLARE_IBASE; 00043 00044 csMovableSectorList (); 00045 ~csMovableSectorList (); 00046 void SetMovable (csMovable* mov) { movable = mov; } 00047 00048 virtual bool PrepareItem (csSome item); 00049 virtual bool FreeItem (csSome item); 00050 00051 class SectorList : public iSectorList 00052 { 00053 public: 00054 SCF_DECLARE_EMBEDDED_IBASE (csMovableSectorList); 00055 00056 virtual int GetCount () const; 00057 virtual iSector *Get (int n) const; 00058 virtual int Add (iSector *obj); 00059 virtual bool Remove (iSector *obj); 00060 virtual bool Remove (int n); 00061 virtual void RemoveAll (); 00062 virtual int Find (iSector *obj) const; 00063 virtual iSector *FindByName (const char *Name) const; 00064 } scfiSectorList; 00065 }; 00066 00074 class csMovable : public iBase 00075 { 00076 private: 00078 csReversibleTransform obj; 00080 csMovableSectorList sectors; 00082 csMovableListenerVector listeners; 00084 csVector listener_userdata; 00085 00093 iMovable* parent; 00094 00098 csMeshWrapper* object; 00099 00101 long updatenr; 00102 00103 public: 00107 csMovable (); 00108 00110 virtual ~csMovable (); 00111 00113 void SetMeshWrapper (csMeshWrapper* obj) 00114 { object = obj; } 00115 00117 csMeshWrapper* GetMeshWrapper () 00118 { return object; } 00119 00121 void SetParent (iMovable* par) 00122 { parent = par; } 00123 00125 iMovable* GetParent () const 00126 { return parent; } 00127 00133 void SetSector (iSector* sector); 00134 00139 void ClearSectors (); 00140 00146 iSectorList *GetSectors () 00147 { 00148 if (parent) return parent->GetSectors (); 00149 else return §ors.scfiSectorList; 00150 } 00151 00155 bool InSector () const 00156 { 00157 return sectors.Length () > 0; 00158 } 00159 00164 void SetPosition (iSector* home, const csVector3& v); 00165 00170 void SetPosition (const csVector3& v) 00171 { 00172 obj.SetOrigin (v); 00173 } 00174 00178 const csVector3& GetPosition () const { return obj.GetOrigin (); } 00179 00185 const csVector3 GetFullPosition () const 00186 { 00187 return GetFullTransform ().GetOrigin (); 00188 } 00189 00193 void SetTransform (const csMatrix3& matrix); 00194 00198 void SetTransform (const csReversibleTransform& t) { obj = t; } 00199 00203 csReversibleTransform& GetTransform () { return obj; } 00204 00208 const csReversibleTransform& GetTransform () const { return obj; } 00209 00214 csReversibleTransform GetFullTransform () const; 00215 00219 void MovePosition (const csVector3& v); 00220 00224 void Transform (const csMatrix3& matrix); 00225 00231 void UpdateMove (); 00232 00237 void AddListener (iMovableListener* listener, void* userdata); 00238 00242 void RemoveListener (iMovableListener* listener); 00243 00249 long GetUpdateNumber () const { return updatenr; } 00250 00251 SCF_DECLARE_IBASE; 00252 00253 //------------------------- iMovable interface ------------------------------- 00254 struct eiMovable : public iMovable 00255 { 00256 SCF_DECLARE_EMBEDDED_IBASE (csMovable); 00257 virtual iMovable* GetParent () const; 00258 virtual void SetParent (iMovable* parent) 00259 { 00260 scfParent->SetParent (parent); 00261 } 00262 virtual void SetSector (iSector* sector); 00263 virtual void ClearSectors (); 00264 virtual iSectorList *GetSectors (); 00265 virtual bool InSector () const; 00266 virtual void SetPosition (iSector* home, const csVector3& v); 00267 virtual void SetPosition (const csVector3& v); 00268 virtual const csVector3& GetPosition () const; 00269 virtual const csVector3 GetFullPosition () const; 00270 virtual void SetTransform (const csMatrix3& matrix); 00271 virtual void SetTransform (const csReversibleTransform& t); 00272 virtual csReversibleTransform& GetTransform (); 00273 virtual csReversibleTransform GetFullTransform () const; 00274 virtual void MovePosition (const csVector3& v); 00275 virtual void Transform (const csMatrix3& matrix); 00276 virtual void AddListener (iMovableListener* listener, void* userdata); 00277 virtual void RemoveListener (iMovableListener* listener); 00278 virtual void UpdateMove (); 00279 virtual long GetUpdateNumber () const; 00280 } scfiMovable; 00281 friend struct eiMovable; 00282 }; 00283 00284 #endif // __CS_MOVABLE_H__ Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000 |