CrystalSpace

Public API Reference

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

sector.h

00001 /*
00002     Copyright (C) 1998-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_SECTOR_H__
00020 #define __CS_SECTOR_H__
00021 
00022 #include "csgeom/math3d.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/nobjvec.h"
00025 #include "csutil/refarr.h"
00026 #include "csutil/cscolor.h"
00027 #include "csutil/array.h"
00028 #include "iutil/objref.h"
00029 #include "csengine/light.h"
00030 #include "csengine/meshobj.h"
00031 #include "csengine/rdrprior.h"
00032 #include "iengine/sector.h"
00033 #include "ivideo/graph3d.h"
00034 #include "csutil/array.h"
00035 #include "ivideo/rndbuf.h"
00036 #include "ivideo/shader/shader.h"
00037 #include "iengine/viscull.h"
00038 
00039 class csEngine;
00040 class csProgressPulse;
00041 class csSector;
00042 class csStatLight;
00043 class csMeshWrapper;
00044 class csKDTree;
00045 struct iPolygon3D;
00046 struct iStatLight;
00047 struct iVisibilityCuller;
00048 struct iRenderView;
00049 struct iMeshWrapper;
00050 struct iFrustumView;
00051 
00053 class csSectorLightList : public csLightList
00054 {
00055 private:
00056   csSector* sector;
00057   csKDTree* kdtree; // kdtree to help find lights faster.
00058 
00059 public:
00061   csSectorLightList ();
00063   virtual ~csSectorLightList ();
00065   void SetSector (csSector* s) { sector = s; }
00066 
00068   virtual void PrepareItem (iLight* light);
00070   virtual void FreeItem (iLight* item);
00071 
00073   csKDTree* GetLightKDTree () const { return kdtree; }
00074 };
00075 
00077 class csSectorMeshList : public csMeshList
00078 {
00079 private:
00080   csSector* sector;
00081 
00082 public:
00084   csSectorMeshList ();
00086   virtual ~csSectorMeshList () { RemoveAll (); }
00088   void SetSector (csSector* sec) { sector = sec; }
00089 
00091   virtual void PrepareItem (iMeshWrapper* item);
00093   virtual void FreeItem (iMeshWrapper* item);
00094 };
00095 
00096 SCF_VERSION (csSector, 0, 0, 2);
00097 
00102 class csSector : public csObject
00103 {
00104 private:
00110   csSectorMeshList meshes;
00111 
00112 
00116   uint32 current_visnr;
00117 
00122   csRenderQueueSet RenderQueues;
00123 
00127   csArray<iReference*> references;
00128 
00132   csRefArray<iSectorCallback> sector_cb_vector;
00133 
00138   csSectorLightList lights;
00139 
00144   csColor dynamic_ambient_color;
00145 
00147   csEngine* engine;
00148 
00150   csFog fog;
00151 
00156   csRef<iVisibilityCuller> culler;
00157 
00158 private:
00164   virtual ~csSector ();
00165 
00166 public:
00171   static bool do_portals;
00172 
00179   static int cfg_reflections;
00180 
00188   static bool do_radiosity;
00189 
00196   int draw_busy;
00197 
00198 public:
00202   csSector (csEngine*);
00203 
00208   void CleanupReferences ();
00209 
00210   //----------------------------------------------------------------------
00211   // Mesh manipulation functions
00212   //----------------------------------------------------------------------
00213 
00214   iMeshList* GetMeshes ()
00215     { return &meshes; }
00216 
00220   void RegisterMeshToCuller (iMeshWrapper* mesh);
00221 
00225   void UnregisterMeshToCuller (iMeshWrapper* mesh);
00226 
00231   void PrepareMesh (iMeshWrapper* mesh);
00232 
00237   void UnprepareMesh (iMeshWrapper* mesh);
00238 
00244   void RelinkMesh (iMeshWrapper* mesh);
00245 
00246   //----------------------------------------------------------------------
00247   // Light manipulation functions
00248   //----------------------------------------------------------------------
00249 
00253   iLightList* GetLights ()
00254     { return &lights; }
00255 
00256   //----------------------------------------------------------------------
00257   // Callbacks
00258   //----------------------------------------------------------------------
00259   void SetSectorCallback (iSectorCallback* cb)
00260   {
00261     sector_cb_vector.Push (cb);
00262   }
00263 
00264   void RemoveSectorCallback (iSectorCallback* cb)
00265   {
00266     sector_cb_vector.Delete (cb);
00267   }
00268 
00269   int GetSectorCallbackCount () const
00270   {
00271     return sector_cb_vector.Length ();
00272   }
00273   
00274   iSectorCallback* GetSectorCallback (int idx) const
00275   {
00276     return sector_cb_vector.Get (idx);
00277   }
00278 
00279   //----------------------------------------------------------------------
00280   // Visibility Stuff
00281   //----------------------------------------------------------------------
00282 
00288   bool UseCullerPlugin (const char* plugname);
00289 
00294   iVisibilityCuller* GetVisibilityCuller ();
00295 
00296   //----------------------------------------------------------------------
00297   // Drawing
00298   //----------------------------------------------------------------------
00299 
00303   void PrepareDraw (iRenderView* rview);
00304 
00308   void Draw (iRenderView* rview);
00309 
00310   //----------------------------------------------------------------------
00311   // Utility Functions
00312   //----------------------------------------------------------------------
00313 
00321   iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00322     csVector3& isect);
00323 
00330   iMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00331     csVector3& intersect, iPolygon3D** polygonPtr, bool accurate = false);
00332 
00339   void RealCheckFrustum (iFrustumView* lview);
00340 
00345   void CheckFrustum (iFrustumView* lview);
00346 
00357   iPolygon3D* IntersectSphere (csVector3& center, float radius,
00358                                float* pr = 0);
00359 
00378   iSector* FollowSegment (csReversibleTransform& t, csVector3& new_position,
00379                           bool& mirror, bool only_portals = false);
00380 
00397   iPolygon3D* IntersectSegment (const csVector3& start,
00398         const csVector3& end, csVector3& isect,
00399         float* pr = 0, bool only_portals = false,
00400         iMeshWrapper** p_mesh = 0);
00401 
00407   void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const;
00408 
00409   //------------------------------------------------
00410   // Everything for setting up the lighting system.
00411   //------------------------------------------------
00412 
00422   void ShineLights (csProgressPulse* = 0);
00423 
00425   void ShineLights (iMeshWrapper*, csProgressPulse* = 0);
00426 
00428   void SetDynamicAmbientLight(const csColor& color);
00429 
00431   csKDTree* GetLightKDTree () const { return lights.GetLightKDTree (); }
00432 
00433   //----------------------------------------------------------------------
00434   // Various
00435   //----------------------------------------------------------------------
00436 
00438   csEngine* GetEngine () const { return engine; }
00439 
00441   bool HasFog () const { return fog.enabled; }
00442 
00444   csFog& GetFog () { return fog; }
00445 
00447   void SetFog (float density, const csColor& color)
00448   {
00449     fog.enabled = true;
00450     fog.density = density;
00451     fog.red = color.red;
00452     fog.green = color.green;
00453     fog.blue = color.blue;
00454   }
00455 
00457   void DisableFog () { fog.enabled = false; }
00458 
00459   SCF_DECLARE_IBASE_EXT (csObject);
00460 
00461   //-------------------- iReferencedObject interface --------------------------
00462   struct ReferencedObject : public iReferencedObject
00463   {
00464     SCF_DECLARE_EMBEDDED_IBASE (csSector);
00465     virtual void AddReference (iReference* ref);
00466     virtual void RemoveReference (iReference* ref);
00467   } scfiReferencedObject;
00468   friend struct ReferencedObject;
00469 
00470   //--------------------- iVisibilityCullerListner interface ------------------
00471   struct eiVisibilityCullerListener : public iVisibilityCullerListener
00472   {
00473     SCF_DECLARE_EMBEDDED_IBASE (csSector);
00474     virtual void ObjectVisible (iVisibilityObject *visobj, iMeshWrapper *mesh)
00475       { scfParent->ObjectVisible (visobj, mesh);  }
00476   } scfiVisibilityCullerListener;
00477 
00478   void ObjectVisible (iVisibilityObject *visobj, iMeshWrapper *mesh)
00479   {
00480     visobj->SetVisibilityNumber (current_visnr);
00481   }
00482 
00483   //------------------------- iSector interface -------------------------------
00484   struct eiSector : public iSector
00485   {
00486     SCF_DECLARE_EMBEDDED_IBASE (csSector);
00487 
00488     virtual csSector *GetPrivateObject ()
00489       { return (csSector*)scfParent; }
00490     virtual iObject *QueryObject()
00491       { return scfParent; }
00492     virtual int GetRecLevel () const
00493       { return scfParent->draw_busy; }
00494     virtual bool SetVisibilityCullerPlugin (const char *Name)
00495       { return scfParent->UseCullerPlugin (Name); }
00496     virtual iVisibilityCuller* GetVisibilityCuller ()
00497       { return scfParent->GetVisibilityCuller (); }
00498     virtual iMeshList* GetMeshes ()
00499       { return scfParent->GetMeshes (); }
00500     virtual iLightList* GetLights ()
00501       { return scfParent->GetLights (); }
00502     virtual void ShineLights ()
00503       { scfParent->ShineLights (); }
00504     virtual void ShineLights (iMeshWrapper* mesh)
00505       { scfParent->ShineLights (mesh); }
00506     virtual void SetDynamicAmbientLight(const csColor& color)
00507       { scfParent->SetDynamicAmbientLight(color); }  
00508     virtual csColor GetDynamicAmbientLight() const
00509       { return scfParent->dynamic_ambient_color; }  
00510     virtual void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const
00511       { scfParent->CalculateSectorBBox (bbox, do_meshes); }
00512     virtual bool HasFog () const
00513       { return scfParent->HasFog (); }
00514     virtual csFog *GetFog () const
00515       { return &scfParent->fog; }
00516     virtual void SetFog (float density, const csColor& color)
00517       { scfParent->SetFog (density, color); }
00518     virtual void DisableFog ()
00519       { scfParent->DisableFog (); }
00520     virtual iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00521     csVector3& isect);
00522     virtual iMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00523     csVector3& intersect, iPolygon3D** polygonPtr, bool accurate = false);
00524     virtual iSector* FollowSegment (csReversibleTransform& t,
00525     csVector3& new_position, bool& mirror, bool only_portals = false);
00526     virtual void Draw (iRenderView* rview)
00527       { scfParent->Draw (rview); }
00528     virtual void PrepareDraw (iRenderView* rview)
00529     { scfParent->PrepareDraw (rview); }
00530     virtual void SetSectorCallback (iSectorCallback* cb)
00531     {
00532       scfParent->SetSectorCallback (cb);
00533     }
00534     virtual void RemoveSectorCallback (iSectorCallback* cb)
00535     {
00536       scfParent->RemoveSectorCallback (cb);
00537     }
00538     virtual int GetSectorCallbackCount () const
00539     {
00540       return scfParent->GetSectorCallbackCount ();
00541     }
00542     virtual iSectorCallback* GetSectorCallback (int idx) const
00543     {
00544       return scfParent->GetSectorCallback (idx);
00545     }
00546     virtual void CheckFrustum (iFrustumView* lview)
00547     {
00548       scfParent->CheckFrustum (lview);
00549     }
00550   } scfiSector;
00551   friend struct eiSector;
00552 };
00553 
00555 class csSectorList : public iSectorList
00556 {
00557 private:
00558   csRefArrayObject<iSector> list;
00559 
00560 public:
00561   SCF_DECLARE_IBASE;
00562   bool CleanupReferences;
00563 
00565   csSectorList (bool CleanupReferences);
00567   virtual ~csSectorList () { RemoveAll (); }
00568 
00570   virtual void FreeItem (iSector* item);
00571 
00572   virtual int GetCount () const { return list.Length (); }
00573   virtual iSector *Get (int n) const { return list.Get (n); }
00574   virtual int Add (iSector *obj);
00575   virtual bool Remove (iSector *obj);
00576   virtual bool Remove (int n);
00577   virtual void RemoveAll ();
00578   virtual int Find (iSector *obj) const;
00579   virtual iSector *FindByName (const char *Name) const;
00580 };
00581 
00582 #endif // __CS_SECTOR_H__

Generated for Crystal Space by doxygen 1.2.14