Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SimUtils DrawBone function #6477

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading