@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
27 lines (24 loc) • 870 B
JavaScript
import { v3_length } from "../../vec3/v3_length.js";
/**
* Normalizes plane representation.
* Note plane normal must have a non-zero length.
* @param {number[]} destination
* @param {number} destination_offset
* @param {number} x plane normal X
* @param {number} y plane normal Y
* @param {number} z plane normal Z
* @param {number} w planar offset constant
*/
export function plane3_normalize(
destination, destination_offset,
x, y, z, w
) {
// compute vector length
const length = v3_length(x, y, z);
const inverse_length = 1.0 / length;
// apply normalization
destination[destination_offset] = x * inverse_length;
destination[destination_offset + 1] = y * inverse_length;
destination[destination_offset + 2] = z * inverse_length;
destination[destination_offset + 3] = w * inverse_length;
}