mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 03:05:42 +00:00
Skip DegreesToRadians by generating value from 0-2pi
This commit is contained in:
parent
b4f09e0a94
commit
22deba8428
@ -1,4 +1,4 @@
|
||||
using System.Numerics;
|
||||
using System.Numerics;
|
||||
|
||||
namespace X10D.Numerics;
|
||||
|
||||
@ -57,7 +57,7 @@ public static class RandomExtensions
|
||||
y = seededRandom.NextSingle(-1f, 1f);
|
||||
z = seededRandom.NextSingle(-1f, 1f);
|
||||
normal = (w * w) + (x * x) + (y * y) + (z * z);
|
||||
} while (normal > 1f || normal == 0f);
|
||||
} while (normal is 0f or > 1f);
|
||||
|
||||
normal = MathF.Sqrt(normal);
|
||||
return new Quaternion(x / normal, y / normal, z / normal, w / normal);
|
||||
@ -77,11 +77,10 @@ public static class RandomExtensions
|
||||
{
|
||||
throw new ArgumentNullException(nameof(random));
|
||||
}
|
||||
|
||||
// no need to construct a seeded random here, since we only call Next once
|
||||
|
||||
int seed = random.Next();
|
||||
var seededRandom = new Random(seed);
|
||||
|
||||
float angle = seededRandom.NextSingle(0, 360).DegreesToRadians();
|
||||
float angle = random.NextSingle(0, MathF.PI * 2.0f);
|
||||
float x = MathF.Cos(angle);
|
||||
float y = MathF.Sin(angle);
|
||||
|
||||
@ -106,7 +105,7 @@ public static class RandomExtensions
|
||||
int seed = random.Next();
|
||||
var seededRandom = new Random(seed);
|
||||
|
||||
float angle = seededRandom.NextSingle(0, 360).DegreesToRadians();
|
||||
float angle = seededRandom.NextSingle(0, MathF.PI * 2.0f);
|
||||
float z = seededRandom.NextSingle(-1, 1);
|
||||
float mp = MathF.Sqrt(1 - (z * z));
|
||||
float x = mp * MathF.Cos(angle);
|
||||
|
Loading…
Reference in New Issue
Block a user