Skip to content

Instantly share code, notes, and snippets.

View MrTelanie's full-sized avatar

Stefan Eckert MrTelanie

  • Sport Alliance
  • Hamburg Germany
View GitHub Profile
@MrTelanie
MrTelanie / gist:a5828d06f4bdbcf3007f2aea89af9556
Created February 23, 2019 12:50
Operator Handler for Arrays
proposal or How I could use it:
// hijack valeOf & toString of Array.prototype
// create vector by numbers
const pos = [5, 6, 7];
const dir = [1, 0, 0];
console.log(debug`pos:${pos}, dir: ${dir}`);
// pos: { x: 5, y: 6, z: 7 } dir: { x: 1, y: 0, z: 0 }
/**
* https://github.com/jMonkeyEngine/jmonkeyengine/blob/d57c362ec3b510c1ba6356f719efa3b1576b95c6/jme3-core/src/main/java/com/jme3/math/Transform.java#L237
*/
transformVector(in, store){
// multiply with scale first, then rotate, finally translate (cf.
// Eberly)
return rot.mult(store.set(in).multLocal(scale), store).addLocal(translation);
}
2D 3D Mutable Immutable
Vector
Victor
IVector
Point
IPoint
(function () {
const packs = new Map();
let currentPack;
function dynamicImport(path) {
let pack = packs.get(path);
if (!pack) {
let load;
const prom = new Promise((resolve) => load = resolve);
pack = { path, load, prom };
@MrTelanie
MrTelanie / formula.js
Created August 18, 2019 10:38
reverse a function
const REV_FORM = Symbol("reverse-formula");
const SCALE = 10;
function createReverseFormula(formula) {
const list = new Array(SCALE + 1).fill(0).map((_, i) => {
const inp = i / SCALE;
const out = formula(inp);
return { inp, out };
});
/* original */
export function fromOrientation({ alpha, beta, gamma }, orientation) {
let rot = iquaternion(UP, degree(alpha))
.mul(RIGHT, degree(beta))
.mul(FORWARD, degree(gamma))
.mul(LEFT90);
rot = iquaternion(rot.dir, degree(orientation))
.mul(rot);
const ORG_SHARED = Symbol('org shared');
const checkOrg = (array, one) => {
if (one instanceof SharedArrayBuffer) {
array[ORG_SHARED] = one;
}
};
class MyInt8Array extends Int8Array {
constructor(one, two, three) {
@MrTelanie
MrTelanie / get.glsl
Created November 8, 2020 16:06
glsl: dynamic index expression (and branchless)
/**
* vec[index] throws an error:
* '[]' : Index expression must be constant
* get(vec, index) works fine
* branchless implementation
**/
float get(vec2 vec, int index) {
vec2 mult = vec2(float(index == 0), float(index == 1));
vec2 bet = mult * vec;