Skip to main content
Skip to main content

MathUtil

MathUtil

Description

Util for mathematic operations

Functions

directionToPitchYaw

Description

Calculates the pitch and yaw in radians of the given direction.

Definition

directionToPitchYaw(float directionX, float directionY, float directionZ)

Arguments

floatdirectionXThe x axis of the direction.
floatdirectionYThe y axis of the direction.
floatdirectionZThe z axis of the direction.

Return Values

floatpitchThe pitch (x axis) of the rotation.
floatyawThe yaw (y axis) of the rotation.

Code

function MathUtil.directionToPitchYaw(directionX, directionY, directionZ)
return math.asin( - directionY), math.atan2(directionX, directionZ)
end

eulerToDirection

Description

Converts the given euler yaw and pitch into a direction vector.

Definition

eulerToDirection(float yaw, float pitch)

Arguments

floatyawThe yaw (y rotation) of the euler.
floatpitchThe pitch (x rotation) of the euler.

Return Values

floatxThe x axis of the direction.
floatyThe y axis of the direction.
floatzThe z axis of the direction.

Code

function MathUtil.eulerToDirection(yaw, pitch)

-- The length of the x and y axis.When the direction is pointing straight up or down; this will be 0.
local xzLength = math.cos( - pitch)

-- Rotate the node around the y axis.
return xzLength * math.sin(yaw), math.sin( - pitch), xzLength * math.cos(yaw)
end