I made it for CCVS, which recently removed its getYaw(), getRoll(), etc. so we need to deal with Quaternions. Maybe you will find this useful:
-- Converts a quaternion to yaw (rotation around Y axis)
function quaternionToYaw(q)
local yaw = math.atan2(2 * (q.w * q.y + q.x * q.z), 1 - 2 * (q.y * q.y + q.x * q.x))
return yaw
end
-- Converts a quaternion to pitch (rotation around X axis)
function quaternionToPitch(q)
-- Clamp the input to asin to avoid invalid domain errors
local sinp = 2 * (q.w * q.x - q.y * q.z)
sinp = math.min(1, math.max(-1, sinp))
local pitch = math.asin(sinp)
return pitch
end
-- Converts a quaternion to roll (rotation around Z axis)
function quaternionToRoll(q)
local roll = math.atan2(2 * (q.w * q.z + q.y * q.x), 1 - 2 * (q.z * q.z + q.x * q.x))
return roll
end
-- Converts radians to degrees
function radiansToDegrees(rad)
return rad * (180 / math.pi)
end
-- Gets all Euler angles from a quaternion (in radians)
function quaternionToEuler(q)
return {
yaw = quaternionToYaw(q),
pitch = quaternionToPitch(q),
roll = quaternionToRoll(q)
}
end
-- Gets all Euler angles from a quaternion (in degrees)
function quaternionToEulerDegrees(q)
local euler = quaternionToEuler(q)
return {
yaw = radiansToDegrees(euler.yaw),
pitch = radiansToDegrees(euler.pitch),
roll = radiansToDegrees(euler.roll)
}
end
So, to get a Valkyrien Skies ship yaw, for example, you’ll need to:
local quan = ship.getQuaternion()
local yaw = quaternionToYaw(quan)
Note that now yaw in the example above holds the yaw of the ship, but as radians. To convert it to degrees You’ll need to:
local quan = ship.getQuaternion()
local yaw = quaternionToYaw(quan)
-- Convert to degrees
local yawDeg = radiansToDegrees(yaw)
-- or just
yaw = radiansToDegrees(yaw)
The library: https://github.com/Shlomo1412/Quanty
Hope you find this useful. Have a good day!
image.png
:clueless: