UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

60 lines (54 loc) 1.86 kB
/** * Constructs an orthographic hexahedron from an Axis-Aligned Bounding Box. * The planes are stored as 4-tuples (nx, ny, nz, d). * * Normals are facing inwards, i.e., the volume of positive. * * This can also be used for an orthographic camera frustum. * * @param {Float32Array|number[]} output * @param {number} output_offset * @param {number} x0 - Minimum X * @param {number} y0 - Minimum Y * @param {number} z0 - Minimum Z * @param {number} x1 - Maximum X * @param {number} y1 - Maximum Y * @param {number} z1 - Maximum Z */ export function hexahedron_from_aabb( output, output_offset, x0, y0, z0, x1, y1, z1 ){ // Right plane (x = x1): Normal points -X output[output_offset + 0] = -1; output[output_offset + 1] = 0; output[output_offset + 2] = 0; output[output_offset + 3] = x1; // Left plane (x = x0): Normal points +X output[output_offset + 4] = 1; output[output_offset + 5] = 0; output[output_offset + 6] = 0; output[output_offset + 7] = -x0; // Top plane (y = y1): Normal points -Y output[output_offset + 8] = 0; output[output_offset + 9] = -1; output[output_offset + 10] = 0; output[output_offset + 11] = y1; // Bottom plane (y = y0): Normal points +Y output[output_offset + 12] = 0; output[output_offset + 13] = 1; output[output_offset + 14] = 0; output[output_offset + 15] = -y0; // Near plane (z = z0): Normal points +Z output[output_offset + 16] = 0; output[output_offset + 17] = 0; output[output_offset + 18] = 1; output[output_offset + 19] = -z0; // Far plane (z = z1): Normal points -Z output[output_offset + 20] = 0; output[output_offset + 21] = 0; output[output_offset + 22] = -1; output[output_offset + 23] = z1; }