Google

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 csMeshFactoryWrapper;
00038 class csLight;
00039 
00040 CS_DECLARE_OBJECT_VECTOR (csMeshListHelper, iMeshWrapper);
00041 
00047 class csMeshList : public csMeshListHelper
00048 {
00049 public:
00050   SCF_DECLARE_IBASE;
00051 
00053   csMeshList ();
00054 
00055   class MeshList : public iMeshList
00056   {
00057     SCF_DECLARE_EMBEDDED_IBASE (csMeshList);
00058     virtual int GetCount () const;
00059     virtual iMeshWrapper *Get (int n) const;
00060     virtual int Add (iMeshWrapper *obj);
00061     virtual bool Remove (iMeshWrapper *obj);
00062     virtual bool Remove (int n);
00063     virtual void RemoveAll ();
00064     virtual int Find (iMeshWrapper *obj) const;
00065     virtual iMeshWrapper *FindByName (const char *Name) const;
00066   } scfiMeshList;
00067 };
00068 
00072 class csMeshMeshList : public csMeshList
00073 {
00074 private:
00075   csMeshWrapper* mesh;
00076 
00077 public:
00078   csMeshMeshList () : mesh (NULL) { }
00079   ~csMeshMeshList () { DeleteAll (); }
00080   void SetMesh (csMeshWrapper* m) { mesh = m; }
00081   virtual bool PrepareItem (csSome Item);
00082   virtual bool FreeItem (csSome Item);
00083 };
00084 
00085 CS_DECLARE_OBJECT_VECTOR (csMeshFactoryListHelper, iMeshFactoryWrapper);
00086 
00090 class csMeshFactoryList : public csMeshFactoryListHelper
00091 {
00092 public:
00093   SCF_DECLARE_IBASE;
00094 
00096   csMeshFactoryList ();
00097 
00098   class MeshFactoryList : public iMeshFactoryList
00099   {
00100     SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryList);
00101     virtual int GetCount () const;
00102     virtual iMeshFactoryWrapper *Get (int n) const;
00103     virtual int Add (iMeshFactoryWrapper *obj);
00104     virtual bool Remove (iMeshFactoryWrapper *obj);
00105     virtual bool Remove (int n);
00106     virtual void RemoveAll ();
00107     virtual int Find (iMeshFactoryWrapper *obj) const;
00108     virtual iMeshFactoryWrapper *FindByName (const char *Name) const;
00109   } scfiMeshFactoryList;
00110 };
00111 
00115 class csMeshFactoryFactoryList : public csMeshFactoryList
00116 {
00117 private:
00118   csMeshFactoryWrapper* meshfact;
00119 
00120 public:
00121   csMeshFactoryFactoryList () : meshfact (NULL) {}
00122   ~csMeshFactoryFactoryList () { DeleteAll (); }
00123   void SetMeshFactory (csMeshFactoryWrapper* m) { meshfact = m; }
00124   virtual bool PrepareItem (csSome Item);
00125   virtual bool FreeItem (csSome Item);
00126 };
00127 
00128 SCF_VERSION (csMeshWrapper, 0, 0, 1);
00129 
00133 class csMeshWrapper : public csObject
00134 {
00135   friend class csMovable;
00136   friend class csMovableSectorList;
00137 
00138 protected:
00139 
00141   iMeshWrapper *Parent;
00142 
00148   csBox3 wor_bbox;
00150   long wor_bbox_movablenr;
00151 
00153   int defered_num_lights;
00154 
00156   int defered_lighting_flags;
00157 
00164   csTicks last_anim_time;
00165 
00172   bool is_visible;
00173 
00177   csMovable movable;
00178 
00185   long render_priority;
00186 
00188   void UpdateDeferedLighting (const csVector3& pos);
00189 
00190 private:
00192   iMeshObject* mesh;
00193 
00195   csMeshMeshList children;
00196 
00198   iMeshDrawCallback* draw_cb;
00199 
00201   iMeshFactoryWrapper* factory;
00202 
00204   csZBufMode zbufMode;
00205 
00206 public:
00208   csFlags flags;
00209 
00210 protected:
00212   void MoveToSector (csSector* s);
00213 
00215   void RemoveFromSectors ();
00216 
00224   void UpdateMove ();
00225 
00231   void DrawInt (iRenderView* rview);
00232 
00237   virtual ~csMeshWrapper ();
00238 
00239 public:
00241   csMeshWrapper (iMeshWrapper* theParent, iMeshObject* mesh);
00243   csMeshWrapper (iMeshWrapper* theParent);
00244 
00246   void SetParentContainer (iMeshWrapper* newParent) { Parent = newParent; }
00248   iMeshWrapper* GetParentContainer () const { return Parent; }
00249 
00251   void SetFactory (iMeshFactoryWrapper* factory)
00252   {
00253     csMeshWrapper::factory = factory;
00254   }
00256   iMeshFactoryWrapper* GetFactory () const
00257   {
00258     return factory;
00259   }
00260 
00262   void SetMeshObject (iMeshObject* mesh);
00264   iMeshObject* GetMeshObject () const {return mesh;}
00265 
00267   void SetZBufMode (csZBufMode mode) { zbufMode = mode; }
00269   csZBufMode GetZBufMode () const { return zbufMode; }
00270 
00279   void SetDrawCallback (iMeshDrawCallback* cb)
00280   {
00281     if (cb) cb->IncRef ();
00282     if (draw_cb) draw_cb->DecRef ();
00283     draw_cb = cb;
00284   }
00285 
00287   iMeshDrawCallback* GetDrawCallback () const
00288   {
00289     return draw_cb;
00290   }
00291 
00293   void MarkVisible () { is_visible = true; }
00294 
00296   void MarkInvisible () { is_visible = false; }
00297 
00299   bool IsVisible () const { return is_visible; }
00300 
00305   void UpdateLighting (iLight** lights, int num_lights);
00306 
00312   void DeferUpdateLighting (int flags, int num_lights);
00313 
00319   void Draw (iRenderView* rview);
00320 
00322   bool WantToDie () { return mesh->WantToDie (); }
00323 
00331   csMovable& GetMovable () { return movable; }
00332 
00345   void PlaceMesh ();
00346 
00351   int HitBeamBBox (const csVector3& start, const csVector3& end,
00352          csVector3& isect, float* pr);
00357   bool HitBeamOutline (const csVector3& start, const csVector3& end,
00358          csVector3& isect, float* pr);
00363   bool HitBeamObject (const csVector3& start, const csVector3& end,
00364         csVector3& isect, float* pr);
00369   bool HitBeam (const csVector3& start, const csVector3& end,
00370         csVector3& isect, float* pr);
00371 
00373   const csMeshMeshList& GetChildren () const { return children; }
00374 
00376   void GetRadius (csVector3& rad, csVector3& cent) const;
00377 
00387   void HardTransform (const csReversibleTransform& t);
00388 
00394   void GetWorldBoundingBox (csBox3& cbox);
00395 
00401   void GetTransformedBoundingBox (const csReversibleTransform& trans,
00402         csBox3& cbox);
00403 
00409   float GetScreenBoundingBox (const iCamera *camera, csBox2& sbox,
00410         csBox3& cbox);
00411 
00413   void SetRenderPriority (long rp);
00415   long GetRenderPriority () const
00416   {
00417     return render_priority;
00418   }
00419 
00420   SCF_DECLARE_IBASE_EXT (csObject);
00421 
00422   //--------------------- iMeshWrapper implementation --------------------//
00423   struct MeshWrapper : public iMeshWrapper
00424   {
00425     SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00426     virtual csMeshWrapper* GetPrivateObject ()
00427     {
00428       return (csMeshWrapper*)scfParent;
00429     }
00430     virtual iObject *QueryObject ()
00431     {
00432       return scfParent;
00433     }
00434     virtual iMeshObject* GetMeshObject () const
00435     {
00436       return scfParent->GetMeshObject ();
00437     }
00438     virtual void SetMeshObject (iMeshObject* m)
00439     {
00440       scfParent->SetMeshObject (m);
00441     }
00442     virtual iMeshFactoryWrapper* GetFactory () const
00443     {
00444       return scfParent->GetFactory ();
00445     }
00446     virtual void SetFactory (iMeshFactoryWrapper* m)
00447     {
00448       scfParent->SetFactory (m);
00449     }
00450     virtual void DeferUpdateLighting (int flags, int num_lights)
00451     {
00452       scfParent->DeferUpdateLighting (flags, num_lights);
00453     }
00454     virtual void UpdateLighting (iLight** lights, int num_lights)
00455     {
00456       scfParent->UpdateLighting (lights, num_lights);
00457     }
00458     virtual iMovable* GetMovable () const
00459     {
00460       return &(scfParent->movable.scfiMovable);
00461     }
00462     virtual void PlaceMesh ()
00463     {
00464       scfParent->PlaceMesh ();
00465     }
00466     virtual int HitBeamBBox (const csVector3& start, const csVector3& end,
00467           csVector3& isect, float* pr)
00468     {
00469       return scfParent->HitBeamBBox (start, end, isect, pr);
00470     }
00471     virtual bool HitBeamOutline (const csVector3& start, const csVector3& end,
00472           csVector3& isect, float* pr)
00473     {
00474       return scfParent->HitBeamOutline (start, end, isect, pr);
00475     }
00476     virtual bool HitBeamObject (const csVector3& start, const csVector3& end,
00477         csVector3& isect, float* pr)
00478     {
00479       return scfParent->HitBeamObject (start, end, isect, pr);
00480     }
00481     virtual bool HitBeam (const csVector3& start, const csVector3& end,
00482         csVector3& isect, float* pr)
00483     {
00484       return scfParent->HitBeam (start, end, isect, pr);
00485     }
00486     virtual void SetDrawCallback (iMeshDrawCallback* cb)
00487     {
00488       scfParent->SetDrawCallback (cb);
00489     }
00490     virtual iMeshDrawCallback* GetDrawCallback () const
00491     {
00492       return scfParent->GetDrawCallback ();
00493     }
00494     virtual void SetRenderPriority (long rp)
00495     {
00496       scfParent->SetRenderPriority (rp);
00497     }
00498     virtual long GetRenderPriority () const
00499     {
00500       return scfParent->GetRenderPriority ();
00501     }
00502     virtual csFlags& GetFlags ()
00503     {
00504       return scfParent->flags;
00505     }
00506     virtual void SetZBufMode (csZBufMode mode)
00507     {
00508       scfParent->SetZBufMode (mode);
00509     }
00510     virtual csZBufMode GetZBufMode () const
00511     {
00512       return scfParent->GetZBufMode ();
00513     }
00514     virtual void HardTransform (const csReversibleTransform& t)
00515     {
00516       scfParent->HardTransform (t);
00517     }
00518     virtual void GetWorldBoundingBox (csBox3& cbox)
00519     {
00520       scfParent->GetWorldBoundingBox (cbox);
00521     }
00522     virtual void GetTransformedBoundingBox (const csReversibleTransform& trans,
00523         csBox3& cbox)
00524     {
00525       scfParent->GetTransformedBoundingBox (trans, cbox);
00526     }
00527     virtual float GetScreenBoundingBox (iCamera* camera, csBox2& sbox,
00528         csBox3& cbox);
00529     virtual iMeshList* GetChildren ()
00530     {
00531       return &(scfParent->children.scfiMeshList);
00532     }
00533     virtual iMeshWrapper* GetParentContainer ()
00534     {
00535       return scfParent->GetParentContainer ();
00536     }
00537     virtual void SetParentContainer (iMeshWrapper* p)
00538     {
00539       scfParent->SetParentContainer (p);
00540     }
00541     virtual void GetRadius (csVector3& rad, csVector3 &cent) const
00542     {
00543       scfParent->GetRadius (rad,cent);
00544     }
00545     virtual void Draw (iRenderView* rview)
00546     {
00547       scfParent->Draw (rview);
00548     }
00549     virtual bool WantToDie ()
00550     {
00551       return scfParent->WantToDie ();
00552     }
00553   } scfiMeshWrapper;
00554   friend struct MeshWrapper;
00555 
00556   //-------------------- iVisibilityObject interface implementation ----------
00557   struct VisObject : public iVisibilityObject
00558   {
00559     SCF_DECLARE_EMBEDDED_IBASE (csMeshWrapper);
00560     virtual iMovable* GetMovable () const
00561     {
00562       return &(scfParent->movable.scfiMovable);
00563     }
00564     virtual long GetShapeNumber () const
00565     {
00566       return scfParent->mesh->GetShapeNumber ();
00567     }
00568     virtual void GetBoundingBox (csBox3& bbox)
00569     {
00570       scfParent->mesh->GetObjectBoundingBox (bbox, CS_BBOX_MAX);
00571     }
00572     virtual void MarkVisible () { scfParent->MarkVisible (); }
00573     virtual void MarkInvisible () { scfParent->MarkInvisible (); }
00574     virtual bool IsVisible () const { return scfParent->IsVisible (); }
00575   } scfiVisibilityObject;
00576   friend struct VisObject;
00577 };
00578 
00579 SCF_VERSION (csMeshFactoryWrapper, 0, 0, 3);
00580 
00584 class csMeshFactoryWrapper : public csObject
00585 {
00586 private:
00588   iMeshObjectFactory* meshFact;
00589 
00591   iMeshFactoryWrapper* parent;
00592 
00594   csReversibleTransform transform;
00595 
00597   csMeshFactoryFactoryList children;
00598 
00599 private:
00601   virtual ~csMeshFactoryWrapper ();
00602 
00603 public:
00605   csMeshFactoryWrapper (iMeshObjectFactory* meshFact);
00607   csMeshFactoryWrapper ();
00608 
00610   void SetMeshObjectFactory (iMeshObjectFactory* meshFact);
00611 
00613   iMeshObjectFactory* GetMeshObjectFactory () const
00614   {
00615     return meshFact;
00616   }
00617 
00621   iMeshWrapper* NewMeshObject ();
00622 
00632   void HardTransform (const csReversibleTransform& t);
00633 
00635   void PrepareChild (iMeshFactoryWrapper* child);
00637   void UnprepareChild (iMeshFactoryWrapper* child);
00638 
00642   csReversibleTransform& GetTransform () { return transform; }
00643 
00647   void SetTransform (const csReversibleTransform& tr) { transform = tr; }
00648 
00649   SCF_DECLARE_IBASE_EXT (csObject);
00650 
00651   //----------------- iMeshFactoryWrapper implementation --------------------//
00652   struct MeshFactoryWrapper : public iMeshFactoryWrapper
00653   {
00654     SCF_DECLARE_EMBEDDED_IBASE (csMeshFactoryWrapper);
00655     virtual iMeshObjectFactory* GetMeshObjectFactory () const
00656       { return scfParent->GetMeshObjectFactory (); }
00657     virtual void SetMeshObjectFactory (iMeshObjectFactory* fact)
00658       { scfParent->SetMeshObjectFactory (fact); }
00659     virtual iObject *QueryObject ()
00660       { return scfParent; }
00661     virtual void HardTransform (const csReversibleTransform& t)
00662       { scfParent->HardTransform (t); }
00663     virtual iMeshWrapper* CreateMeshWrapper ()
00664       { return scfParent->NewMeshObject (); }
00665     virtual iMeshFactoryWrapper* GetParentContainer () const
00666       { return scfParent->parent; }
00667     virtual void SetParentContainer (iMeshFactoryWrapper *p)
00668       { scfParent->parent = p; }
00669     virtual iMeshFactoryList* GetChildren ()
00670       { return &(scfParent->children.scfiMeshFactoryList); }
00671     virtual csReversibleTransform& GetTransform ()
00672       { return scfParent->GetTransform (); }
00673     virtual void SetTransform (const csReversibleTransform& tr)
00674       { scfParent->SetTransform (tr); }
00675   } scfiMeshFactoryWrapper;
00676   friend struct MeshFactoryWrapper;
00677 };
00678 
00679 #endif // __CS_MESHOBJ_H__

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