forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateVec3.js
More file actions
36 lines (31 loc) · 1021 Bytes
/
RotateVec3.js
File metadata and controls
36 lines (31 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var Vector3 = require('../math/Vector3');
var Matrix4 = require('../math/Matrix4');
var Quaternion = require('../math/Quaternion');
var tmpMat4 = new Matrix4();
var tmpQuat = new Quaternion();
var tmpVec3 = new Vector3();
/**
* Rotates a vector in place by axis angle.
*
* This is the same as transforming a point by an
* axis-angle quaternion, but it has higher precision.
*
* @function Phaser.Math.RotateVec3
* @since 3.0.0
*
* @param {Phaser.Math.Vector3} vec - [description]
* @param {Phaser.Math.Vector3} axis - [description]
* @param {float} radians - [description]
*
* @return {Phaser.Math.Vector3} [description]
*/
var RotateVec3 = function (vec, axis, radians)
{
// Set the quaternion to our axis angle
tmpQuat.setAxisAngle(axis, radians);
// Create a rotation matrix from the axis angle
tmpMat4.fromRotationTranslation(tmpQuat, tmpVec3.set(0, 0, 0));
// Multiply our vector by the rotation matrix
return vec.transformMat4(tmpMat4);
};
module.exports = RotateVec3;