arcade-physics
Version:
Use Arcade Physics without Phaser.
42 lines • 1.65 kB
JavaScript
;
/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2020 Photon Storm Ltd.
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RotateVec3 = void 0;
const Vector3_js_1 = __importDefault(require("../math/Vector3.js"));
const Matrix4_js_1 = __importDefault(require("../math/Matrix4.js"));
const Quaternion_js_1 = __importDefault(require("../math/Quaternion.js"));
const tmpMat4 = new Matrix4_js_1.default();
const tmpQuat = new Quaternion_js_1.default();
const tmpVec3 = new Vector3_js_1.default();
/**
* 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 - The vector to be rotated.
* @param {Phaser.Math.Vector3} axis - The axis to rotate around.
* @param {number} radians - The angle of rotation in radians.
*
* @return {Phaser.Math.Vector3} The given vector.
*/
const RotateVec3 = (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);
};
exports.RotateVec3 = RotateVec3;
//# sourceMappingURL=RotateVec3.js.map