Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

light.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_LIGHT_H__
00020 #define __CS_LIGHT_H__
00021 
00022 #include "csgeom/transfrm.h"
00023 #include "csutil/csobject.h"
00024 #include "csutil/cscolor.h"
00025 #include "csutil/flags.h"
00026 #include "csutil/csvector.h"
00027 #include "csutil/nobjvec.h"
00028 #include "csengine/lview.h"
00029 #include "iengine/light.h"
00030 #include "iengine/statlght.h"
00031 #include "iengine/dynlight.h"
00032 
00033 class csLightMap;
00034 class csDynLight;
00035 class csLightPatchPool;
00036 class csHalo;
00037 class csPolygon3D;
00038 class csCurve;
00039 class csSector;
00040 struct iMeshWrapper;
00041 
00047 #define CS_LIGHT_THINGSHADOWS   0x00000001
00048 
00054 #define CS_LIGHT_ACTIVEHALO     0x80000000
00055 
00082 class csLight : public csObject
00083 {
00084 private:
00086   unsigned long light_id;
00088   static unsigned long last_light_id;
00089 
00090 protected:
00092   csSector* sector;
00094   csVector3 center;
00096   float dist;
00098   float sqdist;
00100   float inv_dist;
00102   csColor color;
00104   csHalo *halo;
00105 
00107   int attenuation;
00108 
00109 public:
00111   csFlags flags;
00112 
00113 public:
00115   static int ambient_red;
00117   static int ambient_green;
00119   static int ambient_blue;
00120 
00121 public:
00127   csLight (float x, float y, float z, float dist,
00128          float red, float green, float blue);
00129 
00136   virtual ~csLight ();
00137 
00139   unsigned long GetLightID () { return light_id; }
00140 
00144   virtual void SetSector (csSector* sector) { csLight::sector = sector; }
00145 
00149   csSector* GetSector () const { return sector; }
00150 
00154   void SetCenter (const csVector3& v) { center = v; }
00155 
00159   const csVector3& GetCenter () { return center; }
00160 
00164   float GetRadius () const { return dist; }
00165 
00169   float GetSquaredRadius () const { return sqdist; }
00170 
00174   float GetInverseRadius () const { return inv_dist; }
00175 
00179   void SetRadius (float radius)
00180     { dist = radius; sqdist = dist*dist; inv_dist = 1 / dist; }
00181 
00185   csColor& GetColor () { return color; }
00186 
00194   virtual void SetColor (const csColor& col) { color = col; }
00195 
00199   csHalo *GetHalo () { return halo; }
00200 
00204   void SetHalo (csHalo *Halo);
00205 
00209   int GetAttenuation () {return attenuation;}
00210 
00214   void SetAttenuation (int a) {attenuation = a;}
00215 
00219   float GetBrightnessAtDistance (float d);
00220 
00221   //------------------------ iLight interface -----------------------------
00222   SCF_DECLARE_IBASE_EXT (csObject);
00223 
00224   struct Light : public iLight
00225   {
00226     SCF_DECLARE_EMBEDDED_IBASE (csLight);
00227     virtual csLight* GetPrivateObject ();
00228     virtual unsigned long GetLightID ();
00229     virtual iObject *QueryObject();
00230     virtual const csVector3& GetCenter ();
00231     virtual void SetCenter (const csVector3& pos);
00232     virtual iSector *GetSector ();
00233     virtual void SetSector (iSector* sector);
00234     virtual float GetRadius ();
00235     virtual float GetSquaredRadius ();
00236     virtual float GetInverseRadius ();
00237     virtual void SetRadius (float r);
00238     virtual const csColor& GetColor ();
00239     virtual void SetColor (const csColor& col);
00240     virtual int GetAttenuation ();
00241     virtual void SetAttenuation (int a);
00242     virtual float GetBrightnessAtDistance (float d);
00243     virtual iCrossHalo* CreateCrossHalo (float intensity, float cross);
00244     virtual iNovaHalo* CreateNovaHalo (int seed, int num_spokes,
00245         float roundness);
00246     virtual iFlareHalo* CreateFlareHalo ();
00247   } scfiLight;
00248 };
00249 
00257 class csStatLight : public csLight
00258 {
00259 private:
00266   bool dynamic;
00267 
00269   csVector lightmaps;
00270 
00271 public:
00279   csStatLight (float x, float y, float z, float dist,
00280          float red, float green, float blue,
00281          bool dynamic);
00288   virtual ~csStatLight ();
00289 
00293   bool IsDynamic () { return dynamic; }
00294 
00305   virtual void SetColor (const csColor& col);
00306 
00312   void RegisterLightMap (csLightMap* lmap);
00313 
00321   void CalculateLighting ();
00322 
00329   void CalculateLighting (iMeshWrapper* mesh);
00330 
00331   //------------------------ iStatLight interface -----------------------------
00332   SCF_DECLARE_IBASE_EXT (csLight);
00333 
00334   struct eiStaticLight : public iStatLight
00335   {
00336     SCF_DECLARE_EMBEDDED_IBASE (csStatLight);
00337 
00339     virtual csStatLight *GetPrivateObject ()
00340     { return scfParent; }
00341     virtual iObject *QueryObject ()
00342     { return scfParent; }
00343     virtual iLight *QueryLight ()
00344     { return &scfParent->scfiLight; }
00345   } scfiStatLight;
00346   friend struct eiStaticLight;
00347 };
00348 
00357 class csLightPatch
00358 {
00359   friend class csLightPatchPool;
00360 
00361 private:
00362   csLightPatch* next_poly;
00363   csLightPatch* prev_poly;
00364   csLightPatch* next_light;
00365   csLightPatch* prev_light;
00366 
00368   csVector3* vertices;
00370   int num_vertices;
00372   int max_vertices;
00373 
00375   csPolygon3D* polygon;
00377   csCurve* curve;
00378 
00380   csDynLight* light;
00381 
00383   csShadowBlock shadows;
00384 
00386   csFrustum *light_frustum;
00387 
00388 public:
00392   csLightPatch ();
00393 
00398   ~csLightPatch ();
00399 
00404   void Initialize (int n);
00405 
00409   void RemovePatch ();
00410 
00414   csPolygon3D* GetPolygon () { return polygon; }
00415 
00419   csCurve* GetCurve () { return curve; }
00420 
00424   csDynLight* GetLight () { return light; }
00425 
00427   csShadowBlock& GetShadowBlock () { return shadows; }
00428 
00430   int GetVertexCount () { return num_vertices; }
00432   csVector3* GetVertices () { return vertices; }
00433 
00435   csVector3& GetVertex (int i)
00436   {
00437     CS_ASSERT (vertices != NULL);
00438     CS_ASSERT (i >= 0 && i < num_vertices);
00439     return vertices[i];
00440   }
00441 
00446   csLightPatch* GetNextPoly () { return next_poly; }
00447 
00452   csLightPatch* GetNextLight () { return next_light; }
00453 
00455   void SetPolyCurve (csPolygon3D* pol) { polygon = pol; curve = NULL; }
00457   void SetPolyCurve (csCurve* c) { curve = c; polygon = NULL; }
00459   void SetLight (csDynLight* l) { light = l; }
00461   void AddPolyList (csLightPatch*& first)
00462   {
00463     next_poly = first;
00464     prev_poly = NULL;
00465     if (first)
00466       first->prev_poly = this;
00467     first = this;
00468   }
00470   void RemovePolyList (csLightPatch*& first)
00471   {
00472     if (next_poly) next_poly->prev_poly = prev_poly;
00473     if (prev_poly) prev_poly->next_poly = next_poly;
00474     else first = next_poly;
00475     prev_poly = next_poly = NULL;
00476     polygon = NULL;
00477     curve = NULL;
00478   }
00480   void AddLightList (csLightPatch*& first)
00481   {
00482     next_light = first;
00483     prev_light = NULL;
00484     if (first)
00485       first->prev_light = this;
00486     first = this;
00487   }
00489   void RemoveLightList (csLightPatch*& first)
00490   {
00491     if (next_light) next_light->prev_light = prev_light;
00492     if (prev_light) prev_light->next_light = next_light;
00493     else first = next_light;
00494     prev_light = next_light = NULL;
00495     light = NULL;
00496   }
00497 
00499   void SetLightFrustum (csFrustum* lf) { light_frustum = lf; }
00501   csFrustum* GetLightFrustum () { return light_frustum; }
00502 };
00503 
00509 class csDynLight : public csLight
00510 {
00511 private:
00512   csDynLight* next;
00513   csDynLight* prev;
00514 
00516   csLightPatch* lightpatches;
00517 
00518 public:
00525   csDynLight (float x, float y, float z, float dist,
00526          float red, float green, float blue);
00527 
00532   virtual ~csDynLight ();
00533 
00541   void Setup ();
00542 
00547   virtual void SetColor (const csColor& col);
00548 
00554   void UnlinkLightpatch (csLightPatch* lp);
00555 
00559   void AddLightpatch (csLightPatch* lp);
00560 
00562   void SetNext (csDynLight* n) { next = n; }
00564   void SetPrev (csDynLight* p) { prev = p; }
00566   csDynLight* GetNext () { return next; }
00568   csDynLight* GetPrev () { return prev; }
00569 
00570   //------------------------ iDynLight interface -----------------------------
00571   SCF_DECLARE_IBASE_EXT (csLight);
00572 
00573   struct eiDynLight : public iDynLight
00574   {
00575     SCF_DECLARE_EMBEDDED_IBASE (csDynLight);
00576 
00578     virtual csDynLight* GetPrivateObject ()
00579     { return scfParent; }
00580     virtual void Setup ()
00581     { scfParent->Setup (); }
00582     virtual iObject *QueryObject ()
00583     { return scfParent; }
00584     virtual iLight *QueryLight ()
00585     { return &(scfParent->scfiLight); }
00586     virtual iDynLight* GetNext ()
00587     { return &(scfParent->GetNext())->scfiDynLight; }
00588   } scfiDynLight;
00589   friend struct eiDynLight;
00590 };
00591 
00592 
00593 CS_DECLARE_OBJECT_VECTOR (csLightListHelper, iLight);
00594 
00598 class csLightList : public csLightListHelper
00599 {
00600 public:
00601   SCF_DECLARE_IBASE;
00602 
00604   csLightList ();
00605 
00607   iLight *FindByID (unsigned long id) const;
00608 
00609   class LightList : public iLightList
00610   {
00611     SCF_DECLARE_EMBEDDED_IBASE (csLightList);
00612     virtual int GetCount () const;
00613     virtual iLight *Get (int n) const;
00614     virtual int Add (iLight *obj);
00615     virtual bool Remove (iLight *obj);
00616     virtual bool Remove (int n);
00617     virtual void RemoveAll ();
00618     virtual int Find (iLight *obj) const;
00619     virtual iLight *FindByName (const char *Name) const;
00620     virtual iLight *FindByID (unsigned long id) const;
00621   } scfiLightList;
00622 };
00623 
00624 #endif // __CS_LIGHT_H__

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