Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_Shape.c
Go to the documentation of this file.
1 class SCR_Shape
2 {
3  static void GetBoundsPoints(vector min, vector max, out vector points[19])
4  {
5  //--- Front
6  points[0] = min;
7  points[1] = Vector(max[0], min[1], min[2]);
8  points[2] = Vector(max[0], max[1], min[2]);
9  points[3] = Vector(min[0], max[1], min[2]);
10 
11  //--- Left
12  points[4] = min;
13  points[5] = Vector(min[0], min[1], max[2]);
14  points[6] = Vector(min[0], max[1], max[2]);
15 
16  //--- Top
17  points[7] = Vector(min[0], max[1], min[2]);
18  points[8] = Vector(max[0], max[1], min[2]);
19  points[9] = max;
20 
21  //--- Back
22  points[10] = Vector(min[0], max[1], max[2]);
23  points[11] = Vector(min[0], min[1], max[2]);
24  points[12] = Vector(max[0], min[1], max[2]);
25 
26  //--- Right
27  points[13] = max;
28  points[14] = Vector(max[0], max[1], min[2]);
29  points[15] = Vector(max[0], min[1], min[2]);
30 
31  //--- Bottom
32  points[16] = Vector(max[0], min[1], max[2]);
33  points[17] = Vector(min[0], min[1], max[2]);
34  points[18] = min;
35  }
36  static Shape CreateBounds(vector min, vector max, int color, ShapeFlags flags)
37  {
38  vector points[19];
39  GetBoundsPoints(min, max, points);
40 
41  return Shape.CreateLines(Color.RED, ShapeFlags.NOZBUFFER, points, 19);
42  }
43 
52  static Resource CreateAreaMesh(array<vector> positions, float height, string material, bool strechMaterial)
53  {
54  if (!material)
55  return null;
56 
57  int resolution = positions.Count();
58  if (resolution == 0) return null;
59 
60  if (resolution * 12 > 720)
61  {
62  Print(string.Format("Cannot generate shape, resolution %1 is above maximum value %2!", resolution, 720 / 12), LogLevel.ERROR);
63  return null;
64  }
65 
66  vector verts[244];
67  int indices[732];
68  float uvs[1464];
69 
70  float dirStep = Math.PI2 / resolution;
71  float uvsTemplate[] = {0,0, 0,1, 1,0, 1,1};
72  int vertsTemplate[] = {0,2,1, 1,2,3, 3,2,1, 1,2,0};
73  int indicesMod = 4 * resolution;
74  int vI, iI, uI;
75  vector vectorUp = vector.Up * height;
76  vector pos0, pos1, pos2, pos3;
77  vector matrix[4];
78  float entitySurfaceY;
79 
80  for (int v = -1; v < resolution; v++)
81  {
82  /*
83  1 - 3 - 5...
84  | \ | \ |
85  0 - 2 - 4...
86 
87  Vertex 1: 0-2-1
88  Vertex 2: 1-2-3
89  Vertex 3: 2-4-3
90  Vertex 4: 3-4-5
91  ...
92  */
93  int id = v;
94  if (id < 0) id += resolution;
95  pos2 = positions[id];
96  pos3 = pos2 + vectorUp;
97 
98  if (v != -1)
99  {
100  verts[vI] = pos3; vI++;
101  verts[vI] = pos2; vI++;
102  verts[vI] = pos1; vI++;
103  verts[vI] = pos0; vI++;
104 
105  int iIS = iI;
106  for (int i = 0; i < 12; i++)
107  {
108  indices[iI] = (vI + vertsTemplate[iI - iIS]) % indicesMod; iI++;
109  }
110  int uIS = uI;
111  for (int i = 0; i < 4; i++)
112  {
113  if (strechMaterial)
114  {
115  uvs[uI] = (resolution - v + uvsTemplate[uI - uIS]) / resolution;
116  if (v == 0) uvs[uI] = uvs[uI] - 1;
117  }
118  else
119  {
120  uvs[uI] = uvsTemplate[uI - uIS];
121  }
122  uI++;
123  uvs[uI] = uvsTemplate[uI - uIS]; uI++;
124  }
125  }
126 
127  pos0 = pos2;
128  pos1 = pos3;
129  }
130 
131  int numVertices[] = {vI};
132  int numIndices[] = {iI};
133  string materials[1] = {material};
134 
135  Resource res = MeshObject.Create(1, numVertices, numIndices, materials, 0);
136  MeshObject meshObject = res.GetResource().ToMeshObject();
137  meshObject.UpdateVerts(0, verts, uvs);
138  meshObject.UpdateIndices(0, indices);
139 
140  return res;
141  }
142 
143  //------------------------------------------------------------------------------------------------
154  static void DrawCircle(vector transform[4], float radius, int colorOutline, int colorPlane, ShapeFlags shapeFlags)
155  {
156 
157  const int sectionCount = 36;
158  const int linesCount = sectionCount + 1; // one extra line is needed to complete outline
159  const int trisCount = sectionCount * 3;
160  vector lines[linesCount];
161  vector tris[trisCount];
162 
163  // If angle and section count become parametrized, this could become DrawArc
164  float sectionStep = -360 / sectionCount;
165 
166  vector pivot = transform[3];
167  vector point = (vector.Forward * radius).Multiply4(transform);
168 
169  for (int i; i < sectionCount; i++)
170  {
171  lines[i] = point;
172  tris[i*3] = pivot;
173  tris[i*3 + 1] = point;
174  point = (Vector(sectionStep * (i + 1), 0, 0).AnglesToVector() * radius);
175  point = point.Multiply4(transform);
176  tris[i*3 + 2] = point;
177  }
178 
179  // one extra line is needed to complete outline
180  lines[sectionCount] = point;
181 
182  Shape.CreateLines(colorOutline, shapeFlags, lines, linesCount);
183  Shape.CreateTris(colorPlane, shapeFlags, tris, sectionCount);
184  }
185 }
SCR_Shape
Definition: SCR_Shape.c:1