Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DebugShapeManager.c
Go to the documentation of this file.
2{
3 protected ref set<ref Shape> m_Shapes = new set<ref Shape>();
4 protected ref set<ref DebugTextWorldSpace> m_ScreenSpaceTexts = new set<ref DebugTextWorldSpace>();
5
6 protected static const int DEFAULT_SHAPE_COLOUR = Color.RED;
7 protected static const ShapeFlags DEFAULT_SHAPE_FLAGS = ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP;
8
9 protected static const int DEFAULT_TEXT_COLOUR = Color.WHITE;
10 protected static const int DEFAULT_TEXT_BACKGROUND_COLOUR = 0x88000000;
11 protected static const DebugTextFlags DEFAULT_TEXT_FLAGS = DebugTextFlags.CENTER | DebugTextFlags.FACE_CAMERA | DebugTextFlags.IN_WORLD;
12
13 //------------------------------------------------------------------------------------------------
20 Shape AddBBox(vector min, vector max, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
21 {
22 Shape shape = Shape.Create(ShapeType.BBOX, colour, DEFAULT_SHAPE_FLAGS | additionalFlags, min, max);
23 m_Shapes.Insert(shape);
24 return shape;
25 }
26
27 //------------------------------------------------------------------------------------------------
34 Shape AddLine(vector from, vector to, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
35 {
36 vector points[2] = { from, to };
37 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS | additionalFlags, points, 2);
38 m_Shapes.Insert(shape);
39 return shape;
40 }
41
42 //------------------------------------------------------------------------------------------------
47 Shape AddPolyLine(notnull array<vector> points, int colour = DEFAULT_SHAPE_COLOUR)
48 {
49 int count = points.Count();
50 if (count < 2)
51 return null;
52
53 if (count > 50)
54 count = 50;
55
56 vector pointsS[50];
57 for (int i; i < count; i++)
58 {
59 pointsS[i] = points[i];
60 }
61
62 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS, pointsS, count);
63 m_Shapes.Insert(shape);
64 return shape;
65 }
66
67 //------------------------------------------------------------------------------------------------
75 Shape AddArrow(vector from, vector to, float customSize = 0, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
76 {
77 if (customSize <= 0)
78 customSize = vector.Distance(from, to) * 0.333;
79
80 Shape shape = Shape.CreateArrow(from, to, customSize, colour, DEFAULT_SHAPE_FLAGS | additionalFlags);
81 m_Shapes.Insert(shape);
82 return shape;
83 }
84
85 //------------------------------------------------------------------------------------------------
91 Shape AddCircleXZ(vector centre, float radius, int colour = DEFAULT_SHAPE_COLOUR)
92 {
93 Shape shape = CreateCircle(centre, vector.Up, radius, colour, radius * Math.PI, DEFAULT_SHAPE_FLAGS);
94 m_Shapes.Insert(shape);
95 return shape;
96 }
97
98 //------------------------------------------------------------------------------------------------
106 Shape AddCircleArcXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour = DEFAULT_SHAPE_COLOUR)
107 {
108 if (coveredAngleRad < 0)
109 {
110 angleStartRad += coveredAngleRad;
111 coveredAngleRad = -coveredAngleRad;
112 }
113
114 if (angleStartRad < 0 || angleStartRad > Math.PI2)
115 angleStartRad = Math.Repeat(angleStartRad, Math.PI2);
116
117 if (/* coveredAngleRad < 0 || */ coveredAngleRad > Math.PI2)
118 coveredAngleRad = Math.Repeat(coveredAngleRad, Math.PI2);
119
120 vector forward = { Math.Cos(angleStartRad), 0, Math.Sin(angleStartRad) };
121
122 Shape shape = CreateCircleArc(centre, vector.Up, forward, 0, coveredAngleRad * Math.RAD2DEG, radius, colour, radius * (Math.PI2 - coveredAngleRad), DEFAULT_SHAPE_FLAGS);
123 m_Shapes.Insert(shape);
124 return shape;
125 }
126
127 //------------------------------------------------------------------------------------------------
135 Shape AddCircleSliceXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour = DEFAULT_SHAPE_COLOUR)
136 {
137 if (coveredAngleRad < 0)
138 {
139 angleStartRad -= coveredAngleRad;
140 coveredAngleRad *= -1;
141 }
142
143 if (angleStartRad < 0 || angleStartRad > Math.PI2)
144 angleStartRad = Math.Repeat(angleStartRad, Math.PI2);
145
146 if (coveredAngleRad < 0 || coveredAngleRad > Math.PI2)
147 coveredAngleRad = Math.Repeat(coveredAngleRad, Math.PI2);
148
149 vector forward = { Math.Cos(angleStartRad), 0, Math.Sin(angleStartRad) };
150
151 float angleDeg = coveredAngleRad * Math.RAD2DEG;
152 Shape shape = CreateCircleSlice(centre, vector.Up, forward, 0, angleDeg, radius, colour, radius * (Math.PI2 - coveredAngleRad), DEFAULT_SHAPE_FLAGS);
153 m_Shapes.Insert(shape);
154 return shape;
155 }
156
157 //------------------------------------------------------------------------------------------------
165 Shape AddRectangle(vector origin, vector vectorDir, float length, float width, int colour = DEFAULT_SHAPE_COLOUR)
166 {
167 vector endPos = origin + vectorDir.Normalized() * length;
168
169 width *= 0.5;
170
171 float directionRad = Math.Atan2(vectorDir[2], vectorDir[0]);
172 vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
173 vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
174 vector points[5] = {
175 endPos + leftWidth, // top-right
176 endPos + rightWidth, // bottom-right
177 origin + rightWidth, // bottom-left
178 origin + leftWidth, // top-left
179 endPos + leftWidth, // top-right
180 };
181
182 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS, points, 5);
183 m_Shapes.Insert(shape);
184 return shape;
185 }
186
187 //------------------------------------------------------------------------------------------------
194 {
195 vector points[5];
196 points[0] = Vector(min[0], min[1], max[2]); // top-left
197 points[1] = Vector(max[0], max[1], max[2]); // top-right
198 points[2] = Vector(max[0], max[1], min[2]); // bottom-right
199 points[3] = Vector(min[0], min[1], min[2]); // bottom-left
200 points[4] = Vector(min[0], min[1], max[2]); // top-left
201 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS, points, 5);
202 m_Shapes.Insert(shape);
203 return shape;
204 }
205
206 //------------------------------------------------------------------------------------------------
214 Shape AddRectangleXZ(vector origin, float directionRad, float length, float width, int colour = DEFAULT_SHAPE_COLOUR)
215 {
216 vector endPos = origin + { Math.Cos(directionRad) * length, 0, Math.Sin(directionRad) * length };
217
218 width *= 0.5;
219 vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
220 vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
221 vector points[5] = {
222 endPos + leftWidth, // top-right
223 endPos + rightWidth, // bottom-right
224 origin + rightWidth, // bottom-left
225 origin + leftWidth, // top-left
226 endPos + leftWidth, // top-right
227 };
228
229 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS, points, 5);
230 m_Shapes.Insert(shape);
231 return shape;
232 }
233
234 //------------------------------------------------------------------------------------------------
242 array<ref Shape> AddParallelLines(vector origin, vector vectorDir, float length, float width, int colour = DEFAULT_SHAPE_COLOUR)
243 {
244 vector endPos = origin + vectorDir.Normalized() * length;
245
246 width *= 0.5; // width 100 = -50 / +50
247 float directionRad = Math.Atan2(vectorDir[2], vectorDir[0]);
248 vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
249 vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
250
251 return {
252 AddLine(origin + leftWidth, endPos + leftWidth, colour),
253 AddLine(origin + rightWidth, endPos + rightWidth, colour),
254 };
255 }
256
257 //------------------------------------------------------------------------------------------------
265 Shape AddBounds(notnull array<vector> boundsPositionsWorldSpace, float height, vector upDirection = vector.Up, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
266 {
267 vector verts[400];
268 int numberOfVerts;
269 int lastId = boundsPositionsWorldSpace.Count() - 1;
270 vector heightOffset = upDirection * height;
271 vector nextPosition;
272 foreach (int i, vector position : boundsPositionsWorldSpace)
273 {
274 verts[numberOfVerts] = position;
275 numberOfVerts++;
276 if (i < lastId)
277 nextPosition = boundsPositionsWorldSpace[i + 1];
278 else
279 nextPosition = boundsPositionsWorldSpace[0];
280
281 verts[numberOfVerts] = nextPosition + heightOffset; // diagonal
282 numberOfVerts++;
283 verts[numberOfVerts] = nextPosition; // right edge
284 numberOfVerts++;
285 verts[numberOfVerts] = position; // bottom edge
286 numberOfVerts++;
287 verts[numberOfVerts] = position + heightOffset; // left edge
288 numberOfVerts++;
289 verts[numberOfVerts] = nextPosition + heightOffset; // top edge
290 numberOfVerts++;
291 }
292
293 Shape shape = Shape.CreateLines(colour, ShapeFlags.DEFAULT | additionalFlags, verts, numberOfVerts);
294 m_Shapes.Insert(shape);
295 return shape;
296 }
297
298 //------------------------------------------------------------------------------------------------
305 Shape AddSphere(vector centre, float radius, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
306 {
307 Shape shape = Shape.CreateSphere(colour, DEFAULT_SHAPE_FLAGS | additionalFlags, centre, radius);
308 m_Shapes.Insert(shape);
309 return shape;
310 }
311
312 //------------------------------------------------------------------------------------------------
322 Shape AddTrapezoidalPrism(vector centerOfTopBasePos, vector directionUp, float smallBaseRadius, float largeBaseRadius, float height, int subdivisions = 6, int colour = DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags = 0)
323 {
324 if (subdivisions < 2)
325 subdivisions = 2;
326
327 if (subdivisions > 50)
328 subdivisions = 50;
329
330 vector forward = directionUp.Perpend();
331 forward.Normalize();
332
333 vector right = directionUp * forward;
334 right.Normalize();
335
336 vector mat[3] = { right, directionUp, forward };
337
338 float sectionDeg = 360 / subdivisions;
339 subdivisions++;
340
341 vector points[400];
342 int pointsCount;
343 vector point;
344 vector bigBasePos = centerOfTopBasePos + vector.Up.Multiply3(mat) * height;
345 for (int i; i < subdivisions; i++)
346 {
347 point = vector.FromYaw(sectionDeg * i) * smallBaseRadius;
348 point = point.Multiply3(mat);
349 points[pointsCount] = point + centerOfTopBasePos;
350 pointsCount++;
351
352 point = vector.FromYaw(sectionDeg * i) * largeBaseRadius;
353 point = point.Multiply3(mat);
354 points[pointsCount] = point + bigBasePos;
355 pointsCount++;
356
357 point = vector.FromYaw(sectionDeg * (i + 1)) * largeBaseRadius;
358 point = point.Multiply3(mat);
359 points[pointsCount] = point + bigBasePos;
360 pointsCount++;
361
362 points[pointsCount] = points[pointsCount - 2];
363 pointsCount++;
364
365 points[pointsCount] = points[pointsCount - 4];
366 pointsCount++;
367
368 point = vector.FromYaw(sectionDeg * (i + 1)) * smallBaseRadius;
369 point = point.Multiply3(mat);
370 points[pointsCount] = point + centerOfTopBasePos;
371 pointsCount++;
372 }
373
374 Shape shape = Shape.CreateLines(colour, DEFAULT_SHAPE_FLAGS | additionalFlags, points, pointsCount);
375 m_Shapes.Insert(shape);
376 return shape;
377 }
378
379 //------------------------------------------------------------------------------------------------
387 DebugTextWorldSpace AddText(string text, vector worldPos, float size = 2.0, int colour = DEFAULT_TEXT_COLOUR, int backgroundColour = DEFAULT_TEXT_BACKGROUND_COLOUR)
388 {
389#ifdef WORKBENCH
390 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
391 BaseWorld world = worldEditor.GetApi().GetWorld();
392#else // normal game
393 BaseWorld world = GetGame().GetWorld();
394#endif // WORKBENCH
395
396 if (!world)
397 {
398 Print("[SCR_DebugShapeManager.AddText] cannot determine world (" + __FILE__ + " L" + __LINE__ + ")", LogLevel.WARNING);
399 return null;
400 }
401
402 if (size < 0.1)
403 size = 0.1;
404
405 if (size > 10)
406 size = 10;
407
408 DebugTextWorldSpace debugText = DebugTextWorldSpace.Create(world, text, DEFAULT_TEXT_FLAGS, worldPos[0], worldPos[1], worldPos[2], size, colour, backgroundColour);
409 m_ScreenSpaceTexts.Insert(debugText);
410 return debugText;
411 }
412
413 //------------------------------------------------------------------------------------------------
416 void Add(notnull Shape shape)
417 {
418 m_Shapes.Insert(shape);
419 }
420
421 //------------------------------------------------------------------------------------------------
424 void Add(notnull DebugTextWorldSpace text)
425 {
426 m_ScreenSpaceTexts.Insert(text);
427 }
428
429 //------------------------------------------------------------------------------------------------
432 void Remove(notnull Shape shape)
433 {
434 m_Shapes.RemoveItem(shape);
435 }
436
437 //------------------------------------------------------------------------------------------------
440 void Remove(notnull DebugTextWorldSpace text)
441 {
442 m_ScreenSpaceTexts.RemoveItem(text);
443 }
444
445 //------------------------------------------------------------------------------------------------
447 void Clear()
448 {
449 m_Shapes.Clear();
450 m_ScreenSpaceTexts.Clear();
451 }
452
453 //------------------------------------------------------------------------------------------------
456 {
457 m_Shapes.Clear();
458 }
459
460 //------------------------------------------------------------------------------------------------
463 {
464 m_ScreenSpaceTexts.Clear();
465 }
466}
Shape CreateCircleSlice(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
Shape CreateCircle(vector pos, vector aroundDir, float radius, int color, int subdivisions, ShapeFlags flags)
Definition DebugShapes.c:91
Shape CreateCircleArc(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
ArmaReforgerScripted GetGame()
Definition game.c:1398
int size
vector position
Definition Color.c:13
Definition Math.c:13
Shape AddArrow(vector from, vector to, float customSize=0, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
void Remove(notnull DebugTextWorldSpace text)
void Add(notnull Shape shape)
ref set< ref Shape > m_Shapes
void Clear()
Remove all stored shapes and texts.
void Remove(notnull Shape shape)
Shape AddRectangleXZ(vector origin, float directionRad, float length, float width, int colour=DEFAULT_SHAPE_COLOUR)
static const DebugTextFlags DEFAULT_TEXT_FLAGS
Shape AddLine(vector from, vector to, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
array< ref Shape > AddParallelLines(vector origin, vector vectorDir, float length, float width, int colour=DEFAULT_SHAPE_COLOUR)
DebugTextWorldSpace AddText(string text, vector worldPos, float size=2.0, int colour=DEFAULT_TEXT_COLOUR, int backgroundColour=DEFAULT_TEXT_BACKGROUND_COLOUR)
Shape AddAABBRectangleXZ(vector min, vector max, int colour=DEFAULT_SHAPE_COLOUR)
void Add(notnull DebugTextWorldSpace text)
Shape AddPolyLine(notnull array< vector > points, int colour=DEFAULT_SHAPE_COLOUR)
Shape AddRectangle(vector origin, vector vectorDir, float length, float width, int colour=DEFAULT_SHAPE_COLOUR)
Shape AddBBox(vector min, vector max, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
ref set< ref DebugTextWorldSpace > m_ScreenSpaceTexts
static const ShapeFlags DEFAULT_SHAPE_FLAGS
Shape AddTrapezoidalPrism(vector centerOfTopBasePos, vector directionUp, float smallBaseRadius, float largeBaseRadius, float height, int subdivisions=6, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
static const int DEFAULT_TEXT_COLOUR
static const int DEFAULT_TEXT_BACKGROUND_COLOUR
static const int DEFAULT_SHAPE_COLOUR
Shape AddCircleArcXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour=DEFAULT_SHAPE_COLOUR)
void ClearTexts()
Remove all stored texts.
Shape AddSphere(vector centre, float radius, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
Shape AddBounds(notnull array< vector > boundsPositionsWorldSpace, float height, vector upDirection=vector.Up, int colour=DEFAULT_SHAPE_COLOUR, ShapeFlags additionalFlags=0)
Shape AddCircleSliceXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour=DEFAULT_SHAPE_COLOUR)
Shape AddCircleXZ(vector centre, float radius, int colour=DEFAULT_SHAPE_COLOUR)
void ClearShapes()
Remove all stored shapes.
Instance of created debug visualizer.
Definition Shape.c:14
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ShapeType
Definition ShapeType.c:13
DebugTextFlags
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
ShapeFlags
Definition ShapeFlags.c:13
proto native vector Vector(float x, float y, float z)