124 | function 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 |
169 | end |
57 | function 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) |
84 | end |