#region File Description
//-----------------------------------------------------------------------------
// HelperMath.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
#endregion
namespace RobotGameData.Helper
{
///
/// Useful functions about math
///
public static class HelperMath
{
#region Fields
public static Random Random = new Random();
public const float Epsilon = 1E-5f; //for numerical imprecision
#endregion
///
/// Return a random integer.
///
/// Random integer
public static int Randomi()
{
return Random.Next();
}
///
/// It specifies the maximum value and returns a random integer.
///
/// Max integer
/// Random integer
public static int Randomi(int max)
{
return Random.Next(max);
}
///
/// It specifies the maximum and the minimum and returns a random integer.
///
/// Min integer
/// Max integer
/// Random integer
public static int Randomi(int min, int max)
{
return Random.Next(min, max);
}
///
/// Return a random floating point between 0.0 to 1.0
///
/// Random floating point
public static float RandomNormal()
{
// randomed 0.0 to 1.0
return (float)Random.NextDouble();
}
///
/// Return a random floating point between -1.0 to 1.0
///
/// Random floating point
public static float RandomNormal2()
{
// randomed -1.0 to 1.0
return (float)Random.Next(-1, 2) * (float)Random.NextDouble();
}
///
/// Return a randomed vector3 between 0.0 to 1.0
///
public static Vector3 RandomVector()
{
return new Vector3(RandomNormal(), RandomNormal(), RandomNormal());
}
///
/// Return a randomed vector3 between -1.0 to 1.0
///
public static Vector3 RandomVector2()
{
return new Vector3(RandomNormal2(), RandomNormal2(), RandomNormal2());
}
///
/// It calculates the remainder of the division of value1 by value2.
///
/// value 1
/// value 2
///
public static float CalculateModulo(float value1, float value2)
{
while (value1 - value2 >= 0)
{
value1 -= value2;
}
return value1;
}
///
/// Vector value change to integer, and reduce 0.5 coordinate
///
public static Vector3 Make2DCoord(Vector3 vec)
{
int x = (int)vec.X;
int y = (int)vec.Y;
int z = (int)vec.Z;
return new Vector3((float)x - 0.5f,
(float)y - 0.5f,
(float)z - 0.5f);
}
///
/// Vector value change to integer, and reduce 0.5 coordinate
///
public static Vector2 Make2DCoord(Vector2 vec)
{
int x = (int)vec.X;
int y = (int)vec.Y;
return new Vector2((float)x - 0.5f,
(float)y - 0.5f);
}
}
}