Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ShapeAnalyser.c
Go to the documentation of this file.
1
4{
5 protected bool m_bIsSpline;
6 protected bool m_bIsClosed;
7
8 protected ref array<ref SCR_Ray> m_aAbsoluteAnchorRays;
9 protected ref array<ref SCR_Ray> m_aAbsoluteMidPointRays;
10 protected ref array<ref SCR_Ray> m_aAbsoluteTesselatedPointRays;
11 protected ref array<vector> m_aRelativeAnchorPoints;
12 protected ref array<vector> m_aAbsoluteAnchorPoints;
13 protected ref array<vector> m_aRelativeTesselatedPoints;
14 protected ref array<vector> m_aAbsoluteTesselatedPoints;
15
16 // stats
17 protected float m_fLength2D;
18 protected float m_fLength3D;
19 protected float m_fSurface;
21 protected float m_fMinSlope, m_fMaxSlope;
22
23 //------------------------------------------------------------------------------------------------
25 bool IsClosed()
26 {
27 return m_bIsClosed;
28 }
29
30 //------------------------------------------------------------------------------------------------
32 bool IsSpline()
33 {
34 return m_bIsSpline;
35 }
36
37 //------------------------------------------------------------------------------------------------
39 array<ref SCR_Ray> GetAbsoluteAnchorPointRays()
40 {
41 array<ref SCR_Ray> result = {};
42 foreach (SCR_Ray point : m_aAbsoluteAnchorRays)
43 {
44 result.Insert(point);
45 }
46 return result;
47 }
48
49 //------------------------------------------------------------------------------------------------
52 {
53 array<vector> result = {};
54 result.Copy(m_aAbsoluteAnchorPoints);
55 return result;
56 }
57
58 //------------------------------------------------------------------------------------------------
61 {
62 array<vector> result = {};
63 result.Copy(m_aRelativeAnchorPoints);
64 return result;
65 }
66
67 //------------------------------------------------------------------------------------------------
70 {
71 array<vector> result = {};
72 result.Copy(m_aAbsoluteTesselatedPoints);
73 return result;
74 }
75
76 //------------------------------------------------------------------------------------------------
79 {
80 array<vector> result = {};
81 result.Copy(m_aRelativeTesselatedPoints);
82 return result;
83 }
84
85 //------------------------------------------------------------------------------------------------
87 array<ref SCR_Ray> GetAbsoluteMiddlePointRays()
88 {
89 return SCR_ArrayHelperRefT<SCR_Ray>.GetCopy(m_aAbsoluteMidPointRays);
90 }
91
92 //------------------------------------------------------------------------------------------------
94 array<ref SCR_Ray> GetAbsoluteTesselatedPointRays()
95 {
96 return SCR_ArrayHelperRefT<SCR_Ray>.GetCopy(m_aAbsoluteTesselatedPointRays);
97 }
98
99 //------------------------------------------------------------------------------------------------
106
107 //------------------------------------------------------------------------------------------------
109 static SCR_ShapeAnalyser CreateFromShape(notnull ShapeEntity shapeEntity)
110 {
112 result.m_bIsSpline = SplineShapeEntity.Cast(shapeEntity) != null;
113 result.m_bIsClosed = shapeEntity.IsClosed();
114
115 result.m_aRelativeAnchorPoints = {};
116 shapeEntity.GetPointsPositions(result.m_aRelativeAnchorPoints);
117
118 int pointsCount = result.m_aRelativeAnchorPoints.Count();
119 if (pointsCount < 2)
120 return null;
121
122 result.m_aAbsoluteAnchorPoints = {};
123 foreach (vector relativeAnchorPoint : result.m_aRelativeAnchorPoints)
124 {
125 result.m_aAbsoluteAnchorPoints.Insert(shapeEntity.CoordToParent(relativeAnchorPoint));
126 }
127 result.m_aRelativeTesselatedPoints = {};
128 shapeEntity.GenerateTesselatedShape(result.m_aRelativeTesselatedPoints);
129
130 result.m_aAbsoluteTesselatedPoints = {};
131 result.m_aAbsoluteTesselatedPoints.Reserve(result.m_aRelativeTesselatedPoints.Count());
132 foreach (int i, vector relPoint : result.m_aRelativeTesselatedPoints)
133 {
134 result.m_aAbsoluteTesselatedPoints.Insert(shapeEntity.CoordToParent(relPoint));
135 }
136
137 result.m_aAbsoluteAnchorRays = {};
139
140 vector diff;
141 vector prevTessPoint;
142 int anchorIndex;
143 vector currAnchorPoint = result.m_aAbsoluteAnchorPoints[anchorIndex];
144
145 array<int> pointTesselatedIndices = {};
146
147 // stats
148 array<float> polygon2D = {};
149 result.m_fMinAltitude = currAnchorPoint[1];
150 result.m_fMaxAltitude = result.m_fMinAltitude;
151 result.m_fMinSlope = float.INFINITY;
152 result.m_fMaxSlope = -float.INFINITY;
153
154 int tessCount = result.m_aAbsoluteTesselatedPoints.Count();
155 SCR_Ray ray;
156 foreach (int i, vector currTessPoint : result.m_aAbsoluteTesselatedPoints)
157 {
158 if (i == 0)
159 diff = vector.Direction(currTessPoint, result.m_aAbsoluteTesselatedPoints[1]);
160 else
161 diff = vector.Direction(prevTessPoint, currTessPoint);
162
163 ray = new SCR_Ray();
164 ray.m_vPosition = currTessPoint; // absolute (world) position
165
166 result.m_aAbsoluteAnchorPoints.Insert(ray.m_vPosition);
167
168 float slopeRad = Math.Atan2(diff[1], vector.DistanceXZ(diff, vector.Zero));
169
170 if (i == 0) // first
171 ray.m_vDirection = vector.Direction(currTessPoint, result.m_aAbsoluteTesselatedPoints[i + 1]).Normalized();
172 else if (i < tessCount - 1) // mid-curve - averages previous and next vector
173 ray.m_vDirection = vector.Direction(
174 vector.Direction(currTessPoint, prevTessPoint).Normalized(),
175 vector.Direction(currTessPoint, result.m_aAbsoluteTesselatedPoints[i + 1]).Normalized()
176 ).Normalized();
177 else // last
178 ray.m_vDirection = vector.Direction(prevTessPoint, currTessPoint).Normalized();
179
180 result.m_aAbsoluteTesselatedPointRays.Insert(ray);
181
182 if (currTessPoint == currAnchorPoint)
183 {
184 pointTesselatedIndices.Insert(i);
185 result.m_aAbsoluteAnchorRays.Insert(ray);
186
187 anchorIndex++;
188 if (anchorIndex >= pointsCount)
189 anchorIndex = 0;
190
191 currAnchorPoint = result.m_aAbsoluteAnchorPoints[anchorIndex];
192 }
193
194 // stats
195 if (prevTessPoint)
196 {
197 result.m_fLength2D += vector.DistanceXZ(prevTessPoint, currTessPoint);
198 result.m_fLength3D += vector.Distance(prevTessPoint, currTessPoint);
199 }
200
201 if (ray.m_vPosition[1] < result.m_fMinAltitude)
202 result.m_fMinAltitude = ray.m_vPosition[1];
203
204 if (ray.m_vPosition[1] > result.m_fMaxAltitude)
205 result.m_fMaxAltitude = ray.m_vPosition[1];
206
207 if (slopeRad < result.m_fMinSlope)
208 result.m_fMinSlope = slopeRad;
209
210 if (slopeRad > result.m_fMaxSlope)
211 result.m_fMaxSlope = slopeRad;
212
213 polygon2D.Insert(ray.m_vPosition[0]);
214 polygon2D.Insert(ray.m_vPosition[2]);
215
216 // loop
217 prevTessPoint = currTessPoint;
218 }
219
220 result.m_aAbsoluteMidPointRays = {};
221 if (result.m_bIsSpline) // take the middle point
222 {
223 int prevIndex = pointTesselatedIndices[0];
224 int nextIndex;
225 for (int i = 1, count = pointTesselatedIndices.Count(); i < count; i++)
226 {
227 nextIndex = pointTesselatedIndices[i];
228 result.m_aAbsoluteMidPointRays.Insert(result.m_aAbsoluteTesselatedPointRays[prevIndex + 0.5 * (nextIndex - prevIndex)]);
229 prevIndex = nextIndex;
230 }
231 }
232 else
233 {
234 SCR_Ray currRay = result.m_aAbsoluteAnchorRays[0];
235 SCR_Ray nextRay;
236 for (int i = 1, count = result.m_aAbsoluteAnchorRays.Count(); i < count; i++) // start from 1
237 {
238 nextRay = result.m_aAbsoluteAnchorRays[i];
239 result.m_aAbsoluteMidPointRays.Insert(SCR_Ray.Lerp(currRay, nextRay, 0.5));
240 currRay = nextRay;
241 }
242
243 if (result.m_bIsClosed)
244 result.m_aAbsoluteMidPointRays.Insert(SCR_Ray.Lerp(currRay, result.m_aAbsoluteAnchorRays[0], 0.5));
245 }
246
247 result.m_fSurface = SCR_Math2D.GetPolygonArea(polygon2D); // closed or not
248
249 return result;
250 }
251
252 //---
253 // constructor
254 protected void SCR_ShapeAnalyser();
255}
Definition Math.c:13
array< vector > GetRelativeAnchorPoints()
static SCR_ShapeAnalyser CreateFromShape(notnull ShapeEntity shapeEntity)
array< ref SCR_Ray > GetAbsoluteMiddlePointRays()
array< vector > GetAbsoluteTesselatedPoints()
ref array< vector > m_aAbsoluteAnchorPoints
ref array< vector > m_aAbsoluteTesselatedPoints
array< ref SCR_Ray > GetAbsoluteAnchorPointRays()
ref array< ref SCR_Ray > m_aAbsoluteAnchorRays
points as shown by the Vector tool
float m_fMaxSlope
in radians
array< vector > GetRelativeTesselatedPoints()
ref array< ref SCR_Ray > m_aAbsoluteMidPointRays
tesselated points between two "normal" points, regardless of distance (by num of tesselated points)
array< ref SCR_Ray > GetAbsoluteTesselatedPointRays()
ref array< vector > m_aRelativeAnchorPoints
array< float > GetStats()
void SCR_ShapeAnalyser()
ref array< ref SCR_Ray > m_aAbsoluteTesselatedPointRays
intermediate points
ref array< vector > m_aRelativeTesselatedPoints
array< vector > GetAbsoluteAnchorPoints()