52 | function DebugUtil.drawDebugArea(start, width, height, r,g,b, alignToGround, drawNodes, drawCircle, offsetY) |
53 | offsetY = offsetY or 0 |
54 | local x,y,z = getWorldTranslation(start) |
55 | local x1,y1,z1 = getWorldTranslation(width) |
56 | local x2,y2,z2 = getWorldTranslation(height) |
57 | |
58 | y = y + offsetY |
59 | y1 = y1 + offsetY |
60 | y2 = y2 + offsetY |
61 | |
62 | DebugUtil.drawDebugAreaRectangle(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b) |
63 | |
64 | if drawNodes == nil or drawNodes then |
65 | DebugUtil.drawDebugNode(start, getName(start), alignToGround, offsetY) |
66 | DebugUtil.drawDebugNode(width, getName(width), alignToGround, offsetY) |
67 | DebugUtil.drawDebugNode(height, getName(height), alignToGround, offsetY) |
68 | end |
69 | |
70 | local lsx, lsy, lsz, lex, ley, lez, radius = DensityMapHeightUtil.getLineByArea(start, width, height, 0.5) |
71 | |
72 | lsy = lsy + offsetY |
73 | ley = ley + offsetY |
74 | |
75 | if alignToGround then |
76 | lsy = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lsx,0,lsz)+0.1 |
77 | ley = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, lex,0,lez)+0.1 |
78 | end |
79 | |
80 | if drawCircle == nil or drawCircle then |
81 | drawDebugLine(lsx, lsy, lsz, 1,1,1, lex, ley, lez, 1,1,1) |
82 | DebugUtil.drawDebugCircle((lsx+lex)*0.5, (lsy+ley)*0.5, (lsz+lez)*0.5, radius, 20, nil) |
83 | end |
84 | end |
109 | function DebugUtil.drawDebugAreaRectangle(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b) |
110 | if alignToGround then |
111 | y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1 |
112 | y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1 |
113 | y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1 |
114 | end |
115 | |
116 | drawDebugLine(x,y,z, r,g,b, x1, y1, z1, r,g,b) |
117 | drawDebugLine(x,y,z, r,g,b, x2, y2, z2, r,g,b) |
118 | |
119 | local dirX1, dirY1, dirZ1 = x1-x, y1-y, z1-z |
120 | local dirX2, dirY2, dirZ2 = x2-x, y2-y, z2-z |
121 | |
122 | drawDebugLine(x2,y2,z2, r,g,b, x2+dirX1, y2+dirY1, z2+dirZ1, r,g,b) |
123 | drawDebugLine(x1,y1,z1, r,g,b, x1+dirX2, y1+dirY2, z1+dirZ2, r,g,b) |
124 | end |
128 | function DebugUtil.drawDebugAreaRectangleFilled(x,y,z, x1,y1,z1, x2,y2,z2, alignToGround, r,g,b,a) |
129 | local x3, y3, z3 = x1, (y1+y2)/2, z2 |
130 | |
131 | if alignToGround then |
132 | y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1 |
133 | y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1 |
134 | y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1 |
135 | y3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,0,z3)+0.1 |
136 | end |
137 | |
138 | drawDebugTriangle(x,y,z, x2,y2,z2, x1,y1,z1, r,g,b,a, false) |
139 | drawDebugTriangle(x1,y1,z1, x2,y2,z2, x3,y3,z3, r,g,b,a, false) |
140 | end |
165 | function DebugUtil.drawDebugCircle(x,y,z, radius, steps, color, alignToTerrain, filled) |
166 | local r, g, b = 1, 0, 0 |
167 | if color ~= nil then |
168 | r, g, b = color[1], color[2], color[3] |
169 | end |
170 | local terrainNode = g_currentMission.terrainRootNode |
171 | |
172 | for i=1,steps do |
173 | local a1 = ((i-1)/steps)*2*math.pi |
174 | local a2 = ((i)/steps)*2*math.pi |
175 | |
176 | local c = math.cos(a1) * radius |
177 | local s = math.sin(a1) * radius |
178 | local x1, y1, z1 = x+c, y, z+s |
179 | |
180 | c = math.cos(a2) * radius |
181 | s = math.sin(a2) * radius |
182 | local x2, y2, z2 = x+c, y, z+s |
183 | |
184 | if alignToTerrain then |
185 | y = getTerrainHeightAtWorldPos(terrainNode, x, y, z) + 0.25 |
186 | y1 = getTerrainHeightAtWorldPos(terrainNode, x1, y, z1) + 0.25 |
187 | y2 = getTerrainHeightAtWorldPos(terrainNode, x2, y, z2) + 0.25 |
188 | end |
189 | |
190 | drawDebugLine(x1, y1, z1, r, g, b, x2, y2, z2, r, g, b) |
191 | |
192 | if filled then |
193 | drawDebugTriangle(x, y, z, x2, y2, z2, x1, y1, z1, r, g, b, 0.3, true) |
194 | end |
195 | end |
196 | end |
206 | function DebugUtil.drawDebugCircleAtNode(node, radius, steps, color, vertical, offset) |
207 | local ox, oy, oz = 0, 0, 0 |
208 | if offset ~= nil then |
209 | ox, oy, oz = offset[1], offset[2], offset[3] |
210 | end |
211 | |
212 | for i=1,steps do |
213 | local a1 = ((i-1)/steps)*2*math.pi |
214 | local a2 = ((i)/steps)*2*math.pi |
215 | |
216 | local c = math.cos(a1) * radius |
217 | local s = math.sin(a1) * radius |
218 | local x1, y1, z1 |
219 | if vertical then |
220 | x1, y1, z1 = localToWorld(node, ox + 0, oy + c, oz + s) |
221 | else |
222 | x1, y1, z1 = localToWorld(node, ox + c, oy + 0, oz + s) |
223 | end |
224 | |
225 | c = math.cos(a2) * radius |
226 | s = math.sin(a2) * radius |
227 | local x2, y2, z2 |
228 | if vertical then |
229 | x2, y2, z2 = localToWorld(node, ox + 0, oy + c, oz + s) |
230 | else |
231 | x2, y2, z2 = localToWorld(node, ox + c, oy + 0, oz + s) |
232 | end |
233 | |
234 | if color == nil then |
235 | drawDebugLine(x1,y1,z1, 1,0,0, x2,y2,z2, 1,0,0) |
236 | else |
237 | drawDebugLine(x1,y1,z1, color[1],color[2],color[3], x2,y2,z2, color[1],color[2],color[3]) |
238 | end |
239 | end |
240 | end |
288 | function DebugUtil.drawDebugCube(node, sizeX, sizeY, sizeZ, r, g, b, offsetX, offsetY, offsetZ) |
289 | sizeX, sizeY, sizeZ = sizeX * 0.5, sizeY * 0.5, sizeZ * 0.5 |
290 | r = r or 1 |
291 | g = g or 1 |
292 | b = b or 1 |
293 | |
294 | local x, y, z = localToWorld(node, offsetX or 0, offsetY or 0, offsetZ or 0) |
295 | local up1X, up1Y, up1Z = localDirectionToWorld(node, 1, 0, 0) |
296 | local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0) |
297 | local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1) |
298 | |
299 | up1X, up1Y, up1Z = up1X*sizeX, up1Y*sizeX, up1Z*sizeX |
300 | upX, upY, upZ = upX*sizeY, upY*sizeY, upZ*sizeY |
301 | dirX, dirY, dirZ = dirX*sizeZ, dirY*sizeZ, dirZ*sizeZ |
302 | |
303 | drawDebugLine(x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b, x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b) |
304 | drawDebugLine(x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b, x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b) |
305 | drawDebugLine(x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b, x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b) |
306 | drawDebugLine(x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b, x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b) |
307 | |
308 | drawDebugLine(x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b, x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b) |
309 | drawDebugLine(x - up1X - dirX + upX, y - up1Y - dirY + upY, z - up1Z - dirZ + upZ, r, g, b, x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b) |
310 | drawDebugLine(x - up1X + dirX + upX, y - up1Y + dirY + upY, z - up1Z + dirZ + upZ, r, g, b, x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b) |
311 | drawDebugLine(x + up1X + dirX + upX, y + up1Y + dirY + upY, z + up1Z + dirZ + upZ, r, g, b, x + up1X - dirX + upX, y + up1Y - dirY + upY, z + up1Z - dirZ + upZ, r, g, b) |
312 | |
313 | drawDebugLine(x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b, x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b) |
314 | drawDebugLine(x - up1X - dirX - upX, y - up1Y - dirY - upY, z - up1Z - dirZ - upZ, r, g, b, x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b) |
315 | drawDebugLine(x - up1X + dirX - upX, y - up1Y + dirY - upY, z - up1Z + dirZ - upZ, r, g, b, x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b) |
316 | drawDebugLine(x + up1X + dirX - upX, y + up1Y + dirY - upY, z + up1Z + dirZ - upZ, r, g, b, x + up1X - dirX - upX, y + up1Y - dirY - upY, z + up1Z - dirZ - upZ, r, g, b) |
317 | end |
34 | function DebugUtil.drawDebugGizmoAtWorldPos(x,y,z, dirX, dirY, dirZ, upX, upY, upZ, text, alignToGround, color) |
35 | local sideX, sideY, sideZ = MathUtil.crossProduct(upX, upY, upZ, dirX, dirY, dirZ) |
36 | |
37 | if alignToGround then |
38 | y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x,0,z)+0.1 |
39 | end |
40 | |
41 | drawDebugLine(x,y,z,1,0,0, x+sideX*0.3,y+sideY*0.3,z+sideZ*0.3, 1,0,0) |
42 | drawDebugLine(x,y,z,0,1,0, x+upX*0.3, y+upY*0.3, z+upZ*0.3, 0,1,0) |
43 | drawDebugLine(x,y,z,0,0,1, x+dirX*0.3, y+dirY*0.3, z+dirZ*0.3, 0,0,1) |
44 | |
45 | if text ~= nil then |
46 | Utils.renderTextAtWorldPosition(x,y,z, tostring(text), getCorrectTextSize(0.012), 0, color) |
47 | end |
48 | end |
88 | function DebugUtil.drawDebugLine(x1, y1, z1, x2, y2, z2, r, g, b, radius, alignToGround) |
89 | y1 = y1 or 0 |
90 | y2 = y2 or 0 |
91 | if alignToGround then |
92 | y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1)+0.1 |
93 | y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2)+0.1 |
94 | end |
95 | |
96 | r = r or 1 |
97 | g = g or 1 |
98 | b = b or 1 |
99 | drawDebugLine(x1, y1, z1, r, g, b, x2, y2, z2, r, g, b) |
100 | |
101 | if radius ~= nil then |
102 | DebugUtil.drawDebugCircle(x1, y1, z1, radius, 20, nil) |
103 | DebugUtil.drawDebugCircle(x2, y2, z2, radius, 20, nil) |
104 | end |
105 | end |
393 | function DebugUtil.drawDebugParallelogram(x,z, widthX,widthZ, heightX,heightZ, heightOffset, r,g,b,a, fixedHeight) |
394 | |
395 | local x0, z0 = x, z |
396 | local y0 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x0,0,z0) + heightOffset |
397 | |
398 | local x1 = x0 + widthX |
399 | local z1 = z0 + widthZ |
400 | local y1 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x1,0,z1) + heightOffset |
401 | |
402 | local x2 = x0 + heightX |
403 | local z2 = z0 + heightZ |
404 | local y2 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x2,0,z2) + heightOffset |
405 | |
406 | local x3 = x0 + widthX + heightX |
407 | local z3 = z0 + widthZ + heightZ |
408 | local y3 = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x3,0,z3) + heightOffset |
409 | |
410 | if fixedHeight then |
411 | y0, y1, y2, y3 = heightOffset, heightOffset, heightOffset, heightOffset |
412 | end |
413 | |
414 | drawDebugTriangle(x0,y0,z0, x1,y1,z1, x2,y2,z2, r,g,b,a, false) |
415 | drawDebugTriangle(x1,y1,z1, x3,y3,z3, x2,y2,z2, r,g,b,a, false) |
416 | -- and reverse order |
417 | drawDebugTriangle(x0,y0,z0, x2,y2,z2, x1,y1,z1, r,g,b,a, false) |
418 | drawDebugTriangle(x2,y2,z2, x3,y3,z3, x1,y1,z1, r,g,b,a, false) |
419 | |
420 | drawDebugLine(x0,y0,z0, r,g,b, x1,y1,z1, r,g,b) |
421 | drawDebugLine(x1,y1,z1, r,g,b, x2,y2,z2, r,g,b) |
422 | drawDebugLine(x2,y2,z2, r,g,b, x0,y0,z0, r,g,b) |
423 | |
424 | drawDebugLine(x1,y1,z1, r,g,b, x3,y3,z3, r,g,b) |
425 | drawDebugLine(x3,y3,z3, r,g,b, x2,y2,z2, r,g,b) |
426 | |
427 | end |
144 | function DebugUtil.drawDebugRectangle(node, minX, maxX, minZ, maxZ, yOffset, r, g, b) |
145 | local leftFrontX, leftFrontY, leftFrontZ = localToWorld(node, minX, yOffset, maxZ) |
146 | local rightFrontX, rightFrontY, rightFrontZ = localToWorld(node, maxX, yOffset, maxZ) |
147 | |
148 | local leftBackX, leftBackY, leftBackZ = localToWorld(node, minX, yOffset, minZ) |
149 | local rightBackX, rightBackY, rightBackZ = localToWorld(node, maxX, yOffset, minZ) |
150 | |
151 | drawDebugLine(leftFrontX, leftFrontY, leftFrontZ, r,g,b, rightFrontX, rightFrontY, rightFrontZ, r,g,b) |
152 | drawDebugLine(rightFrontX, rightFrontY, rightFrontZ, r,g,b, rightBackX, rightBackY, rightBackZ, r,g,b) |
153 | drawDebugLine(rightBackX, rightBackY, rightBackZ, r,g,b, leftBackX, leftBackY, leftBackZ, r,g,b) |
154 | drawDebugLine(leftBackX, leftBackY, leftBackZ, r,g,b, leftFrontX, leftFrontY, leftFrontZ, r,g,b) |
155 | end |
371 | function DebugUtil.drawDebugReferenceAxis(posX, posY, posZ, upX, upY, upZ, dirX, dirY, dirZ ) |
372 | local sideX, sideY, sideZ = MathUtil.crossProduct(upX, upY, upZ, dirX, dirY, dirZ) |
373 | local length = 0.2 |
374 | |
375 | drawDebugLine((posX - sideX * length), (posY - sideY * length), (posZ - sideZ * length), 1, 1, 1, (posX + sideX * length), (posY + sideY * length), (posZ + sideZ * length), 1, 0, 0) |
376 | drawDebugLine((posX - upX * length), (posY - upY * length), (posZ - upZ * length), 1, 1, 1, (posX + upX * length), (posY + upY * length), (posZ + upZ * length), 0, 1, 0) |
377 | drawDebugLine((posX - dirX * length), (posY - dirY * length), (posZ - dirZ * length), 1, 1, 1, (posX + dirX * length), (posY + dirY * length), (posZ + dirZ * length), 0, 0, 1) |
378 | end |
328 | function DebugUtil.drawSimpleDebugCube(x, y, z, width, r, g, b) |
329 | local halfWidth = width * 0.5 |
330 | |
331 | drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y - halfWidth, z - halfWidth, r, g, b) |
332 | drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x - halfWidth, y + halfWidth, z - halfWidth, r, g, b) |
333 | drawDebugLine(x - halfWidth, y - halfWidth, z - halfWidth, r, g, b, x - halfWidth, y - halfWidth, z + halfWidth, r, g, b) |
334 | drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b) |
335 | drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b) |
336 | drawDebugLine(x + halfWidth, y + halfWidth, z + halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b) |
337 | drawDebugLine(x - halfWidth, y - halfWidth, z + halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b) |
338 | drawDebugLine(x - halfWidth, y - halfWidth, z + halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b) |
339 | drawDebugLine(x - halfWidth, y + halfWidth, z - halfWidth, r, g, b, x - halfWidth, y + halfWidth, z + halfWidth, r, g, b) |
340 | drawDebugLine(x - halfWidth, y + halfWidth, z - halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b) |
341 | drawDebugLine(x + halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y + halfWidth, z - halfWidth, r, g, b) |
342 | drawDebugLine(x + halfWidth, y - halfWidth, z - halfWidth, r, g, b, x + halfWidth, y - halfWidth, z + halfWidth, r, g, b) |
343 | drawDebugPoint(x, y, z, r, g, b, 1) |
344 | end |