MCPcopy
hub / github.com/spritejs/spritejs / normalize

Function normalize

docs/demo/spritejs.js:5161–5176  ·  view source on GitHub ↗

* Normalize a vec3 * * @param {vec3} out the receiving vector * @param {ReadonlyVec3} a vector to normalize * @returns {vec3} out

(out, a)

Source from the content-addressed store, hash-verified

5159 */
5160
5161function normalize(out, a) {
5162 var x = a[0];
5163 var y = a[1];
5164 var z = a[2];
5165 var len = x * x + y * y + z * z;
5166
5167 if (len > 0) {
5168 //TODO: evaluate use of glm_invsqrt here?
5169 len = 1 / Math.sqrt(len);
5170 }
5171
5172 out[0] = a[0] * len;
5173 out[1] = a[1] * len;
5174 out[2] = a[2] * len;
5175 return out;
5176}
5177/**
5178 * Calculates the dot product of two vec3's
5179 *

Callers 3

spritejs.jsFile · 0.70
computeMiterFunction · 0.70
directionFunction · 0.70

Calls 3

squaredLengthFunction · 0.70
quadraticFunction · 0.70
lineFunction · 0.70

Tested by

no test coverage detected