Removed the Vector random methods and moved to their own function as they're swappable between each other

This commit is contained in:
Richard Davey 2017-09-18 21:48:26 +01:00
parent 44ab157523
commit 11aa39e29e
7 changed files with 47 additions and 41 deletions

13
v3/src/math/RandomXY.js Normal file
View file

@ -0,0 +1,13 @@
var RandomXY = function (vector, scale)
{
if (scale === undefined) { scale = 1; }
var r = Math.random() * 2 * Math.PI;
vector.x = Math.cos(r) * scale;
vector.y = Math.sin(r) * scale;
return vector;
};
module.exports = RandomXY;

17
v3/src/math/RandomXYZ.js Normal file
View file

@ -0,0 +1,17 @@
// Position Vector randomly in a spherical area defined by the given radius
var RandomXYZ = function (vector, radius)
{
if (radius === undefined) { radius = 1; }
var r = Math.random() * 2 * Math.PI;
var z = (Math.random() * 2) - 1;
var zScale = Math.sqrt(1 - z * z) * radius;
vector.x = Math.cos(r) * zScale;
vector.y = Math.sin(r) * zScale;
vector.z = z * radius;
return vector;
};
module.exports = RandomXYZ;

14
v3/src/math/RandomXYZW.js Normal file
View file

@ -0,0 +1,14 @@
var RandomXYZW = function (vector, scale)
{
if (scale === undefined) { scale = 1; }
// Not spherical; should fix this for more uniform distribution
vector.x = (Math.random() * 2 - 1) * scale;
vector.y = (Math.random() * 2 - 1) * scale;
vector.z = (Math.random() * 2 - 1) * scale;
vector.w = (Math.random() * 2 - 1) * scale;
return vector;
};
module.exports = RandomXYZW;

View file

@ -198,18 +198,6 @@ var Vector2 = new Class({
this.x = 0;
this.y = 0;
return this;
},
random: function (scale)
{
if (scale === undefined) { scale = 1; }
var r = Math.random() * 2 * Math.PI;
this.x = Math.cos(r) * scale;
this.y = Math.sin(r) * scale;
return this;
}

View file

@ -327,22 +327,6 @@ var Vector3 = new Class({
return this.project(invProjectionView);
},
// Position Vector randomly in a spherical area defined by the given radius
random: function (radius)
{
if (radius === undefined) { radius = 1; }
var r = Math.random() * 2 * Math.PI;
var z = (Math.random() * 2) - 1;
var zScale = Math.sqrt(1 - z * z) * radius;
this.x = Math.cos(r) * zScale;
this.y = Math.sin(r) * zScale;
this.z = z * radius;
return this;
},
reset: function ()
{
this.x = 0;

View file

@ -246,19 +246,6 @@ var Vector4 = new Class({
return this;
},
random: function (scale)
{
if (scale === undefined) { scale = 1; }
// Not spherical; should fix this for more uniform distribution
this.x = (Math.random() * 2 - 1) * scale;
this.y = (Math.random() * 2 - 1) * scale;
this.z = (Math.random() * 2 - 1) * scale;
this.w = (Math.random() * 2 - 1) * scale;
return this;
},
reset: function ()
{
this.x = 0;

View file

@ -29,6 +29,9 @@ module.exports = {
MinSub: require('./MinSub'),
Percent: require('./Percent'),
RadToDeg: require('./RadToDeg'),
RandomXY: require('./RandomXY'),
RandomXYZ: require('./RandomXYZ'),
RandomXYZW: require('./RandomXYZW'),
Rotate: require('./Rotate'),
RotateAround: require('./RotateAround'),
RotateAroundDistance: require('./RotateAroundDistance'),