LUADOC - Farming Simulator 19

DebugCube

Functions

createSimple

Description
Definition
createSimple()
Code
94function DebugCube:createSimple(x, y, z, size)
95 self:createWithWorldPosAndRot(x, y, z, 0, 0, 0, size, size, size)
96end

createWithNode

Description
Definition
createWithNode()
Code
108function DebugCube:createWithNode(node, sizeX, sizeY, sizeZ)
109 local x, y, z = getWorldTranslation(node)
110 local normX, normY, normZ = localDirectionToWorld(node, 1, 0, 0)
111 local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0)
112 local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1)
113
114 self.x, self.y, self.z = x, y, z
115 self.normX, self.normY, self.normZ = normX*sizeX, normY*sizeX, normZ*sizeX
116 self.upX, self.upY, self.upZ = upX*sizeY, upY*sizeY, upZ*sizeY
117 self.dirX, self.dirY, self.dirZ = dirX*sizeZ, dirY*sizeZ, dirZ*sizeZ
118
119 local pos = self.positionNodes
120 pos[1] = { x - self.normX - self.upX - self.dirX,
121 y - self.normY - self.upY - self.dirY,
122 z - self.normZ - self.upZ - self.dirZ}
123
124 pos[2] = { x + self.normX - self.upX - self.dirX,
125 y + self.normY - self.upY - self.dirY,
126 z + self.normZ - self.upZ - self.dirZ}
127
128 pos[3] = { x + self.normX - self.upX + self.dirX,
129 y + self.normY - self.upY + self.dirY,
130 z + self.normZ - self.upZ + self.dirZ}
131
132 pos[4] = { x - self.normX - self.upX + self.dirX,
133 y - self.normY - self.upY + self.dirY,
134 z - self.normZ - self.upZ + self.dirZ}
135
136 pos[5] = { x - self.normX + self.upX - self.dirX,
137 y - self.normY + self.upY - self.dirY,
138 z - self.normZ + self.upZ - self.dirZ}
139
140 pos[6] = { x + self.normX + self.upX - self.dirX,
141 y + self.normY + self.upY - self.dirY,
142 z + self.normZ + self.upZ - self.dirZ}
143
144 pos[7] = { x + self.normX + self.upX + self.dirX,
145 y + self.normY + self.upY + self.dirY,
146 z + self.normZ + self.upZ + self.dirZ}
147
148 pos[8] = { x - self.normX + self.upX + self.dirX,
149 y - self.normY + self.upY + self.dirY,
150 z - self.normZ + self.upZ + self.dirZ}
151end

createWithPlacementSize

Description
Definition
createWithPlacementSize()
Code
100function DebugCube:createWithPlacementSize(node, sizeWidth, sizeLength, widthOffset, lengthOffset, updatePosition)
101 local rotX, rotY, rotZ = getWorldRotation(node)
102 local x, y, z = localToWorld(node, widthOffset, 0, lengthOffset)
103 self:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, sizeWidth * 0.5, 1, sizeLength * 0.5)
104end

createWithWorldPosAndDir

Description
Definition
createWithWorldPosAndDir()
Code
155function DebugCube:createWithWorldPosAndDir(x, y, z, dirX, dirY, dirZ, upX, upY, upZ, sizeX, sizeY, sizeZ)
156 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
157 link(getRootNode(), temp)
158 setTranslation(temp, x, y, z)
159 setDirection(temp, dirX, dirY, dirZ, upX, upY, upZ)
160 self:createWithNode(temp, sizeX, sizeY, sizeZ)
161 delete(temp)
162end

createWithWorldPosAndRot

Description
Definition
createWithWorldPosAndRot()
Code
166function DebugCube:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, sizeX, sizeY, sizeZ)
167 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
168 link(getRootNode(), temp)
169 setTranslation(temp, x, y, z)
170 setRotation(temp, rotX, rotY, rotZ)
171 self:createWithNode(temp, sizeX, sizeY, sizeZ)
172 delete(temp)
173end

draw

Description
Definition
draw()
Code
57function DebugCube:draw()
58 local r, g, b = unpack(self.color)
59 local pos = self.positionNodes
60
61 drawDebugLine(pos[1][1], pos[1][2], pos[1][3], r, g, b, pos[2][1], pos[2][2], pos[2][3], r, g, b)
62 drawDebugLine(pos[2][1], pos[2][2], pos[2][3], r, g, b, pos[3][1], pos[3][2], pos[3][3], r, g, b)
63 drawDebugLine(pos[3][1], pos[3][2], pos[3][3], r, g, b, pos[4][1], pos[4][2], pos[4][3], r, g, b)
64 drawDebugLine(pos[4][1], pos[4][2], pos[4][3], r, g, b, pos[1][1], pos[1][2], pos[1][3], r, g, b)
65
66 drawDebugLine(pos[5][1], pos[5][2], pos[5][3], r, g, b, pos[6][1], pos[6][2], pos[6][3], r, g, b)
67 drawDebugLine(pos[6][1], pos[6][2], pos[6][3], r, g, b, pos[7][1], pos[7][2], pos[7][3], r, g, b)
68 drawDebugLine(pos[7][1], pos[7][2], pos[7][3], r, g, b, pos[8][1], pos[8][2], pos[8][3], r, g, b)
69 drawDebugLine(pos[8][1], pos[8][2], pos[8][3], r, g, b, pos[5][1], pos[5][2], pos[5][3], r, g, b)
70
71 drawDebugLine(pos[1][1], pos[1][2], pos[1][3], r, g, b, pos[5][1], pos[5][2], pos[5][3], r, g, b)
72 drawDebugLine(pos[2][1], pos[2][2], pos[2][3], r, g, b, pos[6][1], pos[6][2], pos[6][3], r, g, b)
73 drawDebugLine(pos[3][1], pos[3][2], pos[3][3], r, g, b, pos[7][1], pos[7][2], pos[7][3], r, g, b)
74 drawDebugLine(pos[4][1], pos[4][2], pos[4][3], r, g, b, pos[8][1], pos[8][2], pos[8][3], r, g, b)
75
76 local x, y, z = self.x, self.y, self.z
77 local sideX, sideY, sideZ = self.normX, self.normY, self.normZ
78 local upX, upY, upZ = self.upX, self.upY, self.upZ
79 local dirX, dirY, dirZ = self.dirX, self.dirY, self.dirZ
80
81 drawDebugLine(x, y, z, 1, 0, 0, x + sideX, y + sideY, z + sideZ, 1, 0, 0)
82 drawDebugLine(x, y, z, 0, 1, 0, x + upX, y + upY, z + upZ, 0, 1, 0)
83 drawDebugLine(x, y, z, 0, 0, 1, x + dirX, y + dirY, z + dirZ, 0, 0, 1)
84end

new

Description
Definition
new()
Code
15function DebugCube:new(customMt)
16 local self = setmetatable({}, customMt or DebugCube_mt)
17
18
19-- 8_________7
20-- / | / |
21-- 5/__|____6/ | Y Z
22-- | | | | ^ /
23-- | 4|_____|__|3 | /
24-- | / | / |/____> X
25-- |/_______|/
26-- 1 2
27
28 self.color = {1, 1, 1}
29
30 self.x, self.y, self.z = 0, 0, 0
31 self.normX, self.normY, self.normZ = 1, 0, 0
32 self.upX, self.upY, self.upZ = 0, 1, 0
33 self.dirX, self.dirY, self.dirZ = 0, 0, 1
34
35 self.positionNodes = {
36 {-1, -1, -1},
37 {1, -1, -1},
38 {1, -1, 1},
39 {-1, -1, 1},
40 {-1, 1, -1},
41 {1, 1, -1},
42 {1, 1, 1},
43 {-1, 1, 1}
44 }
45
46 return self
47end

setColor

Description
Definition
setColor()
Code
88function DebugCube:setColor(r, g, b)
89 self.color = {r, g, b}
90end