Mega Code Archive

 
Categories / C# / Development Class
 

Get Random Vector3

////////////////////////////////////////////////////////////////////// //  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 <http://www.gnu.org/licenses/>. //////////////////////////////////////////////////////////////////////// using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; namespace Ale.Tools {     /// <summary>     ///      /// </summary>     public static class AleMathUtils     {         public static Random Random = new Random();         /// <summary>         /// Gets the perpendicular vector to a specified vector         /// </summary>         /// <param name="vec"></param>         /// <returns></returns>         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;         }         /// <summary>         /// Get a random number arround 0         /// </summary>         /// <param name="variation"></param>         /// <returns></returns>         public static float GetRandomFloat(float variation)         {             return ((float)Random.NextDouble() - 0.5f) * variation;         }     } }