LUADOC - Farming Simulator 22

DebugText

Functions

createWithNode

Description
Definition
createWithNode()
Code
67function DebugText:createWithNode(node, text, size)
68 local x, y, z = getWorldTranslation(node)
69 local rotX, rotY, rotZ = getWorldRotation(node)
70
71 return self:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, text, size)
72end

createWithNodeToCamera

Description
Definition
createWithNodeToCamera()
Code
76function DebugText:createWithNodeToCamera(node, yOffset, text, size)
77 self.alignToCamera = true
78 local x, y, z = localToWorld(node, 0, yOffset, 0)
79
80 return self:createWithWorldPosAndRot(x, y, z, 0, self:getRotationToCamera(x, y, z), 0, text, size)
81end

createWithWorldPosAndRot

Description
Definition
createWithWorldPosAndRot()
Code
85function DebugText:createWithWorldPosAndRot(x, y, z, rotX, rotY, rotZ, text, size)
86 self.x, self.y, self.z = x, y, z
87 self.rotX, self.rotY, self.rotZ = rotX, rotY, rotZ
88 self.text = text
89 self.size = size
90
91 return self
92end

draw

Description
Definition
draw()
Code
46function DebugText:draw()
47 if self.clipDistance ~= nil then
48 local x, y, z = getWorldTranslation(getCamera())
49 if MathUtil.vector3Length(x-self.x, y-self.y, z-self.z) > self.clipDistance then
50 return
51 end
52 end
53 setTextDepthTestEnabled(false)
54 setTextAlignment(self.alignment)
55 setTextVerticalAlignment(self.verticalAlignment)
56 setTextColor(self.r, self.g, self.b, self.a)
57
58 renderText3D(self.x, self.y, self.z, self.rotX, self.rotY, self.rotZ, self.size, self.text)
59
60 setTextAlignment(RenderText.ALIGN_LEFT)
61 setTextVerticalAlignment(RenderText.VERTICAL_ALIGN_BASELINE)
62 setTextDepthTestEnabled(true)
63end

getRotationToCamera

Description
Definition
getRotationToCamera()
Code
96function DebugText:getRotationToCamera(x, y, z)
97 local cx, cy, cz = getWorldTranslation(getCamera())
98 local dirX, _, dirZ = MathUtil.vector3Normalize(cx-x, cy-y, cz-z)
99 return MathUtil.getYRotationFromDirection(dirX, dirZ)
100end

new

Description
Definition
new()
Code
15function DebugText.new(customMt)
16 local self = setmetatable({}, customMt or DebugText_mt)
17
18 self.x, self.y, self.z = 0, 0, 0
19 self.rotX, self.rotY, self.rotZ = 0, 0, 0
20 self.alignment = RenderText.ALIGN_CENTER
21 self.verticalAlignment = RenderText.VERTICAL_ALIGN_MIDDLE
22 self.r, self.g, self.b, self.a = 1, 1, 1, 1
23 self.size = 0.1
24
25 self.text = nil
26 self.alignToGround = false
27 self.alignToCamera = false
28 self.clipDistance = nil
29
30 return self
31end

setClipDistance

Description
Definition
setClipDistance()
Code
115function DebugText:setClipDistance(clipDistance)
116 self.clipDistance = clipDistance
117
118 return self
119end

setColor

Description
Definition
setColor()
Code
104function DebugText:setColor(r, g, b, a)
105 self.r = r or self.r
106 self.g = g or self.g
107 self.b = b or self.b
108 self.a = a or self.a
109
110 return self
111end

update

Description
Definition
update()
Code
38function DebugText:update(dt)
39 if self.alignToCamera then
40 self.rotY = self:getRotationToCamera(self.x, self.y, self.z)
41 end
42end