5. Boost package for math
The math boost module implements collection of helper macros and functions to accompany math.
All functions and symbols are in “math_boost” module, use require to get access to it.
require daslib/math_boost
5.1. Structures
- AABR
axis aligned bounding rectangle
- Fields:
min : float2 - min coordinates
max : float2 - max coordinates
- AABB
axis aligned bounding box
- Fields:
min : float3 - min coordinates
max : float3 - max coordinates
- Ray
ray (direction and origin)
- Fields:
dir : float3 - direction
origin : float3 - origin
5.2. Angle conversions
- degrees(f: float): float
convert radians to degrees
- Arguments:
f : float
- radians(f: float): float
convert degrees to radians
- Arguments:
f : float
5.3. Intersections
- is_intersecting(a: AABR; b: AABR): bool
returns true if inputs intersect
- is_intersecting(a: AABB; b: AABB): bool
returns true if inputs intersect
- is_intersecting(ray: Ray; aabb: AABB; Tmin: float = 0f; Tmax: float = FLT_MAX): bool
returns true if ray intersects aabb within [Tmin, Tmax]
5.4. Matrices
- look_at_lh(Eye: float3; At: float3; Up: float3): float4x4
left-handed (z forward) look at matrix with origin at Eye and target at At, and up vector Up.
- Arguments:
Eye : float3
At : float3
Up : float3
- look_at_rh(Eye: float3; At: float3; Up: float3): float4x4
right-handed (z towards viewer) look at matrix with origin at Eye and target at At, and up vector Up.
- Arguments:
Eye : float3
At : float3
Up : float3
- perspective_lh(fovy: float; aspect: float; zn: float; zf: float): float4x4
left-handed (z forward) perspective matrix
- Arguments:
fovy : float
aspect : float
zn : float
zf : float
- perspective_rh(fovy: float; aspect: float; zn: float; zf: float): float4x4
right-handed (z toward viewer) perspective matrix
- Arguments:
fovy : float
aspect : float
zn : float
zf : float
- perspective_rh_opengl(fovy: float; aspect: float; zn: float; zf: float): float4x4
right-handed (z toward viewer) opengl (z in [-1..1]) perspective matrix
- Arguments:
fovy : float
aspect : float
zn : float
zf : float
- ortho_rh(left: float; right: float; bottom: float; top: float; zNear: float; zFar: float): float4x4
right handed (z towards viwer) orthographic (parallel) projection matrix
- Arguments:
left : float
right : float
bottom : float
top : float
zNear : float
zFar : float
- planar_shadow(Light: float4; Plane: float4): float4x4
planar shadow projection matrix, i.e. all light shadows to be projected on a plane
- Arguments:
Light : float4
Plane : float4
5.5. Plane
- plane_dot(Plane: float4; Vec: float4): float
dot product of Plane and ‘Vec’
- Arguments:
Plane : float4
Vec : float4
- plane_normalize(Plane: float4): float4
normalize `Plane’, length xyz will be 1.0 (or 0.0 for no plane)
- Arguments:
Plane : float4
- plane_from_point_normal(p: float3; n: float3): float4
construct plane from point p and normal n
- Arguments:
p : float3
n : float3
5.6. Color conversions
- linear_to_SRGB(x: float): float
convert value from linear space to sRGB curve space
- Arguments:
x : float
- linear_to_SRGB(c: float3): float3
convert value from linear space to sRGB curve space
- Arguments:
c : float3
- linear_to_SRGB(c: float4): float4
convert value from linear space to sRGB curve space
- Arguments:
c : float4
5.7. Color packig and unpacking
- RGBA_TO_UCOLOR(x: float; y: float; z: float; w: float): uint
conversion from RGBA to ucolor. x,y,z,w are in [0,1] range
- Arguments:
x : float
y : float
z : float
w : float
- RGBA_TO_UCOLOR(xyzw: float4): uint
conversion from RGBA to ucolor. xyzw components are in [0,1] range
- Arguments:
xyzw : float4
- UCOLOR_TO_RGBA(x: uint): float4
conversion from ucolor to RGBA. x components are in [0,255] range
- Arguments:
x : uint
- UCOLOR_TO_RGB(x: uint): float3
conversion from ucolor to RGB. x components are in [0,255] range. result is float3(x,y,z)
- Arguments:
x : uint