phaser/src/math/RandomXYZW.js
2018-06-26 23:19:14 +01:00

31 lines
906 B
JavaScript

/**
* @author Richard Davey <rich@photonstorm.com>
* @copyright 2018 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* Compute a random four-dimensional vector.
*
* @function Phaser.Math.RandomXYZW
* @since 3.0.0
*
* @param {Phaser.Math.Vector4} vec4 - The Vector to compute random values for.
* @param {number} [scale=1] - The scale of the random values.
*
* @return {Phaser.Math.Vector4} The given Vector.
*/
var RandomXYZW = function (vec4, scale)
{
if (scale === undefined) { scale = 1; }
// TODO: Not spherical; should fix this for more uniform distribution
vec4.x = (Math.random() * 2 - 1) * scale;
vec4.y = (Math.random() * 2 - 1) * scale;
vec4.z = (Math.random() * 2 - 1) * scale;
vec4.w = (Math.random() * 2 - 1) * scale;
return vec4;
};
module.exports = RandomXYZW;