OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FoWLightSection.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2014-2016, The OpenClonk Team and contributors
5  *
6  * Distributed under the terms of the ISC license; see accompanying file
7  * "COPYING" for details.
8  *
9  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10  * See accompanying file "TRADEMARK" for details.
11  *
12  * To redistribute this file separately, substitute the full license texts
13  * for the above references.
14  */
15 
16 #ifndef C4FOWLIGHTSECTION_H
17 #define C4FOWLIGHTSECTION_H
18 
20 
21 #ifndef USE_CONSOLE
22 
23 #include "lib/C4Rect.h"
24 
25 class C4FoWLight;
26 class C4FoWRegion;
27 class C4FoWBeam;
28 class C4FoWBeamTriangle;
29 
37 {
38 public:
39  C4FoWLightSection(C4FoWLight *pLight, int r);
41 
42 private:
43 
44  /* Center light */
45  C4FoWLight *pLight;
46 
47  /* Transformation matrix */
48  int iRot;
49  int a, b, c, d;
50  int ra, rb, rc, rd;
51 
52  /* This section's beams */
53  C4FoWBeam *pBeams;
54 
55 public:
56 
58  void Invalidate(C4Rect r);
60  void Update(C4Rect r);
61 
62 
63  std::list<C4FoWBeamTriangle> CalculateTriangles(C4FoWRegion *region) const;
64 
67  void Prune(int32_t reach);
70  void Dirty(int32_t reach);
71 
72 private:
73 
75  void ClearBeams();
76 
77  // Beam coordinate to landscape coordinate. Beam coordinates are relative to the light source.
78  template <class T> T transDX(T dx, T dy) const;
79  template <class T> T transDY(T dx, T dy) const;
80  template <class T> T transX(T x, T y) const;
81  template <class T> T transY(T x, T y) const;
82 
83  // Landscape coordinate to beam coordinate. Beam coordinates are relative to the light source.
84  template <class T> T rtransDX(T dx, T dy) const;
85  template <class T> T rtransDY(T dx, T dy) const;
86  template <class T> T rtransX(T x, T y) const;
87  template <class T> T rtransY(T x, T y) const;
88 
90  void transTriangles(std::list<C4FoWBeamTriangle> &triangles) const;
91 
93  C4Rect rtransRect(C4Rect r) const {
94  C4Rect Rect(rtransX(r.x, r.y), rtransY(r.x, r.y),
95  rtransDX(r.Wdt, r.Hgt), rtransDY(r.Wdt, r.Hgt));
96  Rect.Normalize();
97  return Rect;
98  }
99 
100  bool isConsistent() const;
101 
106  inline int32_t RectLeftMostX(const C4Rect &r) const { return r.x; }
107  inline int32_t RectLeftMostY(const C4Rect &r) const { return std::max(0, r.x >= 0 ? r.y + r.Hgt : r.y); }
112  inline int32_t RectRightMostX(const C4Rect &r) const { return r.x + r.Wdt; }
113  inline int32_t RectRightMostY(const C4Rect &r) const { return std::max(0, r.x + r.Wdt <= 0 ? r.y + r.Hgt : r.y); }
114 
115  inline void LightBallExtremePoint(float x, float y, float dir, float &lightX, float &lightY) const;
116 
119  inline void LightBallRightMostPoint(float x, float y, float &lightX, float &lightY) const;
120 
123  inline void LightBallLeftMostPoint(float x, float y, float &lightX, float &lightY) const;
124 
125 
127  C4FoWBeam *FindBeamLeftOf(int32_t x, int32_t y) const;
128 
132  int32_t FindBeamsClipped(const C4Rect &rect, C4FoWBeam *&firstBeam, C4FoWBeam *&endBeam) const;
133 
134 public:
135  // Serialization for debugging purposes
136  void CompileFunc(StdCompiler *pComp);
137 
138 };
139 
140 #endif
141 
142 #endif
void Invalidate(C4Rect r)
void Dirty(int32_t reach)
Definition: C4Rect.h:27
void Prune(int32_t reach)
void Normalize()
Definition: C4Rect.h:48
std::list< C4FoWBeamTriangle > CalculateTriangles(C4FoWRegion *region) const
int32_t Wdt
Definition: C4Rect.h:30
void CompileFunc(StdCompiler *pComp)
int32_t y
Definition: C4Rect.h:30
C4FoWLightSection(C4FoWLight *pLight, int r)
int32_t x
Definition: C4Rect.h:30
int32_t Hgt
Definition: C4Rect.h:30