69 | function DebugGizmo:createWithNode(node, text, alignToGround, textOffset, scale, solid, hideWhenGUIOpen) |
70 | local x, y, z = getWorldTranslation(node) |
71 | local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0) |
72 | local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1) |
73 | |
74 | return self:createWithWorldPosAndDir(x, y, z, dirX, dirY, dirZ, upX, upY, upZ, text, alignToGround, textOffset, scale, solid, hideWhenGUIOpen) |
75 | end |
79 | function DebugGizmo:createWithWorldPosAndDir(x, y, z, dirX, dirY, dirZ, upX, upY, upZ, text, alignToGround, textOffset, scale, solid, hideWhenGUIOpen) |
80 | |
81 | if alignToGround and g_currentMission.terrainRootNode ~= nil then |
82 | y = getTerrainHeightAtWorldPos(g_currentMission.terrainRootNode, x, 0, z) + 0.1 |
83 | end |
84 | |
85 | self.x, self.y, self.z = x, y, z |
86 | self.dirX, self.dirY, self.dirZ = dirX, dirY, dirZ |
87 | self.upX, self.upY, self.upZ = upX, upY, upZ |
88 | self.normX, self.normY, self.normZ = MathUtil.crossProduct(upX, upY, upZ, dirX, dirY, dirZ) |
89 | self.text = text |
90 | self.scale = scale or 1 |
91 | self.solid = Utils.getNoNil(solid, self.solid) |
92 | |
93 | if textOffset then |
94 | self.textOffset.x = textOffset.x or self.textOffset.x |
95 | self.textOffset.y = textOffset.y or self.textOffset.y |
96 | self.textOffset.z = textOffset.z or self.textOffset.z |
97 | end |
98 | self.alignToGround = Utils.getNoNil(alignToGround, self.alignToGround) |
99 | self.hideWhenGuiIsOpen = Utils.getNoNil(hideWhenGUIOpen, self.hideWhenGuiIsOpen) |
100 | |
101 | return self |
102 | end |
47 | function DebugGizmo:draw() |
48 | if self.hideWhenGuiIsOpen and g_gui:getIsGuiVisible() then |
49 | return |
50 | end |
51 | local x, y, z = self.x, self.y, self.z |
52 | local normX, normY, normZ = self.normX, self.normY, self.normZ |
53 | local upX, upY, upZ = self.upX, self.upY, self.upZ |
54 | local dirX, dirY, dirZ = self.dirX, self.dirY, self.dirZ |
55 | local scale = self.scale |
56 | local solid = self.solid |
57 | |
58 | drawDebugLine(x, y, z, 1, 0, 0, x + scale*normX, y + scale*normY, z + scale*normZ, 1, 0, 0, solid) |
59 | drawDebugLine(x, y, z, 0, 1, 0, x + scale*upX, y + scale*upY, z + scale*upZ, 0, 1, 0, solid) |
60 | drawDebugLine(x, y, z, 0, 0, 1, x + scale*dirX, y + scale*dirY, z + scale*dirZ, 0, 0, 1, solid) |
61 | |
62 | if self.text ~= nil then |
63 | Utils.renderTextAtWorldPosition(x + self.textOffset.x, y + self.textOffset.y, z + self.textOffset.z, tostring(self.text), getCorrectTextSize(0.012), 0, self.textColor) |
64 | end |
65 | end |
15 | function DebugGizmo.new(customMt) |
16 | local self = setmetatable({}, customMt or DebugGizmo_mt) |
17 | |
18 | -- Y Z |
19 | -- ^ / |
20 | -- | / |
21 | -- |/____> X |
22 | |
23 | self.x, self.y, self.z = 0, 0, 0 |
24 | self.normX, self.normY, self.normZ = 1, 0, 0 |
25 | self.upX, self.upY, self.upZ = 0, 1, 0 |
26 | self.dirX, self.dirY, self.dirZ = 0, 0, 1 |
27 | self.scale = 1 |
28 | self.solid = true |
29 | |
30 | self.text = nil |
31 | self.textOffset = {x=0, y=0, z=0} |
32 | self.textColor = nil |
33 | self.alignToGround = false |
34 | self.hideWhenGuiIsOpen = false |
35 | |
36 | return self |
37 | end |