00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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 csKDTreeChild;
00040 struct iMeshWrapper;
00041 struct iLightingInfo;
00042 struct iSector;
00043
00049 class csLight : public csObject
00050 {
00051 private:
00053 char* light_id;
00054
00056 csKDTreeChild* childnode;
00057
00058 protected:
00060 iSector* sector;
00062 csVector3 center;
00064 csColor color;
00066 csHalo *halo;
00067
00069 int attenuation;
00071 csVector3 attenuationvec;
00072
00074 float influenceRadius;
00076 float influenceRadiusSq;
00078 float inv_dist;
00079
00081 bool influenceValid;
00082
00087 static float influenceIntensityFraction;
00088
00090 uint32 lightnr;
00091
00095 csRefArray<iLightCallback> light_cb_vector;
00096
00098 const char* GenerateUniqueID ();
00099
00103 void CalculateInfluenceRadius ();
00104
00105 public:
00107 csFlags flags;
00108
00109 public:
00113 static int ambient_red;
00117 static int ambient_green;
00121 static int ambient_blue;
00122
00123 public:
00129 csLight (float x, float y, float z, float dist,
00130 float red, float green, float blue);
00131
00138 virtual ~csLight ();
00139
00144 void SetChildNode (csKDTreeChild* childnode)
00145 {
00146 csLight::childnode = childnode;
00147 }
00148
00152 csKDTreeChild* GetChildNode () const { return childnode; }
00153
00155 const char* GetLightID () { return GenerateUniqueID (); }
00156
00158 virtual bool IsDynamic () const { return false; }
00159
00163 virtual void SetSector (iSector* sector);
00164
00168 iSector* GetSector () const { return sector; }
00169
00173 void SetCenter (const csVector3& v);
00174
00178 const csVector3& GetCenter () { return center; }
00179
00183 csColor& GetColor () { return color; }
00184
00192 virtual void SetColor (const csColor& col);
00193
00197 csHalo *GetHalo () { return halo; }
00198
00202 void SetHalo (csHalo *Halo);
00203
00207 int GetAttenuation () {return attenuation;}
00208
00212 void SetAttenuation (int a);
00213
00218 void SetAttenuationVector (const csVector3& pattenv);
00219
00224 const csVector3 &GetAttenuationVector();
00225
00229 float GetInfluenceRadius ();
00230
00234 float GetInfluenceRadiusSq ();
00235
00239 void SetInfluenceRadius (float radius);
00240
00248 void CalculateAttenuationVector (int atttype, float radius = 1.0f,
00249 float brightness = 1.0f);
00250
00258 bool GetDistanceForBrightness (float brightness, float& distance);
00259
00263 float GetBrightnessAtDistance (float d);
00264
00265
00266
00267
00268 void SetLightCallback (iLightCallback* cb)
00269 {
00270 light_cb_vector.Push (cb);
00271 }
00272
00273 void RemoveLightCallback (iLightCallback* cb)
00274 {
00275 light_cb_vector.Delete (cb);
00276 }
00277
00278 int GetLightCallbackCount () const
00279 {
00280 return light_cb_vector.Length ();
00281 }
00282
00283 iLightCallback* GetLightCallback (int idx) const
00284 {
00285 return (iLightCallback*)light_cb_vector.Get (idx);
00286 }
00287
00288
00289 SCF_DECLARE_IBASE_EXT (csObject);
00290
00292 struct Light : public iLight
00293 {
00294 SCF_DECLARE_EMBEDDED_IBASE (csLight);
00295 virtual csLight* GetPrivateObject () { return scfParent; }
00296 virtual const char* GetLightID () { return scfParent->GetLightID (); }
00297 virtual iObject *QueryObject() { return scfParent; }
00298 virtual const csVector3& GetCenter () { return scfParent->GetCenter (); }
00299 virtual void SetCenter (const csVector3& pos)
00300 {
00301 scfParent->SetCenter (pos);
00302 }
00303 virtual iSector *GetSector () { return scfParent->GetSector (); }
00304 virtual void SetSector (iSector* sector) { scfParent->SetSector (sector); }
00305 virtual float GetInfluenceRadius ()
00306 {
00307 return scfParent->GetInfluenceRadius();
00308 }
00309 virtual float GetInfluenceRadiusSq ()
00310 {
00311 return scfParent->GetInfluenceRadiusSq();
00312 }
00313 virtual void SetInfluenceRadius (float radius)
00314 {
00315 scfParent->SetInfluenceRadius (radius);
00316 }
00317 virtual const csColor& GetColor () { return scfParent->GetColor (); }
00318 virtual void SetColor (const csColor& col) { scfParent->SetColor (col); }
00319 virtual bool IsDynamic () const { return scfParent->IsDynamic (); }
00320 virtual int GetAttenuation () { return scfParent->GetAttenuation (); }
00321 virtual void SetAttenuation (int a) { scfParent->SetAttenuation (a); }
00322 virtual float GetBrightnessAtDistance (float d)
00323 {
00324 return scfParent->GetBrightnessAtDistance (d);
00325 }
00326 virtual void SetAttenuationVector(const csVector3& attenv)
00327 { scfParent->SetAttenuationVector(attenv); }
00328 virtual const csVector3 &GetAttenuationVector()
00329 {
00330 return scfParent->GetAttenuationVector();
00331 }
00332 virtual void CalculateAttenuationVector (int atttype, float radius,
00333 float brightness) { scfParent->CalculateAttenuationVector
00334 (atttype, radius, brightness); }
00335 virtual bool GetDistanceForBrightness (float brightness, float& distance)
00336 { return scfParent->GetDistanceForBrightness (brightness, distance); }
00337 virtual iCrossHalo* CreateCrossHalo (float intensity, float cross);
00338 virtual iNovaHalo* CreateNovaHalo (int seed, int num_spokes,
00339 float roundness);
00340 virtual iFlareHalo* CreateFlareHalo ();
00341 virtual csFlags& GetFlags () { return scfParent->flags; }
00342 virtual void SetLightCallback (iLightCallback* cb)
00343 {
00344 scfParent->SetLightCallback (cb);
00345 }
00346 virtual void RemoveLightCallback (iLightCallback* cb)
00347 {
00348 scfParent->RemoveLightCallback (cb);
00349 }
00350 virtual int GetLightCallbackCount () const
00351 {
00352 return scfParent->GetLightCallbackCount ();
00353 }
00354 virtual iLightCallback* GetLightCallback (int idx) const
00355 {
00356 return scfParent->GetLightCallback (idx);
00357 }
00358 virtual uint32 GetLightNumber () const
00359 {
00360 return scfParent->lightnr;
00361 }
00362 } scfiLight;
00363 friend struct Light;
00364 };
00365
00373 class csStatLight : public csLight
00374 {
00375 private:
00382 bool dynamic;
00383
00385 csHashSet lightinginfos;
00386
00387 public:
00395 csStatLight (float x, float y, float z, float dist,
00396 float red, float green, float blue,
00397 bool dynamic);
00404 virtual ~csStatLight ();
00405
00409 virtual bool IsDynamic () const { return dynamic; }
00410
00421 virtual void SetColor (const csColor& col);
00422
00424 void AddAffectedLightingInfo (iLightingInfo* li);
00425
00433 void CalculateLighting ();
00434
00441 void CalculateLighting (iMeshWrapper* mesh);
00442
00443
00444 SCF_DECLARE_IBASE_EXT (csLight);
00445
00447 struct eiStaticLight : public iStatLight
00448 {
00449 SCF_DECLARE_EMBEDDED_IBASE (csStatLight);
00450
00452 virtual csStatLight *GetPrivateObject ()
00453 { return scfParent; }
00454 virtual iObject *QueryObject ()
00455 { return scfParent; }
00456 virtual iLight *QueryLight ()
00457 { return &scfParent->scfiLight; }
00458 virtual void AddAffectedLightingInfo (iLightingInfo* li)
00459 { scfParent->AddAffectedLightingInfo (li); }
00460 } scfiStatLight;
00461 friend struct eiStaticLight;
00462 };
00463
00469 class csDynLight : public csLight
00470 {
00471 private:
00472 csDynLight* next;
00473 csDynLight* prev;
00474
00476 csHashSet lightinginfos;
00477
00478 public:
00485 csDynLight (float x, float y, float z, float dist,
00486 float red, float green, float blue);
00487
00492 virtual ~csDynLight ();
00493
00501 void Setup ();
00502
00507 virtual void SetColor (const csColor& col);
00508
00514 void AddAffectedLightingInfo (iLightingInfo* li);
00515
00519 void RemoveAffectedLightingInfo (iLightingInfo* li);
00520
00522 void SetNext (csDynLight* n) { next = n; }
00524 void SetPrev (csDynLight* p) { prev = p; }
00526 csDynLight* GetNext () { return next; }
00528 csDynLight* GetPrev () { return prev; }
00529
00530
00531 SCF_DECLARE_IBASE_EXT (csLight);
00532
00534 struct eiDynLight : public iDynLight
00535 {
00536 SCF_DECLARE_EMBEDDED_IBASE (csDynLight);
00537
00539 virtual csDynLight* GetPrivateObject ()
00540 { return scfParent; }
00541 virtual void AddAffectedLightingInfo (iLightingInfo* li)
00542 { scfParent->AddAffectedLightingInfo (li); }
00543 virtual void RemoveAffectedLightingInfo (iLightingInfo* li)
00544 { scfParent->RemoveAffectedLightingInfo (li); }
00545 virtual void Setup ()
00546 { scfParent->Setup (); }
00547 virtual iObject *QueryObject ()
00548 { return scfParent; }
00549 virtual iLight *QueryLight ()
00550 { return &(scfParent->scfiLight); }
00551 virtual iDynLight* GetNext ()
00552 {
00553 csDynLight* n = scfParent->GetNext ();
00554 return n ? &(n->scfiDynLight) : 0;
00555 }
00556 } scfiDynLight;
00557 friend struct eiDynLight;
00558 };
00559
00560
00564 class csLightList : public iLightList
00565 {
00566 private:
00567 csRefArrayObject<iLight> list;
00568
00569 public:
00570 SCF_DECLARE_IBASE;
00571
00573 csLightList ();
00574 virtual ~csLightList () { RemoveAll (); }
00575
00577 virtual void PrepareItem (iLight*) { }
00579 virtual void FreeItem (iLight*) { }
00580
00581 virtual int GetCount () const { return list.Length (); }
00582 virtual iLight *Get (int n) const { return list.Get (n); }
00583 virtual int Add (iLight *obj);
00584 virtual bool Remove (iLight *obj);
00585 virtual bool Remove (int n);
00586 virtual void RemoveAll ();
00587 virtual int Find (iLight *obj) const;
00588 virtual iLight *FindByName (const char *Name) const;
00589 virtual iLight *FindByID (const char* id) const;
00590 };
00591
00595 struct csLightingProcessInfo : public iLightingProcessInfo
00596 {
00597 private:
00598
00599 csLight* light;
00600
00601 bool dynamic;
00602
00603 csColor color;
00604
00605 csRefArray<iLightingProcessData> userdatas;
00606
00607 public:
00608 csLightingProcessInfo (csLight* light, bool dynamic);
00609 virtual ~csLightingProcessInfo () { }
00610
00614 csLight* GetCsLight () const { return light; }
00615 virtual iLight* GetLight () const { return &(light->scfiLight); }
00616
00620 virtual bool IsDynamic () const { return dynamic; }
00621
00625 virtual void SetColor (const csColor& col) { color = col; }
00626
00630 virtual const csColor& GetColor () const { return color; }
00631
00633 virtual void AttachUserdata (iLightingProcessData* userdata);
00634
00636 virtual csPtr<iLightingProcessData> QueryUserdata (scfInterfaceID id,
00637 int version);
00638
00640 virtual void FinalizeLighting ();
00641
00642 SCF_DECLARE_IBASE;
00643 };
00644
00645 #endif // __CS_LIGHT_H__
00646