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/csvector.h"
00027 #include "csengine/lview.h"
00028 #include "csengine/sector.h"
00029 #include "iengine/light.h"
00030 #include "iengine/statlght.h"
00031 #include "iengine/dynlight.h"
00032 #include "iengine/sector.h"
00033
00034 class csLightMap;
00035 class csDynLight;
00036 class csLightPatchPool;
00037 class csHalo;
00038 struct iMeshWrapper;
00039
00045 #define CS_LIGHT_THINGSHADOWS 0x00000001
00046
00052 #define CS_LIGHT_ACTIVEHALO 0x80000000
00053
00080 class csLight : public csObject
00081 {
00082 private:
00084 unsigned long light_id;
00086 static unsigned long last_light_id;
00087
00088 protected:
00090 csSector* sector;
00092 csVector3 center;
00094 float dist;
00096 float sqdist;
00098 float inv_dist;
00100 csColor color;
00102 csHalo *halo;
00103
00105 int attenuation;
00106
00107 public:
00109 csFlags flags;
00110
00111 public:
00113 static int ambient_red;
00115 static int ambient_green;
00117 static int ambient_blue;
00118
00119 public:
00125 csLight (float x, float y, float z, float dist,
00126 float red, float green, float blue);
00127
00134 virtual ~csLight ();
00135
00137 unsigned long GetLightID () { return light_id; }
00138
00142 virtual void SetSector (csSector* sector) { csLight::sector = sector; }
00143
00147 csSector* GetSector () const { return sector; }
00148
00152 void SetCenter (const csVector3& v) { center = v; }
00153
00157 const csVector3& GetCenter () { return center; }
00158
00162 float GetRadius () const { return dist; }
00163
00167 float GetSquaredRadius () const { return sqdist; }
00168
00172 float GetInverseRadius () const { return inv_dist; }
00173
00177 void SetRadius (float radius)
00178 { dist = radius; sqdist = dist*dist; inv_dist = 1 / dist; }
00179
00183 csColor& GetColor () { return color; }
00184
00192 virtual void SetColor (const csColor& col) { color = 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) {attenuation = a;}
00213
00217 float GetBrightnessAtDistance (float d);
00218
00219
00220 SCF_DECLARE_IBASE_EXT (csObject);
00221
00222 struct Light : public iLight
00223 {
00224 SCF_DECLARE_EMBEDDED_IBASE (csLight);
00225 virtual csLight* GetPrivateObject ()
00226 { return scfParent; }
00227 virtual unsigned long GetLightID ()
00228 { return scfParent->GetLightID (); }
00229 virtual iObject *QueryObject()
00230 { return scfParent; }
00231 virtual const csVector3& GetCenter ()
00232 { return scfParent->GetCenter (); }
00233 virtual void SetCenter (const csVector3& pos)
00234 { scfParent->SetCenter (pos); }
00235 virtual iSector *GetSector ()
00236 { return &scfParent->GetSector ()->scfiSector; }
00237 virtual void SetSector (iSector* sector)
00238 { scfParent->SetSector (sector->GetPrivateObject ()); }
00239 virtual float GetRadius ()
00240 { return scfParent->GetRadius (); }
00241 virtual float GetSquaredRadius ()
00242 { return scfParent->GetSquaredRadius (); }
00243 virtual float GetInverseRadius ()
00244 { return scfParent->GetInverseRadius (); }
00245 virtual void SetRadius (float r)
00246 { scfParent->SetRadius (r); }
00247 virtual const csColor& GetColor ()
00248 { return scfParent->GetColor (); }
00249 virtual void SetColor (const csColor& col)
00250 { scfParent->SetColor (col); }
00251 virtual int GetAttenuation ()
00252 { return scfParent->GetAttenuation (); }
00253 virtual void SetAttenuation (int a)
00254 { scfParent->SetAttenuation (a); }
00255 virtual float GetBrightnessAtDistance (float d)
00256 { return scfParent->GetBrightnessAtDistance (d); }
00257
00258 virtual iCrossHalo* CreateCrossHalo (float intensity, float cross);
00259 virtual iNovaHalo* CreateNovaHalo (int seed, int num_spokes,
00260 float roundness);
00261 virtual iFlareHalo* CreateFlareHalo ();
00262 } scfiLight;
00263 };
00264
00272 class csStatLight : public csLight
00273 {
00274 private:
00281 bool dynamic;
00282
00284 csVector lightmaps;
00285
00286 public:
00294 csStatLight (float x, float y, float z, float dist,
00295 float red, float green, float blue,
00296 bool dynamic);
00303 virtual ~csStatLight ();
00304
00308 bool IsDynamic () { return dynamic; }
00309
00320 virtual void SetColor (const csColor& col);
00321
00327 void RegisterLightMap (csLightMap* lmap);
00328
00336 void CalculateLighting ();
00337
00344 void CalculateLighting (iMeshWrapper* mesh);
00345
00346
00347 SCF_DECLARE_IBASE_EXT (csLight);
00348
00349 struct eiStaticLight : public iStatLight
00350 {
00351 SCF_DECLARE_EMBEDDED_IBASE (csStatLight);
00352
00354 virtual csStatLight *GetPrivateObject ()
00355 { return scfParent; }
00356 virtual iObject *QueryObject ()
00357 { return scfParent; }
00358 virtual iLight *QueryLight ()
00359 { return &scfParent->scfiLight; }
00360 } scfiStatLight;
00361 friend struct eiStaticLight;
00362 };
00363
00372 class csLightPatch
00373 {
00374 friend class csLightPatchPool;
00375
00376 private:
00377 csLightPatch* next_poly;
00378 csLightPatch* prev_poly;
00379 csLightPatch* next_light;
00380 csLightPatch* prev_light;
00381
00383 csVector3* vertices;
00385 int num_vertices;
00387 int max_vertices;
00388
00390 csPolygon3D* polygon;
00392 csCurve* curve;
00393
00395 csDynLight* light;
00396
00398 csShadowBlock shadows;
00399
00401 csFrustum *light_frustum;
00402
00403 private:
00407 csLightPatch ();
00408
00413 ~csLightPatch ();
00414
00415 public:
00420 void Initialize (int n);
00421
00425 void RemovePatch ();
00426
00430 csPolygon3D* GetPolygon () { return polygon; }
00431
00435 csCurve* GetCurve () { return curve; }
00436
00440 csDynLight* GetLight () { return light; }
00441
00443 csShadowBlock& GetShadowBlock () { return shadows; }
00444
00446 int GetVertexCount () { return num_vertices; }
00448 csVector3* GetVertices () { return vertices; }
00449
00451 csVector3& GetVertex (int i)
00452 {
00453 CS_ASSERT (vertices != NULL);
00454 CS_ASSERT (i >= 0 && i < num_vertices);
00455 return vertices[i];
00456 }
00457
00462 csLightPatch* GetNextPoly () { return next_poly; }
00463
00468 csLightPatch* GetNextLight () { return next_light; }
00469
00471 void SetPolyCurve (csPolygon3D* pol) { polygon = pol; curve = NULL; }
00473 void SetPolyCurve (csCurve* c) { curve = c; polygon = NULL; }
00475 void SetLight (csDynLight* l) { light = l; }
00477 void AddPolyList (csLightPatch*& first)
00478 {
00479 next_poly = first;
00480 prev_poly = NULL;
00481 if (first)
00482 first->prev_poly = this;
00483 first = this;
00484 }
00486 void RemovePolyList (csLightPatch*& first)
00487 {
00488 if (next_poly) next_poly->prev_poly = prev_poly;
00489 if (prev_poly) prev_poly->next_poly = next_poly;
00490 else first = next_poly;
00491 prev_poly = next_poly = NULL;
00492 polygon = NULL;
00493 curve = NULL;
00494 }
00496 void AddLightList (csLightPatch*& first)
00497 {
00498 next_light = first;
00499 prev_light = NULL;
00500 if (first)
00501 first->prev_light = this;
00502 first = this;
00503 }
00505 void RemoveLightList (csLightPatch*& first)
00506 {
00507 if (next_light) next_light->prev_light = prev_light;
00508 if (prev_light) prev_light->next_light = next_light;
00509 else first = next_light;
00510 prev_light = next_light = NULL;
00511 light = NULL;
00512 }
00513
00515 void SetLightFrustum (csFrustum* lf) { light_frustum = lf; }
00517 csFrustum* GetLightFrustum () { return light_frustum; }
00518 };
00519
00525 class csDynLight : public csLight
00526 {
00527 private:
00528 csDynLight* next;
00529 csDynLight* prev;
00530
00532 csLightPatch* lightpatches;
00533
00534 public:
00541 csDynLight (float x, float y, float z, float dist,
00542 float red, float green, float blue);
00543
00548 virtual ~csDynLight ();
00549
00557 void Setup ();
00558
00563 virtual void SetColor (const csColor& col);
00564
00570 void UnlinkLightpatch (csLightPatch* lp);
00571
00575 void AddLightpatch (csLightPatch* lp);
00576
00578 void SetNext (csDynLight* n) { next = n; }
00580 void SetPrev (csDynLight* p) { prev = p; }
00582 csDynLight* GetNext () { return next; }
00584 csDynLight* GetPrev () { return prev; }
00585
00586
00587 SCF_DECLARE_IBASE_EXT (csLight);
00588
00589 struct eiDynLight : public iDynLight
00590 {
00591 SCF_DECLARE_EMBEDDED_IBASE (csDynLight);
00592
00594 virtual csDynLight* GetPrivateObject ()
00595 { return scfParent; }
00596 virtual void Setup ()
00597 { scfParent->Setup (); }
00598 virtual iObject *QueryObject ()
00599 { return scfParent; }
00600 virtual iLight *QueryLight ()
00601 { return &(scfParent->scfiLight); }
00602 virtual iDynLight* GetNext ()
00603 { return &(scfParent->GetNext())->scfiDynLight; }
00604 } scfiDynLight;
00605 friend struct eiDynLight;
00606 };
00607
00608 #endif // __CS_LIGHT_H__