Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl/llms.txt

Use this file to discover all available pages before exploring further.

Prowl’s math library provides double-precision vector and matrix types that mirror the Unity-style API while giving full 64-bit accuracy — critical for large open worlds and high-precision simulations. The core types (Vector2, Vector3, Vector4, Quaternion, Matrix4x4) are value types (struct) with aggressive-inlining annotations. Convenience .ToFloat() methods bridge to System.Numerics types required by Veldrid and other float-based libraries. The MathD and Mathf static utility classes wrap System.Math with concise names and add higher-level operations like Lerp, PingPong, Smooth01, and ClampMagnitude.

Vector Types

Vector2

Double-precision 2D vector.
public struct Vector2 : IEquatable<Vector2>, IFormattable
MemberTypeDescription
x, ydoubleComponents
magnitudedoubleLength: √(x²+y²)
sqrMagnitudedoubleSquared length
normalizedVector2Unit vector
Vector2.zerostatic(0, 0)
Vector2.onestatic(1, 1)
Normalize(v)staticReturns unit vector
Dot(a, b)staticDot product
Distance(a, b)staticEuclidean distance
Lerp(a, b, t)via MathDLinear interpolation
Scale(v, scale)staticComponent-wise multiply
ToFloat()instanceConverts to System.Numerics.Vector2

Vector3

Double-precision 3D vector. The most frequently used math type in Prowl.
public struct Vector3 : IEquatable<Vector3>, IFormattable
MemberTypeDescription
x, y, zdoubleComponents
magnitudedoubleLength: √(x²+y²+z²)
sqrMagnitudedoubleSquared length
normalizedVector3Unit vector (instance property)
Vector3.zerostatic(0, 0, 0)
Vector3.onestatic(1, 1, 1)
Vector3.rightstatic(1, 0, 0)
Vector3.leftstatic(-1, 0, 0)
Vector3.upstatic(0, 1, 0)
Vector3.downstatic(0, -1, 0)
Vector3.forwardstatic(0, 0, 1)
Vector3.backwardstatic(0, 0, -1)
Vector3.infinitystatic(∞, ∞, ∞)
Normalize(v)staticReturns unit vector
Dot(a, b)staticDot product
Cross(a, b)staticCross product
Distance(a, b)staticEuclidean distance
AngleBetween(from, to)staticAngle in radians
Scale(v, scale)staticComponent-wise multiply
Transform(v, m)staticTransform by Matrix4x4
IsFinate()instancetrue if no NaN or infinity
ToFloat()instanceConverts to System.Numerics.Vector3

Vector4

Double-precision 4D vector.
public struct Vector4 : IEquatable<Vector4>, IFormattable
MemberTypeDescription
x, y, z, wdoubleComponents
xyzVector3First three components as Vector3
magnitudedoubleLength
sqrMagnitudedoubleSquared length
normalizedVector4Unit vector
Normalize(v)staticReturns unit vector
Dot(a, b)staticDot product
Transform(v, m)staticTransform by Matrix4x4
ToFloat()instanceConverts to System.Numerics.Vector4

Integer Vector Types

Prowl provides integer variants for pixel coordinates, grid indices, and similar discrete quantities.
TypeComponentsCommon use
Vector2Intint x, yScreen/texture coordinates
Vector3Intint x, y, zVoxel/grid positions, texture rect origins
Vector4Intint x, y, z, w4-component integer data
Each provides standard arithmetic operators, indexer access, zero, one, and conversion operators to their double counterparts.

Quaternion

Double-precision quaternion for representing 3D rotations.
public struct Quaternion : IEquatable<Quaternion>
MemberTypeDescription
x, y, z, wdoubleComponents
eulerAnglesVector3Gets/sets Euler angles in degrees
Quaternion.identitystatic(0, 0, 0, 1) — no rotation
Magnitude()instanceLength
SqrMagnitude()instanceSquared length
ToEuler()instanceReturns Euler angles in degrees
Normalize(q)staticReturns unit quaternion
NormalizeSafe(q)staticReturns identity if magnitude is near zero
Conjugate(q)staticNegates x, y, z
Inverse(q)staticMultiplicative inverse
Euler(x, y, z)staticFrom degree Euler angles
Euler(Vector3)staticFrom degree Euler vector
AngleAxis(angle, axis)staticFrom axis (normalised) and angle in radians
Slerp(a, b, t)staticSpherical interpolation
Lerp(a, b, t)staticLinear interpolation (not normalised)
RotateTowards(from, to, step)staticClamp-stepped rotation
Dot(a, b)staticQuaternion dot product
operator *Quaternion × Quaternion (compose) or Quaternion × Vector3 (rotate)
// Rotate 90° around the Y axis
Quaternion rot = Quaternion.Euler(0, 90, 0);

// Compose rotations
Quaternion combined = parentRot * childRot;

// Rotate a direction vector
Vector3 rotated = myRotation * Vector3.forward;

Matrix4x4

Double-precision 4×4 matrix used for transforms, projections, and view matrices.
public struct Matrix4x4 : IEquatable<Matrix4x4>

Properties

MemberDescription
M11M44Individual double elements
M1M4Row accessors as Vector4
TranslationGets/sets the translation component (M41, M42, M43)
IdentityStatic identity matrix
IsIdentityWhether all off-diagonal elements are zero and diagonal is one

Factory Methods

MethodDescription
TRS(pos, rot, scale)Translation × Rotation × Scale matrix
CreateTranslation(x, y, z)Pure translation
CreateScale(x, y, z)Non-uniform scale
CreateScale(scale)Uniform scale
CreateRotationX/Y/Z(radians)Axis-aligned rotation
CreateFromAxisAngle(axis, angle)Arbitrary axis rotation
CreateFromQuaternion(q)From quaternion
CreatePerspectiveFieldOfView(fov, aspect, near, far)Left-handed perspective
CreatePerspectiveFieldOfViewRightHanded(fov, aspect, near, far)Right-handed perspective
CreateOrthographic(w, h, near, far)Left-handed orthographic
CreateOrthographicOffCenter(…)Off-centre orthographic
CreateLookAt(pos, target, up)Left-handed look-at (target point) view matrix
CreateLookAtRightHanded(pos, target, up)Right-handed look-at (target point) view matrix
CreateLookTo(pos, dir, up)Left-handed look-towards (direction) view matrix
CreateLookToRightHanded(pos, dir, up)Right-handed look-towards (direction) view matrix
CreateBillboard(…)Billboard matrix facing camera
FromFloat(System.Numerics.Matrix4x4)Converts from float matrix

Instance Methods

MethodDescription
MultiplyPoint(Vector3)Transforms a point (applies translation)
Invert()Returns the inverse, or identity if not invertible
ToFloat()Converts to System.Numerics.Matrix4x4

Static Utility Methods

MethodDescription
static bool Decompose(matrix, out scale, out rot, out trans)Decomposes a matrix into TRS components
static Matrix4x4 Transpose(matrix)Returns the transposed matrix
static bool Invert(matrix, out result)Tries to invert; returns false if singular
// Build a world matrix
Matrix4x4 world = Matrix4x4.TRS(position, rotation, scale);

// Build a GPU perspective projection
Matrix4x4 proj = Matrix4x4.CreatePerspectiveFieldOfView(
    MathD.PI / 3.0,   // 60° FOV
    aspectRatio, 0.1, 1000.0);
proj = Graphics.GetGPUProjectionMatrix(proj);

Transform (Component)

Transform is a class (not a struct) attached to every GameObject. It manages the local/world position, rotation, and scale hierarchy.
public class Transform : ICloneExplicit

Position

position
Vector3
World-space position. Setting automatically computes the correct local position.
localPosition
Vector3
Local position relative to the parent.

Rotation

rotation
Quaternion
World-space rotation.
localRotation
Quaternion
Local rotation relative to the parent.
eulerAngles
Vector3
World Euler angles in degrees.
localEulerAngles
Vector3
Local Euler angles in degrees.

Scale

localScale
Vector3
Local scale (author-set).
lossyScale
Vector3
Effective world scale (product of all parent scales).

Direction Vectors

forward
Vector3
rotation * Vector3.forward
right
Vector3
rotation * Vector3.right
up
Vector3
rotation * Vector3.up

Matrices

localToWorldMatrix
Matrix4x4
Cached TRS matrix from local to world space.
worldToLocalMatrix
Matrix4x4
Inverse of localToWorldMatrix.

Methods

public void Translate(Vector3 translation, Transform? relativeTo = null)
public void Rotate(Vector3 eulerAngles, bool relativeToSelf = true)
public void Rotate(Vector3 axis, double angle, bool relativeToSelf = true)
public void RotateAround(Vector3 point, Vector3 axis, double angle)
public void LookAt(Vector3 worldPosition, Vector3 worldUp)

public Vector3    TransformPoint(Vector3 inPosition)
public Vector3    InverseTransformPoint(Vector3 inPosition)
public Vector3    TransformDirection(Vector3 inDirection)
public Vector3    InverseTransformDirection(Vector3 inDirection)
public Vector3    TransformVector(Vector3 inVector)
public Vector3    InverseTransformVector(Vector3 inVector)
public Quaternion TransformRotation(Quaternion inRotation)
public Quaternion InverseTransformRotation(Quaternion worldRotation)

Bounds

Axis-aligned bounding box (AABB) defined by min and max corners.
public struct Bounds : IEquatable<Bounds>
MemberDescription
min, maxCorner vectors (stored directly)
center(min + max) * 0.5 — get/set
extentsHalf-size — get/set
sizemax - min — get/set
Bounds(center, size)Constructor
Contains(Bounds)ContainmentTypeDisjoint / Contains / Intersects
Contains(Vector3)boolPoint containment
Intersects(Bounds)boolOverlap test
Transform(Matrix4x4)Returns a new AABB enclosing the transformed box
Expand(Vector3)Expands the box to include a point

Ray

A ray defined by an origin point and a direction vector.
public struct Ray : IEquatable<Ray>
{
    public Vector3 origin;
    public Vector3 direction;
}
MethodReturnsDescription
Ray(position, direction)Constructor
Position(double distance)Vector3Point along the ray at origin + direction * distance
Intersects(Bounds box)double?Distance to AABB intersection, or null if no hit
Intersects(Plane plane)double?Distance to plane intersection
Intersects(v1, v2, v3, cullBackface)double?Möller–Trumbore triangle intersection

Rect

A 2D rectangle defined by Min (upper-left) and Max (lower-right) Vector2 points.
public struct Rect
{
    public Vector2 Min; // Upper-left
    public Vector2 Max; // Lower-right
}
MemberDescription
x, yPosition of the left/top edge
width, heightDimensions
PositionGets/sets Min
Center(Min + Max) / 2
Rect.EmptyRect with inverted extremes
Rect.ZeroZero-sized rect at origin
CreateFromMinMax(min, max)Static factory
Contains(Vector2)Point-in-rect test
Overlaps(Rect)Rectangle overlap test

Plane

An infinite plane defined by a normal and a distance from the origin.
public struct Plane
{
    public Vector3 normal;
    public double  distance;
}
distance is the signed distance from the world origin along normal. Intersection with a Ray is computed via Ray.Intersects(Plane).

BoundingFrustum

Camera view-frustum built from a view-projection matrix. Used for frustum culling.
BoundingFrustum frustum = new BoundingFrustum(viewProjectionMatrix);
ContainmentType result  = frustum.Contains(bounds);
Vector3[]       corners = frustum.GetCorners(); // 8 frustum corner points

MathD — Double Utilities

MathD is a static class of double math helpers in Prowl.Runtime.

Constants

ConstantValueDescription
MathD.PI3.14159265359π
MathD.TAU6.28318530717959
MathD.E2.71828182846Euler’s number
MathD.SQRT21.41421356237√2
MathD.GOLDEN_RATIO1.61803398875φ
MathD.Deg2RadTAU / 360Multiply degrees to get radians
MathD.Rad2Deg360 / TAUMultiply radians to get degrees
MathD.Infinitydouble.PositiveInfinity
MathD.NegativeInfinitydouble.NegativeInfinity
MathD.Small0.000001Tolerance for approximate equality

Methods

MethodDescription
Sin(x), Cos(x), Tan(x)Trigonometric functions
Asin(x), Acos(x), Atan(x)Inverse trig
Atan(y, x)atan2(y, x)
Sqrt(x), Pow(x, e), Exp(x)Power / root
Abs(x)Absolute value
Log(x), Log(x, base), Log10(x)Logarithms
Clamp(v, min, max)Clamp (double and int overloads)
Clamp01(v)Clamp to [0, 1]
Min(params double[]) / Max(params double[])Varargs min/max
Floor(x), FloorToInt(x)Floor
Ceil(x), CeilToInt(x)Ceiling
Round(x), RoundToInt(x)Rounding with MidpointRounding
Sign(x)Returns 1 or -1
Frac(x)Fractional part: x - Floor(x)
Repeat(v, length)Modulo looping in [0, length]
PingPong(t, length)Ping-pong oscillation
Lerp(double a, double b, double t)Scalar linear interpolation
Lerp(Vector2 a, Vector2 b, Vector2 t)Component-wise Vector2 lerp
Lerp(Vector3 a, Vector3 b, Vector3 t)Component-wise Vector3 lerp
Lerp(Vector4 a, Vector4 b, Vector4 t)Component-wise Vector4 lerp
LerpClamped(a, b, t)Lerp with t clamped to [0,1]
LerpSmooth(a, b, t)Smoothstep lerp
InverseLerp(a, b, t)Inverse linear interpolation
InverseLerpClamped(a, b, t)Clamped inverse lerp
LerpAngle(a, b, t)Lerp over shortest arc between angles
Smooth01(x)x²(3 - 2x) smoothstep
Smoother01(x)x³(x(6x - 15) + 10) Ken Perlin’s smoother
MoveTowards(current, target, maxDelta)Moves current toward target by at most maxDelta
ClampMagnitude(v, min, max)Clamps vector length (Vector2 and Vector3 overloads)
Angle(q, r)Angle in radians between two quaternions
ApproximatelyEquals(a, b)Checks if `a - b< Small`
IsValid(x)true if not NaN and not infinity

Mathf — Float Utilities

Mathf provides approximate-equality helpers for single-precision System.Numerics types:
Mathf.ApproximatelyEquals(float a, float b)
Mathf.ApproximatelyEquals(System.Numerics.Vector2 a, System.Numerics.Vector2 b)
Mathf.ApproximatelyEquals(System.Numerics.Vector3 a, System.Numerics.Vector3 b)
Mathf.ApproximatelyEquals(System.Numerics.Vector4 a, System.Numerics.Vector4 b)
Uses float.Epsilon as the tolerance. Use this when comparing System.Numerics types from Veldrid interop.

Bool3

A memory-efficient structure packing three bool values into a single byte.
public struct Bool3 : IEquatable<Bool3>
{
    public bool x, y, z;
}
MemberDescription
Bool3(x, y, z)Constructor
Bool3(value)All-same constructor
Bool3.zero(false, false, false)
Bool3.one(true, true, true)
Any()true if any component is true
All()true if all components are true
CountTrue()Number of true components
SetAll(value)Set all components at once
ToArray()Returns bool[] of length 3
operator &Component-wise AND
operator |Component-wise OR
operator ^Component-wise XOR
operator !Component-wise NOT
implicit bool → Bool3Sets all components
explicit Bool3 → byteRaw backing byte

Random

Static helper for random values using System.Random.Shared.
public static class Random
MemberReturnsDescription
ValuedoubleUniform [0, 1)
Signdouble-1 or +1 with equal probability
Range(double min, double max)doubleUniform in [min, max]
Range(int min, int max)intUniform in [min, max)
Booleanbool50/50 true or false
AngledoubleUniform angle in [0, TAU)
OnUnitCircleVector2Random point on unit circle
InUnitCircleVector2Random point inside unit circle
InUnitSquareVector2Random (x, y) in [0,1]²
OnUnitSphereVector3Random point on unit sphere
InUnitSphereVector3Random point inside unit sphere
InUnitCubeVector3Random (x, y, z) in [0,1]³
RotationQuaternionUniformly distributed rotation
ColorColorRandom RGBA colour
// Random direction
Vector3 dir = Random.OnUnitSphere;

// Random pitch variation
float pitch = (float)Random.Range(0.9, 1.1);

// Random spawn inside area
Vector3 spawn = transform.position + Random.InUnitSphere * spawnRadius;

Build docs developers (and LLMs) love