00001 #region File Description
00002
00003
00004
00005 #endregion
00006
00007 namespace NewGamePhysics.Utilities
00008 {
00009 using System;
00010 using Microsoft.Xna.Framework;
00011 using NewGamePhysics.Mathematics;
00012
00017 public class VectorFormatConverter
00018 {
00024 public static Vector2[] VectorNToVector2(VectorN[] vectors)
00025 {
00026 if (null == vectors)
00027 {
00028 throw new ArgumentNullException("vectors");
00029 }
00030
00031 int size = vectors.Length;
00032
00033 if (size == 0)
00034 {
00035 throw new ArgumentOutOfRangeException(
00036 "vectors",
00037 "Input array must contain 1 or more elements");
00038 }
00039
00040 Vector2[] result = new Vector2[size];
00041 for (int i = 0; i < size; i++)
00042 {
00043 if (vectors[i].N != 2)
00044 {
00045 throw new ArgumentException(
00046 "All input vectors must be 2 dimensional.",
00047 "vectors");
00048 }
00049
00050 result[i].X = Convert.ToSingle(vectors[i][0]);
00051 result[i].Y = Convert.ToSingle(vectors[i][1]);
00052 }
00053
00054 return result;
00055 }
00056
00062 public static Vector3[] VectorNToVector3(VectorN[] vectors)
00063 {
00064 if (null == vectors)
00065 {
00066 throw new ArgumentNullException("vectors");
00067 }
00068
00069 int size = vectors.Length;
00070
00071 if (size == 0)
00072 {
00073 throw new ArgumentOutOfRangeException(
00074 "vectors",
00075 "Input array must contain 1 or more elements");
00076 }
00077
00078 Vector3[] result = new Vector3[size];
00079 for (int i = 0; i < size; i++)
00080 {
00081 if (vectors[i].N != 3)
00082 {
00083 throw new ArgumentException(
00084 "All input vectors must be 3 dimensional.",
00085 "vectors");
00086 }
00087
00088 result[i].X = Convert.ToSingle(vectors[i][0]);
00089 result[i].Y = Convert.ToSingle(vectors[i][1]);
00090 result[i].Z = Convert.ToSingle(vectors[i][2]);
00091 }
00092
00093 return result;
00094 }
00095 }
00096 }