CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

movable.h

00001 /*
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/refarr.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 
00033 class csMovableSectorList : public csRefArrayObject<iSector>
00034 {
00035 private:
00036   csMovable* movable;
00037 
00038 public:
00039   SCF_DECLARE_IBASE;
00040 
00041   csMovableSectorList ();
00042   virtual ~csMovableSectorList ();
00043   void SetMovable (csMovable* mov) { movable = mov; }
00044 
00045   bool PrepareItem (iSector* item);
00046 
00047   class SectorList : public iSectorList
00048   {
00049   public:
00050     SCF_DECLARE_EMBEDDED_IBASE (csMovableSectorList);
00051 
00052     virtual int GetCount () const;
00053     virtual iSector *Get (int n) const;
00054     virtual int Add (iSector *obj);
00055     virtual bool Remove (iSector *obj);
00056     virtual bool Remove (int n);
00057     virtual void RemoveAll ();
00058     virtual int Find (iSector *obj) const;
00059     virtual iSector *FindByName (const char *Name) const;
00060   } scfiSectorList;
00061 };
00062 
00070 class csMovable : public iBase
00071 {
00072 private:
00074   csReversibleTransform obj;
00076   bool is_identity;
00078   csMovableSectorList sectors;
00080   csRefArray<iMovableListener> listeners;
00081 
00089   iMovable* parent;
00090 
00094   csMeshWrapper* object;
00095 
00097   long updatenr;
00098 
00099 public:
00103   csMovable ();
00104 
00106   virtual ~csMovable ();
00107 
00109   void SetMeshWrapper (csMeshWrapper* obj)
00110   { object = obj; }
00111 
00113   csMeshWrapper* GetMeshWrapper ()
00114   { return object; }
00115 
00117   void SetParent (iMovable* par)
00118   { parent = par; }
00119 
00121   iMovable* GetParent () const
00122   { return parent; }
00123 
00129   void SetSector (iSector* sector);
00130 
00135   void ClearSectors ();
00136 
00142   iSectorList *GetSectors ()
00143   {
00144     if (parent) return parent->GetSectors ();
00145     else return &sectors.scfiSectorList;
00146   }
00147 
00151   bool InSector () const
00152   {
00153     return sectors.Length () > 0;
00154   }
00155 
00160   void SetPosition (iSector* home, const csVector3& v);
00161 
00166   void SetPosition (const csVector3& v)
00167   {
00168     obj.SetOrigin (v);
00169   }
00170 
00174   const csVector3& GetPosition () const { return obj.GetOrigin (); }
00175 
00181   const csVector3 GetFullPosition () const
00182   {
00183     return GetFullTransform ().GetOrigin ();
00184   }
00185 
00189   void SetTransform (const csMatrix3& matrix);
00190 
00194   void SetTransform (const csReversibleTransform& t) { obj = t; }
00195 
00199   csReversibleTransform& GetTransform () { return obj; }
00200 
00204   const csReversibleTransform& GetTransform () const { return obj; }
00205 
00210   csReversibleTransform GetFullTransform () const;
00211 
00215   void MovePosition (const csVector3& v);
00216 
00220   void Transform (const csMatrix3& matrix);
00221 
00227   void UpdateMove ();
00228 
00233   void AddListener (iMovableListener* listener);
00234 
00238   void RemoveListener (iMovableListener* listener);
00239 
00245   long GetUpdateNumber () const { return updatenr; }
00246 
00247   bool IsTransformIdentity () const
00248   {
00249     return is_identity;
00250   }
00251   bool IsFullTransformIdentity () const
00252   {
00253     if (!is_identity) return false;
00254     if (parent != 0)
00255       return parent->IsFullTransformIdentity ();
00256     return true;
00257   }
00258   void TransformIdentity ()
00259   {
00260     obj.Identity ();
00261   }
00262 
00263   SCF_DECLARE_IBASE;
00264 
00265   //------------------------- iMovable interface -------------------------------
00266   struct eiMovable : public iMovable
00267   {
00268     SCF_DECLARE_EMBEDDED_IBASE (csMovable);
00269     virtual iMovable* GetParent () const;
00270     virtual void SetParent (iMovable* parent)
00271     {
00272       scfParent->SetParent (parent);
00273     }
00274     virtual void SetSector (iSector* sector);
00275     virtual void ClearSectors ();
00276     virtual iSectorList *GetSectors ();
00277     virtual bool InSector () const;
00278     virtual void SetPosition (iSector* home, const csVector3& v);
00279     virtual void SetPosition (const csVector3& v);
00280     virtual const csVector3& GetPosition () const;
00281     virtual const csVector3 GetFullPosition () const;
00282     virtual void SetTransform (const csMatrix3& matrix);
00283     virtual void SetTransform (const csReversibleTransform& t);
00284     virtual csReversibleTransform& GetTransform ();
00285     virtual csReversibleTransform GetFullTransform () const;
00286     virtual void MovePosition (const csVector3& v);
00287     virtual void Transform (const csMatrix3& matrix);
00288     virtual void AddListener (iMovableListener* listener);
00289     virtual void RemoveListener (iMovableListener* listener);
00290     virtual void UpdateMove ();
00291     virtual long GetUpdateNumber () const;
00292     virtual bool IsTransformIdentity () const
00293     {
00294       return scfParent->IsTransformIdentity ();
00295     }
00296     virtual bool IsFullTransformIdentity () const
00297     {
00298       return scfParent->IsFullTransformIdentity ();
00299     }
00300     virtual void TransformIdentity ()
00301     {
00302       scfParent->TransformIdentity ();
00303     }
00304   } scfiMovable;
00305   friend struct eiMovable;
00306 };
00307 
00308 #endif // __CS_MOVABLE_H__

Generated for Crystal Space by doxygen 1.2.14