2.4. Boost package for math
The MATH_BOOST module adds geometric types (AABB, AABR, Ray),
angle conversion (degrees, radians), intersection tests, color space
conversion (linear_to_SRGB, RGBA_TO_UCOLOR), and view/projection
matrix construction (look_at_lh, perspective_rh).
All functions and symbols are in “math_boost” module, use require to get access to it.
require daslib/math_boost
Example:
require daslib/math_boost
[export]
def main() {
print("degrees(PI) = {degrees(PI)}\n")
print("radians(180) = {radians(180.0)}\n")
var box = AABB(min = float3(0), max = float3(10))
print("box = ({box.min}) - ({box.max})\n")
}
// output:
// degrees(PI) = 180
// radians(180) = 3.1415927
// box = (0,0,0) - (10,10,10)
2.4.1. Structures
- math_boost::AABR
axis aligned bounding rectangle
- Fields
min : float2 - min coordinates
max : float2 - max coordinates
- math_boost::AABB
axis aligned bounding box
- Fields
min : float3 - min coordinates
max : float3 - max coordinates
- math_boost::Ray
ray (direction and origin)
- Fields
dir : float3 - direction
origin : float3 - origin
2.4.2. Angle conversions
- math_boost::degrees(f: float) : float()
convert radians to degrees
- Arguments
f : float
- math_boost::radians(f: float) : float()
convert degrees to radians
- Arguments
f : float
2.4.3. Intersections
2.4.4. Matrices
- math_boost::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
- math_boost::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
- math_boost::ortho_rh(left: float; right: float; bottom: float; top: float; zNear: float; zFar: float) : float4x4()
right handed (z towards viewer) orthographic (parallel) projection matrix
- Arguments
left : float
right : float
bottom : float
top : float
zNear : float
zFar : float
- math_boost::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
- math_boost::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
- math_boost::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
- math_boost::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
2.4.5. Plane
- math_boost::plane_dot(Plane: float4; Vec: float4) : float()
dot product of Plane and ‘Vec’
- Arguments
Plane : float4
Vec : float4
- math_boost::plane_from_point_normal(p: float3; n: float3) : float4()
construct plane from point p and normal n
- Arguments
p : float3
n : float3
- math_boost::plane_normalize(Plane: float4) : float4()
normalize Plane, length xyz will be 1.0 (or 0.0 for no plane)
- Arguments
Plane : float4
2.4.6. Color conversions
2.4.7. Color packing and unpacking
2.4.7.1. RGBA_TO_UCOLOR
- math_boost::RGBA_TO_UCOLOR(xyzw: float4) : uint()
conversion from RGBA to ucolor. xyzw components are in [0,1] range
- Arguments
xyzw : float4
- math_boost::RGBA_TO_UCOLOR(x: float; y: float; z: float; w: float) : uint()
- math_boost::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
- math_boost::UCOLOR_TO_RGBA(x: uint) : float4()
conversion from ucolor to RGBA. x components are in [0,255] range
- Arguments
x : uint