using System;
namespace Plankton
{
public struct PlanktonXYZ
{
#region members
internal float _x;
internal float _y;
internal float _z;
#endregion
#region constructors
Constructs a new vector from 3 single precision numbers.
public PlanktonXYZ(float x, float y, float z)
{
_x = x;
_y = y;
_z = z;
}
#endregion
#region static properties
public static PlanktonXYZ Zero
{
get { return new PlanktonXYZ(); }
}
public static PlanktonXYZ XAxis
{
get { return new PlanktonXYZ(1f, 0f, 0f); }
}
public static PlanktonXYZ YAxis
{
get { return new PlanktonXYZ(0f, 1f, 0f); }
}
public static PlanktonXYZ ZAxis
{
get { return new PlanktonXYZ(0f, 0f, 1f); }
}
#endregion static properties
#region properties
public float X { get { return _x; } set { _x = value; } }
public float Y { get { return _y; } set { _y = value; } }
public float Z { get { return _z; } set { _z = value; } }
#endregion
Computes a hash number that represents the current vector.
A hash code that is not unique for each vector.
public override int GetHashCode()
{
// MSDN docs recommend XOR'ing the internal values to get a hash code
return _x.GetHashCode() ^ _y.GetHashCode() ^ _z.GetHashCode();
}
Sums up two vectors.
A new vector that results from the componentwise addition of the two vectors.
public static PlanktonXYZ operator +(PlanktonXYZ v1, PlanktonXYZ v2)
{
return new PlanktonXYZ(v1._x + v2._x, v1._y + v2._y, v1._z + v2._z);
}
Subtracts one vector from another.
The first vector minus the second vector
public static PlanktonXYZ operator -(PlanktonXYZ v1, PlanktonXYZ v2)
{
return new PlanktonXYZ(v1._x - v2._x, v1._y - v2._y, v1._z - v2._z);
}
Multiplies a vector by a number, having the effect of scaling it.
A new vector that is the original vector coordinatewise multiplied by t.
public static PlanktonXYZ operator *(PlanktonXYZ vector, float t)
{
return new PlanktonXYZ(vector._x * t, vector._y * t, vector._z * t);
}
Computes the cross product (or vector product, or exterior product) of two vectors. This operation is not commutative.
A new vector that is perpendicular to both a and b, has Length == a.Length * b.Length and
with a result that is oriented following the right hand rule.
public static PlanktonXYZ CrossProduct(PlanktonXYZ a, PlanktonXYZ b)
{
return new PlanktonXYZ(a._y * b._z - b._y * a._z, a._z * b._x - b._z * a._x, a._x * b._y - b._x * a._y);
}
public float Length
{
get { return (float)Math.Sqrt(this._x * this._x + this._y * this._y + this._z * this._z); }
}
public override string ToString()
{
return string.Format("{0}, {1}, {2}", this._x, this._y, this._z);
}
Determines whether two vectors have equal values.
true if the components of the two vectors are exactly equal; otherwise false.
public static bool operator ==(PlanktonXYZ a, PlanktonXYZ b)
{
return (a._x == b._x && a._y == b._y && a._z == b._z);
}
Determines whether two vectors have different values.
true if the two vectors differ in any component; false otherwise.
public static bool operator !=(PlanktonXYZ a, PlanktonXYZ b)
{
return (a._x != b._x || a._y != b._y || a._z != b._z);
}
Determines whether the specified System.Object is a Vector3f and has the same values as the present vector.
true if obj is Vector3f and has the same components as this; otherwise false.
public override bool Equals(object obj)
{
return (obj is PlanktonXYZ && this == (PlanktonXYZ)obj);
}
Determines whether the specified vector has the same values as the present vector.
true if vector has the same components as this; otherwise false.
public bool Equals(PlanktonXYZ vector)
{
return this == vector;
}
}
}