quat.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.setAxes = exports.sqlerp = exports.rotationTo = exports.equals = exports.exactEquals = exports.normalize = exports.sqrLen = exports.squaredLength = exports.len = exports.length = exports.lerp = exports.dot = exports.scale = exports.mul = exports.add = exports.set = exports.copy = exports.fromValues = exports.clone = undefined;
  6. exports.create = create;
  7. exports.identity = identity;
  8. exports.setAxisAngle = setAxisAngle;
  9. exports.getAxisAngle = getAxisAngle;
  10. exports.multiply = multiply;
  11. exports.rotateX = rotateX;
  12. exports.rotateY = rotateY;
  13. exports.rotateZ = rotateZ;
  14. exports.calculateW = calculateW;
  15. exports.slerp = slerp;
  16. exports.random = random;
  17. exports.invert = invert;
  18. exports.conjugate = conjugate;
  19. exports.fromMat3 = fromMat3;
  20. exports.fromEuler = fromEuler;
  21. exports.str = str;
  22. var _common = require("./common.js");
  23. var glMatrix = _interopRequireWildcard(_common);
  24. var _mat = require("./mat3.js");
  25. var mat3 = _interopRequireWildcard(_mat);
  26. var _vec = require("./vec3.js");
  27. var vec3 = _interopRequireWildcard(_vec);
  28. var _vec2 = require("./vec4.js");
  29. var vec4 = _interopRequireWildcard(_vec2);
  30. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  31. /**
  32. * Quaternion
  33. * @module quat
  34. */
  35. /**
  36. * Creates a new identity quat
  37. *
  38. * @returns {quat} a new quaternion
  39. */
  40. function create() {
  41. var out = new glMatrix.ARRAY_TYPE(4);
  42. if (glMatrix.ARRAY_TYPE != Float32Array) {
  43. out[0] = 0;
  44. out[1] = 0;
  45. out[2] = 0;
  46. }
  47. out[3] = 1;
  48. return out;
  49. }
  50. /**
  51. * Set a quat to the identity quaternion
  52. *
  53. * @param {quat} out the receiving quaternion
  54. * @returns {quat} out
  55. */
  56. function identity(out) {
  57. out[0] = 0;
  58. out[1] = 0;
  59. out[2] = 0;
  60. out[3] = 1;
  61. return out;
  62. }
  63. /**
  64. * Sets a quat from the given angle and rotation axis,
  65. * then returns it.
  66. *
  67. * @param {quat} out the receiving quaternion
  68. * @param {vec3} axis the axis around which to rotate
  69. * @param {Number} rad the angle in radians
  70. * @returns {quat} out
  71. **/
  72. function setAxisAngle(out, axis, rad) {
  73. rad = rad * 0.5;
  74. var s = Math.sin(rad);
  75. out[0] = s * axis[0];
  76. out[1] = s * axis[1];
  77. out[2] = s * axis[2];
  78. out[3] = Math.cos(rad);
  79. return out;
  80. }
  81. /**
  82. * Gets the rotation axis and angle for a given
  83. * quaternion. If a quaternion is created with
  84. * setAxisAngle, this method will return the same
  85. * values as providied in the original parameter list
  86. * OR functionally equivalent values.
  87. * Example: The quaternion formed by axis [0, 0, 1] and
  88. * angle -90 is the same as the quaternion formed by
  89. * [0, 0, 1] and 270. This method favors the latter.
  90. * @param {vec3} out_axis Vector receiving the axis of rotation
  91. * @param {quat} q Quaternion to be decomposed
  92. * @return {Number} Angle, in radians, of the rotation
  93. */
  94. function getAxisAngle(out_axis, q) {
  95. var rad = Math.acos(q[3]) * 2.0;
  96. var s = Math.sin(rad / 2.0);
  97. if (s > glMatrix.EPSILON) {
  98. out_axis[0] = q[0] / s;
  99. out_axis[1] = q[1] / s;
  100. out_axis[2] = q[2] / s;
  101. } else {
  102. // If s is zero, return any axis (no rotation - axis does not matter)
  103. out_axis[0] = 1;
  104. out_axis[1] = 0;
  105. out_axis[2] = 0;
  106. }
  107. return rad;
  108. }
  109. /**
  110. * Multiplies two quat's
  111. *
  112. * @param {quat} out the receiving quaternion
  113. * @param {quat} a the first operand
  114. * @param {quat} b the second operand
  115. * @returns {quat} out
  116. */
  117. function multiply(out, a, b) {
  118. var ax = a[0],
  119. ay = a[1],
  120. az = a[2],
  121. aw = a[3];
  122. var bx = b[0],
  123. by = b[1],
  124. bz = b[2],
  125. bw = b[3];
  126. out[0] = ax * bw + aw * bx + ay * bz - az * by;
  127. out[1] = ay * bw + aw * by + az * bx - ax * bz;
  128. out[2] = az * bw + aw * bz + ax * by - ay * bx;
  129. out[3] = aw * bw - ax * bx - ay * by - az * bz;
  130. return out;
  131. }
  132. /**
  133. * Rotates a quaternion by the given angle about the X axis
  134. *
  135. * @param {quat} out quat receiving operation result
  136. * @param {quat} a quat to rotate
  137. * @param {number} rad angle (in radians) to rotate
  138. * @returns {quat} out
  139. */
  140. function rotateX(out, a, rad) {
  141. rad *= 0.5;
  142. var ax = a[0],
  143. ay = a[1],
  144. az = a[2],
  145. aw = a[3];
  146. var bx = Math.sin(rad),
  147. bw = Math.cos(rad);
  148. out[0] = ax * bw + aw * bx;
  149. out[1] = ay * bw + az * bx;
  150. out[2] = az * bw - ay * bx;
  151. out[3] = aw * bw - ax * bx;
  152. return out;
  153. }
  154. /**
  155. * Rotates a quaternion by the given angle about the Y axis
  156. *
  157. * @param {quat} out quat receiving operation result
  158. * @param {quat} a quat to rotate
  159. * @param {number} rad angle (in radians) to rotate
  160. * @returns {quat} out
  161. */
  162. function rotateY(out, a, rad) {
  163. rad *= 0.5;
  164. var ax = a[0],
  165. ay = a[1],
  166. az = a[2],
  167. aw = a[3];
  168. var by = Math.sin(rad),
  169. bw = Math.cos(rad);
  170. out[0] = ax * bw - az * by;
  171. out[1] = ay * bw + aw * by;
  172. out[2] = az * bw + ax * by;
  173. out[3] = aw * bw - ay * by;
  174. return out;
  175. }
  176. /**
  177. * Rotates a quaternion by the given angle about the Z axis
  178. *
  179. * @param {quat} out quat receiving operation result
  180. * @param {quat} a quat to rotate
  181. * @param {number} rad angle (in radians) to rotate
  182. * @returns {quat} out
  183. */
  184. function rotateZ(out, a, rad) {
  185. rad *= 0.5;
  186. var ax = a[0],
  187. ay = a[1],
  188. az = a[2],
  189. aw = a[3];
  190. var bz = Math.sin(rad),
  191. bw = Math.cos(rad);
  192. out[0] = ax * bw + ay * bz;
  193. out[1] = ay * bw - ax * bz;
  194. out[2] = az * bw + aw * bz;
  195. out[3] = aw * bw - az * bz;
  196. return out;
  197. }
  198. /**
  199. * Calculates the W component of a quat from the X, Y, and Z components.
  200. * Assumes that quaternion is 1 unit in length.
  201. * Any existing W component will be ignored.
  202. *
  203. * @param {quat} out the receiving quaternion
  204. * @param {quat} a quat to calculate W component of
  205. * @returns {quat} out
  206. */
  207. function calculateW(out, a) {
  208. var x = a[0],
  209. y = a[1],
  210. z = a[2];
  211. out[0] = x;
  212. out[1] = y;
  213. out[2] = z;
  214. out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
  215. return out;
  216. }
  217. /**
  218. * Performs a spherical linear interpolation between two quat
  219. *
  220. * @param {quat} out the receiving quaternion
  221. * @param {quat} a the first operand
  222. * @param {quat} b the second operand
  223. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  224. * @returns {quat} out
  225. */
  226. function slerp(out, a, b, t) {
  227. // benchmarks:
  228. // http://jsperf.com/quaternion-slerp-implementations
  229. var ax = a[0],
  230. ay = a[1],
  231. az = a[2],
  232. aw = a[3];
  233. var bx = b[0],
  234. by = b[1],
  235. bz = b[2],
  236. bw = b[3];
  237. var omega = void 0,
  238. cosom = void 0,
  239. sinom = void 0,
  240. scale0 = void 0,
  241. scale1 = void 0;
  242. // calc cosine
  243. cosom = ax * bx + ay * by + az * bz + aw * bw;
  244. // adjust signs (if necessary)
  245. if (cosom < 0.0) {
  246. cosom = -cosom;
  247. bx = -bx;
  248. by = -by;
  249. bz = -bz;
  250. bw = -bw;
  251. }
  252. // calculate coefficients
  253. if (1.0 - cosom > glMatrix.EPSILON) {
  254. // standard case (slerp)
  255. omega = Math.acos(cosom);
  256. sinom = Math.sin(omega);
  257. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  258. scale1 = Math.sin(t * omega) / sinom;
  259. } else {
  260. // "from" and "to" quaternions are very close
  261. // ... so we can do a linear interpolation
  262. scale0 = 1.0 - t;
  263. scale1 = t;
  264. }
  265. // calculate final values
  266. out[0] = scale0 * ax + scale1 * bx;
  267. out[1] = scale0 * ay + scale1 * by;
  268. out[2] = scale0 * az + scale1 * bz;
  269. out[3] = scale0 * aw + scale1 * bw;
  270. return out;
  271. }
  272. /**
  273. * Generates a random quaternion
  274. *
  275. * @param {quat} out the receiving quaternion
  276. * @returns {quat} out
  277. */
  278. function random(out) {
  279. // Implementation of http://planning.cs.uiuc.edu/node198.html
  280. // TODO: Calling random 3 times is probably not the fastest solution
  281. var u1 = glMatrix.RANDOM();
  282. var u2 = glMatrix.RANDOM();
  283. var u3 = glMatrix.RANDOM();
  284. var sqrt1MinusU1 = Math.sqrt(1 - u1);
  285. var sqrtU1 = Math.sqrt(u1);
  286. out[0] = sqrt1MinusU1 * Math.sin(2.0 * Math.PI * u2);
  287. out[1] = sqrt1MinusU1 * Math.cos(2.0 * Math.PI * u2);
  288. out[2] = sqrtU1 * Math.sin(2.0 * Math.PI * u3);
  289. out[3] = sqrtU1 * Math.cos(2.0 * Math.PI * u3);
  290. return out;
  291. }
  292. /**
  293. * Calculates the inverse of a quat
  294. *
  295. * @param {quat} out the receiving quaternion
  296. * @param {quat} a quat to calculate inverse of
  297. * @returns {quat} out
  298. */
  299. function invert(out, a) {
  300. var a0 = a[0],
  301. a1 = a[1],
  302. a2 = a[2],
  303. a3 = a[3];
  304. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  305. var invDot = dot ? 1.0 / dot : 0;
  306. // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  307. out[0] = -a0 * invDot;
  308. out[1] = -a1 * invDot;
  309. out[2] = -a2 * invDot;
  310. out[3] = a3 * invDot;
  311. return out;
  312. }
  313. /**
  314. * Calculates the conjugate of a quat
  315. * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
  316. *
  317. * @param {quat} out the receiving quaternion
  318. * @param {quat} a quat to calculate conjugate of
  319. * @returns {quat} out
  320. */
  321. function conjugate(out, a) {
  322. out[0] = -a[0];
  323. out[1] = -a[1];
  324. out[2] = -a[2];
  325. out[3] = a[3];
  326. return out;
  327. }
  328. /**
  329. * Creates a quaternion from the given 3x3 rotation matrix.
  330. *
  331. * NOTE: The resultant quaternion is not normalized, so you should be sure
  332. * to renormalize the quaternion yourself where necessary.
  333. *
  334. * @param {quat} out the receiving quaternion
  335. * @param {mat3} m rotation matrix
  336. * @returns {quat} out
  337. * @function
  338. */
  339. function fromMat3(out, m) {
  340. // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  341. // article "Quaternion Calculus and Fast Animation".
  342. var fTrace = m[0] + m[4] + m[8];
  343. var fRoot = void 0;
  344. if (fTrace > 0.0) {
  345. // |w| > 1/2, may as well choose w > 1/2
  346. fRoot = Math.sqrt(fTrace + 1.0); // 2w
  347. out[3] = 0.5 * fRoot;
  348. fRoot = 0.5 / fRoot; // 1/(4w)
  349. out[0] = (m[5] - m[7]) * fRoot;
  350. out[1] = (m[6] - m[2]) * fRoot;
  351. out[2] = (m[1] - m[3]) * fRoot;
  352. } else {
  353. // |w| <= 1/2
  354. var i = 0;
  355. if (m[4] > m[0]) i = 1;
  356. if (m[8] > m[i * 3 + i]) i = 2;
  357. var j = (i + 1) % 3;
  358. var k = (i + 2) % 3;
  359. fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
  360. out[i] = 0.5 * fRoot;
  361. fRoot = 0.5 / fRoot;
  362. out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
  363. out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
  364. out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
  365. }
  366. return out;
  367. }
  368. /**
  369. * Creates a quaternion from the given euler angle x, y, z.
  370. *
  371. * @param {quat} out the receiving quaternion
  372. * @param {x} Angle to rotate around X axis in degrees.
  373. * @param {y} Angle to rotate around Y axis in degrees.
  374. * @param {z} Angle to rotate around Z axis in degrees.
  375. * @returns {quat} out
  376. * @function
  377. */
  378. function fromEuler(out, x, y, z) {
  379. var halfToRad = 0.5 * Math.PI / 180.0;
  380. x *= halfToRad;
  381. y *= halfToRad;
  382. z *= halfToRad;
  383. var sx = Math.sin(x);
  384. var cx = Math.cos(x);
  385. var sy = Math.sin(y);
  386. var cy = Math.cos(y);
  387. var sz = Math.sin(z);
  388. var cz = Math.cos(z);
  389. out[0] = sx * cy * cz - cx * sy * sz;
  390. out[1] = cx * sy * cz + sx * cy * sz;
  391. out[2] = cx * cy * sz - sx * sy * cz;
  392. out[3] = cx * cy * cz + sx * sy * sz;
  393. return out;
  394. }
  395. /**
  396. * Returns a string representation of a quatenion
  397. *
  398. * @param {quat} a vector to represent as a string
  399. * @returns {String} string representation of the vector
  400. */
  401. function str(a) {
  402. return 'quat(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ')';
  403. }
  404. /**
  405. * Creates a new quat initialized with values from an existing quaternion
  406. *
  407. * @param {quat} a quaternion to clone
  408. * @returns {quat} a new quaternion
  409. * @function
  410. */
  411. var clone = exports.clone = vec4.clone;
  412. /**
  413. * Creates a new quat initialized with the given values
  414. *
  415. * @param {Number} x X component
  416. * @param {Number} y Y component
  417. * @param {Number} z Z component
  418. * @param {Number} w W component
  419. * @returns {quat} a new quaternion
  420. * @function
  421. */
  422. var fromValues = exports.fromValues = vec4.fromValues;
  423. /**
  424. * Copy the values from one quat to another
  425. *
  426. * @param {quat} out the receiving quaternion
  427. * @param {quat} a the source quaternion
  428. * @returns {quat} out
  429. * @function
  430. */
  431. var copy = exports.copy = vec4.copy;
  432. /**
  433. * Set the components of a quat to the given values
  434. *
  435. * @param {quat} out the receiving quaternion
  436. * @param {Number} x X component
  437. * @param {Number} y Y component
  438. * @param {Number} z Z component
  439. * @param {Number} w W component
  440. * @returns {quat} out
  441. * @function
  442. */
  443. var set = exports.set = vec4.set;
  444. /**
  445. * Adds two quat's
  446. *
  447. * @param {quat} out the receiving quaternion
  448. * @param {quat} a the first operand
  449. * @param {quat} b the second operand
  450. * @returns {quat} out
  451. * @function
  452. */
  453. var add = exports.add = vec4.add;
  454. /**
  455. * Alias for {@link quat.multiply}
  456. * @function
  457. */
  458. var mul = exports.mul = multiply;
  459. /**
  460. * Scales a quat by a scalar number
  461. *
  462. * @param {quat} out the receiving vector
  463. * @param {quat} a the vector to scale
  464. * @param {Number} b amount to scale the vector by
  465. * @returns {quat} out
  466. * @function
  467. */
  468. var scale = exports.scale = vec4.scale;
  469. /**
  470. * Calculates the dot product of two quat's
  471. *
  472. * @param {quat} a the first operand
  473. * @param {quat} b the second operand
  474. * @returns {Number} dot product of a and b
  475. * @function
  476. */
  477. var dot = exports.dot = vec4.dot;
  478. /**
  479. * Performs a linear interpolation between two quat's
  480. *
  481. * @param {quat} out the receiving quaternion
  482. * @param {quat} a the first operand
  483. * @param {quat} b the second operand
  484. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  485. * @returns {quat} out
  486. * @function
  487. */
  488. var lerp = exports.lerp = vec4.lerp;
  489. /**
  490. * Calculates the length of a quat
  491. *
  492. * @param {quat} a vector to calculate length of
  493. * @returns {Number} length of a
  494. */
  495. var length = exports.length = vec4.length;
  496. /**
  497. * Alias for {@link quat.length}
  498. * @function
  499. */
  500. var len = exports.len = length;
  501. /**
  502. * Calculates the squared length of a quat
  503. *
  504. * @param {quat} a vector to calculate squared length of
  505. * @returns {Number} squared length of a
  506. * @function
  507. */
  508. var squaredLength = exports.squaredLength = vec4.squaredLength;
  509. /**
  510. * Alias for {@link quat.squaredLength}
  511. * @function
  512. */
  513. var sqrLen = exports.sqrLen = squaredLength;
  514. /**
  515. * Normalize a quat
  516. *
  517. * @param {quat} out the receiving quaternion
  518. * @param {quat} a quaternion to normalize
  519. * @returns {quat} out
  520. * @function
  521. */
  522. var normalize = exports.normalize = vec4.normalize;
  523. /**
  524. * Returns whether or not the quaternions have exactly the same elements in the same position (when compared with ===)
  525. *
  526. * @param {quat} a The first quaternion.
  527. * @param {quat} b The second quaternion.
  528. * @returns {Boolean} True if the vectors are equal, false otherwise.
  529. */
  530. var exactEquals = exports.exactEquals = vec4.exactEquals;
  531. /**
  532. * Returns whether or not the quaternions have approximately the same elements in the same position.
  533. *
  534. * @param {quat} a The first vector.
  535. * @param {quat} b The second vector.
  536. * @returns {Boolean} True if the vectors are equal, false otherwise.
  537. */
  538. var equals = exports.equals = vec4.equals;
  539. /**
  540. * Sets a quaternion to represent the shortest rotation from one
  541. * vector to another.
  542. *
  543. * Both vectors are assumed to be unit length.
  544. *
  545. * @param {quat} out the receiving quaternion.
  546. * @param {vec3} a the initial vector
  547. * @param {vec3} b the destination vector
  548. * @returns {quat} out
  549. */
  550. var rotationTo = exports.rotationTo = function () {
  551. var tmpvec3 = vec3.create();
  552. var xUnitVec3 = vec3.fromValues(1, 0, 0);
  553. var yUnitVec3 = vec3.fromValues(0, 1, 0);
  554. return function (out, a, b) {
  555. var dot = vec3.dot(a, b);
  556. if (dot < -0.999999) {
  557. vec3.cross(tmpvec3, xUnitVec3, a);
  558. if (vec3.len(tmpvec3) < 0.000001) vec3.cross(tmpvec3, yUnitVec3, a);
  559. vec3.normalize(tmpvec3, tmpvec3);
  560. setAxisAngle(out, tmpvec3, Math.PI);
  561. return out;
  562. } else if (dot > 0.999999) {
  563. out[0] = 0;
  564. out[1] = 0;
  565. out[2] = 0;
  566. out[3] = 1;
  567. return out;
  568. } else {
  569. vec3.cross(tmpvec3, a, b);
  570. out[0] = tmpvec3[0];
  571. out[1] = tmpvec3[1];
  572. out[2] = tmpvec3[2];
  573. out[3] = 1 + dot;
  574. return normalize(out, out);
  575. }
  576. };
  577. }();
  578. /**
  579. * Performs a spherical linear interpolation with two control points
  580. *
  581. * @param {quat} out the receiving quaternion
  582. * @param {quat} a the first operand
  583. * @param {quat} b the second operand
  584. * @param {quat} c the third operand
  585. * @param {quat} d the fourth operand
  586. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  587. * @returns {quat} out
  588. */
  589. var sqlerp = exports.sqlerp = function () {
  590. var temp1 = create();
  591. var temp2 = create();
  592. return function (out, a, b, c, d, t) {
  593. slerp(temp1, a, d, t);
  594. slerp(temp2, b, c, t);
  595. slerp(out, temp1, temp2, 2 * t * (1 - t));
  596. return out;
  597. };
  598. }();
  599. /**
  600. * Sets the specified quaternion with values corresponding to the given
  601. * axes. Each axis is a vec3 and is expected to be unit length and
  602. * perpendicular to all other specified axes.
  603. *
  604. * @param {vec3} view the vector representing the viewing direction
  605. * @param {vec3} right the vector representing the local "right" direction
  606. * @param {vec3} up the vector representing the local "up" direction
  607. * @returns {quat} out
  608. */
  609. var setAxes = exports.setAxes = function () {
  610. var matr = mat3.create();
  611. return function (out, view, right, up) {
  612. matr[0] = right[0];
  613. matr[3] = right[1];
  614. matr[6] = right[2];
  615. matr[1] = up[0];
  616. matr[4] = up[1];
  617. matr[7] = up[2];
  618. matr[2] = -view[0];
  619. matr[5] = -view[1];
  620. matr[8] = -view[2];
  621. return normalize(out, fromMat3(out, matr));
  622. };
  623. }();