@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
47 lines (38 loc) • 1.38 kB
JavaScript
import { lerp } from "../../../math/lerp.js";
/**
* TODO this produces increasingly incorrect when planes diverge
* Interpolate between two planes in linear space
* @param {number[]} destination
* @param {number} destination_offset
* @param {number} a_normal_x
* @param {number} a_normal_y
* @param {number} a_normal_z
* @param {number} a_constant
* @param {number} b_normal_x
* @param {number} b_normal_y
* @param {number} b_normal_z
* @param {number} b_constant
* @param {number} t
*/
export function plane3_lerp_v0(
destination, destination_offset,
a_normal_x, a_normal_y, a_normal_z, a_constant,
b_normal_x, b_normal_y, b_normal_z, b_constant,
t
) {
const n_x = lerp(a_normal_x, b_normal_x, t);
const n_y = lerp(a_normal_y, b_normal_y, t);
const n_z = lerp(a_normal_z, b_normal_z, t);
const v_len_sqr = n_x * n_x + n_y * n_y + n_z * n_z;
const v_len = Math.sqrt(v_len_sqr);
const v_len_1 = 1 / v_len;
const nn_x = n_x * v_len_1;
const nn_y = n_y * v_len_1;
const nn_z = n_z * v_len_1;
const distance = lerp(a_constant, b_constant, t);
// write result
destination[destination_offset] = nn_x;
destination[destination_offset + 1] = nn_y;
destination[destination_offset + 2] = nn_z;
destination[destination_offset + 3] = distance;
}