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 #include <list>
25 
26 class C4FoWLight;
27 class C4FoWRegion;
28 class C4FoWBeam;
29 class C4FoWBeamTriangle;
30 
38 {
39 public:
40  C4FoWLightSection(C4FoWLight *pLight, int r);
42 
43 private:
44 
45  /* Center light */
46  C4FoWLight *pLight;
47 
48  /* Transformation matrix */
49  int iRot;
50  int a, b, c, d;
51  int ra, rb, rc, rd;
52 
53  /* This section's beams */
54  C4FoWBeam *pBeams;
55 
56 public:
57 
59  void Invalidate(C4Rect r);
61  void Update(C4Rect r);
62 
63 
64  std::list<C4FoWBeamTriangle> CalculateTriangles(C4FoWRegion *region) const;
65 
68  void Prune(int32_t reach);
71  void Dirty(int32_t reach);
72 
73 private:
74 
76  void ClearBeams();
77 
78  // Beam coordinate to landscape coordinate. Beam coordinates are relative to the light source.
79  template <class T> T transDX(T dx, T dy) const;
80  template <class T> T transDY(T dx, T dy) const;
81  template <class T> T transX(T x, T y) const;
82  template <class T> T transY(T x, T y) const;
83 
84  // Landscape coordinate to beam coordinate. Beam coordinates are relative to the light source.
85  template <class T> T rtransDX(T dx, T dy) const;
86  template <class T> T rtransDY(T dx, T dy) const;
87  template <class T> T rtransX(T x, T y) const;
88  template <class T> T rtransY(T x, T y) const;
89 
91  void transTriangles(std::list<C4FoWBeamTriangle> &triangles) const;
92 
94  C4Rect rtransRect(C4Rect r) const {
95  C4Rect Rect(rtransX(r.x, r.y), rtransY(r.x, r.y),
96  rtransDX(r.Wdt, r.Hgt), rtransDY(r.Wdt, r.Hgt));
97  Rect.Normalize();
98  return Rect;
99  }
100 
101  bool isConsistent() const;
102 
107  inline int32_t RectLeftMostX(const C4Rect &r) const { return r.x; }
108  inline int32_t RectLeftMostY(const C4Rect &r) const { return std::max(0, r.x >= 0 ? r.y + r.Hgt : r.y); }
113  inline int32_t RectRightMostX(const C4Rect &r) const { return r.x + r.Wdt; }
114  inline int32_t RectRightMostY(const C4Rect &r) const { return std::max(0, r.x + r.Wdt <= 0 ? r.y + r.Hgt : r.y); }
115 
116  inline void LightBallExtremePoint(float x, float y, float dir, float &lightX, float &lightY) const;
117 
120  inline void LightBallRightMostPoint(float x, float y, float &lightX, float &lightY) const;
121 
124  inline void LightBallLeftMostPoint(float x, float y, float &lightX, float &lightY) const;
125 
126 
128  C4FoWBeam *FindBeamLeftOf(int32_t x, int32_t y) const;
129 
133  int32_t FindBeamsClipped(const C4Rect &rect, C4FoWBeam *&firstBeam, C4FoWBeam *&endBeam) const;
134 
135 public:
136  // Serialization for debugging purposes
137  void CompileFunc(StdCompiler *pComp);
138 
139 };
140 
141 #endif
142 
143 #endif
void Invalidate(C4Rect r)
void Dirty(int32_t reach)
Definition: C4Rect.h:29
void Prune(int32_t reach)
void Normalize()
Definition: C4Rect.h:50
std::list< C4FoWBeamTriangle > CalculateTriangles(C4FoWRegion *region) const
int32_t Wdt
Definition: C4Rect.h:32
void CompileFunc(StdCompiler *pComp)
int32_t y
Definition: C4Rect.h:32
C4FoWLightSection(C4FoWLight *pLight, int r)
int32_t x
Definition: C4Rect.h:32
int32_t Hgt
Definition: C4Rect.h:32