nightshade-api 0.53.0

Procedural high level API for the nightshade game engine
Documentation
// Composite vector helpers on plain [x, y, z] arrays, on top of the global vec
// ops the engine registers (dot, cross, normalize, distance, ...). Import with:
// import "std/vec" as vec; then call vec::reflect(v, n), vec::midpoint(a, b).
fn midpoint(a, b) {
    [(a[0] + b[0]) * 0.5, (a[1] + b[1]) * 0.5, (a[2] + b[2]) * 0.5]
}

// Reflects v about the plane with unit normal n.
fn reflect(v, n) {
    let d = v[0] * n[0] + v[1] * n[1] + v[2] * n[2];
    [v[0] - 2.0 * d * n[0], v[1] - 2.0 * d * n[1], v[2] - 2.0 * d * n[2]]
}

// Projects v onto the vector onto.
fn project(v, onto) {
    let d = v[0] * onto[0] + v[1] * onto[1] + v[2] * onto[2];
    let len_sq = onto[0] * onto[0] + onto[1] * onto[1] + onto[2] * onto[2];
    if len_sq < 0.000001 {
        [0.0, 0.0, 0.0]
    } else {
        let s = d / len_sq;
        [onto[0] * s, onto[1] * s, onto[2] * s]
    }
}