MCPcopy Create free account
hub / github.com/microsoft/SandDance / lookAt

Function lookAt

docs/app/js/sanddance-app.js:73912–73976  ·  view source on GitHub ↗
(out, eye, center, up)

Source from the content-addressed store, hash-verified

73910 return out;
73911}
73912function lookAt(out, eye, center, up) {
73913 var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
73914 var eyex = eye[0];
73915 var eyey = eye[1];
73916 var eyez = eye[2];
73917 var upx = up[0];
73918 var upy = up[1];
73919 var upz = up[2];
73920 var centerx = center[0];
73921 var centery = center[1];
73922 var centerz = center[2];
73923 if (Math.abs(eyex - centerx) < _commonJs.EPSILON && Math.abs(eyey - centery) < _commonJs.EPSILON && Math.abs(eyez - centerz) < _commonJs.EPSILON) return identity(out);
73924 z0 = eyex - centerx;
73925 z1 = eyey - centery;
73926 z2 = eyez - centerz;
73927 len = 1 / Math.hypot(z0, z1, z2);
73928 z0 *= len;
73929 z1 *= len;
73930 z2 *= len;
73931 x0 = upy * z2 - upz * z1;
73932 x1 = upz * z0 - upx * z2;
73933 x2 = upx * z1 - upy * z0;
73934 len = Math.hypot(x0, x1, x2);
73935 if (!len) {
73936 x0 = 0;
73937 x1 = 0;
73938 x2 = 0;
73939 } else {
73940 len = 1 / len;
73941 x0 *= len;
73942 x1 *= len;
73943 x2 *= len;
73944 }
73945 y0 = z1 * x2 - z2 * x1;
73946 y1 = z2 * x0 - z0 * x2;
73947 y2 = z0 * x1 - z1 * x0;
73948 len = Math.hypot(y0, y1, y2);
73949 if (!len) {
73950 y0 = 0;
73951 y1 = 0;
73952 y2 = 0;
73953 } else {
73954 len = 1 / len;
73955 y0 *= len;
73956 y1 *= len;
73957 y2 *= len;
73958 }
73959 out[0] = x0;
73960 out[1] = y0;
73961 out[2] = z0;
73962 out[3] = 0;
73963 out[4] = x1;
73964 out[5] = y1;
73965 out[6] = z1;
73966 out[7] = 0;
73967 out[8] = x2;
73968 out[9] = y2;
73969 out[10] = z2;

Callers

nothing calls this directly

Calls 1

identityFunction · 0.70

Tested by

no test coverage detected