@thi.ng/matrices
Version:
Matrix & quaternion operations for 2D/3D geometry processing
33 lines (32 loc) • 663 B
JavaScript
import { cross3 } from "@thi.ng/vectors/cross";
import { dot3 } from "@thi.ng/vectors/dot";
import { normalize3 } from "@thi.ng/vectors/normalize";
import { setC } from "@thi.ng/vectors/setc";
import { sub3 } from "@thi.ng/vectors/sub";
const lookAt = (out, eye, target, up) => {
const z = normalize3(null, sub3([], eye, target));
const x = normalize3(null, cross3([], up, z));
const y = normalize3(null, cross3([], z, x));
return setC(
out || [],
x[0],
y[0],
z[0],
0,
x[1],
y[1],
z[1],
0,
x[2],
y[2],
z[2],
0,
-dot3(eye, x),
-dot3(eye, y),
-dot3(eye, z),
1
);
};
export {
lookAt
};