UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

38 lines (32 loc) 890 B
/** * * @param {function} random * @param {number[]} result * @param {number} result_offset */ export function randomPointOnBox(random, result, result_offset) { //pick a side const side = random(); //determine axis of the side const axis = side % 0.5; //convert side and axis to a fixed value for the axis const fixedAxis = side > 0.5 ? -0.5 : 0.5; let x, y, z; if (axis < 0.16666666666) { x = fixedAxis; y = random() - 0.5; z = random() - 0.5; } else if (axis < 0.33333333333) { x = random() - 0.5; y = fixedAxis; z = random() - 0.5; } else { x = random() - 0.5; y = random() - 0.5; z = fixedAxis; } //write the result result[result_offset] = x; result[result_offset + 1] = y; result[result_offset + 2] = z; }