A while ago i wrote my own vector library with support for arithmetic operator overloading.
But i intensively use playcanvas and didn’t want to mix multiple vector types.
So i have made an adapter combining playcanvas vec2 and vec3 with my Operator class.
I provide a new function on pc
object called calc
, with that you can make real arithmetic operations.
const pos = pc.vec3(5, 6, 7);
const dir = pc.vec3(1, 0, 0);
// pos: { x: 5, y: 6, z: 7 } dir: { x: 1, y: 0, z: 0 }
const offsetA = pc.calc(() => dir * 30 + pos);
// offsetA: { x: 35, y: 6, z: 7 }
Here is a small documentation how it can be used.
I hope you enjoy :).