Main Page   Class Hierarchy   Compound List   File List   Compound Members  

meshobj.h

00001 /*
00002     Copyright (C) 2000-2001 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_MESHOBJ_H__
00020 #define __CS_MESHOBJ_H__
00021 
00022 #include "csgeom/transfrm.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/nobjvec.h"
00025 #include "csutil/flags.h"
00026 #include "csutil/garray.h"
00027 #include "csengine/movable.h"
00028 #include "imesh/object.h"
00029 #include "iengine/mesh.h"
00030 #include "iengine/viscull.h"
00031 #include "ivideo/graph3d.h"
00032 
00033 struct iMeshWrapper;
00034 struct iRenderView;
00035 struct iMovable;
00036 class csMeshWrapper;
00037 class csCamera;
00038 class csMeshFactoryWrapper;
00039 class csLight;
00040 
00041 CS_DECLARE_OBJECT_VECTOR (csMeshListHelper, iMeshWrapper);
00042 
00048 class csMeshList : public csMeshListHelper
00049 {
00050 public:
00051   SCF_DECLARE_IBASE;
00052 
00054   csMeshList ();
00056   ~csMeshList ();
00057 
00059   virtual bool FreeItem (csSome Item);
00061   virtual void AddMesh (iMeshWrapper* mesh);
00063   virtual void RemoveMesh (iMeshWrapper* mesh);
00064 
00065   class MeshList : public iMeshList
00066   {
00067     SCF_DECLARE_EMBEDDED_IBASE (csMeshList);
00068     virtual int GetCount () const;
00069     virtual iMeshWrapper *Get (int n) const;
00070     virtual int Add (iMeshWrapper *obj);
00071     virtual bool Remove (iMeshWrapper *obj);
00072     virtual bool Remove (int n);
00073     virtual void RemoveAll ();
00074     virtual int Find (iMeshWrapper *obj) const;
00075     virtual iMeshWrapper *FindByName (const char *Name) const;
00076   } scfiMeshList;
00077 };
00078 
00082 class csMeshMeshList : public csMeshList
00083 {
00084 private:
00085   csMeshWrapper* mesh;
00086 
00087 public:
00088   csMeshMeshList () : mesh (NULL) { }
00089   void SetMesh (csMeshWrapper* m) { mesh = m; }
00090   virtual void AddMesh (iMeshWrapper* child);
00091   virtual void RemoveMesh (iMeshWrapper* child);
00092 };
00093 
00094 CS_DECLARE_OBJECT_VECTOR (csMeshFactoryListHelper, iMeshFactoryWrapper);
00095 
00099 class csMeshFactoryList : public csMeshFactoryListHelper
00100 {
00101 public:
00102   SCF_DECLARE_IBASE;
00103 
00105   csMeshFactoryList ();
00107   ~csMeshFactoryList ();
00108 
00110   virtual void AddMeshFactory (iMeshFactoryWrapper* mesh);
00112   virtual void RemoveMeshFactory (iMeshFactoryWrapper* mesh);
00113 
00114   class MeshFactoryList : public iMeshFactoryList
00115   {
00116     SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryList);
00117     virtual int GetCount () const;
00118     virtual iMeshFactoryWrapper *Get (int n) const;
00119     virtual int Add (iMeshFactoryWrapper *obj);
00120     virtual bool Remove (iMeshFactoryWrapper *obj);
00121     virtual bool Remove (int n);
00122     virtual void RemoveAll ();
00123     virtual int Find (iMeshFactoryWrapper *obj) const;
00124     virtual iMeshFactoryWrapper *FindByName (const char *Name) const;
00125   } scfiMeshFactoryList;
00126 };
00127 
00131 class csMeshFactoryFactoryList : public csMeshFactoryList
00132 {
00133 private:
00134   csMeshFactoryWrapper* meshfact;
00135 
00136 public:
00137   csMeshFactoryFactoryList () : meshfact (NULL) { }
00138   void SetMeshFactory (csMeshFactoryWrapper* m) { meshfact = m; }
00139   virtual void AddMeshFactory (iMeshFactoryWrapper* child);
00140   virtual void RemoveMeshFactory (iMeshFactoryWrapper* child);
00141 };
00142 
00143 SCF_VERSION (csMeshWrapper, 0, 0, 1);
00144 
00148 class csMeshWrapper : public csObject
00149 {
00150   friend class csMovable;
00151   friend class csMovableSectorList;
00152 
00153 protected:
00154 
00156   iMeshWrapper *Parent;
00157 
00163   csBox3 wor_bbox;
00165   long wor_bbox_movablenr;
00166 
00168   int defered_num_lights;
00169 
00171   int defered_lighting_flags;
00172 
00179   csTicks last_anim_time;
00180 
00187   bool is_visible;
00188 
00192   csMovable movable;
00193 
00200   long render_priority;
00201 
00203   void UpdateDeferedLighting (const csVector3& pos);
00204 
00205 private:
00207   iMeshObject* mesh;
00208 
00210   csMeshMeshList children;
00211 
00213   iMeshDrawCallback* draw_cb;
00214 
00216   csMeshFactoryWrapper* factory;
00217 
00219   csZBufMode zbufMode;
00220 
00221 public:
00223   csFlags flags;
00224 
00225 protected:
00227   void MoveToSector (csSector* s);
00228 
00230   void RemoveFromSectors ();
00231 
00239   void UpdateMove ();
00240 
00246   void DrawInt (iRenderView* rview);
00247 
00252   virtual ~csMeshWrapper ();
00253 
00254 public:
00256   csMeshWrapper (iMeshWrapper* theParent, iMeshObject* mesh);
00258   csMeshWrapper (iMeshWrapper* theParent);
00259 
00261   void SetParentContainer (iMeshWrapper* newParent) { Parent = newParent; }
00263   iMeshWrapper* GetParentContainer () const { return Parent; }
00264 
00266   void SetFactory (csMeshFactoryWrapper* factory)
00267   {
00268     csMeshWrapper::factory = factory;
00269   }
00271   csMeshFactoryWrapper* GetFactory () const
00272   {
00273     return factory;
00274   }
00275 
00277   void SetMeshObject (iMeshObject* mesh);
00279   iMeshObject* GetMeshObject () const {return mesh;}
00280 
00282   void SetZBufMode (csZBufMode mode) { zbufMode = mode; }
00284   csZBufMode GetZBufMode () const { return zbufMode; }
00285 
00294   void SetDrawCallback (iMeshDrawCallback* cb)
00295   {
00296     if (cb) cb->IncRef ();
00297     if (draw_cb) draw_cb->DecRef ();
00298     draw_cb = cb;
00299   }
00300 
00302   iMeshDrawCallback* GetDrawCallback () const
00303   {
00304     return draw_cb;
00305   }
00306 
00308   void MarkVisible () { is_visible = true; }
00309 
00311   void MarkInvisible () { is_visible = false; }
00312 
00314   bool IsVisible () const { return is_visible; }
00315 
00320   void UpdateLighting (iLight** lights, int num_lights);
00321 
00327   void DeferUpdateLighting (int flags, int num_lights);
00328 
00334   void Draw (iRenderView* rview);
00335 
00337   bool WantToDie () { return mesh->WantToDie (); }
00338 
00346   csMovable& GetMovable () { return movable; }
00347 
00360   void PlaceMesh ();
00361 
00366   int HitBeamBBox (const csVector3& start, const csVector3& end, 
00367          csVector3& isect, float* pr);
00372   bool HitBeamOutline (const csVector3& start, const csVector3& end,
00373          csVector3& isect, float* pr);
00378   bool HitBeamObject (const csVector3& start, const csVector3& end,
00379         csVector3& isect, float* pr);
00384   bool HitBeam (const csVector3& start, const csVector3& end,
00385         csVector3& isect, float* pr);
00386 
00388   const csMeshMeshList& GetChildren () const { return children; }
00389 
00391   void GetRadius (csVector3& rad, csVector3& cent) const 
00392         { mesh->GetRadius (rad,cent); }
00393 
00403   void HardTransform (const csReversibleTransform& t);
00404 
00410   void GetWorldBoundingBox (csBox3& cbox);
00411 
00417   void GetTransformedBoundingBox (const csReversibleTransform& trans,
00418         csBox3& cbox);
00419 
00425   float GetScreenBoundingBox (const csCamera& camera, csBox2& sbox,
00426         csBox3& cbox);
00427 
00432   void Rotate (float angle);
00433 
00438   void ScaleBy (float factor);
00439 
00441   void SetRenderPriority (long rp);
00443   long GetRenderPriority () const
00444   {
00445     return render_priority;
00446   }
00447 
00449   void AddChild (iMeshWrapper* child);
00451   void RemoveChild (iMeshWrapper* child);
00452 
00453   SCF_DECLARE_IBASE_EXT (csObject);
00454 
00455   //--------------------- iMeshWrapper implementation --------------------//
00456   struct MeshWrapper : public iMeshWrapper
00457   {
00458     SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00459     virtual csMeshWrapper* GetPrivateObject ()
00460     {
00461       return (csMeshWrapper*)scfParent;
00462     }
00463     virtual iMeshObject* GetMeshObject () const
00464     {
00465       return scfParent->GetMeshObject ();
00466     }
00467     virtual void SetMeshObject (iMeshObject* m)
00468     {
00469       scfParent->SetMeshObject (m);
00470     }
00471     virtual iObject *QueryObject ()
00472     {
00473       return scfParent;
00474     }
00475     virtual void DeferUpdateLighting (int flags, int num_lights)
00476     {
00477       scfParent->DeferUpdateLighting (flags, num_lights);
00478     }
00479     virtual void UpdateLighting (iLight** lights, int num_lights)
00480     {
00481       scfParent->UpdateLighting (lights, num_lights);
00482     }
00483     virtual iMovable* GetMovable () const
00484     {
00485       return &(scfParent->movable.scfiMovable);
00486     }
00487     virtual void PlaceMesh ()
00488     {
00489       scfParent->PlaceMesh ();
00490     }
00491     virtual int HitBeamBBox (const csVector3& start, const csVector3& end,
00492           csVector3& isect, float* pr)
00493     {
00494       return scfParent->HitBeamBBox (start, end, isect, pr);
00495     }
00496     virtual bool HitBeamOutline (const csVector3& start, const csVector3& end,
00497           csVector3& isect, float* pr)
00498     {
00499       return scfParent->HitBeamOutline (start, end, isect, pr);
00500     }
00501     virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00502         csVector3& isect, float* pr)
00503     {
00504       return scfParent->HitBeamObject (start, end, isect, pr);
00505     }
00506     virtual bool HitBeam (const csVector3& start, const csVector3& end,
00507         csVector3& isect, float* pr)
00508     {
00509       return scfParent->HitBeam (start, end, isect, pr);
00510     }
00511     virtual void SetDrawCallback (iMeshDrawCallback* cb)
00512     {
00513       scfParent->SetDrawCallback (cb);
00514     }
00515     virtual iMeshDrawCallback* GetDrawCallback () const
00516     {
00517       return scfParent->GetDrawCallback ();
00518     }
00519     virtual void SetFactory (iMeshFactoryWrapper* factory);
00520     virtual void SetRenderPriority (long rp)
00521     {
00522       scfParent->SetRenderPriority (rp);
00523     }
00524     virtual long GetRenderPriority () const
00525     {
00526       return scfParent->GetRenderPriority ();
00527     }
00528     virtual csFlags& GetFlags ()
00529     {
00530       return scfParent->flags;
00531     }
00532     virtual void SetZBufMode (csZBufMode mode)
00533     {
00534       scfParent->SetZBufMode (mode);
00535     }
00536     virtual csZBufMode GetZBufMode () const
00537     {
00538       return scfParent->GetZBufMode ();
00539     }
00540     virtual void HardTransform (const csReversibleTransform& t)
00541     {
00542       scfParent->HardTransform (t);
00543     }
00544     virtual void GetWorldBoundingBox (csBox3& cbox)
00545     {
00546       scfParent->GetWorldBoundingBox (cbox);
00547     }
00548     virtual void GetTransformedBoundingBox (const csReversibleTransform& trans,
00549         csBox3& cbox)
00550     {
00551       scfParent->GetTransformedBoundingBox (trans, cbox);
00552     }
00553     virtual float GetScreenBoundingBox (iCamera* camera, csBox2& sbox,
00554         csBox3& cbox);
00555     virtual iMeshList* GetChildren ()
00556     {
00557       return &(scfParent->children.scfiMeshList);
00558     }
00559     virtual iMeshWrapper* GetParentContainer ()
00560     {
00561       return scfParent->GetParentContainer ();
00562     }
00563     virtual void SetParentContainer (iMeshWrapper* p)
00564     {
00565       scfParent->SetParentContainer (p);
00566     }
00567     virtual void GetRadius (csVector3& rad, csVector3 &cent) const 
00568           { scfParent->GetRadius (rad,cent); }
00569     virtual void Draw (iRenderView* rview)
00570     {
00571       scfParent->Draw (rview);
00572     }
00573     virtual bool WantToDie ()
00574     {
00575       return scfParent->WantToDie ();
00576     }
00577   } scfiMeshWrapper;
00578   friend struct MeshWrapper;
00579 
00580   //-------------------- iVisibilityObject interface implementation ----------
00581   struct VisObject : public iVisibilityObject
00582   {
00583     SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00584     virtual iMovable* GetMovable () const
00585     {
00586       return &(scfParent->movable.scfiMovable);
00587     }
00588     virtual long GetShapeNumber () const
00589     {
00590       return scfParent->mesh->GetShapeNumber ();
00591     }
00592     virtual void GetBoundingBox (csBox3& bbox)
00593     {
00594       scfParent->mesh->GetObjectBoundingBox (bbox, CS_BBOX_MAX);
00595     }
00596     virtual void MarkVisible () { scfParent->MarkVisible (); }
00597     virtual void MarkInvisible () { scfParent->MarkInvisible (); }
00598     virtual bool IsVisible () const { return scfParent->IsVisible (); }
00599   } scfiVisibilityObject;
00600   friend struct VisObject;
00601 };
00602 
00603 SCF_VERSION (csMeshFactoryWrapper, 0, 0, 3);
00604 
00608 class csMeshFactoryWrapper : public csObject
00609 {
00610 private:
00612   iMeshObjectFactory* meshFact;
00613 
00615   csMeshFactoryWrapper* parent;
00617   csReversibleTransform transform;
00618 
00620   csMeshFactoryFactoryList children;
00621 
00622 private:
00624   virtual ~csMeshFactoryWrapper ();
00625 
00626 public:
00628   csMeshFactoryWrapper (iMeshObjectFactory* meshFact);
00630   csMeshFactoryWrapper ();
00631 
00633   void SetMeshObjectFactory (iMeshObjectFactory* meshFact);
00634 
00636   iMeshObjectFactory* GetMeshObjectFactory () const
00637   {
00638     return meshFact;
00639   }
00640 
00644   csMeshWrapper* NewMeshObject ();
00645 
00655   void HardTransform (const csReversibleTransform& t);
00656 
00658   void AddChild (iMeshFactoryWrapper* child);
00660   void RemoveChild (iMeshFactoryWrapper* child);
00661 
00665   csReversibleTransform& GetTransform () { return transform; }
00666 
00670   void SetTransform (const csReversibleTransform& tr) { transform = tr; }
00671 
00672   SCF_DECLARE_IBASE_EXT (csObject);
00673 
00674   //----------------- iMeshFactoryWrapper implementation --------------------//
00675   struct MeshFactoryWrapper : public iMeshFactoryWrapper
00676   {
00677     SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryWrapper);
00678     virtual csMeshFactoryWrapper* GetPrivateObject ()
00679     {
00680       return (csMeshFactoryWrapper*)scfParent;
00681     }
00682     virtual iMeshObjectFactory* GetMeshObjectFactory () const
00683     {
00684       return scfParent->GetMeshObjectFactory ();
00685     }
00686     virtual void SetMeshObjectFactory (iMeshObjectFactory* fact)
00687     {
00688       scfParent->SetMeshObjectFactory (fact);
00689     }
00690     virtual iObject *QueryObject ()
00691     {
00692       return scfParent;
00693     }
00694     virtual void HardTransform (const csReversibleTransform& t)
00695     {
00696       scfParent->HardTransform (t);
00697     }
00698     virtual iMeshWrapper* CreateMeshWrapper ();
00699     virtual iMeshFactoryWrapper* GetParentContainer () const;
00700     virtual iMeshFactoryList* GetChildren ()
00701     {
00702       return &(scfParent->children.scfiMeshFactoryList);
00703     }
00704     virtual csReversibleTransform& GetTransform ()
00705     {
00706       return scfParent->GetTransform ();
00707     }
00708     virtual void SetTransform (const csReversibleTransform& tr)
00709     {
00710       scfParent->SetTransform (tr);
00711     }
00712   } scfiMeshFactoryWrapper;
00713   friend struct MeshFactoryWrapper;
00714 };
00715 
00716 #endif // __CS_MESHOBJ_H__

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000