2007-03-19 Jeffrey Stedfast <fejj@gnome.org>

* 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


svn path=/trunk/DemoLib/; revision=74588
This commit is contained in:
Jeffrey Stedfast 2007-03-19 05:13:22 +00:00
Родитель d76e78aaca
Коммит 9293fa77c4
3 изменённых файлов: 130 добавлений и 0 удалений

Просмотреть файл

@ -1,5 +1,11 @@
2007-03-19 Jeffrey Stedfast <fejj@gnome.org>
* 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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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) {