31using System.Runtime.InteropServices;
33using System.Xml.Serialization;
40 [StructLayout(LayoutKind.Sequential, Size = Vector3D.Size)]
41 [AdvBrowsableOrder(
"X,Y,Z")]
42#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !NETFX_CORE
58 #region readonly fields
83 #region static methods
86 Copy(ref vector, destArray, 0);
92 destArray[index] = vector.X;
93 destArray[++index] = vector.Y;
94 destArray[++index] = vector.Z;
98 Copy(sourceArray, 0, out result);
104 result.X = sourceArray[index];
105 result.Y = sourceArray[++index];
106 result.Z = sourceArray[++index];
138 Lerp(ref left, ref right, ref amount, out result);
143 result.X = (right.X - left.X) * amount + left.X;
144 result.Y = (right.Y - left.Y) * amount + left.Y;
145 result.Z = (right.Z - left.Z) * amount + left.Z;
150 Lerp(ref left, ref right, ref amount, out result);
155 result.X = (right.X - left.X) * amount.X + left.X;
156 result.Y = (right.Y - left.Y) * amount.Y + left.Y;
157 result.Z = (right.Z - left.Z) * amount.Z + left.Z;
163 Distance(ref left, ref right, out result);
169 Subtract(ref left, ref right, out diff);
181 Subtract(ref left, ref right, out diff);
195 result.
X = left.
X + right.
X;
196 result.
Y = left.
Y + right.
Y;
197 result.
Z = left.
Z + right.
Z;
202 result.X = left.X + right.X;
203 result.Y = left.Y + right.Y;
204 result.Z = left.Z + right.Z;
210 Add(ref left, ref right, out result);
215 result.X = left.X + right.X;
216 result.Y = left.Y + right.Y;
222 Add(ref left, ref right, out result);
227 result.X = left.X + right.X;
228 result.Y = left.Y + right.Y;
243 result.
X = left.
X - right.
X;
244 result.
Y = left.
Y - right.
Y;
245 result.
Z = left.
Z - right.
Z;
250 result.X = left.X - right.X;
251 result.Y = left.Y - right.Y;
252 result.Z = left.Z - right.Z;
258 Subtract(ref left, ref right, out result);
263 result.X = left.X - right.X;
264 result.Y = left.Y - right.Y;
270 Subtract(ref left, ref right, out result);
275 result.X = left.X - right.X;
276 result.Y = left.Y - right.Y;
290 result.
X = source.
X * scalar;
291 result.
Y = source.
Y * scalar;
292 result.
Z = source.
Z * scalar;
297 result.X = source.X * scalar;
298 result.Y = source.Y * scalar;
299 result.Z = source.Z * scalar;
311 result.
X = scalar * source.
X;
312 result.
Y = scalar * source.
Y;
313 result.
Z = scalar * source.
Z;
318 result.X = scalar * source.X;
319 result.Y = scalar * source.Y;
320 result.Z = scalar * source.Z;
332 result.
X = matrix.
m00 * vector.
X + matrix.
m01 * vector.
Y + matrix.
m02 * vector.
Z;
333 result.
Y = matrix.
m10 * vector.
X + matrix.
m11 * vector.
Y + matrix.
m12 * vector.
Z;
334 result.
Z = matrix.
m20 * vector.
X + matrix.
m21 * vector.
Y + matrix.
m22 * vector.
Z;
342 result.X = matrix.m00 *
X + matrix.m01 *
Y + matrix.m02 * vector.Z;
343 result.Y = matrix.m10 *
X + matrix.m11 *
Y + matrix.m12 * vector.Z;
344 result.Z = matrix.m20 *
X + matrix.m21 *
Y + matrix.m22 * vector.Z;
356 result.
X = matrix.
m00 * vector.
X + matrix.
m01 * vector.
Y + matrix.
m02 * vector.
Z;
357 result.
Y = matrix.
m10 * vector.
X + matrix.
m11 * vector.
Y + matrix.
m12 * vector.
Z;
358 result.
Z = matrix.
m20 * vector.
X + matrix.
m21 * vector.
Y + matrix.
m22 * vector.
Z;
366 result.X = matrix.m00 *
X + matrix.m01 *
Y + matrix.m02 * vector.Z;
367 result.Y = matrix.m10 *
X + matrix.m11 *
Y + matrix.m12 * vector.Z;
368 result.Z = matrix.m20 *
X + matrix.m21 *
Y + matrix.m22 * vector.Z;
385 Scalar inverseW = 1 / (matrix.
m30 * vector.
X + matrix.
m31 * vector.
Y + matrix.
m32 * vector.
Z + matrix.
m33);
386 result.
X = ((matrix.
m00 * vector.
X) + (matrix.
m01 * vector.
Y) + (matrix.
m02 * vector.
Z) + matrix.
m03) * inverseW;
387 result.
Y = ((matrix.
m10 * vector.
X) + (matrix.
m11 * vector.
Y) + (matrix.
m12 * vector.
Z) + matrix.
m13) * inverseW;
388 result.
Z = ((matrix.
m20 * vector.
X) + (matrix.
m21 * vector.
Y) + (matrix.
m22 * vector.
Z) + matrix.
m23) * inverseW;
396 Scalar inverseW = 1 / (matrix.m30 *
X + matrix.m31 *
Y + matrix.m32 * vector.Z + matrix.m33);
397 result.X = ((matrix.m00 *
X) + (matrix.m01 *
Y) + (matrix.m02 * vector.Z) + matrix.m03) * inverseW;
398 result.Y = ((matrix.m10 *
X) + (matrix.m11 *
Y) + (matrix.m12 * vector.Z) + matrix.m13) * inverseW;
399 result.Z = ((matrix.m20 *
X) + (matrix.m21 *
Y) + (matrix.m22 * vector.Z) + matrix.m23) * inverseW;
454 return left.
Y * right.
Y + left.
X * right.
X + left.
Z * right.
Z;
458 result = left.Y * right.Y + left.X * right.X + left.Z * right.Z;
470 result.
X = left.
Y * right.
Z - left.
Z * right.
Y;
471 result.
Y = left.
Z * right.
X - left.
X * right.
Z;
472 result.
Z = left.
X * right.
Y - left.
Y * right.
X;
477 Scalar X = left.Y * right.Z - left.Z * right.Y;
478 Scalar Y = left.Z * right.X - left.X * right.Z;
479 result.Z = left.X * right.Y - left.Y * right.X;
490 return source.
X * source.
X + source.
Y * source.
Y + source.
Z * source.
Z;
494 result = source.X * source.X + source.Y * source.Y + source.Z * source.Z;
507 result =
MathHelper.
Sqrt(source.X * source.X + source.Y * source.Y + source.Z * source.Z);
525 if (oldmagnitude > 0 && magnitude != 0)
527 oldmagnitude = (magnitude / oldmagnitude);
528 Multiply(ref source, ref oldmagnitude, out result);
546 if (oldmagnitude == 0) {
return Zero; }
547 oldmagnitude = (1 / oldmagnitude);
549 result.
X = source.
X * oldmagnitude;
550 result.
Y = source.
Y * oldmagnitude;
551 result.
Z = source.
Z * oldmagnitude;
558 if (oldmagnitude == 0) { result =
Zero;
return; }
559 oldmagnitude = (1 / oldmagnitude);
560 result.
X = source.X * oldmagnitude;
561 result.Y = source.Y * oldmagnitude;
562 result.Z = source.Z * oldmagnitude;
576 result.
X = -source.
X;
577 result.
Y = -source.
Y;
578 result.
Z = -source.
Z;
583 Negate(ref source, out source);
587 result.X = -source.X;
588 result.Y = -source.Y;
589 result.Z = -source.Z;
602 Project(ref left, ref right, out result);
608 Dot(ref left, ref right, out tmp);
611 Multiply(ref right, ref tmp, out result);
617 Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
624 result.X = h1 * value1.X + h2 * value2.X + h3 * tangent1.X + h4 * tangent2.X;
625 result.Y = h1 * value1.Y + h2 * value2.Y + h3 * tangent1.Y + h4 * tangent2.Y;
626 result.Z = h1 * value1.Z + h2 * value2.Z + h3 * tangent1.Z + h4 * tangent2.Z;
632 CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
637 Scalar amountSq = amount * amount;
638 Scalar amountCu = amountSq * amount;
640 0.5f * ((2 * value2.X) +
641 (-value1.X + value3.X) * amount +
642 (2 * value1.X - 5 * value2.X + 4 * value3.X - value4.X) * amountSq +
643 (-value1.X + 3 * value2.X - 3 * value3.X + value4.X) * amountCu);
645 0.5f * ((2 * value2.Y) +
646 (-value1.Y + value3.Y) * amount +
647 (2 * value1.Y - 5 * value2.Y + 4 * value3.Y - value4.Y) * amountSq +
648 (-value1.Y + 3 * value2.Y - 3 * value3.Y + value4.Y) * amountCu);
650 0.5f * ((2 * value2.Z) +
651 (-value1.Z + value3.Z) * amount +
652 (2 * value1.Z - 5 * value2.Z + 4 * value3.Z - value4.Z) * amountSq +
653 (-value1.Z + 3 * value2.Z - 3 * value3.Z + value4.Z) * amountCu);
659 Max(ref value1, ref value2, out result);
664 result.X = (value1.X < value2.X) ? (value2.X) : (value1.X);
665 result.Y = (value1.Y < value2.Y) ? (value2.Y) : (value1.Y);
666 result.Z = (value1.Z < value2.Z) ? (value2.Z) : (value1.Z);
672 Min(ref value1, ref value2, out result);
677 result.X = (value1.X > value2.X) ? (value2.X) : (value1.X);
678 result.Y = (value1.Y > value2.Y) ? (value2.Y) : (value1.Y);
679 result.Z = (value1.Z > value2.Z) ? (value2.Z) : (value1.Z);
690 [
System.ComponentModel.Description(
"The Magnitude on the X-Axis")]
699 [
System.ComponentModel.Description(
"The Magnitude on the Y-Axis")]
708 [
System.ComponentModel.Description(
"The Magnitude on the Z-Axis")]
719 [InstanceConstructor(
"X,Y,Z")]
730 Copy(vals, index, out
this);
743 public Scalar this[
int index]
750 fixed (
Scalar* ptr = &this.X)
758 ThrowHelper.CheckIndex(
"index", index,
Count);
761 fixed (
Scalar* ptr = &this.X)
770 #region public properties
780 return MathHelper.
Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
794 return this.X * this.X + this.Y * this.Y + this.Z * this.
Z;
814 #region public methods
818 Copy(ref
this, array, 0);
823 Copy(array, index, out
this);
827 Copy(ref
this, array, index);
841 result.
X = left.
X + right.
X;
842 result.
Y = left.
Y + right.
Y;
843 result.
Z = left.
Z + right.
Z;
849 Add(ref left, ref right, out result);
855 Add(ref left, ref right, out result);
868 result.
X = left.
X - right.
X;
869 result.
Y = left.
Y - right.
Y;
870 result.
Z = left.
Z - right.
Z;
876 Subtract(ref left, ref right, out result);
882 Subtract(ref left, ref right, out result);
895 result.
X = source.
X * scalar;
896 result.
Y = source.
Y * scalar;
897 result.
Z = source.
Z * scalar;
910 result.
X = scalar * source.
X;
911 result.
Y = scalar * source.
Y;
912 result.
Z = scalar * source.
Z;
924 return left.
X * right.
X + left.
Y * right.
Y + left.
Z * right.
Z;
941 Scalar inverseW = 1 / (matrix.
m30 * vector.
X + matrix.
m31 * vector.
Y + matrix.
m32 * vector.
Z + matrix.
m33);
942 result.
X = ((matrix.
m00 * vector.
X) + (matrix.
m01 * vector.
Y) + (matrix.
m02 * vector.
Z) + matrix.
m03) * inverseW;
943 result.
Y = ((matrix.
m10 * vector.
X) + (matrix.
m11 * vector.
Y) + (matrix.
m12 * vector.
Z) + matrix.
m13) * inverseW;
944 result.
Z = ((matrix.
m20 * vector.
X) + (matrix.
m21 * vector.
Y) + (matrix.
m22 * vector.
Z) + matrix.
m23) * inverseW;
958 result.
X = matrix.
m00 * vector.
X + matrix.
m01 * vector.
Y + matrix.
m02 * vector.
Z;
959 result.
Y = matrix.
m10 * vector.
X + matrix.
m11 * vector.
Y + matrix.
m12 * vector.
Z;
960 result.
Z = matrix.
m20 * vector.
X + matrix.
m21 * vector.
Y + matrix.
m22 * vector.
Z;
973 Cross(ref qvec, ref vector, out uv);
974 Cross(ref qvec, ref uv, out uuv);
975 Cross(ref qvec, ref uv, out uuv);
977 Add(ref uv, ref uuv, out uv);
979 Add(ref vector, ref uv, out uv);
1002 result.
X = matrix.
m00 * vector.
X + matrix.
m01 * vector.
Y + matrix.
m02 * vector.
Z;
1003 result.
Y = matrix.
m10 * vector.
X + matrix.
m11 * vector.
Y + matrix.
m12 * vector.
Z;
1004 result.
Z = matrix.
m20 * vector.
X + matrix.
m21 * vector.
Y + matrix.
m22 * vector.
Z;
1016 result.
X = -source.
X;
1017 result.
Y = -source.
Y;
1018 result.
Z = -source.
Z;
1033 result.
X = left.
Y * right.
Z - left.
Z * right.
Y;
1034 result.
Y = left.
Z * right.
X - left.
X * right.
Z;
1035 result.
Z = left.
X * right.
Y - left.
Y * right.
X;
1046 return left.
X == right.
X && left.
Y == right.
Y && left.
Z == right.
Z;
1056 return !(left.
X == right.
X && left.
Y == right.
Y && left.
Z == right.
Z);
1062 result.
X = source.
X;
1063 result.
Y = source.
Y;
1071 result.
X = source.
X;
1072 result.
Y = source.
Y;
1073 result.
Z = source.
Z;
1091#if !CompactFramework && !WindowsCE && !PocketPC && !XBOX360 && !SILVERLIGHT
1100 if (vals.Length !=
Count)
1105 if (
Scalar.TryParse(vals[0], out result.X) &&
1106 Scalar.TryParse(vals[1], out result.Y) &&
1107 Scalar.TryParse(vals[2], out result.Z))
1123 throw new ArgumentNullException(
"s");
1126 if (vals.Length !=
Count)
1131 value.
X =
Scalar.Parse(vals[0]);
1132 value.
Y =
Scalar.Parse(vals[1]);
1133 value.
Z =
Scalar.Parse(vals[2]);
1148 return X.GetHashCode() ^
Y.GetHashCode() ^
Z.GetHashCode();
1163 return Equals(ref
this, ref other);
1168 left.
X == right.
X &&
1169 left.
Y == right.
Y &&
1175 left.X == right.X &&
1176 left.Y == right.Y &&
static Scalar Clamp(Scalar value, Scalar min, Scalar max)
static Scalar Sqrt(Scalar d)
static void HermiteHelper(Scalar amount, out Scalar h1, out Scalar h2, out Scalar h3, out Scalar h4)
static string CreateVectorFormatableString(int Count)
static string CreateVectorFormatString(int Count)
static string[] SplitStringVector(string s)
static void ThrowVectorFormatException(string value, int count, string format)
static void CheckCopy(Scalar[] array, int index, int count)
int Count
Gets a 32-bit integer that represents the total number of elements in all the dimensions of IAdvanceV...
A 3x3 matrix which can represent rotations around axes.
Summary description for Quaternion.
This is the Vector Class.
Scalar X
This is the X value. (Usually represents a horizontal position or direction.)
Scalar Y
This is the Y value. (Usually represents a vertical position or direction.)
A Vector with 3 dimensions.
static Vector3D Add(Vector3D left, Vector2D right)
static readonly Vector3D XAxis
Vector3D(1,0,0)
const int Size
The Size of the class in bytes;
Scalar MagnitudeSq
Gets the Squared Magnitude of the Vector3D.
static void Copy(Scalar[] sourceArray, int index, out Vector3D result)
static void Copy(ref Vector4D source, out Vector3D dest)
static void Normalize(ref Vector3D source)
override int GetHashCode()
Provides a unique hash code based on the member variables of this class. This should be done because ...
static Vector3D Min(Vector3D value1, Vector3D value2)
static bool operator!=(Vector3D left, Vector3D right)
Specifies whether the Vector3Ds do not contain the same coordinates.
static bool Equals(ref Vector3D left, ref Vector3D right)
Scalar X
This is the X value.
void CopyFrom(Scalar[] array, int index)
static void Negate(ref Vector3D source)
static void Transform(ref Vector3D vector, ref Matrix3x3 matrix, out Vector3D result)
static void Multiply(ref Vector3D source, ref Scalar scalar, out Vector3D result)
static void Multiply(ref Quaternion quat, ref Vector3D vector, out Vector3D result)
static void Transform(ref Matrix3x3 matrix, ref Vector3D vector, out Vector3D result)
static void Add(ref Vector2D left, ref Vector3D right, out Vector3D result)
static void Subtract(ref Vector3D left, ref Vector3D right, out Vector3D result)
static Scalar Dot(Vector3D left, Vector3D right)
Does a Dot Operation Also know as an Inner Product.
static Vector3D Subtract(Vector3D left, Vector3D right)
Subtracts 2 Vector3Ds.
static Vector3D Lerp(Vector3D left, Vector3D right, Scalar amount)
void CopyTo(Scalar[] array, int index)
static void Negate(ref Vector3D source, out Vector3D result)
static Vector3D Lerp(Vector3D left, Vector3D right, Vector3D amount)
static void Normalize(ref Vector3D source, out Vector3D result)
static void Subtract(ref Vector2D left, ref Vector3D right, out Vector3D result)
static void Lerp(ref Vector3D left, ref Vector3D right, ref Vector3D amount, out Vector3D result)
static Vector3D Transform(Vector3D vector, Matrix3x3 matrix)
vector * matrix [1x3 * 3x3 = 1x3]
static Vector3D Negate(Vector3D source)
Negates a Vector3D.
static void Min(ref Vector3D value1, ref Vector3D value2, out Vector3D result)
static void Copy(ref Vector3D vector, Scalar[] destArray, int index)
static void Distance(ref Vector3D left, ref Vector3D right, out Scalar result)
bool Equals(Vector3D other)
static Vector3D operator-(Vector3D left, Vector3D right)
Subtracts 2 Vector3Ds.
static Vector3D Multiply(Scalar scalar, Vector3D source)
Does Scaler Multiplication on a Vector3D.
static readonly Vector3D ZAxis
Vector3D(0,0,1)
Vector3D(Scalar[] vals, int index)
static void Add(ref Vector3D left, ref Vector2D right, out Vector3D result)
static readonly Vector3D One
Vector3D(1,1,1)
static Vector3D operator+(Vector3D left, Vector3D right)
Adds 2 Vectors2Ds.
static Vector3D Cross(Vector3D left, Vector3D right)
Does a Cross Operation Also know as an Outer Product.
static void Subtract(ref Vector3D left, ref Vector2D right, out Vector3D result)
static Vector3D Normalize(Vector3D source)
This returns the Normalized Vector3D that is passed. This is also known as a Unit Vector.
static Vector3D Hermite(Vector3D value1, Vector3D tangent1, Vector3D value2, Vector3D tangent2, Scalar amount)
static Scalar GetMagnitudeSq(Vector3D source)
Gets the Squared Magnitude of the Vector3D that is passed.
Scalar Magnitude
Gets or Sets the Magnitude (Length) of the Vector3D.
static readonly Vector3D Zero
Vector3D(0,0,0)
static void GetMagnitude(ref Vector3D source, out Scalar result)
static Scalar GetMagnitude(Vector3D source)
Gets the Magnitude of the Vector3D that is passed.
static void Project(ref Vector3D left, ref Vector3D right, out Vector3D result)
static Vector3D Clamp(Vector3D value, Vector3D min, Vector3D max)
const int Count
The number of Scalar values in the class.
static Vector3D Subtract(Vector3D left, Vector2D right)
static Vector3D Subtract(Vector2D left, Vector3D right)
string ToStringInternal(string FormatString)
Vector3D(Scalar X, Scalar Y, Scalar Z)
Creates a New Vector3D Instance on the Stack.
static void Copy(ref Vector2D source, ref Vector3D dest)
static Vector3D Multiply(Vector3D source, Scalar scalar)
Does Scaler Multiplication on a Vector3D.
static Scalar Distance(Vector3D left, Vector3D right)
static void Copy(ref Vector3D vector, Scalar[] destArray)
static Vector3D Parse(string s)
static Vector3D Transform(Matrix4x4 matrix, Vector3D vector)
Transforms the given 3-D vector by the matrix, projecting the result back into w = 1....
string ToString(string format)
static void Hermite(ref Vector3D value1, ref Vector3D tangent1, ref Vector3D value2, ref Vector3D tangent2, Scalar amount, out Vector3D result)
static bool TryParse(string s, out Vector3D result)
static void DistanceSq(ref Vector3D left, ref Vector3D right, out Scalar result)
static readonly Vector3D YAxis
Vector3D(0,1,0)
static Vector3D Multiply(Quaternion quat, Vector3D vector)
override bool Equals(object obj)
Compares this Vector to another object. This should be done because the equality operators (==,...
static void Add(ref Vector3D left, ref Vector3D right, out Vector3D result)
static Vector3D CatmullRom(Vector3D value1, Vector3D value2, Vector3D value3, Vector3D value4, Scalar amount)
Vector3D Normalized
Gets the Normalized Vector3D. (Unit Vector)
static Vector3D Add(Vector3D left, Vector3D right)
Adds 2 Vectors2Ds.
static readonly string FormatableString
static Vector3D SetMagnitude(Vector3D source, Scalar magnitude)
Sets the Magnitude of a Vector3D.
static void Dot(ref Vector3D left, ref Vector3D right, out Scalar result)
static void GetMagnitudeSq(ref Vector3D source, out Scalar result)
static bool Equals(Vector3D left, Vector3D right)
static Vector3D operator*(Vector3D source, Scalar scalar)
Does Scaler Multiplication on a Vector3D.
Scalar Y
This is the Y value.
static void Clamp(ref Vector3D value, ref Vector3D min, ref Vector3D max, out Vector3D result)
static void Max(ref Vector3D value1, ref Vector3D value2, out Vector3D result)
static Vector3D Transform(Matrix3x3 matrix, Vector3D vector)
matrix * vector [3x3 * 3x1 = 3x1]
static void Cross(ref Vector3D left, ref Vector3D right, out Vector3D result)
static Vector3D Max(Vector3D value1, Vector3D value2)
static Vector3D operator^(Vector3D left, Vector3D right)
Does a "2D" Cross Product also know as an Outer Product.
static void Lerp(ref Vector3D left, ref Vector3D right, ref Scalar amount, out Vector3D result)
static void Copy(Scalar[] sourceArray, out Vector3D result)
static Scalar DistanceSq(Vector3D left, Vector3D right)
Scalar Z
This is the Z value.
static Vector3D Project(Vector3D left, Vector3D right)
Thie Projects the left Vector3D onto the Right Vector3D.
int IAdvanceValueType. Count
The Number of Variables accesable though the indexer.
static void Transform(ref Matrix4x4 matrix, ref Vector3D vector, out Vector3D result)
static void CatmullRom(ref Vector3D value1, ref Vector3D value2, ref Vector3D value3, ref Vector3D value4, Scalar amount, out Vector3D result)
static void Multiply(ref Scalar scalar, ref Vector3D source, out Vector3D result)
override string ToString()
static readonly string FormatString
static Vector3D Add(Vector2D left, Vector3D right)
static bool operator==(Vector3D left, Vector3D right)
Specifies whether the Vector3Ds contain the same coordinates.
static void SetMagnitude(ref Vector3D source, ref Scalar magnitude, out Vector3D result)
A Vector with 4 dimensions.
Scalar X
This is the X value.
Scalar Y
This is the Y value.
Scalar Z
This is the Z value.