#region --- License --- /* Copyright (c) 2006 - 2008 The Open Toolkit library. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #endregion using System; using System.Runtime.InteropServices; using System.Xml.Serialization; namespace OpenTK { /// Represents a 4D vector using four double-precision floating-point numbers. [Serializable] [StructLayout(LayoutKind.Sequential)] public struct Vector4d : IEquatable { #region Fields /// /// The X component of the Vector4d. /// public double X; /// /// The Y component of the Vector4d. /// public double Y; /// /// The Z component of the Vector4d. /// public double Z; /// /// The W component of the Vector4d. /// public double W; /// /// Defines a unit-length Vector4d that points towards the X-axis. /// public static readonly Vector4d UnitX = new Vector4d(1, 0, 0, 0); /// /// Defines a unit-length Vector4d that points towards the Y-axis. /// public static readonly Vector4d UnitY = new Vector4d(0, 1, 0, 0); /// /// Defines a unit-length Vector4d that points towards the Z-axis. /// public static readonly Vector4d UnitZ = new Vector4d(0, 0, 1, 0); /// /// Defines a unit-length Vector4d that points towards the W-axis. /// public static readonly Vector4d UnitW = new Vector4d(0, 0, 0, 1); /// /// Defines a zero-length Vector4d. /// public static readonly Vector4d Zero = new Vector4d(0, 0, 0, 0); /// /// Defines an instance with all components set to 1. /// public static readonly Vector4d One = new Vector4d(1, 1, 1, 1); /// /// Defines the size of the Vector4d struct in bytes. /// public static readonly int SizeInBytes = Marshal.SizeOf(new Vector4d()); #endregion #region Constructors /// /// Constructs a new instance. /// /// The value that will initialize this instance. public Vector4d(double value) { X = value; Y = value; Z = value; W = value; } /// /// Constructs a new Vector4d. /// /// The x component of the Vector4d. /// The y component of the Vector4d. /// The z component of the Vector4d. /// The w component of the Vector4d. public Vector4d(double x, double y, double z, double w) { X = x; Y = y; Z = z; W = w; } /// /// Constructs a new Vector4d from the given Vector2d. /// /// The Vector2d to copy components from. public Vector4d(Vector2d v) { X = v.X; Y = v.Y; Z = 0.0f; W = 0.0f; } /// /// Constructs a new Vector4d from the given Vector3d. /// The w component is initialized to 0. /// /// The Vector3d to copy components from. /// public Vector4d(Vector3d v) { X = v.X; Y = v.Y; Z = v.Z; W = 0.0f; } /// /// Constructs a new Vector4d from the specified Vector3d and w component. /// /// The Vector3d to copy components from. /// The w component of the new Vector4. public Vector4d(Vector3d v, double w) { X = v.X; Y = v.Y; Z = v.Z; W = w; } /// /// Constructs a new Vector4d from the given Vector4d. /// /// The Vector4d to copy components from. public Vector4d(Vector4d v) { X = v.X; Y = v.Y; Z = v.Z; W = v.W; } #endregion #region Public Members /// /// Gets or sets the value at the index of the Vector. /// public double this[int index] { get{ if(index == 0) return X; else if(index == 1) return Y; else if(index == 2) return Z; else if(index == 3) return W; throw new IndexOutOfRangeException("You tried to access this vector at index: " + index); } set{ if(index == 0) X = value; else if(index == 1) Y = value; else if(index == 2) Z = value; else if(index == 3) W = value; else throw new IndexOutOfRangeException("You tried to set this vector at index: " + index); } } #region Instance #region public void Add() /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [Obsolete("Use static Add() method instead.")] public void Add(Vector4d right) { this.X += right.X; this.Y += right.Y; this.Z += right.Z; this.W += right.W; } /// Add the Vector passed as parameter to this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] [Obsolete("Use static Add() method instead.")] public void Add(ref Vector4d right) { this.X += right.X; this.Y += right.Y; this.Z += right.Z; this.W += right.W; } #endregion public void Add() #region public void Sub() /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [Obsolete("Use static Subtract() method instead.")] public void Sub(Vector4d right) { this.X -= right.X; this.Y -= right.Y; this.Z -= right.Z; this.W -= right.W; } /// Subtract the Vector passed as parameter from this instance. /// Right operand. This parameter is only read from. [CLSCompliant(false)] [Obsolete("Use static Subtract() method instead.")] public void Sub(ref Vector4d right) { this.X -= right.X; this.Y -= right.Y; this.Z -= right.Z; this.W -= right.W; } #endregion public void Sub() #region public void Mult() /// Multiply this instance by a scalar. /// Scalar operand. [Obsolete("Use static Multiply() method instead.")] public void Mult(double f) { this.X *= f; this.Y *= f; this.Z *= f; this.W *= f; } #endregion public void Mult() #region public void Div() /// Divide this instance by a scalar. /// Scalar operand. [Obsolete("Use static Divide() method instead.")] public void Div(double f) { double mult = 1.0 / f; this.X *= mult; this.Y *= mult; this.Z *= mult; this.W *= mult; } #endregion public void Div() #region public double Length /// /// Gets the length (magnitude) of the vector. /// /// /// public double Length { get { return System.Math.Sqrt(X * X + Y * Y + Z * Z + W * W); } } #endregion #region public double LengthFast /// /// Gets an approximation of the vector length (magnitude). /// /// /// This property uses an approximation of the square root function to calculate vector magnitude, with /// an upper error bound of 0.001. /// /// /// public double LengthFast { get { return 1.0 / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W); } } #endregion #region public double LengthSquared /// /// Gets the square of the vector length (magnitude). /// /// /// This property avoids the costly square root operation required by the Length property. This makes it more suitable /// for comparisons. /// /// public double LengthSquared { get { return X * X + Y * Y + Z * Z + W * W; } } #endregion /// /// Returns a copy of the Vector4d scaled to unit length. /// public Vector4d Normalized() { Vector4d v = this; v.Normalize(); return v; } #region public void Normalize() /// /// Scales the Vector4d to unit length. /// public void Normalize() { double scale = 1.0 / this.Length; X *= scale; Y *= scale; Z *= scale; W *= scale; } #endregion #region public void NormalizeFast() /// /// Scales the Vector4d to approximately unit length. /// public void NormalizeFast() { double scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z + W * W); X *= scale; Y *= scale; Z *= scale; W *= scale; } #endregion #region public void Scale() /// /// Scales the current Vector4d by the given amounts. /// /// The scale of the X component. /// The scale of the Y component. /// The scale of the Z component. /// The scale of the Z component. [Obsolete("Use static Multiply() method instead.")] public void Scale(double sx, double sy, double sz, double sw) { this.X = X * sx; this.Y = Y * sy; this.Z = Z * sz; this.W = W * sw; } /// Scales this instance by the given parameter. /// The scaling of the individual components. [Obsolete("Use static Multiply() method instead.")] public void Scale(Vector4d scale) { this.X *= scale.X; this.Y *= scale.Y; this.Z *= scale.Z; this.W *= scale.W; } /// Scales this instance by the given parameter. /// The scaling of the individual components. [CLSCompliant(false)] [Obsolete("Use static Multiply() method instead.")] public void Scale(ref Vector4d scale) { this.X *= scale.X; this.Y *= scale.Y; this.Z *= scale.Z; this.W *= scale.W; } #endregion public void Scale() #endregion #region Static #region Obsolete #region Sub /// /// Subtract one Vector from another /// /// First operand /// Second operand /// Result of subtraction [Obsolete("Use static Subtract() method instead.")] public static Vector4d Sub(Vector4d a, Vector4d b) { a.X -= b.X; a.Y -= b.Y; a.Z -= b.Z; a.W -= b.W; return a; } /// /// Subtract one Vector from another /// /// First operand /// Second operand /// Result of subtraction [Obsolete("Use static Subtract() method instead.")] public static void Sub(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X - b.X; result.Y = a.Y - b.Y; result.Z = a.Z - b.Z; result.W = a.W - b.W; } #endregion #region Mult /// /// Multiply a vector and a scalar /// /// Vector operand /// Scalar operand /// Result of the multiplication [Obsolete("Use static Multiply() method instead.")] public static Vector4d Mult(Vector4d a, double f) { a.X *= f; a.Y *= f; a.Z *= f; a.W *= f; return a; } /// /// Multiply a vector and a scalar /// /// Vector operand /// Scalar operand /// Result of the multiplication [Obsolete("Use static Multiply() method instead.")] public static void Mult(ref Vector4d a, double f, out Vector4d result) { result.X = a.X * f; result.Y = a.Y * f; result.Z = a.Z * f; result.W = a.W * f; } #endregion #region Div /// /// Divide a vector by a scalar /// /// Vector operand /// Scalar operand /// Result of the division [Obsolete("Use static Divide() method instead.")] public static Vector4d Div(Vector4d a, double f) { double mult = 1.0 / f; a.X *= mult; a.Y *= mult; a.Z *= mult; a.W *= mult; return a; } /// /// Divide a vector by a scalar /// /// Vector operand /// Scalar operand /// Result of the division [Obsolete("Use static Divide() method instead.")] public static void Div(ref Vector4d a, double f, out Vector4d result) { double mult = 1.0 / f; result.X = a.X * mult; result.Y = a.Y * mult; result.Z = a.Z * mult; result.W = a.W * mult; } #endregion #endregion #region Add /// /// Adds two vectors. /// /// Left operand. /// Right operand. /// Result of operation. public static Vector4d Add(Vector4d a, Vector4d b) { Add(ref a, ref b, out a); return a; } /// /// Adds two vectors. /// /// Left operand. /// Right operand. /// Result of operation. public static void Add(ref Vector4d a, ref Vector4d b, out Vector4d result) { result = new Vector4d(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W); } #endregion #region Subtract /// /// Subtract one Vector from another /// /// First operand /// Second operand /// Result of subtraction public static Vector4d Subtract(Vector4d a, Vector4d b) { Subtract(ref a, ref b, out a); return a; } /// /// Subtract one Vector from another /// /// First operand /// Second operand /// Result of subtraction public static void Subtract(ref Vector4d a, ref Vector4d b, out Vector4d result) { result = new Vector4d(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W); } #endregion #region Multiply /// /// Multiplies a vector by a scalar. /// /// Left operand. /// Right operand. /// Result of the operation. public static Vector4d Multiply(Vector4d vector, double scale) { Multiply(ref vector, scale, out vector); return vector; } /// /// Multiplies a vector by a scalar. /// /// Left operand. /// Right operand. /// Result of the operation. public static void Multiply(ref Vector4d vector, double scale, out Vector4d result) { result = new Vector4d(vector.X * scale, vector.Y * scale, vector.Z * scale, vector.W * scale); } /// /// Multiplies a vector by the components a vector (scale). /// /// Left operand. /// Right operand. /// Result of the operation. public static Vector4d Multiply(Vector4d vector, Vector4d scale) { Multiply(ref vector, ref scale, out vector); return vector; } /// /// Multiplies a vector by the components of a vector (scale). /// /// Left operand. /// Right operand. /// Result of the operation. public static void Multiply(ref Vector4d vector, ref Vector4d scale, out Vector4d result) { result = new Vector4d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z, vector.W * scale.W); } #endregion #region Divide /// /// Divides a vector by a scalar. /// /// Left operand. /// Right operand. /// Result of the operation. public static Vector4d Divide(Vector4d vector, double scale) { Divide(ref vector, scale, out vector); return vector; } /// /// Divides a vector by a scalar. /// /// Left operand. /// Right operand. /// Result of the operation. public static void Divide(ref Vector4d vector, double scale, out Vector4d result) { Multiply(ref vector, 1 / scale, out result); } /// /// Divides a vector by the components of a vector (scale). /// /// Left operand. /// Right operand. /// Result of the operation. public static Vector4d Divide(Vector4d vector, Vector4d scale) { Divide(ref vector, ref scale, out vector); return vector; } /// /// Divide a vector by the components of a vector (scale). /// /// Left operand. /// Right operand. /// Result of the operation. public static void Divide(ref Vector4d vector, ref Vector4d scale, out Vector4d result) { result = new Vector4d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z, vector.W / scale.W); } #endregion #region Min /// /// Calculate the component-wise minimum of two vectors /// /// First operand /// Second operand /// The component-wise minimum public static Vector4d Min(Vector4d a, Vector4d b) { a.X = a.X < b.X ? a.X : b.X; a.Y = a.Y < b.Y ? a.Y : b.Y; a.Z = a.Z < b.Z ? a.Z : b.Z; a.W = a.W < b.W ? a.W : b.W; return a; } /// /// Calculate the component-wise minimum of two vectors /// /// First operand /// Second operand /// The component-wise minimum public static void Min(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X < b.X ? a.X : b.X; result.Y = a.Y < b.Y ? a.Y : b.Y; result.Z = a.Z < b.Z ? a.Z : b.Z; result.W = a.W < b.W ? a.W : b.W; } #endregion #region Max /// /// Calculate the component-wise maximum of two vectors /// /// First operand /// Second operand /// The component-wise maximum public static Vector4d Max(Vector4d a, Vector4d b) { a.X = a.X > b.X ? a.X : b.X; a.Y = a.Y > b.Y ? a.Y : b.Y; a.Z = a.Z > b.Z ? a.Z : b.Z; a.W = a.W > b.W ? a.W : b.W; return a; } /// /// Calculate the component-wise maximum of two vectors /// /// First operand /// Second operand /// The component-wise maximum public static void Max(ref Vector4d a, ref Vector4d b, out Vector4d result) { result.X = a.X > b.X ? a.X : b.X; result.Y = a.Y > b.Y ? a.Y : b.Y; result.Z = a.Z > b.Z ? a.Z : b.Z; result.W = a.W > b.W ? a.W : b.W; } #endregion #region Clamp /// /// Clamp a vector to the given minimum and maximum vectors /// /// Input vector /// Minimum vector /// Maximum vector /// The clamped vector public static Vector4d Clamp(Vector4d vec, Vector4d min, Vector4d max) { vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X; vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y; vec.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; vec.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W; return vec; } /// /// Clamp a vector to the given minimum and maximum vectors /// /// Input vector /// Minimum vector /// Maximum vector /// The clamped vector public static void Clamp(ref Vector4d vec, ref Vector4d min, ref Vector4d max, out Vector4d result) { result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X; result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y; result.Z = vec.X < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z; result.W = vec.Y < min.W ? min.W : vec.W > max.W ? max.W : vec.W; } #endregion #region Normalize /// /// Scale a vector to unit length /// /// The input vector /// The normalized vector public static Vector4d Normalize(Vector4d vec) { double scale = 1.0 / vec.Length; vec.X *= scale; vec.Y *= scale; vec.Z *= scale; vec.W *= scale; return vec; } /// /// Scale a vector to unit length /// /// The input vector /// The normalized vector public static void Normalize(ref Vector4d vec, out Vector4d result) { double scale = 1.0 / vec.Length; result.X = vec.X * scale; result.Y = vec.Y * scale; result.Z = vec.Z * scale; result.W = vec.W * scale; } #endregion #region NormalizeFast /// /// Scale a vector to approximately unit length /// /// The input vector /// The normalized vector public static Vector4d NormalizeFast(Vector4d vec) { double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W); vec.X *= scale; vec.Y *= scale; vec.Z *= scale; vec.W *= scale; return vec; } /// /// Scale a vector to approximately unit length /// /// The input vector /// The normalized vector public static void NormalizeFast(ref Vector4d vec, out Vector4d result) { double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z + vec.W * vec.W); result.X = vec.X * scale; result.Y = vec.Y * scale; result.Z = vec.Z * scale; result.W = vec.W * scale; } #endregion #region Dot /// /// Calculate the dot product of two vectors /// /// First operand /// Second operand /// The dot product of the two inputs public static double Dot(Vector4d left, Vector4d right) { return left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } /// /// Calculate the dot product of two vectors /// /// First operand /// Second operand /// The dot product of the two inputs public static void Dot(ref Vector4d left, ref Vector4d right, out double result) { result = left.X * right.X + left.Y * right.Y + left.Z * right.Z + left.W * right.W; } #endregion #region Lerp /// /// Returns a new Vector that is the linear blend of the 2 given Vectors /// /// First input vector /// Second input vector /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static Vector4d Lerp(Vector4d a, Vector4d b, double blend) { a.X = blend * (b.X - a.X) + a.X; a.Y = blend * (b.Y - a.Y) + a.Y; a.Z = blend * (b.Z - a.Z) + a.Z; a.W = blend * (b.W - a.W) + a.W; return a; } /// /// Returns a new Vector that is the linear blend of the 2 given Vectors /// /// First input vector /// Second input vector /// The blend factor. a when blend=0, b when blend=1. /// a when blend=0, b when blend=1, and a linear combination otherwise public static void Lerp(ref Vector4d a, ref Vector4d b, double blend, out Vector4d result) { result.X = blend * (b.X - a.X) + a.X; result.Y = blend * (b.Y - a.Y) + a.Y; result.Z = blend * (b.Z - a.Z) + a.Z; result.W = blend * (b.W - a.W) + a.W; } #endregion #region Barycentric /// /// Interpolate 3 Vectors using Barycentric coordinates /// /// First input Vector /// Second input Vector /// Third input Vector /// First Barycentric Coordinate /// Second Barycentric Coordinate /// a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise public static Vector4d BaryCentric(Vector4d a, Vector4d b, Vector4d c, double u, double v) { return a + u * (b - a) + v * (c - a); } /// Interpolate 3 Vectors using Barycentric coordinates /// First input Vector. /// Second input Vector. /// Third input Vector. /// First Barycentric Coordinate. /// Second Barycentric Coordinate. /// Output Vector. a when u=v=0, b when u=1,v=0, c when u=0,v=1, and a linear combination of a,b,c otherwise public static void BaryCentric(ref Vector4d a, ref Vector4d b, ref Vector4d c, double u, double v, out Vector4d result) { result = a; // copy Vector4d temp = b; // copy Subtract(ref temp, ref a, out temp); Multiply(ref temp, u, out temp); Add(ref result, ref temp, out result); temp = c; // copy Subtract(ref temp, ref a, out temp); Multiply(ref temp, v, out temp); Add(ref result, ref temp, out result); } #endregion #region Transform /// Transform a Vector by the given Matrix /// The vector to transform /// The desired transformation /// The transformed vector public static Vector4d Transform(Vector4d vec, Matrix4d mat) { Vector4d result; Transform(ref vec, ref mat, out result); return result; } /// Transform a Vector by the given Matrix /// The vector to transform /// The desired transformation /// The transformed vector public static void Transform(ref Vector4d vec, ref Matrix4d mat, out Vector4d result) { result = new Vector4d( vec.X * mat.Row0.X + vec.Y * mat.Row1.X + vec.Z * mat.Row2.X + vec.W * mat.Row3.X, vec.X * mat.Row0.Y + vec.Y * mat.Row1.Y + vec.Z * mat.Row2.Y + vec.W * mat.Row3.Y, vec.X * mat.Row0.Z + vec.Y * mat.Row1.Z + vec.Z * mat.Row2.Z + vec.W * mat.Row3.Z, vec.X * mat.Row0.W + vec.Y * mat.Row1.W + vec.Z * mat.Row2.W + vec.W * mat.Row3.W); } /// /// Transforms a vector by a quaternion rotation. /// /// The vector to transform. /// The quaternion to rotate the vector by. /// The result of the operation. public static Vector4d Transform(Vector4d vec, Quaterniond quat) { Vector4d result; Transform(ref vec, ref quat, out result); return result; } /// /// Transforms a vector by a quaternion rotation. /// /// The vector to transform. /// The quaternion to rotate the vector by. /// The result of the operation. public static void Transform(ref Vector4d vec, ref Quaterniond quat, out Vector4d result) { Quaterniond v = new Quaterniond(vec.X, vec.Y, vec.Z, vec.W), i, t; Quaterniond.Invert(ref quat, out i); Quaterniond.Multiply(ref quat, ref v, out t); Quaterniond.Multiply(ref t, ref i, out v); result = new Vector4d(v.X, v.Y, v.Z, v.W); } #endregion #endregion #region Swizzle #region 2-component /// /// Gets or sets an OpenTK.Vector2d with the X and Y components of this instance. /// [XmlIgnore] public Vector2d Xy { get { return new Vector2d(X, Y); } set { X = value.X; Y = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the X and Z components of this instance. /// [XmlIgnore] public Vector2d Xz { get { return new Vector2d(X, Z); } set { X = value.X; Z = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the X and W components of this instance. /// [XmlIgnore] public Vector2d Xw { get { return new Vector2d(X, W); } set { X = value.X; W = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the Y and X components of this instance. /// [XmlIgnore] public Vector2d Yx { get { return new Vector2d(Y, X); } set { Y = value.X; X = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the Y and Z components of this instance. /// [XmlIgnore] public Vector2d Yz { get { return new Vector2d(Y, Z); } set { Y = value.X; Z = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the Y and W components of this instance. /// [XmlIgnore] public Vector2d Yw { get { return new Vector2d(Y, W); } set { Y = value.X; W = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the Z and X components of this instance. /// [XmlIgnore] public Vector2d Zx { get { return new Vector2d(Z, X); } set { Z = value.X; X = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the Z and Y components of this instance. /// [XmlIgnore] public Vector2d Zy { get { return new Vector2d(Z, Y); } set { Z = value.X; Y = value.Y; } } /// /// Gets an OpenTK.Vector2d with the Z and W components of this instance. /// [XmlIgnore] public Vector2d Zw { get { return new Vector2d(Z, W); } set { Z = value.X; W = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the W and X components of this instance. /// [XmlIgnore] public Vector2d Wx { get { return new Vector2d(W, X); } set { W = value.X; X = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the W and Y components of this instance. /// [XmlIgnore] public Vector2d Wy { get { return new Vector2d(W, Y); } set { W = value.X; Y = value.Y; } } /// /// Gets or sets an OpenTK.Vector2d with the W and Z components of this instance. /// [XmlIgnore] public Vector2d Wz { get { return new Vector2d(W, Z); } set { W = value.X; Z = value.Y; } } #endregion #region 3-component /// /// Gets or sets an OpenTK.Vector3d with the X, Y, and Z components of this instance. /// [XmlIgnore] public Vector3d Xyz { get { return new Vector3d(X, Y, Z); } set { X = value.X; Y = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the X, Y, and Z components of this instance. /// [XmlIgnore] public Vector3d Xyw { get { return new Vector3d(X, Y, W); } set { X = value.X; Y = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the X, Z, and Y components of this instance. /// [XmlIgnore] public Vector3d Xzy { get { return new Vector3d(X, Z, Y); } set { X = value.X; Z = value.Y; Y = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the X, Z, and W components of this instance. /// [XmlIgnore] public Vector3d Xzw { get { return new Vector3d(X, Z, W); } set { X = value.X; Z = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the X, W, and Y components of this instance. /// [XmlIgnore] public Vector3d Xwy { get { return new Vector3d(X, W, Y); } set { X = value.X; W = value.Y; Y = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the X, W, and Z components of this instance. /// [XmlIgnore] public Vector3d Xwz { get { return new Vector3d(X, W, Z); } set { X = value.X; W = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Y, X, and Z components of this instance. /// [XmlIgnore] public Vector3d Yxz { get { return new Vector3d(Y, X, Z); } set { Y = value.X; X = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Y, X, and W components of this instance. /// [XmlIgnore] public Vector3d Yxw { get { return new Vector3d(Y, X, W); } set { Y = value.X; X = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Y, Z, and X components of this instance. /// [XmlIgnore] public Vector3d Yzx { get { return new Vector3d(Y, Z, X); } set { Y = value.X; Z = value.Y; X = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Y, Z, and W components of this instance. /// [XmlIgnore] public Vector3d Yzw { get { return new Vector3d(Y, Z, W); } set { Y = value.X; Z = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Y, W, and X components of this instance. /// [XmlIgnore] public Vector3d Ywx { get { return new Vector3d(Y, W, X); } set { Y = value.X; W = value.Y; X = value.Z; } } /// /// Gets an OpenTK.Vector3d with the Y, W, and Z components of this instance. /// [XmlIgnore] public Vector3d Ywz { get { return new Vector3d(Y, W, Z); } set { Y = value.X; W = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, X, and Y components of this instance. /// [XmlIgnore] public Vector3d Zxy { get { return new Vector3d(Z, X, Y); } set { Z = value.X; X = value.Y; Y = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, X, and W components of this instance. /// [XmlIgnore] public Vector3d Zxw { get { return new Vector3d(Z, X, W); } set { Z = value.X; X = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, Y, and X components of this instance. /// [XmlIgnore] public Vector3d Zyx { get { return new Vector3d(Z, Y, X); } set { Z = value.X; Y = value.Y; X = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, Y, and W components of this instance. /// [XmlIgnore] public Vector3d Zyw { get { return new Vector3d(Z, Y, W); } set { Z = value.X; Y = value.Y; W = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, W, and X components of this instance. /// [XmlIgnore] public Vector3d Zwx { get { return new Vector3d(Z, W, X); } set { Z = value.X; W = value.Y; X = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the Z, W, and Y components of this instance. /// [XmlIgnore] public Vector3d Zwy { get { return new Vector3d(Z, W, Y); } set { Z = value.X; W = value.Y; Y = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, X, and Y components of this instance. /// [XmlIgnore] public Vector3d Wxy { get { return new Vector3d(W, X, Y); } set { W = value.X; X = value.Y; Y = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, X, and Z components of this instance. /// [XmlIgnore] public Vector3d Wxz { get { return new Vector3d(W, X, Z); } set { W = value.X; X = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, Y, and X components of this instance. /// [XmlIgnore] public Vector3d Wyx { get { return new Vector3d(W, Y, X); } set { W = value.X; Y = value.Y; X = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, Y, and Z components of this instance. /// [XmlIgnore] public Vector3d Wyz { get { return new Vector3d(W, Y, Z); } set { W = value.X; Y = value.Y; Z = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, Z, and X components of this instance. /// [XmlIgnore] public Vector3d Wzx { get { return new Vector3d(W, Z, X); } set { W = value.X; Z = value.Y; X = value.Z; } } /// /// Gets or sets an OpenTK.Vector3d with the W, Z, and Y components of this instance. /// [XmlIgnore] public Vector3d Wzy { get { return new Vector3d(W, Z, Y); } set { W = value.X; Z = value.Y; Y = value.Z; } } #endregion #region 4-component /// /// Gets or sets an OpenTK.Vector4d with the X, Y, W, and Z components of this instance. /// [XmlIgnore] public Vector4d Xywz { get { return new Vector4d(X, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the X, Z, Y, and W components of this instance. /// [XmlIgnore] public Vector4d Xzyw { get { return new Vector4d(X, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the X, Z, W, and Y components of this instance. /// [XmlIgnore] public Vector4d Xzwy { get { return new Vector4d(X, Z, W, Y); } set { X = value.X; Z = value.Y; W = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the X, W, Y, and Z components of this instance. /// [XmlIgnore] public Vector4d Xwyz { get { return new Vector4d(X, W, Y, Z); } set { X = value.X; W = value.Y; Y = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the X, W, Z, and Y components of this instance. /// [XmlIgnore] public Vector4d Xwzy { get { return new Vector4d(X, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, X, Z, and W components of this instance. /// [XmlIgnore] public Vector4d Yxzw { get { return new Vector4d(Y, X, Z, W); } set { Y = value.X; X = value.Y; Z = value.Z; W = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, X, W, and Z components of this instance. /// [XmlIgnore] public Vector4d Yxwz { get { return new Vector4d(Y, X, W, Z); } set { Y = value.X; X = value.Y; W = value.Z; Z = value.W; } } /// /// Gets an OpenTK.Vector4d with the Y, Y, Z, and W components of this instance. /// [XmlIgnore] public Vector4d Yyzw { get { return new Vector4d(Y, Y, Z, W); } set { X = value.X; Y = value.Y; Z = value.Z; W = value.W; } } /// /// Gets an OpenTK.Vector4d with the Y, Y, W, and Z components of this instance. /// [XmlIgnore] public Vector4d Yywz { get { return new Vector4d(Y, Y, W, Z); } set { X = value.X; Y = value.Y; W = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, Z, X, and W components of this instance. /// [XmlIgnore] public Vector4d Yzxw { get { return new Vector4d(Y, Z, X, W); } set { Y = value.X; Z = value.Y; X = value.Z; W = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, Z, W, and X components of this instance. /// [XmlIgnore] public Vector4d Yzwx { get { return new Vector4d(Y, Z, W, X); } set { Y = value.X; Z = value.Y; W = value.Z; X = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, W, X, and Z components of this instance. /// [XmlIgnore] public Vector4d Ywxz { get { return new Vector4d(Y, W, X, Z); } set { Y = value.X; W = value.Y; X = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Y, W, Z, and X components of this instance. /// [XmlIgnore] public Vector4d Ywzx { get { return new Vector4d(Y, W, Z, X); } set { Y = value.X; W = value.Y; Z = value.Z; X = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, X, Y, and Z components of this instance. /// [XmlIgnore] public Vector4d Zxyw { get { return new Vector4d(Z, X, Y, W); } set { Z = value.X; X = value.Y; Y = value.Z; W = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, X, W, and Y components of this instance. /// [XmlIgnore] public Vector4d Zxwy { get { return new Vector4d(Z, X, W, Y); } set { Z = value.X; X = value.Y; W = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, Y, X, and W components of this instance. /// [XmlIgnore] public Vector4d Zyxw { get { return new Vector4d(Z, Y, X, W); } set { Z = value.X; Y = value.Y; X = value.Z; W = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, Y, W, and X components of this instance. /// [XmlIgnore] public Vector4d Zywx { get { return new Vector4d(Z, Y, W, X); } set { Z = value.X; Y = value.Y; W = value.Z; X = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, W, X, and Y components of this instance. /// [XmlIgnore] public Vector4d Zwxy { get { return new Vector4d(Z, W, X, Y); } set { Z = value.X; W = value.Y; X = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the Z, W, Y, and X components of this instance. /// [XmlIgnore] public Vector4d Zwyx { get { return new Vector4d(Z, W, Y, X); } set { Z = value.X; W = value.Y; Y = value.Z; X = value.W; } } /// /// Gets an OpenTK.Vector4d with the Z, W, Z, and Y components of this instance. /// [XmlIgnore] public Vector4d Zwzy { get { return new Vector4d(Z, W, Z, Y); } set { X = value.X; W = value.Y; Z = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, X, Y, and Z components of this instance. /// [XmlIgnore] public Vector4d Wxyz { get { return new Vector4d(W, X, Y, Z); } set { W = value.X; X = value.Y; Y = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, X, Z, and Y components of this instance. /// [XmlIgnore] public Vector4d Wxzy { get { return new Vector4d(W, X, Z, Y); } set { W = value.X; X = value.Y; Z = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, Y, X, and Z components of this instance. /// [XmlIgnore] public Vector4d Wyxz { get { return new Vector4d(W, Y, X, Z); } set { W = value.X; Y = value.Y; X = value.Z; Z = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, Y, Z, and X components of this instance. /// [XmlIgnore] public Vector4d Wyzx { get { return new Vector4d(W, Y, Z, X); } set { W = value.X; Y = value.Y; Z = value.Z; X = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, Z, X, and Y components of this instance. /// [XmlIgnore] public Vector4d Wzxy { get { return new Vector4d(W, Z, X, Y); } set { W = value.X; Z = value.Y; X = value.Z; Y = value.W; } } /// /// Gets or sets an OpenTK.Vector4d with the W, Z, Y, and X components of this instance. /// [XmlIgnore] public Vector4d Wzyx { get { return new Vector4d(W, Z, Y, X); } set { W = value.X; Z = value.Y; Y = value.Z; X = value.W; } } /// /// Gets an OpenTK.Vector4d with the W, Z, Y, and W components of this instance. /// [XmlIgnore] public Vector4d Wzyw { get { return new Vector4d(W, Z, Y, W); } set { X = value.X; Z = value.Y; Y = value.Z; W = value.W; } } #endregion #endregion #region Operators /// /// Adds two instances. /// /// The first instance. /// The second instance. /// The result of the calculation. public static Vector4d operator +(Vector4d left, Vector4d right) { left.X += right.X; left.Y += right.Y; left.Z += right.Z; left.W += right.W; return left; } /// /// Subtracts two instances. /// /// The first instance. /// The second instance. /// The result of the calculation. public static Vector4d operator -(Vector4d left, Vector4d right) { left.X -= right.X; left.Y -= right.Y; left.Z -= right.Z; left.W -= right.W; return left; } /// /// Negates an instance. /// /// The instance. /// The result of the calculation. public static Vector4d operator -(Vector4d vec) { vec.X = -vec.X; vec.Y = -vec.Y; vec.Z = -vec.Z; vec.W = -vec.W; return vec; } /// /// Multiplies an instance by a scalar. /// /// The instance. /// The scalar. /// The result of the calculation. public static Vector4d operator *(Vector4d vec, double scale) { vec.X *= scale; vec.Y *= scale; vec.Z *= scale; vec.W *= scale; return vec; } /// /// Multiplies an instance by a scalar. /// /// The scalar. /// The instance. /// The result of the calculation. public static Vector4d operator *(double scale, Vector4d vec) { vec.X *= scale; vec.Y *= scale; vec.Z *= scale; vec.W *= scale; return vec; } /// /// Divides an instance by a scalar. /// /// The instance. /// The scalar. /// The result of the calculation. public static Vector4d operator /(Vector4d vec, double scale) { double mult = 1 / scale; vec.X *= mult; vec.Y *= mult; vec.Z *= mult; vec.W *= mult; return vec; } /// /// Compares two instances for equality. /// /// The first instance. /// The second instance. /// True, if left equals right; false otherwise. public static bool operator ==(Vector4d left, Vector4d right) { return left.Equals(right); } /// /// Compares two instances for inequality. /// /// The first instance. /// The second instance. /// True, if left does not equa lright; false otherwise. public static bool operator !=(Vector4d left, Vector4d right) { return !left.Equals(right); } /// /// Returns a pointer to the first element of the specified instance. /// /// The instance. /// A pointer to the first element of v. [CLSCompliant(false)] unsafe public static explicit operator double*(Vector4d v) { return &v.X; } /// /// Returns a pointer to the first element of the specified instance. /// /// The instance. /// A pointer to the first element of v. public static explicit operator IntPtr(Vector4d v) { unsafe { return (IntPtr)(&v.X); } } /// Converts OpenTK.Vector4 to OpenTK.Vector4d. /// The Vector4 to convert. /// The resulting Vector4d. public static explicit operator Vector4d(Vector4 v4) { return new Vector4d(v4.X, v4.Y, v4.Z, v4.W); } /// Converts OpenTK.Vector4d to OpenTK.Vector4. /// The Vector4d to convert. /// The resulting Vector4. public static explicit operator Vector4(Vector4d v4d) { return new Vector4((float)v4d.X, (float)v4d.Y, (float)v4d.Z, (float)v4d.W); } #endregion #region Overrides #region public override string ToString() private static string listSeparator = System.Globalization.CultureInfo.CurrentCulture.TextInfo.ListSeparator; /// /// Returns a System.String that represents the current Vector4d. /// /// public override string ToString() { return String.Format("({0}{4} {1}{4} {2}{4} {3})", X, Y, Z, W, listSeparator); } #endregion #region public override int GetHashCode() /// /// Returns the hashcode for this instance. /// /// A System.Int32 containing the unique hashcode for this instance. public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode() ^ W.GetHashCode(); } #endregion #region public override bool Equals(object obj) /// /// Indicates whether this instance and a specified object are equal. /// /// The object to compare to. /// True if the instances are equal; false otherwise. public override bool Equals(object obj) { if (!(obj is Vector4d)) return false; return this.Equals((Vector4d)obj); } #endregion #endregion #endregion #region IEquatable Members /// Indicates whether the current vector is equal to another vector. /// A vector to compare with this vector. /// true if the current vector is equal to the vector parameter; otherwise, false. public bool Equals(Vector4d other) { return X == other.X && Y == other.Y && Z == other.Z && W == other.W; } #endregion } }