2018-02-12 16:01:20 +00:00
|
|
|
/**
|
|
|
|
* @author Richard Davey <rich@photonstorm.com>
|
2019-01-15 16:20:22 +00:00
|
|
|
* @copyright 2019 Photon Storm Ltd.
|
2019-05-10 15:15:04 +00:00
|
|
|
* @license {@link https://opensource.org/licenses/MIT|MIT License}
|
2018-02-12 16:01:20 +00:00
|
|
|
*/
|
|
|
|
|
2017-09-15 15:46:20 +00:00
|
|
|
var Vector3 = require('../math/Vector3');
|
|
|
|
var Matrix4 = require('../math/Matrix4');
|
|
|
|
var Quaternion = require('../math/Quaternion');
|
2017-09-15 03:04:51 +00:00
|
|
|
|
|
|
|
var tmpMat4 = new Matrix4();
|
|
|
|
var tmpQuat = new Quaternion();
|
|
|
|
var tmpVec3 = new Vector3();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rotates a vector in place by axis angle.
|
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* This is the same as transforming a point by an
|
2017-09-15 03:04:51 +00:00
|
|
|
* axis-angle quaternion, but it has higher precision.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
|
|
|
* @function Phaser.Math.RotateVec3
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @param {Phaser.Math.Vector3} vec - The vector to be rotated.
|
|
|
|
* @param {Phaser.Math.Vector3} axis - The axis to rotate around.
|
2018-06-21 17:13:46 +00:00
|
|
|
* @param {number} radians - The angle of rotation in radians.
|
2017-10-06 03:52:41 +00:00
|
|
|
*
|
2018-05-23 09:46:16 +00:00
|
|
|
* @return {Phaser.Math.Vector3} The given vector.
|
2017-09-15 03:04:51 +00:00
|
|
|
*/
|
2017-12-07 02:20:14 +00:00
|
|
|
var RotateVec3 = function (vec, axis, radians)
|
2017-09-16 01:31:33 +00:00
|
|
|
{
|
|
|
|
// Set the quaternion to our axis angle
|
2017-09-15 03:04:51 +00:00
|
|
|
tmpQuat.setAxisAngle(axis, radians);
|
|
|
|
|
2017-09-16 01:31:33 +00:00
|
|
|
// Create a rotation matrix from the axis angle
|
|
|
|
tmpMat4.fromRotationTranslation(tmpQuat, tmpVec3.set(0, 0, 0));
|
2017-09-15 03:04:51 +00:00
|
|
|
|
2017-09-16 01:31:33 +00:00
|
|
|
// Multiply our vector by the rotation matrix
|
|
|
|
return vec.transformMat4(tmpMat4);
|
2017-09-15 03:04:51 +00:00
|
|
|
};
|
|
|
|
|
2017-09-16 01:31:33 +00:00
|
|
|
module.exports = RotateVec3;
|