LUADOC - Farming Simulator 22

DebugCube

Functions

createSimple

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

createWithNode

Description
Definition
createWithNode()
Code
124function DebugCube:createWithNode(node, sizeX, sizeY, sizeZ, offsetX, offsetY, offsetZ)
125 local x, y, z = localToWorld(node, offsetX or 0, offsetY or 0, offsetZ or 0)
126 local normX, normY, normZ = localDirectionToWorld(node, 1, 0, 0)
127 local upX, upY, upZ = localDirectionToWorld(node, 0, 1, 0)
128 local dirX, dirY, dirZ = localDirectionToWorld(node, 0, 0, 1)
129
130 self.x, self.y, self.z = x, y, z
131 self.normX, self.normY, self.normZ = normX*sizeX, normY*sizeX, normZ*sizeX
132 self.upX, self.upY, self.upZ = upX*sizeY, upY*sizeY, upZ*sizeY
133 self.dirX, self.dirY, self.dirZ = dirX*sizeZ, dirY*sizeZ, dirZ*sizeZ
134
135 local pos = self.positionNodes
136 pos[1] = { 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[2] = { 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[3] = { 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[4] = { x - self.normX - self.upX + self.dirX,
149 y - self.normY - self.upY + self.dirY,
150 z - self.normZ - self.upZ + self.dirZ}
151
152 pos[5] = { x - self.normX + self.upX - self.dirX,
153 y - self.normY + self.upY - self.dirY,
154 z - self.normZ + self.upZ - self.dirZ}
155
156 pos[6] = { x + self.normX + self.upX - self.dirX,
157 y + self.normY + self.upY - self.dirY,
158 z + self.normZ + self.upZ - self.dirZ}
159
160 pos[7] = { x + self.normX + self.upX + self.dirX,
161 y + self.normY + self.upY + self.dirY,
162 z + self.normZ + self.upZ + self.dirZ}
163
164 pos[8] = { x - self.normX + self.upX + self.dirX,
165 y - self.normY + self.upY + self.dirY,
166 z - self.normZ + self.upZ + self.dirZ}
167
168 return self
169end

createWithPlacementSize

Description
Definition
createWithPlacementSize()
Code
114function DebugCube:createWithPlacementSize(node, sizeWidth, sizeLength, widthOffset, lengthOffset, updatePosition)
115 local rotX, rotY, rotZ = getWorldRotation(node)
116 local x, y, z = localToWorld(node, widthOffset, 0, lengthOffset)
117 self:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, sizeWidth, 1, sizeLength)
118
119 return self
120end

createWithWorldPosAndDir

Description
Definition
createWithWorldPosAndDir()
Code
224function DebugCube:createWithWorldPosAndDir(x, y, z, dirX, dirY, dirZ, upX, upY, upZ, sizeX, sizeY, sizeZ)
225 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
226 link(getRootNode(), temp)
227 setTranslation(temp, x, y, z)
228 setDirection(temp, dirX, dirY, dirZ, upX, upY, upZ)
229 self:createWithNode(temp, sizeX, sizeY, sizeZ)
230 delete(temp)
231
232 return self
233end

createWithWorldPosAndRot

Description
Definition
createWithWorldPosAndRot()
Code
237function DebugCube:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, sizeX, sizeY, sizeZ)
238 local temp = createTransformGroup("temp_drawDebugCubeAtWorldPos")
239 link(getRootNode(), temp)
240 setTranslation(temp, x, y, z)
241 setRotation(temp, rotX, rotY, rotZ)
242 self:createWithNode(temp, sizeX, sizeY, sizeZ)
243 delete(temp)
244
245 return self
246end

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}
90
91 return self
92end