2014-10-11 21:13:10 +00:00
|
|
|
#ifndef C4FOWLIGHT_H
|
|
|
|
#define C4FOWLIGHT_H
|
|
|
|
|
|
|
|
#include "C4Object.h"
|
|
|
|
#include "C4Surface.h"
|
|
|
|
#include "C4FacetEx.h"
|
2014-11-16 17:57:42 +00:00
|
|
|
#include "C4FoWLightSection.h"
|
|
|
|
#include "C4Rect.h"
|
2014-10-11 21:13:10 +00:00
|
|
|
|
2014-11-17 22:01:12 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
/** This class represents one light source. A light source has an associated object with which the light source moves
|
2014-10-12 10:59:25 +00:00
|
|
|
and one light section that handles the light beams for each direction (up, down, left, right).
|
2014-10-11 21:13:10 +00:00
|
|
|
|
|
|
|
Furthermore, each light source has a size. This is usually the object's PlrViewRange. See SetReach.
|
|
|
|
*/
|
|
|
|
class C4FoWLight
|
|
|
|
{
|
|
|
|
friend class C4FoW;
|
|
|
|
public:
|
|
|
|
C4FoWLight(C4Object *pObj);
|
|
|
|
~C4FoWLight();
|
|
|
|
|
|
|
|
private:
|
|
|
|
int32_t iX, iY; // center position
|
2014-10-12 10:59:25 +00:00
|
|
|
int32_t iReach; // maximum length of beams
|
|
|
|
int32_t iFadeout; // number of pixels over which beams fade out
|
2014-10-11 21:13:10 +00:00
|
|
|
int32_t iSize; // size of the light source. Decides smoothness of shadows
|
|
|
|
C4FoWLight *pNext;
|
|
|
|
C4Object *pObj; // Associated object
|
|
|
|
|
2014-11-17 22:01:12 +00:00
|
|
|
std::vector<C4FoWLightSection*> sections;
|
2014-11-16 17:57:42 +00:00
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
public:
|
|
|
|
int32_t getX() const { return iX; }
|
|
|
|
int32_t getY() const { return iY; }
|
|
|
|
int32_t getReach() const { return iReach; }
|
|
|
|
int32_t getFadeout() const { return iFadeout; }
|
|
|
|
int32_t getTotalReach() const { return iReach + iFadeout; }
|
|
|
|
int32_t getSize() const { return iSize; }
|
|
|
|
C4FoWLight *getNext() const { return pNext; }
|
|
|
|
C4Object *getObj() const { return pObj; }
|
|
|
|
|
|
|
|
/** Sets the light's size in pixels. The reach is the total radius of the light while the fadeout is the number of
|
|
|
|
pixels after which the light should dim down */
|
|
|
|
void SetReach(int32_t iReach, int32_t iFadeout);
|
|
|
|
|
2014-10-12 10:59:25 +00:00
|
|
|
/** Triggers the recalculation of all light beams within the given rectangle for this light because the landscape changed. */
|
2014-10-11 21:13:10 +00:00
|
|
|
void Invalidate(C4Rect r);
|
2014-10-12 10:59:25 +00:00
|
|
|
/** Update all light beams within the given rectangle for this light */
|
2014-10-11 21:13:10 +00:00
|
|
|
void Update(C4Rect r);
|
2014-11-16 17:57:42 +00:00
|
|
|
/** Render this light*/
|
2014-10-11 21:13:10 +00:00
|
|
|
void Render(class C4FoWRegion *pRegion, const C4TargetFacet *pOnScreen = NULL);
|
|
|
|
|
2014-11-16 17:57:42 +00:00
|
|
|
private:
|
|
|
|
/** Calculate the intermediate fade points used for constructing the intermediate fade triangles later on */
|
|
|
|
void CalculateIntermediateFadeTriangles(std::list<class C4FoWBeamTriangle> &triangles);
|
|
|
|
|
|
|
|
/** Draws the triangle fan (the area with 100% light around the light source) with the given strategy */
|
|
|
|
void DrawFan(class C4FoWDrawStrategy* pen, std::list<class C4FoWBeamTriangle> &triangles);
|
|
|
|
/** Draws the fadeoot triangles - those around the triangle fan - with the given strategy */
|
|
|
|
void DrawFade(C4FoWDrawStrategy* pen, std::list<C4FoWBeamTriangle> &triangles);
|
|
|
|
/** Draws the fadeout triangles in between the normal fadeout triangles with the given strategy */
|
|
|
|
void DrawIntermediateFadeTriangles(C4FoWDrawStrategy* pen, std::list<C4FoWBeamTriangle> &triangles);
|
|
|
|
/** Returns the (squared) distance from this light source to the given point. Squared simply because we only need this
|
|
|
|
for comparison of distances. So we don't bother to sqrt it */
|
|
|
|
float GetSquaredDistanceTo(int32_t x, int32_t y) { return (x - getX()) * (x - getX()) + (y - getY()) * (y - getY()); }
|
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
};
|
|
|
|
|
2014-11-20 22:12:00 +00:00
|
|
|
// Finds the point where the line through (ax,ay) and (bx,by) crosses through the line
|
|
|
|
// through (px,py) and (qx,qy)
|
|
|
|
bool find_cross(float ax, float ay, float bx, float by,
|
|
|
|
float px, float py, float qx, float qy,
|
|
|
|
float *ix, float *iy, float *abParameter = NULL);
|
|
|
|
|
2014-10-11 21:13:10 +00:00
|
|
|
#endif
|