diff --git a/ChangeLog b/ChangeLog index b11ad98..33f246e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-03-19 Jeffrey Stedfast + * DemoLib/Vertex.cs: Added 2 more constructors based on float arrays. + (Set): New convenience methods to set x, y, z, and w + + * DemoLib/Vector.cs: Added 2 more constructors based on float arrays. + (Set): New convenience methods to set x, y, z, and w + * DemoLib/FloatingCageScene.cs: Updated to use Vertex and Vector classes diff --git a/DemoLib/Vector.cs b/DemoLib/Vector.cs index 1a9f7b5..b64c0fc 100644 --- a/DemoLib/Vector.cs +++ b/DemoLib/Vector.cs @@ -58,6 +58,33 @@ namespace DemoLib { v[3] = w; } + public Vector (float[] vector) { + int n = Math.Min (vector.Length, 4); + + v = new float[4]; + Array.Copy (vector, v, n); + + while (n < 3) + v[n++] = 0.0f; + + if (n < 4) + v[n] = 1.0f; + } + + public Vector (float[] vector, int length) { + if (length < 0 || length > 4) + throw new ArgumentOutOfRangeException (); + + v = new float[4]; + Array.Copy (vector, v, length); + + while (length < 3) + v[length++] = 0.0f; + + if (length < 4) + v[length] = 1.0f; + } + // Properties public float x { get { return v[0]; } @@ -133,6 +160,41 @@ namespace DemoLib { return new Vector (x, y, z, w); } + public void Set (float x) { + v[0] = x; + } + + public void Set (float x, float y) { + v[0] = x; + v[1] = y; + } + + public void Set (float x, float y, float z) { + v[0] = x; + v[1] = y; + v[2] = z; + } + + public void Set (float x, float y, float z, float w) { + v[0] = x; + v[1] = y; + v[2] = z; + v[3] = w; + } + + public void Set (float[] vector) { + int n = Math.Min (vector.Length, 4); + + Array.Copy (vector, v, n); + } + + public void Set (float[] vector, int length) { + if (length < 0 || length > 4) + throw new ArgumentOutOfRangeException (); + + Array.Copy (vector, v, length); + } + // Normalize this Vector public void Normalize () { float len = Length; diff --git a/DemoLib/Vertex.cs b/DemoLib/Vertex.cs index e8b8655..1dbe992 100644 --- a/DemoLib/Vertex.cs +++ b/DemoLib/Vertex.cs @@ -50,6 +50,33 @@ namespace DemoLib { v[3] = w; } + public Vertex (float[] vector) { + int n = Math.Min (vector.Length, 4); + + v = new float[4]; + Array.Copy (vector, v, n); + + while (n < 3) + v[n++] = 0.0f; + + if (n < 4) + v[n] = 1.0f; + } + + public Vertex (float[] vector, int length) { + if (length < 0 || length > 4) + throw new ArgumentOutOfRangeException (); + + length = new float[4]; + Array.Copy (vector, v, length); + + while (length < 3) + v[length++] = 0.0f; + + if (length < 4) + v[length] = 1.0f; + } + // Properties public float x { get { return v[0]; } @@ -77,6 +104,41 @@ namespace DemoLib { return new Vertex (x, y, z, w); } + public void Set (float x) { + v[0] = x; + } + + public void Set (float x, float y) { + v[0] = x; + v[1] = y; + } + + public void Set (float x, float y, float z) { + v[0] = x; + v[1] = y; + v[2] = z; + } + + public void Set (float x, float y, float z, float w) { + v[0] = x; + v[1] = y; + v[2] = z; + v[3] = w; + } + + public void Set (float[] vector) { + int n = Math.Min (vector.Length, 4); + + Array.Copy (vector, v, n); + } + + public void Set (float[] vector, int length) { + if (length < 0 || length > 4) + throw new ArgumentOutOfRangeException (); + + Array.Copy (vector, v, length); + } + // Overloaded Operators public static explicit operator Vector (Vertex v) {