Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_Shape.c
Go to the documentation of this file.
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
79 for (int v = -1; v < resolution; v++)
80 {
81 /*
82 1 - 3 - 5...
83 | \ | \ |
84 0 - 2 - 4...
85
86 Vertex 1: 0-2-1
87 Vertex 2: 1-2-3
88 Vertex 3: 2-4-3
89 Vertex 4: 3-4-5
90 ...
91 */
92 int id = v;
93 if (id < 0) id += resolution;
94 pos2 = positions[id];
95 pos3 = pos2 + vectorUp;
96
97 if (v != -1)
98 {
99 verts[vI] = pos3; vI++;
100 verts[vI] = pos2; vI++;
101 verts[vI] = pos1; vI++;
102 verts[vI] = pos0; vI++;
103
104 int iIS = iI;
105 for (int i = 0; i < 12; i++)
106 {
107 indices[iI] = (vI + vertsTemplate[iI - iIS]) % indicesMod; iI++;
108 }
109 int uIS = uI;
110 for (int i = 0; i < 4; i++)
111 {
112 if (strechMaterial)
113 {
114 uvs[uI] = (resolution - v + uvsTemplate[uI - uIS]) / resolution;
115 if (v == 0) uvs[uI] = uvs[uI] - 1;
116 }
117 else
118 {
119 uvs[uI] = uvsTemplate[uI - uIS];
120 }
121 uI++;
122 uvs[uI] = uvsTemplate[uI - uIS]; uI++;
123 }
124 }
125
126 pos0 = pos2;
127 pos1 = pos3;
128 }
129
130 int numVertices[] = {vI};
131 int numIndices[] = {iI};
132 string materials[1] = {material};
133
134 Resource res = MeshObject.Create(1, numVertices, numIndices, materials, 0);
135 MeshObject meshObject = res.GetResource().ToMeshObject();
136 meshObject.UpdateVerts(0, verts, uvs);
137 meshObject.UpdateIndices(0, indices);
138
139 return res;
140 }
141
142 //------------------------------------------------------------------------------------------------
153 static void DrawCircle(vector transform[4], float radius, int colorOutline, int colorPlane, ShapeFlags shapeFlags)
154 {
155
156 const int sectionCount = 36;
157 const int linesCount = sectionCount + 1; // one extra line is needed to complete outline
158 const int trisCount = sectionCount * 3;
159 vector lines[linesCount];
160 vector tris[trisCount];
161
162 // If angle and section count become parametrized, this could become DrawArc
163 float sectionStep = -360 / sectionCount;
164
165 vector pivot = transform[3];
166 vector point = (vector.Forward * radius).Multiply4(transform);
167
168 for (int i; i < sectionCount; i++)
169 {
170 lines[i] = point;
171 tris[i*3] = pivot;
172 tris[i*3 + 1] = point;
173 point = (Vector(sectionStep * (i + 1), 0, 0).AnglesToVector() * radius);
174 point = point.Multiply4(transform);
175 tris[i*3 + 2] = point;
176 }
177
178 // one extra line is needed to complete outline
179 lines[sectionCount] = point;
180
181 Shape.CreateLines(colorOutline, shapeFlags, lines, linesCount);
182 Shape.CreateTris(colorPlane, shapeFlags, tris, sectionCount);
183 }
184}
SCR_EAIThreatSectorFlags flags
AddonBuildInfoTool id
Definition Color.c:13
Definition Math.c:13
MeshObject.
Definition MeshObject.c:34
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
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.
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)