|
keys = {u:0, l:0, r:0, d:0};
W.camera({z:2});
W.light({z:-.5});
W.cube({n:"cube", b:"5af"});
t = new DOMMatrix();
onmousedown = e => keys[e.target.id] = 1;
onmouseup = e => keys[e.target.id] = 0;
setInterval(()=>{
let axis = new DOMPoint(
rx = keys.d - keys.u,
ry = keys.r - keys.l,
0
);
let newAxis = axis.matrixTransform((new DOMMatrix(t)).invertSelf());
t.rotateAxisAngleSelf(
newAxis.x, newAxis.y, newAxis.z, Math.hypot(rx, ry) * 2
);
W.move({n:"cube", M: t});
}, 16);
|