Skip to content

Namespace Apogee.Core.Numerics

Classes

BoxSet

Axis-aligned boxes as separate arrays of centers and half extents (structure of arrays), so that a vector instruction tests eight (or four) of them against a plane at once. The arrays are padded to a multiple of with boxes of no size at the origin, which a kernel tests like any other; their results are meaningless and ignored (only the first matter).

FrustumCulling

Tests boxes against a , writing a bit per box (set: at least partly inside): bit k of byte b is box 8b + k. There are three kernels with the same arithmetic in the same order, so they give the same bits: , (four boxes per instruction) and (eight). picks the widest one the process runs fast: NativeAOT builds for x86-64-v2 have 128-bit vectors only (see the profiling chapter of the manual), CoreCLR on a modern CPU has 256.

Structs

Double3

A position in the double-precision world: three doubles (24 bytes). Float has 24 bits of precision, so at 5 km from the origin a float position moves in 0.5 mm steps; a double keeps sub-micrometre steps for thousands of kilometres. Only positions are double. Directions, rotations, scales and everything the GPU sees stay float: positions are turned into float offsets from a nearby origin (the camera) with before they are used. Plain scalar code on purpose: positions are added and subtracted, not crunched in bulk.

Frustum

The view volume of a perspective camera with an infinite far plane, as five planes (left, right, bottom, top, near) in the camera-relative space the renderer works in. A plane is (nx, ny, nz, d) and a point is inside when n·p + d >= 0 for all five. The four side planes pass through the camera, which is the origin, so their d is zero; moves the origin for a scene whose coordinates are relative to something else. The normals are not unit length (the side ones are forward * tan + right); the culling kernel takes that into account.

Trs

A placement in the double-precision world: a position, a rotation and a scale (not a matrix, so a position far from the origin keeps its precision). A point is scaled, then rotated, then moved. Non-uniform scale is allowed, but there is no shear: the scale of a child under a rotated, non-uniformly scaled parent is the product of the two scales, which is exact only when the parent's scale is uniform or its rotation lines up with the child's axes (the usual rule of game engines).