//////////////////////////////////////////////////////////////////////
// Copyright (C) 2010 by Conquera Team
// Part of the Conquera Project
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
namespace Ale.Tools
{
///
///
///
public static class AleMathUtils
{
public static Random Random = new Random();
///
/// Gets the perpendicular vector to a specified vector
///
///
///
public static Vector2 GetPerpVector(Vector2 vec)
{
Vector2 perp;
GetPerpVector(ref vec, out perp);
return perp;
}
public static Vector3 GetRandomVector3(ref Vector3 vec, ref Vector3 variation)
{
Vector3 outVec;
GetRandomVector3(ref vec, ref variation, out outVec);
return outVec;
}
public static void GetRandomVector3(ref Vector3 vec, ref Vector3 variation, out Vector3 outVec)
{
outVec = new Vector3(
GetRandomFloat(vec.X, variation.X),
GetRandomFloat(vec.Y, variation.Y),
GetRandomFloat(vec.Z, variation.Z));
}
public static Vector3 GetRandomVector3(ref Vector3 vec, float variation)
{
Vector3 outVec;
GetRandomVector3(ref vec, variation, out outVec);
return outVec;
}
public static void GetRandomVector3(ref Vector3 vec, float variation, out Vector3 outVec)
{
outVec = new Vector3(
GetRandomFloat(vec.X, variation),
GetRandomFloat(vec.Y, variation),
GetRandomFloat(vec.Z, variation));
}
public static float GetRandomFloat(float value, float variation)
{
return ((float)Random.NextDouble() - 0.5f) * variation + value;
}
///
/// Get a random number arround 0
///
///
///
public static float GetRandomFloat(float variation)
{
return ((float)Random.NextDouble() - 0.5f) * variation;
}
}
}