Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DebugShapeManager.c
Go to the documentation of this file.
2 {
3  protected ref array<ref Shape> m_aShapes = {};
4 
5  protected static const int DEFAULT_COLOUR = Color.RED;
6  protected static const ShapeFlags DEFAULT_FLAGS = ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP;
7 
8  //------------------------------------------------------------------------------------------------
9  Shape AddBBox(vector min, vector max, int colour = DEFAULT_COLOUR, ShapeFlags additionalFlags = 0)
10  {
11  Shape shape = Shape.Create(ShapeType.BBOX, colour, DEFAULT_FLAGS | additionalFlags, min, max);
12  m_aShapes.Insert(shape);
13  return shape;
14  }
15 
16  //------------------------------------------------------------------------------------------------
17  Shape AddLine(vector from, vector to, int colour = DEFAULT_COLOUR)
18  {
19  vector points[2] = { from, to };
20  Shape shape = Shape.CreateLines(colour, DEFAULT_FLAGS, points, 2);
21  m_aShapes.Insert(shape);
22  return shape;
23  }
24 
25  //------------------------------------------------------------------------------------------------
27  Shape AddPolyLine(notnull array<vector> points, int colour = DEFAULT_COLOUR)
28  {
29  int count = points.Count();
30  if (count < 2)
31  return null;
32 
33  if (count > 50)
34  count = 50;
35 
36  vector pointsS[50];
37  for (int i; i < count; i++)
38  {
39  pointsS[i] = points[i];
40  }
41 
42  Shape shape = Shape.CreateLines(colour, DEFAULT_FLAGS, pointsS, count);
43  m_aShapes.Insert(shape);
44  return shape;
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  Shape AddArrow(vector from, vector to, int colour = DEFAULT_COLOUR)
49  {
50  Shape shape = Shape.CreateArrow(from, to, vector.Distance(from, to) * 0.333, colour, DEFAULT_FLAGS);
51  m_aShapes.Insert(shape);
52  return shape;
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  Shape AddCircleXZ(vector centre, float radius, int colour = DEFAULT_COLOUR)
57  {
58  Shape shape = CreateCircle(centre, vector.Up, radius, colour, radius * Math.PI, DEFAULT_FLAGS);
59  m_aShapes.Insert(shape);
60  return shape;
61  }
62 
63  //------------------------------------------------------------------------------------------------
66  Shape AddCircleArcXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour = DEFAULT_COLOUR)
67  {
68  if (coveredAngleRad < 0)
69  {
70  angleStartRad += coveredAngleRad;
71  coveredAngleRad = -coveredAngleRad;
72  }
73 
74  if (angleStartRad < 0 || angleStartRad > Math.PI2)
75  angleStartRad = Math.Repeat(angleStartRad, Math.PI2);
76 
77  if (/* coveredAngleRad < 0 || */ coveredAngleRad > Math.PI2)
78  coveredAngleRad = Math.Repeat(coveredAngleRad, Math.PI2);
79 
80  vector forward = { Math.Cos(angleStartRad), 0, Math.Sin(angleStartRad) };
81 
82  Shape shape = CreateCircleArc(centre, vector.Up, forward, 0, coveredAngleRad * Math.RAD2DEG, radius, colour, radius * (Math.PI2 - coveredAngleRad), DEFAULT_FLAGS);
83  m_aShapes.Insert(shape);
84  return shape;
85  }
86 
87  //------------------------------------------------------------------------------------------------
90  Shape AddCircleSliceXZ(vector centre, float angleStartRad, float coveredAngleRad, float radius, int colour = DEFAULT_COLOUR)
91  {
92  if (coveredAngleRad < 0)
93  {
94  angleStartRad -= coveredAngleRad;
95  coveredAngleRad *= -1;
96  }
97 
98  if (angleStartRad < 0 || angleStartRad > Math.PI2)
99  angleStartRad = Math.Repeat(angleStartRad, Math.PI2);
100 
101  if (coveredAngleRad < 0 || coveredAngleRad > Math.PI2)
102  coveredAngleRad = Math.Repeat(coveredAngleRad, Math.PI2);
103 
104  vector forward = { Math.Cos(angleStartRad), 0, Math.Sin(angleStartRad) };
105 
106  float angleDeg = coveredAngleRad * Math.RAD2DEG;
107  Shape shape = CreateCircleSlice(centre, vector.Up, forward, 0, angleDeg, radius, colour, radius * (Math.PI2 - coveredAngleRad), DEFAULT_FLAGS);
108  m_aShapes.Insert(shape);
109  return shape;
110  }
111 
112  //------------------------------------------------------------------------------------------------
113  Shape AddRectangle(vector origin, vector vectorDir, float length, float width, int colour = DEFAULT_COLOUR)
114  {
115  vector endPos = origin + vectorDir.Normalized() * length;
116 
117  width *= 0.5;
118 
119  float directionRad = Math.Atan2(vectorDir[2], vectorDir[0]);
120  vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
121  vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
122  vector points[5] = {
123  endPos + leftWidth, // top-right
124  endPos + rightWidth, // bottom-right
125  origin + rightWidth, // bottom-left
126  origin + leftWidth, // top-left
127  endPos + leftWidth, // top-right
128  };
129 
130  Shape shape = Shape.CreateLines(colour, DEFAULT_FLAGS, points, 5);
131  m_aShapes.Insert(shape);
132  return shape;
133  }
134 
135  Shape AddAABBRectangleXZ(vector min, vector max, int colour = DEFAULT_COLOUR)
136  {
137  vector points[5];
138  points[0] = Vector(min[0], min[1], max[2]); // top-left
139  points[1] = Vector(max[0], max[1], max[2]); // top-right
140  points[2] = Vector(max[0], max[1], min[2]); // bottom-right
141  points[3] = Vector(min[0], min[1], min[2]); // bottom-left
142  points[4] = Vector(min[0], min[1], max[2]); // top-left
143  Shape shape = Shape.CreateLines(colour, DEFAULT_FLAGS, points, 5);
144  m_aShapes.Insert(shape);
145  return shape;
146  }
147 
149  Shape AddRectangleXZ(vector origin, float directionRad, float length, float width, int colour = DEFAULT_COLOUR)
150  {
151  vector endPos = origin + { Math.Cos(directionRad) * length, 0, Math.Sin(directionRad) * length };
152 
153  width *= 0.5;
154  vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
155  vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
156  vector points[5] = {
157  endPos + leftWidth, // top-right
158  endPos + rightWidth, // bottom-right
159  origin + rightWidth, // bottom-left
160  origin + leftWidth, // top-left
161  endPos + leftWidth, // top-right
162  };
163 
164  Shape shape = Shape.CreateLines(colour, DEFAULT_FLAGS, points, 5);
165  m_aShapes.Insert(shape);
166  return shape;
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  array<ref Shape> AddParallelLines(vector origin, vector vectorDir, float length, float width, int colour = DEFAULT_COLOUR)
171  {
172  vector endPos = origin + vectorDir.Normalized() * length;
173 
174  float directionRad = Math.Atan2(vectorDir[2], vectorDir[0]);
175  vector leftWidth = { Math.Cos(directionRad + Math.PI_HALF) * width, 0, Math.Sin(directionRad + Math.PI_HALF) * width };
176  vector rightWidth = { Math.Cos(directionRad - Math.PI_HALF) * width, 0, Math.Sin(directionRad - Math.PI_HALF) * width };
177 
178  return {
179  AddLine(origin + leftWidth, endPos + leftWidth, colour),
180  AddLine(origin + rightWidth, endPos + rightWidth, colour),
181  };
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  Shape AddSphere(vector centre, float radius, int colour = DEFAULT_COLOUR, ShapeFlags additionalFlags = 0)
186  {
187  Shape shape = Shape.CreateSphere(colour, DEFAULT_FLAGS | additionalFlags, centre, radius);
188  m_aShapes.Insert(shape);
189  return shape;
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  void Remove(notnull Shape shape)
194  {
195  m_aShapes.RemoveItem(shape);
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  void Clear()
200  {
201  m_aShapes.Clear();
202  }
203 }
CreateCircle
Shape CreateCircle(vector pos, vector aroundDir, float radius, int color, int subdivisions, ShapeFlags flags)
Definition: DebugShapes.c:83
CreateCircleArc
Shape CreateCircleArc(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
Definition: DebugShapes.c:119
CreateCircleSlice
Shape CreateCircleSlice(vector pos, vector aroundDir, vector forwardDir, float angMin, float angMax, float radius, int color, int subdivisions, ShapeFlags flags)
Definition: DebugShapes.c:165
SCR_DebugShapeManager
Definition: SCR_DebugShapeManager.c:1