Skip to content

Commit

Permalink
Merge pull request #22 from Courseplay/Gui-Additions
Browse files Browse the repository at this point in the history
Shovel position debug fix and arrow size increased
  • Loading branch information
Tensuko authored Dec 22, 2024
2 parents 2f93029 + f96988e commit 3afefd9
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
10 changes: 7 additions & 3 deletions config/VehicleConfigurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,13 @@ You can define the following custom settings:
turnRadius = "10"
/>
<Vehicle name="lm845.xml"
turnRadius = "10"
fixWheelLoaderDirectionNodeByMovingToolIx = "1"
articulatedAxisReverseNodeInverted = "true"
articulatedAxisReverseNodeInverted = "true"
turnRadius = "10"
fixWheelLoaderDirectionNodeByMovingToolIx = "1"
/>
<Vehicle name="wheelLoader435S.xml"
fixWheelLoaderDirectionNodeByMovingToolIx = "1"
turnRadius = "10"
/>

<!--Vermeer-->
Expand Down
2 changes: 1 addition & 1 deletion scripts/ai/controllers/ShovelController.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ function ShovelController:calculateMinimalUnloadingHeight(triggerNode)
local maxHeightObjectHit = 0
for i=self.MIN_TRIGGER_HEIGHT, self.MAX_TRIGGER_HEIGHT, 0.1 do
self.objectWasHit = false
raycastAll(sx, terrainHeight + i, sz, dx, 0, dz, length
raycastAll(sx, terrainHeight + i, sz, dx, 0, dz, length,
"calculateMinimalUnloadingHeightRaycastCallback", self,
self.TRIGGER_HEIGHT_RAYCAST_COLLISION_MASK)
if self.objectWasHit then
Expand Down
6 changes: 3 additions & 3 deletions scripts/gui/CoursePlot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CoursePlot = CpObject()
-- x = 0, y = 0 is the bottom left corner of the screen, terrainSize is in meters
function CoursePlot:init()
self.lineThickness = 2 / g_screenHeight -- 2 pixels
self.arrowThickness = 3 / g_screenHeight -- 3 pixels
self.arrowThickness = 10 / g_screenHeight -- 10 pixels
-- the normal FS22 blue
self.color = {CpGuiUtil.getNormalizedRgb(42, 193, 237)}
-- a lighter shade of the same color
Expand Down Expand Up @@ -173,7 +173,7 @@ end
---@param a number|nil
---@param isHudMap boolean|nil
function CoursePlot:drawArrow(map, x, z, rotation, r, g, b, a, isHudMap)
local zoom = isHudMap and map.layout:getIconZoom() or map.fullScreenLayout:getIconZoom()
local zoom = map.layout:getIconZoom() * map.layout:getIconZoom()
if isHudMap and map.state == IngameMap.STATE_MAP then
--- When the hud is completely open, then the signs need to be scaled down.
zoom = zoom * 0.5
Expand Down Expand Up @@ -226,7 +226,7 @@ function CoursePlot:draw(map, isHudMap)
-- render the start and stop signs

local signSizeMeters = 0.02
local zoom = isHudMap and map.layout:getIconZoom() or map.fullScreenLayout:getIconZoom()
local zoom = map.layout:getIconZoom()
if isHudMap and map.state == IngameMap.STATE_MAP then
--- When the hud is completely open, then the signs need to be scaled down.
zoom = zoom * 0.5
Expand Down
9 changes: 5 additions & 4 deletions scripts/specializations/CpShovelPositions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function CpShovelPositions:setShovelPosition(dt, shovelLimits, armLimits, height
sy = yMin + 0.01
ey = yMin + 0.01
end
local hasIntersection, i1z, i1y, i2z, i2y = MathUtil.getCircleLineIntersection(
local hasIntersection, i1z, i1y, i2z, i2y = CpMathUtil.getCircleLineIntersection(
az, ay, radiusArmToolToShovelTool,
sz, sy, ez, ey)

Expand Down Expand Up @@ -500,9 +500,10 @@ function CpShovelPositions:setShovelPosition(dt, shovelLimits, armLimits, height
name = "shovelY", value = shovelY})
table.insert(debugData, {
name = "dirRot", value = math.deg(oldRotRelativeArmRot) })
table.insert(debugData, {
name = "distAlpha", value = MathUtil.vector2Length(i1z - tz, i1y - ty) })

if i1z ~= nil and i1y ~= nil then
table.insert(debugData, {
name = "distAlpha", value = MathUtil.vector2Length(i1z - tz, i1y - ty) })
end
table.insert(debugData, {
value = "",
name = "",
Expand Down
26 changes: 25 additions & 1 deletion scripts/util/CpMathUtil.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,28 @@ end
--- Divide a by b, but instead of throwing an error when b is 0, return math.huge
function CpMathUtil.divide(a, b)
return b == 0 and math.huge or a / b
end
end

--- Legancy function form LS22
function CpMathUtil.getCircleLineIntersection(circleX, circleZ, radius, lineStartX, lineStartZ, lineEndX, lineEndZ)
local p3x = lineStartX - circleX
local p3z = lineStartZ - circleZ
local p4x = lineEndX - circleX
local p4z = lineEndZ - circleZ
local m = (p4z - p3z) / (p4x - p3x)
local b = p3z - m * p3x
local dis = math.pow(radius, 2) * math.pow(m, 2) + math.pow(radius, 2) - math.pow(b, 2)

if dis < 0 then
return false
else
local t1 = (-m * b + math.sqrt(dis)) / (math.pow(m, 2) + 1)
local t2 = (-m * b - math.sqrt(dis)) / (math.pow(m, 2) + 1)
local intersect1X = t1 + circleX
local intersect1Z = m * t1 + b + circleZ
local intersect2X = t2 + circleX
local intersect2Z = m * t2 + b + circleZ

return true, intersect1X, intersect1Z, intersect2X, intersect2Z
end
end

0 comments on commit 3afefd9

Please sign in to comment.