Skip to content

move Rot2Fwd from quaternion module to the ll module - #105

Open
tapple wants to merge 1 commit into
secondlife:mainfrom
tapple:move-quaternion-functions
Open

tapple wants to merge 1 commit into
secondlife:mainfrom
tapple:move-quaternion-functions

Conversation

@tapple

@tapple tapple commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Rename the following 3 functions to align with LSL, and to give LSL code the same speedup that Lua has:

  • quaternion.tofwd -> ll.Rot2Fwd
  • quaternion.toleft -> ll.Rot2Left
  • quaternion.toup -> ll.Rot2Up

@tapple tapple changed the title move Rot2Forward from quaternion module to the ll module move Rot2Fwd from quaternion module to the ll module Oct 30, 2026
assert(`{quaternion.slerp(yaw_ninety, quaternion(0, 0, 0, 1), 0.5)}` == "<0, 0, 0.382683, 0.92388>")

-- string cast to deal with precision
assert(`{quaternion.tofwd(yaw_ninety)}` == "<0, 1, 0>")

@tapple tapple Oct 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

made a test script to see if they are actually equal. they aren't:

local function printVector(v: vector)
    -- higher precision than default
    return "<" .. v.x .. ", " .. v.y .. ", " .. v.z .. ">"
end

local function assertQuaternion(q: quaternion)
    if ll.Rot2Fwd(q) ~= quaternion.tofwd(q) then
        print(`ll.Rot2Fwd({q} ~= quaternion.tofwd({q}): {printVector(ll.Rot2Fwd(q))} ~= {printVector(quaternion.tofwd(q))}`)
    end
    if ll.Rot2Left(q) ~= quaternion.toleft(q) then
        print(`ll.Rot2Left({q} ~= quaternion.toleft({q}): {printVector(ll.Rot2Left(q))} ~= {printVector(quaternion.toleft(q))}`)
    end
    if ll.Rot2Up(q) ~= quaternion.toup(q) then
        print(`ll.Rot2Up({q} ~= quaternion.toup({q}): {printVector(ll.Rot2Up(q))} ~= {printVector(quaternion.toup(q))}`)
    end
end

--[[
assertQuaternion(quaternion(0, 0, 0, 0))
for _ = 1, 1000 do
    local q = quaternion(math.random() * 4 - 2, math.random() * 4 - 2, math.random() * 4 - 2, math.random() * 4 - 2)
    assertQuaternion(q)
end
print(done)
--]]
-- print(quaternion(1, 2, 3, 4) + quaternion(4, 3, 2, 1))
-- print(quaternion(1, 2, 3, 4) * 2)
local q = quaternion(-1.426371, 0.787597, -1.999946, -0.307976)
assertQuaternion(q)
print(`      ll.Rot2Left: {printVector(ll.Rot2Left(q))}`)
print(`quaternion.toleft: {printVector(quaternion.toleft(q))}`)
print(`      ll.Rot2Up: {printVector(ll.Rot2Up(q))}`)
print(`quaternion.toup: {printVector(quaternion.toup(q))}`)

Output:

[1:14 AM] Object: ll.Rot2Left(<-1.426371, 0.787597, -1.999946, -0.307976> ~= quaternion.toleft(<-1.426371, 0.787597, -1.999946, -0.307976>): <-0.515400230884552, -0.7880847454071045, -0.33657824993133545> ~= <-0.515400230884552, -0.7880848050117493, -0.33657824993133545>
[1:14 AM] Object: ll.Rot2Up(<-1.426371, 0.787597, -1.999946, -0.307976> ~= quaternion.toup(<-1.426371, 0.787597, -1.999946, -0.307976>): <0.7734240889549255, -0.5969172716140747, 0.21331876516342163> ~= <0.7734240889549255, -0.5969172716140747, 0.21331875026226044>

      ll.Rot2Left: <-0.515400230884552, -0.7880847454071045, -0.33657824993133545>
quaternion.toleft: <-0.515400230884552, -0.7880848050117493, -0.33657824993133545>
      ll.Rot2Up: <0.7734240889549255, -0.5969172716140747, 0.21331876516342163>
quaternion.toup: <0.7734240889549255, -0.5969172716140747, 0.21331875026226044>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant