Math

Module providing various structure to manipulate vectors, matrix as well as quaternion. In addition the module include multiply utility functions to handle color space conversion, interpolation etc...

Functions


Name Description
InverseSqrtf Calculate the inverse square root of a value.
Project Project a 3d point to screen components.
Unproject Unproject an arbitraty screen component back to a 3d point.
GetNearestPoint Return the nearest point on a line.
HitBSphere Function that check wether or not a ray hit a sphere.
HitBSphere2 Function that return the hit point between a ray and a sphere.
HitAABB Function that return if a ray hit an axis align bounding box.
HitAABB2 Function that returns the hit point between a ray and an AABB.
HitAABBNormal Function that return the hit normal between a ray and an AABB.
PointInAABB Determine if an arbitrary point is inside an AABB.
PointInBSphere Determine if an arbitrary point is inside a bounding sphere.
PointInCylinder Determine if an arbitrary point is inside a cylinder.
PointInBBox Determine if an arbitrary point is inside a bounding box.
IntersectTriangle Function that determine if a ray intersect a triangle.
IntersectTriangleCull Function that determine if a ray intersect a triangle taking in consideration back face culling.
IntersectPlane Function that return the hit point between a ray and a plane.
HitBBox Return the hit point between a ray and a bounding box.
HitBBoxNormal Return the hit normal between a ray and a bounding box.
TriOverlapAABB Return wether or not a triangle is intersecting an AABB.
ClosestPointOnTri Function that returns the closests point on a triangle.
ClosestBarycentricOnTri Function that returns the closests barycentric component of a point on a triangle.
Perlin1d Perlin noise function.
Perlin2d Two dimensional Perlin noise function.
OverlapAABB Function that check if two AABB overlap.
OverlapBSphere Function that check if two bounding sphere overlap.
OverlapAABBBSphere Return the hit distance between an AABB and a BSphere.
NormalizeFloat Round up the digits of a floating point value.
NormalizeAngle Normalize a Euler angle in the range of 0.0 to 360.0 degree.
ValueInRange Helper function that check if a value is inside a specific range.
Wrapf Wrap around an arbitrary value to a specific range.
Wrapi Return the active modelview matrix multiplied by the projection matrix.
Clampf Clamp a floating point value to a specific range.
Clampi Clamp an integer value to a specific range.
LookAt Function that build a look at matrix.
RotateAround Return the orbit position of an arbitrary point around pivot.
Randomui Return a random integer value between 0 and max.
Randomf Function that return a random floating point in the range of 0.0 to 1.0.
Snap Snap a component v to an arbitrary unit grid.
Smoothstep Perform a smooth Hermite interpolation between two values.

IVec2


Two-dimensional vector or integers.

Variables


Name Description
x The X component of the vector.
y The Y component of the vector.

Functions


Name Description
Set Set the XY components of the vector.

Vec2


Two-dimensional vector.

Variables


Name Description
x The X component of the vector.
y The Y component of the vector.

Functions


Name Description
Set Set the XY components of the vector.
Setf Set the same value to both XY components of the vector.
Zero Set the vector to zero.
One Set the vector to one.
Invert Invert the vector values.
Print Print the vector value on the console.
IsZero Check if the vector is set to zero.
Equal Check for equality.
Add Adds two vectors.
Sub Subtracts one vector from another.
Mulf Multiplies a vector by a number.
Mul Multiplies a vector by a vector.
Div Divides a vector by a vector.
Divf Divides a vector by a number.
Length Return the dot product of the vector.
Magnitude Return the square length of the vector.
NormalizeFast Normalize the vector using approximation.
Normalize Normalize the vector.
Distance Calculate the distance between two vector.
Dot Return the dot product of two vector.
Cross Return the cross product of two vector.
Angle Return the Euler angle between two normalized vector.
Lerp Linearly interpolate between one vector to another.
Mid Return the middle point between two vector.
Min Return the minimum XY value between two vector.
Max Return the minimum XY value between two vector.
Low Return the lowest value of the vector.
High Return the highest value of the vector.
ToVec3 Convert to a tri-dimensional vector..

IVec3


Three-dimensional vector or integers.

Variables


Name Description
x The X component of the vector.
y The Y component of the vector.

Functions


Name Description
Set Set the XY components of the vector.

Vec3


Tri-dimensional vector.

Variables


Name Description
x The X component of the vector.
y The Y component of the vector.
z The Z component of the vector.

Functions


Name Description
Set Set the XYZ components of the vector.
Setf Set the same value to both XYZ components of the vector.
Zero Set the vector to zero.
One Set the vector to one.
Invert Invert the vector values.
Print Print the vector value on the console.
IsZero Check if the vector is set to zero.
Equal Check for equality.
Add Adds two vectors.
Sub Subtracts one vector from another.
Mulf Multiplies a vector by a number.
Mul Multiplies a vector by a vector.
Div Divides a vector by a vector.
Divf Divides a vector by a number.
Length Return the dot product of the vector.
Magnitude Return the square length of the vector.
NormalizeFast Normalize the vector using approximation.
Normalize Normalize the vector.
NormalizeSafe Normalize the vector avoid division by zero.
Distance Calculate the distance between two vector.
Dot Return the dot product of two vector.
Cross Return the cross product of two vector.
Angle Return the Euler angle between two normalized vector.
Lerp Linearly interpolate between one vector to another.
Mid Return the middle point between two vector.
Min Return the minimum XYZ value between two vector.
Max Return the minimum XYZ value between two vector.
Low Return the lowest value of the vector.
High Return the highest value of the vector.
MulMat3 Multiply the vector by a 3x3 matrix.
MulMat4 Multiple the vector by a 4x4 transformation matrix.
MulMat4 Multiple the vector by the rotation part of a 4x4 transformation matrix.
MulQuat Multiple the vector by a quaternion.
AxisToMat3 Create a 3x3 rotation matrix from normalized vector around the up axis (Z).
GetDominantAxis Return the vector dominant axis.
Ortho Ortho. project the current vector.
Reflect Calculate the reflection direction between a vector and a normal.
Bounce Return the bounce direction of a vector and a normal biased by paramater b.
Project Project a vector onto a plane normal.
AngleX Retrieve the angle X of a normalized direction vector.
AngleZ Retrieve the angle Z of a normalized direction vector.
ToVec4 Convert the 3D vector to a 4D vector.
ToQuat Convert Euler angles based vector to a quaternion.

Vec4


4D vector class.

Variables


Name Description
x The X component of the vector.
y The Y component of the vector.
z The Z component of the vector.
w The W component of the vector.

Functions


Name Description
Set Set the XYZW components of the vector.
Setf Set the same value to both XYZW components of the vector.
Zero Set the vector to zero.
One Set the vector to one.
Invert Invert the vector values.
Print Print the vector value on the console.
IsZero Check if the vector is set to zero.
Equal Check for equality.
Add Adds two vectors.
Sub Subtracts one vector from another.
Mulf Multiplies a vector by a number.
Mul Multiplies a vector by a vector.
Div Divides a vector by a vector.
Divf Divides a vector by a number.
DivVec3 Divides a 4D vector by a 3D vector.
Length Return the dot product of the 4D vector.
Length3 Return the dot product of the 3D part of the vector.
Magnitude Return the square length of the vector.
NormalizeFast Normalize the vector using approximation.
Normalize Normalize the vector.
NormalizeSafe Normalize the vector avoid division by zero.
Dot Return the dot product of two vector.
Lerp Linearly interpolate between one vector to another.
Min Return the minimum XYZW value between two vector.
Max Return the minimum XYZW value between two vector.
Low Return the lowest value of the vector.
High Return the highest value of the vector.
MulVec4 Multiply the tri-dimensional part of the vector with another.
MulMat4 Multiply the vector by a transformation matrix.
ToVec3 Convert to a 3D vector.
SetVec3 Set the XYZ part using a 3D vector.
SetColor Assign the vector as a color.
ToQuat Convert the vector to a quaternion.

Quad


A class that handles box operations in 2D.

Variables


Name Description
x The X coordinate of the quad.
y The Y coordinate of the quad.
width The size of the quad on the X axis.
height The size of the quad on the Y axis.

Functions


Name Description
Set Set the coordinates of the box.
Zero Set box values back to zero.
Print Print the quad coordinates on the console.
Equal Check for equality between two quads.
Hit Function that check if an XY position hit the box avoiding the edges.
HitInclusive Function that check if an XY position hit the box avoiding including the edges.
Inside Helper that check if a quad is in a quad.
Overlap Check if two quads overlap.
Diff Function that calculate the difference between two quads.

Quat


Quaternion manipulation class.

Variables


Name Description
x The X component of the quaternion.
y The Y component of the vector.
z The Z component of the vector.
w The W component of the vector.

Functions


Name Description
Set Set the XYZW components of the quaternion.
Zero Reset the quaternion back to zero.
Identity Reset the quaternion back to identity.
Invert Invert the quaternion values.
Print Print the quaternion value on the console.
Equal Check for quaternion equality.
Add Adds two quaternions.
Sub Subtracts one quaternion from another.
Mulf Multiplies a quaternion by a value.
Mul Multiplies a quaternion by a quaternion.
Length Return the dot product of the quaternion.
Magnitude Return the square length of the quaternion.
NormalizeFast Normalize the quaternion using approximation.
Normalize Normalize the quaternion.
Dot Return the dot product of two quaternion.
MulVec3 Multiply a 3D vector by a quaternion.
Conjugate Invert the quaternion XYZ components.
ToEuler Convert a quaternion to Euler angles.
ToVec4 Convert the quaternion to a 4D vector.
Lerp Linearly interpolate from one quaternion to another.
Slerp Spherically interpolate from one quaternion to another.
Rotate Rotate a quaternion around a specific axis.
Build Calculat the W component of the quaternion.
ToMat3 Convert a quaternion to a 3x3 rotation matrix.

Mat2


Class to manipulate a 2x2 matrix.

Variables


Name Description
r0 The first row of the matrix.
r1 The second row of the matrix.

Functions


Name Description
Set Set each element of the matrix.
Zero Reset the matrix back to zero.
Identity Reset the matrix back to identity.
Equal Check for matrix equality.
Print Print the current matrix values on the console.
SetRow Set a specific row of the matrix.

Mat3


Class to manipulate a 3x3 matrix.

Variables


Name Description
r0 The first row of the matrix.
r1 The second row of the matrix.
r2 Third row of the matrix.

Functions


Name Description
Set Set each element of the matrix.
Zero Reset the matrix back to zero.
Identity Reset the matrix back to identity.
Print Set a specific row of the matrix.
Inverse Calculate the inverse a of 3x3 matrix.
Normalize Normalize the current matrix.
Mul Multiply a 3x3 matrix by another 3x3 matrix.
Rotate Rotate the current 3x3 matrix by a Euler angle.
SetRot Use a Euler angle vector to set the rotation of the matrix.
SetScl Set the scale of a 3x3 matrix.
Scale Scale the matrix using a scale factor for each axis.
Transpose Transpose the current matrix.
GetRot Convert the rotation matrix to a vector of Euler angles.
GetRot Convert the rotation matrix to a vector of Euler angles using the previously used angles to get a better approximation of the current angles.
GetScl Retrieve the current scale of the matrix.
GetDir Retrieve the direction vector of the matrix.
ToMat4 Convert the matrix to a 4x4 transformation matrix.
ToQuat Convert the matrix to a quaternion.
ToQuat2 Convert the matrix to quaternion using the previous quaternion used to create the matrix to better approximate the current result.
ToQuatAlt Alternate method to convert the matrix to a quaternion.
ToQuatAlt2 Alternative to convert the 3x3 matrix to quaternion using the previous quaternion used to create the matrix to better approximate the current result.
ToQuatSafe Safeley convert the matrix to a quaternion avoiding possible division by zero.
FromNormal Generate a 3x3 matrix from a normal vector.
Align Create a 3x3 matrix from two direction vector.
ToArray Convert the matrix to an array or table (Lua).

Mat4


Class to manipulate a 4x4 matrix.

Variables


Name Description
r0 The first row of the matrix.
r1 The second row of the matrix.
r2 Third row of the matrix.
r3 Forth row of the matrix.

Functions


Name Description
Zero Set the matrix back to zero.
Identity Set the matrix to identity.
Bias Create a bias matrix usually used for shadow maps and projectors.
Equal Check for matrix equality.
Print Print the content of the matrix on the console.
Inverse Calculate the inverse of the current matrix.
SetRow Set a specific matrix row.
Set Manually set the value of each row of the matrix.
GetMat3 Convert the matrix to a 3x3 matrix.
Normalize Normalize a 4x4 matrix.
Mul Multiply two 4x4 matrix.
MulMat3 Multiply a the rotational part of 4x4 matrix with a 3x3 matrix.
Translate Multiply the current matrix by a translation matrix.
Rotate Multiply the current matrix by a rotation matrix.
Scale Multiply the current matrix by a general scaling matrix.
Transpose Tanspose a 4x4 matrix.
Ortho Create an orthographic matrix.
Perspective Create a perspective matrix.
GetLoc Extract the location of a 4x4 matrix.
GetRot Extract the Euler angle rotation of a 4x4 matrix.
GetScl Extract the scale of a 4x4 matrix.
SetLoc Set the location of a transformation matrix.
SetRot Set the Euler angle rotation of a transformation matrix.
SetQuat Set the rotational part of a transformation matrix using a quaternion.
SetScl Set the scale of a transformation matrix.
SetLocRotScl Create a matrix specifying a location/rotation and scale.
SetLocQuatScl Create a matrix specifying a location/rotation and scale.
SetMat3 Manually set the rotational part of a 4x4 matrix using a 3x3 matrix.
GetQuat Return the rotational part of a 4x4 using a quaternion.
ToMat3 Convert a 4x4 matrix to a 3x3 matrix.
Lerp Linearly interpolate between one matrix to another.
ToArray Convert the matrix to an array or table (Lua).

Clip


A structure to manipulate frustum clipping planes.

Variables


Name Description
p0 Up clipping plane.
p1 Down clipping plane.
p2 Left clipping plane.
p3 Right clipping plane.
p4 Top clipping plane.
p5 Bottom clipping plane.

Functions


Name Description
Build Build a frustum out of a view-projection matrix.
Point Test if a point is inside a frustum.
BSphere Test if a bounding sphere intersect with the frustum.
BBox Test if a bounding box is intersecting with the frustum.
AABB Test if an axis aligned bounding box intersect with the frustum.

BBox


Bounding box manipulation class.

Variables


Name Description
p0 First vertex.
p1 Second vertex.
p2 Third vertex.
p3 Fourth vertex.
p4 Fifth vertex.
p5 Sixth vertex.
p6 Seventh vertex.
p7 Eight vertex.

Functions


Name Description
Set Set the bounding box vertices.

Bez3


Bounding box manipulation class.

Variables


Name Description
l Left handle.
v Value.
r Right handle.

Functions


Name Description
Set Manually set the Bezier tripple.
Equal Test for Bezier equality.

Hsv


Cylindrical-coordinate representations of points in an RGB color model.

Variables


Name Description
h Hue.
s Saturation.
v Value.

Functions


Name Description
Set Manually set the hue, saturation and value.

Rect4


A structure that Manages the UVs applied on a quad.

Variables


Name Description
uv0 Bottom left UV.
uv1 Bottom right UV.
uv2 Top right UV.
uv3 Bottom right UV.

Functions


Name Description
Set Manually set the quad UVs.

Colorspace


Utility function to deal with different color space.

Functions


Name Description
HexToRGBA Convert from an HTML color representation to RGBA.
RGBAToHex Convert from RGBA to an HTML color representation.
IndexToRGB Convert a 32 bits index to a 24 bits color.
RGBToIndex Convert a 24 bits color to a 32 bits index.
IndexToRGBA Convert a 32 bits index to a color; allowing you to specify the alpha value.
Unpack Unpack a 32 bits RGBA to a float value.
RGBToHSV Convert a RGB value to HSV.
HSVToRGB Convert from RGB to HSV.
GenRGB Randomly generate a RGB value.
GenSRGB Randomly generate a smooth RGB value.
GenRGBA Randomly generate a RGB, specifying the alpha.
GenSRGBA Randomly generate a smooth RGB, specifying the alpha.

Interpolation


Various interpolation routines.

Functions


Name Description
Linear Linear interpolation.
Cosine Cosine interpolation.
Bezier Bezier interpolation.
Cubic Cubic Bezier interpolation.
Catmull Catmul interpolation.
Hermite Hermite interpolation.




NRG - API 2022.4.384543 - Fri Nov 4 2022
Copyright © 2022 nrgcore.com. All Rights Reserved. Terms of Service - Privacy Policy - EULA