Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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 "csutil/csobject.h"
00023 #include "csutil/nobjvec.h"
00024 #include "csgeom/math3d.h"
00025 #include "csengine/bsp.h"
00026 #include "csengine/meshobj.h"
00027 #include "csutil/cscolor.h"
00028 #include "iutil/objref.h"
00029 #include "iengine/movable.h"
00030 #include "iengine/sector.h"
00031 #include "iengine/mesh.h"
00032 #include "iengine/light.h"
00033 #include "ivideo/graph3d.h"
00034 
00035 class csEngine;
00036 class csStatLight;
00037 class csMeshWrapper;
00038 class csPolygon3D;
00039 class csCamera;
00040 class csDynLight;
00041 class csPolygon2DQueue;
00042 class csProgressPulse;
00043 class csSector;
00044 struct iGraphics3D;
00045 struct iStatLight;
00046 struct iVisibilityCuller;
00047 struct iRenderView;
00048 struct iMeshWrapper;
00049 struct iFrustumView;
00050 
00051 CS_DECLARE_OBJECT_VECTOR (csLightListHelper, iLight);
00052 
00056 class csLightList : public csLightListHelper
00057 {
00058 private:
00059   csSector* sector;
00060 public:
00061   SCF_DECLARE_IBASE;
00062 
00064   csLightList ();
00066   ~csLightList ();
00067 
00069   void SetSector (csSector* s) { sector = s; }
00070 
00072   virtual bool FreeItem (csSome Item);
00074   virtual bool PrepareItem (csSome Item);
00075 
00076   class LightList : public iLightList
00077   {
00078     SCF_DECLARE_EMBEDDED_IBASE (csLightList);
00079     virtual int GetCount () const;
00080     virtual iLight *Get (int n) const;
00081     virtual int Add (iLight *obj);
00082     virtual bool Remove (iLight *obj);
00083     virtual bool Remove (int n);
00084     virtual void RemoveAll ();
00085     virtual int Find (iLight *obj) const;
00086     virtual iLight *FindByName (const char *Name) const;
00087   } scfiLightList;
00088 };
00089 
00091 class csSectorMeshList : public csMeshList
00092 {
00093 private:
00094   csSector* sector;
00095 
00096 public:
00097   csSectorMeshList ();
00098   void SetSector (csSector* sec) { sector = sec; }
00099   virtual void AddMesh (iMeshWrapper* mesh);
00100   virtual void RemoveMesh (iMeshWrapper* mesh);
00101 };
00102 
00103 
00104 SCF_VERSION (csSector, 0, 0, 2);
00105 
00110 class csSector : public csObject
00111 {
00112 private:
00118   csSectorMeshList meshes;
00119 
00124   csVector mesh_priority_queues;
00125 
00129   csVector references;
00130 
00135   csLightList lights;
00136 
00138   csEngine* engine;
00139 
00141   csFog fog;
00142 
00147   csMeshWrapper* culler_mesh;
00148 
00153   iVisibilityCuller* culler;
00154 
00155 private:
00161   virtual ~csSector ();
00162 
00163 public:
00168   static bool do_portals;
00169 
00176   static int cfg_reflections;
00177 
00185   static bool do_radiosity;
00186 
00193   int draw_busy;
00194 
00195 public:
00199   csSector (csEngine*);
00200 
00205   void CleanupReferences ();
00206 
00207   //----------------------------------------------------------------------
00208   // Mesh manipulation functions
00209   //----------------------------------------------------------------------
00210 
00211   iMeshList* GetMeshes ()
00212   {
00213     return &(meshes.scfiMeshList);
00214   }
00215 
00219   void AddMesh (csMeshWrapper* mesh);
00220 
00224   void UnlinkMesh (csMeshWrapper* mesh);
00225 
00231   void RelinkMesh (csMeshWrapper* mesh);
00232 
00233   //----------------------------------------------------------------------
00234   // Light manipulation functions
00235   //----------------------------------------------------------------------
00236 
00240   csLightList& GetLights () { return lights; }
00241 
00245   csStatLight* FindLight (float x, float y, float z, float dist) const;
00246 
00250   csStatLight* FindLight (unsigned long id) const;
00251 
00252   //----------------------------------------------------------------------
00253   // Visibility Stuff
00254   //----------------------------------------------------------------------
00255 
00259   csMeshWrapper* GetCullerMesh () const { return culler_mesh; }
00260 
00265   void UseCuller (const char* meshname);
00266 
00271   iVisibilityCuller* GetVisibilityCuller () const { return culler; }
00272 
00273   //----------------------------------------------------------------------
00274   // Drawing
00275   //----------------------------------------------------------------------
00276   
00280   void Draw (iRenderView* rview);
00281 
00282   //----------------------------------------------------------------------
00283   // Utility Functions
00284   //----------------------------------------------------------------------
00285 
00293   csPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00294         csVector3& isect);
00295 
00302   csMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00303         csVector3& intersect, csPolygon3D** polygonPtr);
00304 
00311   void RealCheckFrustum (iFrustumView* lview);
00312 
00317   void CheckFrustum (iFrustumView* lview);
00318 
00325   csObject** GetVisibleObjects (iFrustumView* lview, int& num_objects);
00326 
00337   csPolygon3D* IntersectSphere (csVector3& center, float radius,
00338                                float* pr = NULL);
00339 
00358   csSector* FollowSegment (csReversibleTransform& t, csVector3& new_position, 
00359                           bool& mirror, bool only_portals = false);
00360 
00377   csPolygon3D* IntersectSegment (const csVector3& start,
00378         const csVector3& end, csVector3& isect,
00379         float* pr = NULL, bool only_portals = false,
00380         csMeshWrapper** p_mesh = NULL);
00381 
00387   void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const;
00388 
00389   //------------------------------------------------
00390   // Everything for setting up the lighting system.
00391   //------------------------------------------------
00392 
00402   void ShineLights (csProgressPulse* = 0);
00403 
00405   void ShineLights (iMeshWrapper*, csProgressPulse* = 0);
00406 
00407   //----------------------------------------------------------------------
00408   // Various
00409   //----------------------------------------------------------------------
00410 
00412   csEngine* GetEngine () const { return engine; }
00413 
00415   bool HasFog () const { return fog.enabled; }
00416 
00418   csFog& GetFog () { return fog; }
00419 
00421   void SetFog (float density, const csColor& color)
00422   {
00423     fog.enabled = true;
00424     fog.density = density;
00425     fog.red = color.red;
00426     fog.green = color.green;
00427     fog.blue = color.blue;
00428   }
00429 
00431   void DisableFog () { fog.enabled = false; }
00432 
00433   SCF_DECLARE_IBASE_EXT (csObject);
00434 
00435   //-------------------- iReferencedObject interface --------------------------
00436   struct ReferencedObject : public iReferencedObject
00437   {
00438     SCF_DECLARE_EMBEDDED_IBASE (csSector);
00439     virtual void AddReference (iReference* ref);
00440     virtual void RemoveReference (iReference* ref);
00441   } scfiReferencedObject;
00442   friend struct ReferencedObject;
00443 
00444   //------------------------- iSector interface -------------------------------
00445   struct eiSector : public iSector
00446   {
00447     SCF_DECLARE_EMBEDDED_IBASE (csSector);
00448 
00449     virtual csSector *GetPrivateObject ()
00450     { return (csSector*)scfParent; }
00451     virtual iObject *QueryObject()
00452     { return scfParent; }
00453     virtual int GetRecLevel () const { return scfParent->draw_busy; }
00454     virtual void SetVisibilityCuller (const char *Name)
00455     {
00456       scfParent->UseCuller (Name);
00457     }
00458     virtual iVisibilityCuller* GetVisibilityCuller () const
00459     {
00460       return scfParent->GetVisibilityCuller ();
00461     }
00462 
00463     virtual iMeshList* GetMeshes ()
00464     {
00465       return &(scfParent->meshes.scfiMeshList);
00466     }
00467     virtual iLightList* GetLights ()
00468     {
00469       return &(scfParent->lights.scfiLightList);
00470     }
00471 
00472     virtual iStatLight *FindLight (float x, float y, float z, float dist) const;
00473     virtual void ShineLights ()
00474     { scfParent->ShineLights (); }
00475     virtual void ShineLights (iMeshWrapper* mesh)
00476     { scfParent->ShineLights (mesh); }
00477 
00478     virtual void CalculateSectorBBox (csBox3& bbox, bool do_meshes) const
00479     { scfParent->CalculateSectorBBox (bbox, do_meshes); }
00480 
00481     virtual bool HasFog () const { return scfParent->HasFog (); }
00482     virtual csFog *GetFog () const { return &scfParent->fog; }
00483     virtual void SetFog (float density, const csColor& color)
00484     { scfParent->SetFog (density, color); }
00485     virtual void DisableFog ()
00486     { scfParent->DisableFog (); }
00487     virtual iPolygon3D* HitBeam (const csVector3& start, const csVector3& end,
00488         csVector3& isect);
00489     virtual iMeshWrapper* HitBeam (const csVector3& start, const csVector3& end,
00490         csVector3& intersect, iPolygon3D** polygonPtr);
00491     virtual iSector* FollowSegment (csReversibleTransform& t,
00492         csVector3& new_position, bool& mirror, bool only_portals = false);
00493     virtual void Draw (iRenderView* rview)
00494     { scfParent->Draw (rview); }
00495   } scfiSector;
00496   friend struct eiSector;
00497 };
00498 
00499 CS_DECLARE_OBJECT_VECTOR (csSectorListHelper, iSector);
00500 
00501 class csSectorList : public csSectorListHelper
00502 {
00503 public:
00504   SCF_DECLARE_IBASE;
00505   bool CleanupReferences;
00506 
00508   csSectorList (bool CleanupReferences);
00510   ~csSectorList ();
00511 
00513   virtual bool FreeItem (csSome Item);
00514 
00515   class SectorList : public iSectorList
00516   {
00517   public:
00518     SCF_DECLARE_EMBEDDED_IBASE (csSectorList);
00519 
00520     virtual int GetCount () const;
00521     virtual iSector *Get (int n) const;
00522     virtual int Add (iSector *obj);
00523     virtual bool Remove (iSector *obj);
00524     virtual bool Remove (int n);
00525     virtual void RemoveAll ();
00526     virtual int Find (iSector *obj) const;
00527     virtual iSector *FindByName (const char *Name) const;
00528   } scfiSectorList;
00529 };
00530 
00531 #endif // __CS_SECTOR_H__

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