Skip to content

Commit

Permalink
Add a sim utility function to draw bones (#6477)
Browse files Browse the repository at this point in the history
In particular useful to debug collision beams.
  • Loading branch information
lL1l1 authored Nov 13, 2024
1 parent 5fa3faf commit 191576f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/snippets/other.6477.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- (#6477) Add the function `DrawBone(entity, bone, length)` to `SimUtils.lua`.
9 changes: 4 additions & 5 deletions engine/Sim/Entity.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,11 @@ end
function Entity:GetBoneCount()
end

--- Returns separate three numbers representing the roll, pitch, yaw of the bone
---@see EulerToQuaternion(roll, pitch, yaw) if you need a quaternion instead
--- Returns three separate numbers representing the X, Y, Z direction vector of the bone
---@param bone Bone
---@return number roll
---@return number pitch
---@return number yaw
---@return number x
---@return number y
---@return number z
function Entity:GetBoneDirection(bone)
end

Expand Down
25 changes: 25 additions & 0 deletions lua/SimUtils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,28 @@ function OnAllianceResult(resultData)
end

import("/lua/simplayerquery.lua").AddResultListener("OfferAlliance", OnAllianceResult)

local vectorCross = import('/lua/utilities.lua').Cross
local upVector = Vector(0, 1, 0)

--- Draw XYZ axes of an entity's bone for one tick
---@param entity moho.entity_methods
---@param bone Bone
---@param length number? # length of axes, defaults to 0.2
function DrawBone(entity, bone, length)
if not length then length = 0.2 end

local pos = entity:GetPosition(bone)
local dirX, dirY, dirZ = entity:GetBoneDirection(bone)

local forward = Vector(dirX, dirY, dirZ)
local left = vectorCross(upVector, forward)
local up = vectorCross(forward, left)

-- X axis
DrawLine(pos, pos + left * length, 'FF0000')
-- Y axis
DrawLine(pos, pos + up * length, '00ff00')
-- Z axis
DrawLine(pos, pos + forward * length, '0000ff')
end

0 comments on commit 191576f

Please sign in to comment.