72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Immutable;
|
|
using System.Numerics;
|
|
using MoonTools.Curve;
|
|
|
|
namespace KavTest
|
|
{
|
|
public static class RandomHelper
|
|
{
|
|
private static Random s_random = new Random();
|
|
|
|
public static double RandomDouble(double min, double max)
|
|
{
|
|
return (s_random.NextDouble() * (max - min)) + min;
|
|
}
|
|
|
|
public static float RandomFloat(float min, float max)
|
|
{
|
|
return (float)(RandomDouble(min, max));
|
|
}
|
|
|
|
public static int RandomInt(int min, int max)
|
|
{
|
|
return (int)(Math.Floor(RandomDouble(min, max)));
|
|
}
|
|
|
|
public static SplineCurve3D RandomLoop(Vector3 start, float minMotion, float maxMotion, float minTime, float maxTime)
|
|
{
|
|
var midpoint = start + RandomVector3(minMotion, maxMotion);
|
|
var controlPointTranslation = RandomVector3(minMotion, maxMotion);
|
|
|
|
var curveOne = new QuadraticBezierCurve3D(
|
|
start,
|
|
start + controlPointTranslation,
|
|
midpoint
|
|
);
|
|
var curveTwo = new QuadraticBezierCurve3D(
|
|
midpoint,
|
|
start - controlPointTranslation, // co-linear control points produce smooth curves
|
|
start
|
|
);
|
|
|
|
return new SplineCurve3D(
|
|
ImmutableArray.Create<ICurve3D>(
|
|
curveOne,
|
|
curveTwo
|
|
),
|
|
ImmutableArray.Create<float>(
|
|
RandomFloat(minTime, maxTime / 2),
|
|
RandomFloat(minTime, maxTime / 2)
|
|
),
|
|
true
|
|
);
|
|
}
|
|
|
|
public static Vector3 RandomVector3(float min, float max)
|
|
{
|
|
return new Vector3(
|
|
RandomFloat(min, max),
|
|
RandomFloat(min, max),
|
|
RandomFloat(min, max)
|
|
);
|
|
}
|
|
|
|
public static Microsoft.Xna.Framework.Color RandomColor()
|
|
{
|
|
var randomColor = RandomVector3(0f, 1f);
|
|
return new Microsoft.Xna.Framework.Color(randomColor.X, randomColor.Y, randomColor.Z);
|
|
}
|
|
}
|
|
}
|