Math

Summary
Math
vec3Three dimensional vector.
Constructors
vec3.new( vec3 )Initializes this vector to the value of another.
vec3.new( float )Initializes all elements of this vector to a value.
vec3.new( float, float, float )Initializes the elements of this vector to the provided values.
Elements
xReturns the x element of this vector.
yReturns the y element of this vector.
zReturns the z element of this vector.
Operators
operator==Returns true if the vectors are equal.
operator+Add two vectors.
operator-Subtract two vectors.
operator*Multiply two vectors.
operator/Divide two vectors.
Operations
dotDot product of two vectors.
lengthReturns the length of the vector.
divDivides two vectors element-wise.
div_scalarDivides a vector by a scalar.
mul_scalarMultiplies a vector by a scalar.
roundRounds each component of the vector to the nearest integer.
crossComputes the cross product of two vectors.
normalizeNormalizes the vector.
mul_quatMultiplies a vector by a quaternion.
modRounds and then performs a modulo operation on each component.
NKToStringReturns the vector formatted as a string
NKGetXYZReturns the X, Y and Z components of this Vec3.
NKSetXYZSets the X, Y and Z components of this Vec3.
NKLengthReturns the magnitude of this vector.
NKNormalizeReturns a normalized vector.
NKRotateByQuaternionRotates a vector by a given quaternion.
quatQuaternion.
Constructors
quat.new( float, vec3 )Initializes this quaternion from an angle and axis.
quat.new( vec3 )Initializes this quaternion using an XYZ Euler angle representation.
quat.new( quat )Initializes this quaternion to the value of another.
quat.new( float, float, float, float )Initializes the elements of this quaternion to the provided values.
Elements
wReturns the w element of this quaternion.
xReturns the x element of this quaternion.
yReturns the y element of this quaternion.
zReturns the z element of this quaternion.
Operations
normalizeReturns this quaternion, normalized.
rotateReturns the quaternion resulting from the rotation of this quaternion around a specific axis.
Operators
operator==Returns true if the quaternions are equal.
operator*Multiply two quaternion.
Functions
ForwardReturns the vector facing in the direction of this rotation.
RightReturns the right vector of this quaternion.
UpReturns the up vector of this quaternion.
NKToStringReturns the quaternion formatted as a string
NKGetXYZWReturns the X, Y, Z and W components of this Quat.
NKSetXYZWSets the X, Y, Z and W components of this Quat.
NKGetInverseReturns the inverse of this quaternion.
GLMStatic math functions.
Static Utility
LerpLerp between two vectors by weight.
RotateStatic helper to rotate a quat by an explicit axis and angle.
CeilReturns a value equal to the nearest integer that is greater than or equal to x.
FloorReturns a value equal to the nearest integer that is less than or equal to x.
Cross3Computes the cross product of two vec3s, represented by 6 floats.
CrossVec3Computes the cross product of two vectors.
AngleHelper to find the rotation between two vectors.
LookAtHelper to find the orientation between a source point and a target point.
SlerpSlerp between two vectors by weight.

vec3

Three dimensional vector.

Summary
Constructors
vec3.new( vec3 )Initializes this vector to the value of another.
vec3.new( float )Initializes all elements of this vector to a value.
vec3.new( float, float, float )Initializes the elements of this vector to the provided values.
Elements
xReturns the x element of this vector.
yReturns the y element of this vector.
zReturns the z element of this vector.
Operators
operator==Returns true if the vectors are equal.
operator+Add two vectors.
operator-Subtract two vectors.
operator*Multiply two vectors.
operator/Divide two vectors.
Operations
dotDot product of two vectors.
lengthReturns the length of the vector.
divDivides two vectors element-wise.
div_scalarDivides a vector by a scalar.
mul_scalarMultiplies a vector by a scalar.
roundRounds each component of the vector to the nearest integer.
crossComputes the cross product of two vectors.
normalizeNormalizes the vector.
mul_quatMultiplies a vector by a quaternion.
modRounds and then performs a modulo operation on each component.
NKToStringReturns the vector formatted as a string
NKGetXYZReturns the X, Y and Z components of this Vec3.
NKSetXYZSets the X, Y and Z components of this Vec3.
NKLengthReturns the magnitude of this vector.
NKNormalizeReturns a normalized vector.
NKRotateByQuaternionRotates a vector by a given quaternion.

Constructors

vec3.new( vec3 )

Initializes this vector to the value of another.

Parameters

vec3The vector to copy.

vec3.new( float )

Initializes all elements of this vector to a value.

Parameters

floatThe value to assign.

vec3.new( float, float, float )

Initializes the elements of this vector to the provided values.

Parameters

floatThe value to assign element x.
floatThe value to assign element y.
floatThe value to assign element z.

Elements

x

Returns the x element of this vector.

Returns

floatThe x element of this vector.

y

Returns the y element of this vector.

Returns

floatThe y element of this vector.

z

Returns the z element of this vector.

Returns

floatThe z element of this vector.

Operators

operator==

Returns true if the vectors are equal.

Parameters

vec3Right hand side vector.

Returns

vec3Returns true if these vectors are equal.

operator+

Add two vectors.

Parameters

vec3Right hand side vector.

Returns

vec3the vector sum.

operator-

Subtract two vectors.

Parameters

vec3Right hand side vector.

Returns

vec3the vector difference.

operator*

Multiply two vectors.

Parameters

vec3Right hand side vector.

Returns

vec3the vector product.

operator/

Divide two vectors.

Parameters

vec3Right hand side vector.

Returns

vec3the vector quotient.

Operations

dot

Dot product of two vectors.

Parameters

vec3Right hand side vector.

Returns

floatthe dot product of two vectors

length

Returns the length of the vector.

Returns

floatThe length of the vector.

div

Divides two vectors element-wise.

Parameters

vec3vector divisor.

Returns

vec3quotient.

div_scalar

Divides a vector by a scalar.

Parameters

floatscalar divisor.

Returns

vec3quotient.

mul_scalar

Multiplies a vector by a scalar.

Parameters

floatScalar multiplier.

Returns

vec3The Product.

round

Rounds each component of the vector to the nearest integer.

Returns

vec3The rounded vector.

cross

Computes the cross product of two vectors.

Parameters

vec3The vector with which to evaluate the cross product.

Returns

vec3The cross product.

normalize

Normalizes the vector.

Returns

vec3The normalized vector.

mul_quat

Multiplies a vector by a quaternion.

Parameters

quatOperand.

Returns

vec3This vector rotated by the quat operand.

mod

Rounds and then performs a modulo operation on each component.

Parameters

intThe divisor.

Returns

vec3The result of the modulo operation.

NKToString

Returns the vector formatted as a string

Returns

Stringthe formatted text

NKGetXYZ

Returns the X, Y and Z components of this Vec3.

Example

local x, y, z = myPosition:NKGetXYZ()

Returns

NumberX
NumberY
NumberZ

NKSetXYZ

Sets the X, Y and Z components of this Vec3.

Example

myPosition:NKSetXYZ(1.0, 5.0, 2.2)

Parameters

NumberX
NumberY
NumberZ

NKLength

Returns the magnitude of this vector.

Returns

floatThe magnitude of this vector.

NKNormalize

Returns a normalized vector.

Returns

floatThe normalized vector.

NKRotateByQuaternion

int staticNKRotateByQuaternion(lua_State *vm)

Rotates a vector by a given quaternion.

Parameters

vec3The vector to be rotated.
quatThe quaternion rotation to be applied.

Returns

vec3The result of the rotation.

quat

Quaternion.

Summary
Constructors
quat.new( float, vec3 )Initializes this quaternion from an angle and axis.
quat.new( vec3 )Initializes this quaternion using an XYZ Euler angle representation.
quat.new( quat )Initializes this quaternion to the value of another.
quat.new( float, float, float, float )Initializes the elements of this quaternion to the provided values.
Elements
wReturns the w element of this quaternion.
xReturns the x element of this quaternion.
yReturns the y element of this quaternion.
zReturns the z element of this quaternion.
Operations
normalizeReturns this quaternion, normalized.
rotateReturns the quaternion resulting from the rotation of this quaternion around a specific axis.
Operators
operator==Returns true if the quaternions are equal.
operator*Multiply two quaternion.
Functions
ForwardReturns the vector facing in the direction of this rotation.
RightReturns the right vector of this quaternion.
UpReturns the up vector of this quaternion.
NKToStringReturns the quaternion formatted as a string
NKGetXYZWReturns the X, Y, Z and W components of this Quat.
NKSetXYZWSets the X, Y, Z and W components of this Quat.
NKGetInverseReturns the inverse of this quaternion.

Constructors

quat.new( float, vec3 )

Initializes this quaternion from an angle and axis.

Parameters

floatThe W
vec3The X,Y,Z

quat.new( vec3 )

Initializes this quaternion using an XYZ Euler angle representation.

Parameters

vec3The euler angles in degrees.

quat.new( quat )

Initializes this quaternion to the value of another.

Parameters

quatThe vector to copy.

quat.new( float, float, float, float )

Initializes the elements of this quaternion to the provided values.

Parameters

floatThe value to assign element w.
floatThe value to assign element x.
floatThe value to assign element y.
floatThe value to assign element z.

Elements

w

Returns the w element of this quaternion.

Returns

floatThe w element of this quaternion.

x

Returns the x element of this quaternion.

Returns

floatThe x element of this quaternion.

y

Returns the y element of this quaternion.

Returns

floatThe y element of this quaternion.

z

Returns the z element of this quaternion.

Returns

floatThe z element of this quaternion.

Operations

normalize

Returns this quaternion, normalized.

Returns

quatThis quaternion, normalized.

rotate

Returns the quaternion resulting from the rotation of this quaternion around a specific axis.

Parameters

floatAmount to rotate.
vec3Axis around which to rotate.

Returns

quatThe rotated quaternion.

Operators

operator==

Returns true if the quaternions are equal.

Parameters

quatRight hand side quaternion.

Returns

quatReturns true if these quaternions are equal.

operator*

Multiply two quaternion.

Parameters

quatRight hand side quaternion.

Returns

quatthe quaternion product.

Functions

Forward

Returns the vector facing in the direction of this rotation.

Returns

vec3The forward vector of this quaternion.

Right

Returns the right vector of this quaternion.

Returns

vec3The right vector of this quaternion.

Up

Returns the up vector of this quaternion.

Returns

vec3The up vector of this quaternion.

NKToString

Returns the quaternion formatted as a string

Returns

Stringthe formatted text

NKGetXYZW

Returns the X, Y, Z and W components of this Quat.

Example

local x, y, z, w = myOrientation:NKGetXYZW()

Returns

NumberX
NumberY
NumberZ
NumberW

NKSetXYZW

Sets the X, Y, Z and W components of this Quat.

Example

myOrientation:NKSetXYZW(0.0, 0.0, 0.0, 1.0)

Parameters

NumberX
NumberY
NumberZ
NumberW

NKGetInverse

Returns the inverse of this quaternion.

Returns

quatThe inverse of this quaternion.

GLM

Static math functions.

Summary
Static Utility
LerpLerp between two vectors by weight.
RotateStatic helper to rotate a quat by an explicit axis and angle.
CeilReturns a value equal to the nearest integer that is greater than or equal to x.
FloorReturns a value equal to the nearest integer that is less than or equal to x.
Cross3Computes the cross product of two vec3s, represented by 6 floats.
CrossVec3Computes the cross product of two vectors.
AngleHelper to find the rotation between two vectors.
LookAtHelper to find the orientation between a source point and a target point.
SlerpSlerp between two vectors by weight.

Static Utility

Lerp

static vec3 Lerp(vec3 start,
vec3 end,
float weight)

Lerp between two vectors by weight.

Parameters

vec3Starting vector.
vec3Ending vector.
floatweight.

Returns

vec3The interpolated vector.

Rotate

static void Rotate(quat &out,
float angle,
const vec3 &axis)

Static helper to rotate a quat by an explicit axis and angle.

Parameters

quatThe quat to rotate (out variable).
floatThe angle amount to rotate in degrees.
vec3The axis to rotate about.

Ceil

static vec3 Ceil(const vec3 &v)

Returns a value equal to the nearest integer that is greater than or equal to x.

Parameters

vec3The vector with which to evaluate the ceil.

Returns

vec3The vec3 with each value evaluated to the nearest integer.

Floor

static vec3 Floor(const vec3 &v)

Returns a value equal to the nearest integer that is less than or equal to x.

Parameters

vec3The vector with which to evaluate the floor.

Returns

vec3The vec3 with each value evaluated to the nearest integer.

Cross3

static vec3 Cross3(float x1,
float y1,
float z1,
float x2,
float y2,
float z2)

Computes the cross product of two vec3s, represented by 6 floats.

Parameters

floatX value of the first vector.
floatY value of the first vector.
floatZ value of the first vector.
floatX value of the second vector.
floatY value of the second vector.
floatZ value of the second vector.

Returns

vec3The cross product of the two vectors.

CrossVec3

static vec3 CrossVec3(vec3 v1,
vec3 v2)

Computes the cross product of two vectors.

Parameters

vec3First vector.
vec3Second vector.

Returns

vec3The cross product of the two given vectors.

Angle

static quat Angle(const vec3 &v1,
const vec3 &v2)

Helper to find the rotation between two vectors.

Parameters

vec3Vector v1.
vec3Vector v2.

Returns

quatThe rotation from v1 to v2.

LookAt

static quat LookAt(const vec3 &source,
const vec3 &target)

Helper to find the orientation between a source point and a target point.

Example

-- Set orientation to align with a velocity vector. self:NKSetOrientation(GLM.LookAt(NKMath.ZeroVec3, self.m_velocity))

Parameters

vec3source
vec3target

Returns

quatThe normalized orientation from source to target.

Slerp

static quat Slerp(const quat &v1,
const quat &v2,
float interp)

Slerp between two vectors by weight.

Parameters

vec3Starting vector.
vec3Ending vector.
floatweight.

Returns

vec3The interpolated vector.
int staticNKRotateByQuaternion(lua_State *vm)
Rotates a vector by a given quaternion.
static vec3 Lerp(vec3 start,
vec3 end,
float weight)
Lerp between two vectors by weight.
static void Rotate(quat &out,
float angle,
const vec3 &axis)
Static helper to rotate a quat by an explicit axis and angle.
static vec3 Ceil(const vec3 &v)
Returns a value equal to the nearest integer that is greater than or equal to x.
static vec3 Floor(const vec3 &v)
Returns a value equal to the nearest integer that is less than or equal to x.
static vec3 Cross3(float x1,
float y1,
float z1,
float x2,
float y2,
float z2)
Computes the cross product of two vec3s, represented by 6 floats.
static vec3 CrossVec3(vec3 v1,
vec3 v2)
Computes the cross product of two vectors.
static quat Angle(const vec3 &v1,
const vec3 &v2)
Helper to find the rotation between two vectors.
static quat LookAt(const vec3 &source,
const vec3 &target)
Helper to find the orientation between a source point and a target point.
static quat Slerp(const quat &v1,
const quat &v2,
float interp)
Slerp between two vectors by weight.
Close