CrystalSpace

Public API Reference

Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File 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/nobjvec.h"
00027 #include "csutil/hashmap.h"
00028 #include "csutil/refarr.h"
00029 #include "csengine/lview.h"
00030 #include "iengine/light.h"
00031 #include "iengine/statlght.h"
00032 #include "iengine/dynlight.h"
00033 
00034 class csLightMap;
00035 class csDynLight;
00036 class csHalo;
00037 class csPolygon3D;
00038 class csCurve;
00039 class csSector;
00040 class csKDTreeChild;
00041 struct iMeshWrapper;
00042 struct iLightingInfo;
00043 
00049 class csLight : public csObject
00050 {
00051 private:
00053   char* light_id;
00054 
00056   csKDTreeChild* childnode;
00057 
00058 protected:
00060   csSector* sector;
00062   csVector3 center;
00063 #ifndef CS_USE_NEW_RENDERER
00064 
00065   float dist;
00067   float sqdist;
00069   float inv_dist;
00070 #endif
00071 
00072   csColor color;
00074   csHalo *halo;
00075 
00076 #ifndef CS_USE_NEW_RENDERER
00077 
00078   int attenuation;
00079 
00080 #else
00081 
00082   csVector3 attenuationvec;
00083 
00085   float influenceRadius; 
00087   float influenceRadiusSq; 
00088 
00090   bool influenceValid;
00091 
00096   static float influenceIntensityFraction;
00097 #endif
00098 
00100   uint32 lightnr;
00101 
00105   csRefArray<iLightCallback> light_cb_vector;
00106 
00108   const char* GenerateUniqueID ();
00109 
00113   void CalculateInfluenceRadius ();
00114 public:
00116   csFlags flags;
00117 
00118 public:
00122   static int ambient_red;
00126   static int ambient_green;
00130   static int ambient_blue;
00131 
00132 public:
00138   csLight (float x, float y, float z, float dist,
00139      float red, float green, float blue);
00140 
00147   virtual ~csLight ();
00148 
00153   void SetChildNode (csKDTreeChild* childnode)
00154   {
00155     csLight::childnode = childnode;
00156   }
00157 
00161   csKDTreeChild* GetChildNode () const { return childnode; }
00162 
00164   const char* GetLightID () { return GenerateUniqueID (); }
00165 
00167   virtual bool IsDynamic () const { return false; }
00168 
00172   virtual void SetSector (csSector* sector);
00173 
00177   csSector* GetSector () const { return sector; }
00178 
00182   void SetCenter (const csVector3& v);
00183 
00187   const csVector3& GetCenter () { return center; }
00188 
00189 #ifndef CS_USE_NEW_RENDERER
00190 
00193   float GetRadius () const { return dist; }
00194 
00198   float GetSquaredRadius () const { return sqdist; }
00199 
00203   float GetInverseRadius () const { return inv_dist; }
00204 
00208   void SetRadius (float radius);
00209 #endif
00210 
00214   csColor& GetColor () { return color; }
00215 
00223   virtual void SetColor (const csColor& col);
00224 
00228   csHalo *GetHalo () { return halo; }
00229 
00233   void SetHalo (csHalo *Halo);
00234 
00235 #ifndef CS_USE_NEW_RENDERER
00236 
00239   int GetAttenuation () {return attenuation;}
00240 
00244   void SetAttenuation (int a); 
00245 
00246 #else
00247 
00251   void SetAttenuationVector (csVector3 pattenv);
00252 
00257   const csVector3 &GetAttenuationVector();
00258 
00262   float GetInfluenceRadius ();
00263 
00267   float GetInfluenceRadiusSq ();
00268 
00272   void SetInfluenceRadius (float radius);
00273 
00281   void CalculateAttenuationVector (int atttype, float radius = 1.0f,
00282     float brightness = 1.0f);
00283 
00291   bool GetDistanceForBrightness (float brightness, float& distance);
00292 #endif
00293 
00297   float GetBrightnessAtDistance (float d);
00298 
00299   //----------------------------------------------------------------------
00300   // Callbacks
00301   //----------------------------------------------------------------------
00302   void SetLightCallback (iLightCallback* cb)
00303   {
00304     light_cb_vector.Push (cb);
00305   }
00306 
00307   void RemoveLightCallback (iLightCallback* cb)
00308   {
00309     int idx = light_cb_vector.Find (cb);
00310     if (idx != -1)
00311     {
00312       light_cb_vector.Delete (idx);
00313     }
00314   }
00315 
00316   int GetLightCallbackCount () const
00317   {
00318     return light_cb_vector.Length ();
00319   }
00320   
00321   iLightCallback* GetLightCallback (int idx) const
00322   {
00323     return (iLightCallback*)light_cb_vector.Get (idx);
00324   }
00325 
00326   //------------------------ iLight interface -----------------------------
00327   SCF_DECLARE_IBASE_EXT (csObject);
00328 
00330   struct Light : public iLight
00331   {
00332     SCF_DECLARE_EMBEDDED_IBASE (csLight);
00333     virtual csLight* GetPrivateObject () { return scfParent; }
00334     virtual const char* GetLightID () { return scfParent->GetLightID (); }
00335     virtual iObject *QueryObject() { return scfParent; }
00336     virtual const csVector3& GetCenter () { return scfParent->GetCenter (); }
00337     virtual void SetCenter (const csVector3& pos)
00338     {
00339       scfParent->SetCenter (pos);
00340     }
00341     virtual iSector *GetSector ();
00342     virtual void SetSector (iSector* sector);
00343 #ifndef CS_USE_NEW_RENDERER
00344     virtual float GetRadius () { return scfParent->GetRadius (); }
00345     virtual float GetSquaredRadius () { return scfParent->GetSquaredRadius (); }
00346     virtual float GetInverseRadius () { return scfParent->GetInverseRadius (); }
00347     virtual void SetRadius (float r) { scfParent->SetRadius (r); }
00348 #endif
00349     virtual const csColor& GetColor () { return scfParent->GetColor (); }
00350     virtual void SetColor (const csColor& col) { scfParent->SetColor (col); }
00351     virtual bool IsDynamic () const { return scfParent->IsDynamic (); }
00352 #ifndef CS_USE_NEW_RENDERER
00353     virtual int GetAttenuation () { return scfParent->GetAttenuation (); }
00354     virtual void SetAttenuation (int a) { scfParent->SetAttenuation (a); }
00355 #endif
00356     virtual float GetBrightnessAtDistance (float d)
00357     {
00358       return scfParent->GetBrightnessAtDistance (d);
00359     }
00360 #ifdef CS_USE_NEW_RENDERER
00361     virtual void SetAttenuationVector(csVector3 attenv) 
00362     { scfParent->SetAttenuationVector(attenv); }
00363     virtual const csVector3 &GetAttenuationVector() { return scfParent->GetAttenuationVector(); }
00364     virtual float GetInfluenceRadius () { return scfParent->GetInfluenceRadius(); }
00365     virtual float GetInfluenceRadiusSq () { return scfParent->GetInfluenceRadiusSq(); }
00366     virtual void SetInfluenceRadius (float radius) { scfParent->SetInfluenceRadius (radius); }
00367     virtual void CalculateAttenuationVector (int atttype, float radius,
00368       float brightness) { return scfParent->CalculateAttenuationVector 
00369         (atttype, radius, brightness); }
00370     virtual bool GetDistanceForBrightness (float brightness, float& distance)
00371     { return scfParent->GetDistanceForBrightness (brightness, distance); }
00372 #endif
00373     virtual iCrossHalo* CreateCrossHalo (float intensity, float cross);
00374     virtual iNovaHalo* CreateNovaHalo (int seed, int num_spokes,
00375     float roundness);
00376     virtual iFlareHalo* CreateFlareHalo ();
00377     virtual csFlags& GetFlags () { return scfParent->flags; }
00378     virtual void SetLightCallback (iLightCallback* cb)
00379     {
00380       scfParent->SetLightCallback (cb);
00381     }
00382     virtual void RemoveLightCallback (iLightCallback* cb)
00383     {
00384       scfParent->RemoveLightCallback (cb);
00385     }
00386     virtual int GetLightCallbackCount () const
00387     {
00388       return scfParent->GetLightCallbackCount ();
00389     }
00390     virtual iLightCallback* GetLightCallback (int idx) const
00391     {
00392       return scfParent->GetLightCallback (idx);
00393     }
00394     virtual uint32 GetLightNumber () const
00395     {
00396       return scfParent->lightnr;
00397     }
00398   } scfiLight;
00399   friend struct Light;
00400 };
00401 
00409 class csStatLight : public csLight
00410 {
00411 private:
00418   bool dynamic;
00419 
00421   csHashSet lightinginfos;
00422 
00423 public:
00431   csStatLight (float x, float y, float z, float dist,
00432      float red, float green, float blue,
00433    bool dynamic);
00440   virtual ~csStatLight ();
00441 
00445   virtual bool IsDynamic () const { return dynamic; }
00446 
00457   virtual void SetColor (const csColor& col);
00458 
00460   void AddAffectedLightingInfo (iLightingInfo* li);
00461 
00469   void CalculateLighting ();
00470 
00477   void CalculateLighting (iMeshWrapper* mesh);
00478 
00479   //------------------------ iStatLight interface -----------------------------
00480   SCF_DECLARE_IBASE_EXT (csLight);
00481 
00483   struct eiStaticLight : public iStatLight
00484   {
00485     SCF_DECLARE_EMBEDDED_IBASE (csStatLight);
00486 
00488     virtual csStatLight *GetPrivateObject ()
00489     { return scfParent; }
00490     virtual iObject *QueryObject ()
00491     { return scfParent; }
00492     virtual iLight *QueryLight ()
00493     { return &scfParent->scfiLight; }
00494     virtual void AddAffectedLightingInfo (iLightingInfo* li)
00495     { scfParent->AddAffectedLightingInfo (li); }
00496   } scfiStatLight;
00497   friend struct eiStaticLight;
00498 };
00499 
00505 class csDynLight : public csLight
00506 {
00507 private:
00508   csDynLight* next;
00509   csDynLight* prev;
00510 
00512   csHashSet lightinginfos;
00513 
00514 public:
00521   csDynLight (float x, float y, float z, float dist,
00522      float red, float green, float blue);
00523 
00528   virtual ~csDynLight ();
00529 
00537   void Setup ();
00538 
00543   virtual void SetColor (const csColor& col);
00544 
00550   void AddAffectedLightingInfo (iLightingInfo* li);
00551 
00555   void RemoveAffectedLightingInfo (iLightingInfo* li);
00556 
00558   void SetNext (csDynLight* n) { next = n; }
00560   void SetPrev (csDynLight* p) { prev = p; }
00562   csDynLight* GetNext () { return next; }
00564   csDynLight* GetPrev () { return prev; }
00565 
00566   //------------------------ iDynLight interface -----------------------------
00567   SCF_DECLARE_IBASE_EXT (csLight);
00568 
00570   struct eiDynLight : public iDynLight
00571   {
00572     SCF_DECLARE_EMBEDDED_IBASE (csDynLight);
00573 
00575     virtual csDynLight* GetPrivateObject ()
00576     { return scfParent; }
00577     virtual void AddAffectedLightingInfo (iLightingInfo* li)
00578     { scfParent->AddAffectedLightingInfo (li); }
00579     virtual void RemoveAffectedLightingInfo (iLightingInfo* li)
00580     { scfParent->RemoveAffectedLightingInfo (li); }
00581     virtual void Setup ()
00582     { scfParent->Setup (); }
00583     virtual iObject *QueryObject ()
00584     { return scfParent; }
00585     virtual iLight *QueryLight ()
00586     { return &(scfParent->scfiLight); }
00587     virtual iDynLight* GetNext ()
00588     {
00589       csDynLight* n = scfParent->GetNext ();
00590       return n ? &(n->scfiDynLight) : NULL;
00591     }
00592   } scfiDynLight;
00593   friend struct eiDynLight;
00594 };
00595 
00596 
00600 class csLightList : public iLightList
00601 {
00602 private:
00603   csRefArrayObject<iLight> list;
00604 
00605 public:
00606   SCF_DECLARE_IBASE;
00607 
00609   csLightList ();
00610   virtual ~csLightList () { RemoveAll (); }
00611 
00613   virtual void PrepareItem (iLight*) { }
00615   virtual void FreeItem (iLight*) { }
00616 
00617   virtual int GetCount () const { return list.Length (); }
00618   virtual iLight *Get (int n) const { return list.Get (n); }
00619   virtual int Add (iLight *obj);
00620   virtual bool Remove (iLight *obj);
00621   virtual bool Remove (int n);
00622   virtual void RemoveAll ();
00623   virtual int Find (iLight *obj) const;
00624   virtual iLight *FindByName (const char *Name) const;
00625   virtual iLight *FindByID (const char* id) const;
00626 };
00627 
00631 struct csLightingProcessInfo : public iLightingProcessInfo
00632 {
00633 private:
00634   // Light.
00635   csLight* light;
00636   // For dynamic lighting.
00637   bool dynamic;
00638   // Current lighting color.
00639   csColor color;
00640   // Array of user data.
00641   csRefArray<iLightingProcessData> userdatas;
00642 
00643 public:
00644   csLightingProcessInfo (csLight* light, bool dynamic);
00645   virtual ~csLightingProcessInfo () { }
00646 
00650   csLight* GetCsLight () const { return light; }
00651   virtual iLight* GetLight () const { return &(light->scfiLight); }
00652 
00656   virtual bool IsDynamic () const { return dynamic; }
00657 
00661   virtual void SetColor (const csColor& col) { color = col; }
00662 
00666   virtual const csColor& GetColor () const { return color; }
00667 
00669   virtual void AttachUserdata (iLightingProcessData* userdata);
00670 
00672   virtual csPtr<iLightingProcessData> QueryUserdata (scfInterfaceID id,
00673     int version);
00674 
00676   virtual void FinalizeLighting ();
00677 
00678   SCF_DECLARE_IBASE;
00679 };
00680 
00681 #endif // __CS_LIGHT_H__
00682 

Generated for Crystal Space by doxygen 1.2.14