00001 #region --- License ---
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #endregion
00024
00025 using System;
00026 using System.Runtime.InteropServices;
00027 using System.Xml.Serialization;
00028
00029 namespace OpenTK
00030 {
00034 [Serializable]
00035 [StructLayout(LayoutKind.Sequential)]
00036 public struct Vector3d : IEquatable<Vector3d>
00037 {
00038 #region Fields
00039
00043 public double X;
00044
00048 public double Y;
00049
00053 public double Z;
00054
00055 #endregion
00056
00057 #region Constructors
00058
00065 public Vector3d(double x, double y, double z)
00066 {
00067 X = x;
00068 Y = y;
00069 Z = z;
00070 }
00071
00076 public Vector3d(Vector2d v)
00077 {
00078 X = v.X;
00079 Y = v.Y;
00080 Z = 0.0f;
00081 }
00082
00087 public Vector3d(Vector3d v)
00088 {
00089 X = v.X;
00090 Y = v.Y;
00091 Z = v.Z;
00092 }
00093
00098 public Vector3d(Vector4d v)
00099 {
00100 X = v.X;
00101 Y = v.Y;
00102 Z = v.Z;
00103 }
00104
00105
00106 #endregion
00107
00108 #region Public Members
00109
00110 #region Instance
00111
00112 #region public void Add()
00113
00116 [Obsolete("Use static Add() method instead.")]
00117 public void Add(Vector3d right)
00118 {
00119 this.X += right.X;
00120 this.Y += right.Y;
00121 this.Z += right.Z;
00122 }
00123
00126 [CLSCompliant(false)]
00127 [Obsolete("Use static Add() method instead.")]
00128 public void Add(ref Vector3d right)
00129 {
00130 this.X += right.X;
00131 this.Y += right.Y;
00132 this.Z += right.Z;
00133 }
00134
00135 #endregion public void Add()
00136
00137 #region public void Sub()
00138
00141 [Obsolete("Use static Subtract() method instead.")]
00142 public void Sub(Vector3d right)
00143 {
00144 this.X -= right.X;
00145 this.Y -= right.Y;
00146 this.Z -= right.Z;
00147 }
00148
00151 [CLSCompliant(false)]
00152 [Obsolete("Use static Subtract() method instead.")]
00153 public void Sub(ref Vector3d right)
00154 {
00155 this.X -= right.X;
00156 this.Y -= right.Y;
00157 this.Z -= right.Z;
00158 }
00159
00160 #endregion public void Sub()
00161
00162 #region public void Mult()
00163
00166 [Obsolete("Use static Multiply() method instead.")]
00167 public void Mult(double f)
00168 {
00169 this.X *= f;
00170 this.Y *= f;
00171 this.Z *= f;
00172 }
00173
00174 #endregion public void Mult()
00175
00176 #region public void Div()
00177
00180 [Obsolete("Use static Divide() method instead.")]
00181 public void Div(double f)
00182 {
00183 double mult = 1.0 / f;
00184 this.X *= mult;
00185 this.Y *= mult;
00186 this.Z *= mult;
00187 }
00188
00189 #endregion public void Div()
00190
00191 #region public double Length
00192
00198 public double Length
00199 {
00200 get
00201 {
00202 return System.Math.Sqrt(X * X + Y * Y + Z * Z);
00203 }
00204 }
00205
00206 #endregion
00207
00208 #region public double LengthFast
00209
00219 public double LengthFast
00220 {
00221 get
00222 {
00223 return 1.0 / MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
00224 }
00225 }
00226
00227 #endregion
00228
00229 #region public double LengthSquared
00230
00240 public double LengthSquared
00241 {
00242 get
00243 {
00244 return X * X + Y * Y + Z * Z;
00245 }
00246 }
00247
00248 #endregion
00249
00250 #region public void Normalize()
00251
00255 public void Normalize()
00256 {
00257 double scale = 1.0 / this.Length;
00258 X *= scale;
00259 Y *= scale;
00260 Z *= scale;
00261 }
00262
00263 #endregion
00264
00265 #region public void NormalizeFast()
00266
00270 public void NormalizeFast()
00271 {
00272 double scale = MathHelper.InverseSqrtFast(X * X + Y * Y + Z * Z);
00273 X *= scale;
00274 Y *= scale;
00275 Z *= scale;
00276 }
00277
00278 #endregion
00279
00280 #region public void Scale()
00281
00288 [Obsolete("Use static Multiply() method instead.")]
00289 public void Scale(double sx, double sy, double sz)
00290 {
00291 this.X = X * sx;
00292 this.Y = Y * sy;
00293 this.Z = Z * sz;
00294 }
00295
00298 [Obsolete("Use static Multiply() method instead.")]
00299 public void Scale(Vector3d scale)
00300 {
00301 this.X *= scale.X;
00302 this.Y *= scale.Y;
00303 this.Z *= scale.Z;
00304 }
00305
00308 [CLSCompliant(false)]
00309 [Obsolete("Use static Multiply() method instead.")]
00310 public void Scale(ref Vector3d scale)
00311 {
00312 this.X *= scale.X;
00313 this.Y *= scale.Y;
00314 this.Z *= scale.Z;
00315 }
00316
00317 #endregion public void Scale()
00318
00319 #endregion
00320
00321 #region Static
00322
00323 #region Fields
00324
00328 public static readonly Vector3d UnitX = new Vector3d(1, 0, 0);
00329
00333 public static readonly Vector3d UnitY = new Vector3d(0, 1, 0);
00334
00338 public static readonly Vector3d UnitZ = new Vector3d(0, 0, 1);
00339
00343 public static readonly Vector3d Zero = new Vector3d(0, 0, 0);
00344
00348 public static readonly Vector3d One = new Vector3d(1, 1, 1);
00349
00353 public static readonly int SizeInBytes = Marshal.SizeOf(new Vector3d());
00354
00355 #endregion
00356
00357 #region Obsolete
00358
00359 #region Sub
00360
00367 [Obsolete("Use static Subtract() method instead.")]
00368 public static Vector3d Sub(Vector3d a, Vector3d b)
00369 {
00370 a.X -= b.X;
00371 a.Y -= b.Y;
00372 a.Z -= b.Z;
00373 return a;
00374 }
00375
00382 [Obsolete("Use static Subtract() method instead.")]
00383 public static void Sub(ref Vector3d a, ref Vector3d b, out Vector3d result)
00384 {
00385 result.X = a.X - b.X;
00386 result.Y = a.Y - b.Y;
00387 result.Z = a.Z - b.Z;
00388 }
00389
00390 #endregion
00391
00392 #region Mult
00393
00400 [Obsolete("Use static Multiply() method instead.")]
00401 public static Vector3d Mult(Vector3d a, double f)
00402 {
00403 a.X *= f;
00404 a.Y *= f;
00405 a.Z *= f;
00406 return a;
00407 }
00408
00415 [Obsolete("Use static Multiply() method instead.")]
00416 public static void Mult(ref Vector3d a, double f, out Vector3d result)
00417 {
00418 result.X = a.X * f;
00419 result.Y = a.Y * f;
00420 result.Z = a.Z * f;
00421 }
00422
00423 #endregion
00424
00425 #region Div
00426
00433 [Obsolete("Use static Divide() method instead.")]
00434 public static Vector3d Div(Vector3d a, double f)
00435 {
00436 double mult = 1.0 / f;
00437 a.X *= mult;
00438 a.Y *= mult;
00439 a.Z *= mult;
00440 return a;
00441 }
00442
00449 [Obsolete("Use static Divide() method instead.")]
00450 public static void Div(ref Vector3d a, double f, out Vector3d result)
00451 {
00452 double mult = 1.0 / f;
00453 result.X = a.X * mult;
00454 result.Y = a.Y * mult;
00455 result.Z = a.Z * mult;
00456 }
00457
00458 #endregion
00459
00460 #endregion
00461
00462 #region Add
00463
00470 public static Vector3d Add(Vector3d a, Vector3d b)
00471 {
00472 Add(ref a, ref b, out a);
00473 return a;
00474 }
00475
00482 public static void Add(ref Vector3d a, ref Vector3d b, out Vector3d result)
00483 {
00484 result = new Vector3d(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
00485 }
00486
00487 #endregion
00488
00489 #region Subtract
00490
00497 public static Vector3d Subtract(Vector3d a, Vector3d b)
00498 {
00499 Subtract(ref a, ref b, out a);
00500 return a;
00501 }
00502
00509 public static void Subtract(ref Vector3d a, ref Vector3d b, out Vector3d result)
00510 {
00511 result = new Vector3d(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
00512 }
00513
00514 #endregion
00515
00516 #region Multiply
00517
00524 public static Vector3d Multiply(Vector3d vector, double scale)
00525 {
00526 Multiply(ref vector, scale, out vector);
00527 return vector;
00528 }
00529
00536 public static void Multiply(ref Vector3d vector, double scale, out Vector3d result)
00537 {
00538 result = new Vector3d(vector.X * scale, vector.Y * scale, vector.Z * scale);
00539 }
00540
00547 public static Vector3d Multiply(Vector3d vector, Vector3d scale)
00548 {
00549 Multiply(ref vector, ref scale, out vector);
00550 return vector;
00551 }
00552
00559 public static void Multiply(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
00560 {
00561 result = new Vector3d(vector.X * scale.X, vector.Y * scale.Y, vector.Z * scale.Z);
00562 }
00563
00564 #endregion
00565
00566 #region Divide
00567
00574 public static Vector3d Divide(Vector3d vector, double scale)
00575 {
00576 Divide(ref vector, scale, out vector);
00577 return vector;
00578 }
00579
00586 public static void Divide(ref Vector3d vector, double scale, out Vector3d result)
00587 {
00588 Multiply(ref vector, 1 / scale, out result);
00589 }
00590
00597 public static Vector3d Divide(Vector3d vector, Vector3d scale)
00598 {
00599 Divide(ref vector, ref scale, out vector);
00600 return vector;
00601 }
00602
00609 public static void Divide(ref Vector3d vector, ref Vector3d scale, out Vector3d result)
00610 {
00611 result = new Vector3d(vector.X / scale.X, vector.Y / scale.Y, vector.Z / scale.Z);
00612 }
00613
00614 #endregion
00615
00616 #region ComponentMin
00617
00624 public static Vector3d ComponentMin(Vector3d a, Vector3d b)
00625 {
00626 a.X = a.X < b.X ? a.X : b.X;
00627 a.Y = a.Y < b.Y ? a.Y : b.Y;
00628 a.Z = a.Z < b.Z ? a.Z : b.Z;
00629 return a;
00630 }
00631
00638 public static void ComponentMin(ref Vector3d a, ref Vector3d b, out Vector3d result)
00639 {
00640 result.X = a.X < b.X ? a.X : b.X;
00641 result.Y = a.Y < b.Y ? a.Y : b.Y;
00642 result.Z = a.Z < b.Z ? a.Z : b.Z;
00643 }
00644
00645 #endregion
00646
00647 #region ComponentMax
00648
00655 public static Vector3d ComponentMax(Vector3d a, Vector3d b)
00656 {
00657 a.X = a.X > b.X ? a.X : b.X;
00658 a.Y = a.Y > b.Y ? a.Y : b.Y;
00659 a.Z = a.Z > b.Z ? a.Z : b.Z;
00660 return a;
00661 }
00662
00669 public static void ComponentMax(ref Vector3d a, ref Vector3d b, out Vector3d result)
00670 {
00671 result.X = a.X > b.X ? a.X : b.X;
00672 result.Y = a.Y > b.Y ? a.Y : b.Y;
00673 result.Z = a.Z > b.Z ? a.Z : b.Z;
00674 }
00675
00676 #endregion
00677
00678 #region Min
00679
00686 public static Vector3d Min(Vector3d left, Vector3d right)
00687 {
00688 return left.LengthSquared < right.LengthSquared ? left : right;
00689 }
00690
00691 #endregion
00692
00693 #region Max
00694
00701 public static Vector3d Max(Vector3d left, Vector3d right)
00702 {
00703 return left.LengthSquared >= right.LengthSquared ? left : right;
00704 }
00705
00706 #endregion
00707
00708 #region Clamp
00709
00717 public static Vector3d Clamp(Vector3d vec, Vector3d min, Vector3d max)
00718 {
00719 vec.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
00720 vec.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
00721 vec.Z = vec.Z < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z;
00722 return vec;
00723 }
00724
00732 public static void Clamp(ref Vector3d vec, ref Vector3d min, ref Vector3d max, out Vector3d result)
00733 {
00734 result.X = vec.X < min.X ? min.X : vec.X > max.X ? max.X : vec.X;
00735 result.Y = vec.Y < min.Y ? min.Y : vec.Y > max.Y ? max.Y : vec.Y;
00736 result.Z = vec.Z < min.Z ? min.Z : vec.Z > max.Z ? max.Z : vec.Z;
00737 }
00738
00739 #endregion
00740
00741 #region Normalize
00742
00748 public static Vector3d Normalize(Vector3d vec)
00749 {
00750 double scale = 1.0 / vec.Length;
00751 vec.X *= scale;
00752 vec.Y *= scale;
00753 vec.Z *= scale;
00754 return vec;
00755 }
00756
00762 public static void Normalize(ref Vector3d vec, out Vector3d result)
00763 {
00764 double scale = 1.0 / vec.Length;
00765 result.X = vec.X * scale;
00766 result.Y = vec.Y * scale;
00767 result.Z = vec.Z * scale;
00768 }
00769
00770 #endregion
00771
00772 #region NormalizeFast
00773
00779 public static Vector3d NormalizeFast(Vector3d vec)
00780 {
00781 double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
00782 vec.X *= scale;
00783 vec.Y *= scale;
00784 vec.Z *= scale;
00785 return vec;
00786 }
00787
00793 public static void NormalizeFast(ref Vector3d vec, out Vector3d result)
00794 {
00795 double scale = MathHelper.InverseSqrtFast(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);
00796 result.X = vec.X * scale;
00797 result.Y = vec.Y * scale;
00798 result.Z = vec.Z * scale;
00799 }
00800
00801 #endregion
00802
00803 #region Dot
00804
00811 public static double Dot(Vector3d left, Vector3d right)
00812 {
00813 return left.X * right.X + left.Y * right.Y + left.Z * right.Z;
00814 }
00815
00822 public static void Dot(ref Vector3d left, ref Vector3d right, out double result)
00823 {
00824 result = left.X * right.X + left.Y * right.Y + left.Z * right.Z;
00825 }
00826
00827 #endregion
00828
00829 #region Cross
00830
00837 public static Vector3d Cross(Vector3d left, Vector3d right)
00838 {
00839 Vector3d result;
00840 Cross(ref left, ref right, out result);
00841 return result;
00842 }
00843
00851 public static void Cross(ref Vector3d left, ref Vector3d right, out Vector3d result)
00852 {
00853 result = new Vector3d(left.Y * right.Z - left.Z * right.Y,
00854 left.Z * right.X - left.X * right.Z,
00855 left.X * right.Y - left.Y * right.X);
00856 }
00857
00858 #endregion
00859
00860 #region Lerp
00861
00869 public static Vector3d Lerp(Vector3d a, Vector3d b, double blend)
00870 {
00871 a.X = blend * (b.X - a.X) + a.X;
00872 a.Y = blend * (b.Y - a.Y) + a.Y;
00873 a.Z = blend * (b.Z - a.Z) + a.Z;
00874 return a;
00875 }
00876
00884 public static void Lerp(ref Vector3d a, ref Vector3d b, double blend, out Vector3d result)
00885 {
00886 result.X = blend * (b.X - a.X) + a.X;
00887 result.Y = blend * (b.Y - a.Y) + a.Y;
00888 result.Z = blend * (b.Z - a.Z) + a.Z;
00889 }
00890
00891 #endregion
00892
00893 #region Barycentric
00894
00904 public static Vector3d BaryCentric(Vector3d a, Vector3d b, Vector3d c, double u, double v)
00905 {
00906 return a + u * (b - a) + v * (c - a);
00907 }
00908
00916 public static void BaryCentric(ref Vector3d a, ref Vector3d b, ref Vector3d c, double u, double v, out Vector3d result)
00917 {
00918 result = a;
00919
00920 Vector3d temp = b;
00921 Subtract(ref temp, ref a, out temp);
00922 Multiply(ref temp, u, out temp);
00923 Add(ref result, ref temp, out result);
00924
00925 temp = c;
00926 Subtract(ref temp, ref a, out temp);
00927 Multiply(ref temp, v, out temp);
00928 Add(ref result, ref temp, out result);
00929 }
00930
00931 #endregion
00932
00933 #region Transform
00934
00941 public static Vector3d TransformVector(Vector3d vec, Matrix4d mat)
00942 {
00943 return new Vector3d(
00944 Vector3d.Dot(vec, new Vector3d(mat.Column0)),
00945 Vector3d.Dot(vec, new Vector3d(mat.Column1)),
00946 Vector3d.Dot(vec, new Vector3d(mat.Column2)));
00947 }
00948
00955 public static void TransformVector(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
00956 {
00957 result.X = vec.X * mat.Row0.X +
00958 vec.Y * mat.Row1.X +
00959 vec.Z * mat.Row2.X;
00960
00961 result.Y = vec.X * mat.Row0.Y +
00962 vec.Y * mat.Row1.Y +
00963 vec.Z * mat.Row2.Y;
00964
00965 result.Z = vec.X * mat.Row0.Z +
00966 vec.Y * mat.Row1.Z +
00967 vec.Z * mat.Row2.Z;
00968 }
00969
00978 public static Vector3d TransformNormal(Vector3d norm, Matrix4d mat)
00979 {
00980 mat.Invert();
00981 return TransformNormalInverse(norm, mat);
00982 }
00983
00992 public static void TransformNormal(ref Vector3d norm, ref Matrix4d mat, out Vector3d result)
00993 {
00994 Matrix4d Inverse = Matrix4d.Invert(mat);
00995 Vector3d.TransformNormalInverse(ref norm, ref Inverse, out result);
00996 }
00997
01006 public static Vector3d TransformNormalInverse(Vector3d norm, Matrix4d invMat)
01007 {
01008 return new Vector3d(
01009 Vector3d.Dot(norm, new Vector3d(invMat.Row0)),
01010 Vector3d.Dot(norm, new Vector3d(invMat.Row1)),
01011 Vector3d.Dot(norm, new Vector3d(invMat.Row2)));
01012 }
01013
01022 public static void TransformNormalInverse(ref Vector3d norm, ref Matrix4d invMat, out Vector3d result)
01023 {
01024 result.X = norm.X * invMat.Row0.X +
01025 norm.Y * invMat.Row0.Y +
01026 norm.Z * invMat.Row0.Z;
01027
01028 result.Y = norm.X * invMat.Row1.X +
01029 norm.Y * invMat.Row1.Y +
01030 norm.Z * invMat.Row1.Z;
01031
01032 result.Z = norm.X * invMat.Row2.X +
01033 norm.Y * invMat.Row2.Y +
01034 norm.Z * invMat.Row2.Z;
01035 }
01036
01041 public static Vector3d TransformPosition(Vector3d pos, Matrix4d mat)
01042 {
01043 return new Vector3d(
01044 Vector3d.Dot(pos, new Vector3d(mat.Column0)) + mat.Row3.X,
01045 Vector3d.Dot(pos, new Vector3d(mat.Column1)) + mat.Row3.Y,
01046 Vector3d.Dot(pos, new Vector3d(mat.Column2)) + mat.Row3.Z);
01047 }
01048
01053 public static void TransformPosition(ref Vector3d pos, ref Matrix4d mat, out Vector3d result)
01054 {
01055 result.X = pos.X * mat.Row0.X +
01056 pos.Y * mat.Row1.X +
01057 pos.Z * mat.Row2.X +
01058 mat.Row3.X;
01059
01060 result.Y = pos.X * mat.Row0.Y +
01061 pos.Y * mat.Row1.Y +
01062 pos.Z * mat.Row2.Y +
01063 mat.Row3.Y;
01064
01065 result.Z = pos.X * mat.Row0.Z +
01066 pos.Y * mat.Row1.Z +
01067 pos.Z * mat.Row2.Z +
01068 mat.Row3.Z;
01069 }
01070
01075 public static Vector3d Transform(Vector3d vec, Matrix4d mat)
01076 {
01077 Vector3d result;
01078 Transform(ref vec, ref mat, out result);
01079 return result;
01080 }
01081
01086 public static void Transform(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
01087 {
01088 Vector4d v4 = new Vector4d(vec.X, vec.Y, vec.Z, 1.0);
01089 Vector4d.Transform(ref v4, ref mat, out v4);
01090 result = v4.Xyz;
01091 }
01092
01099 public static Vector3d Transform(Vector3d vec, Quaterniond quat)
01100 {
01101 Vector3d result;
01102 Transform(ref vec, ref quat, out result);
01103 return result;
01104 }
01105
01112 public static void Transform(ref Vector3d vec, ref Quaterniond quat, out Vector3d result)
01113 {
01114
01115
01116 Vector3d xyz = quat.Xyz, temp, temp2;
01117 Vector3d.Cross(ref xyz, ref vec, out temp);
01118 Vector3d.Multiply(ref vec, quat.W, out temp2);
01119 Vector3d.Add(ref temp, ref temp2, out temp);
01120 Vector3d.Cross(ref xyz, ref temp, out temp);
01121 Vector3d.Multiply(ref temp, 2, out temp);
01122 Vector3d.Add(ref vec, ref temp, out result);
01123 }
01124
01131 public static Vector3d TransformPerspective(Vector3d vec, Matrix4d mat)
01132 {
01133 Vector3d result;
01134 TransformPerspective(ref vec, ref mat, out result);
01135 return result;
01136 }
01137
01142 public static void TransformPerspective(ref Vector3d vec, ref Matrix4d mat, out Vector3d result)
01143 {
01144 Vector4d v = new Vector4d(vec);
01145 Vector4d.Transform(ref v, ref mat, out v);
01146 result.X = v.X / v.W;
01147 result.Y = v.Y / v.W;
01148 result.Z = v.Z / v.W;
01149 }
01150
01151 #endregion
01152
01153 #region CalculateAngle
01154
01162 public static double CalculateAngle(Vector3d first, Vector3d second)
01163 {
01164 return System.Math.Acos((Vector3d.Dot(first, second)) / (first.Length * second.Length));
01165 }
01166
01172 public static void CalculateAngle(ref Vector3d first, ref Vector3d second, out double result)
01173 {
01174 double temp;
01175 Vector3d.Dot(ref first, ref second, out temp);
01176 result = System.Math.Acos(temp / (first.Length * second.Length));
01177 }
01178
01179 #endregion
01180
01181 #endregion
01182
01183 #region Swizzle
01184
01188 [XmlIgnore]
01189 public Vector2d Xy { get { return new Vector2d(X, Y); } set { X = value.X; Y = value.Y; } }
01190
01191 #endregion
01192
01193 #region Operators
01194
01201 public static Vector3d operator +(Vector3d left, Vector3d right)
01202 {
01203 left.X += right.X;
01204 left.Y += right.Y;
01205 left.Z += right.Z;
01206 return left;
01207 }
01208
01215 public static Vector3d operator -(Vector3d left, Vector3d right)
01216 {
01217 left.X -= right.X;
01218 left.Y -= right.Y;
01219 left.Z -= right.Z;
01220 return left;
01221 }
01222
01228 public static Vector3d operator -(Vector3d vec)
01229 {
01230 vec.X = -vec.X;
01231 vec.Y = -vec.Y;
01232 vec.Z = -vec.Z;
01233 return vec;
01234 }
01235
01242 public static Vector3d operator *(Vector3d vec, double scale)
01243 {
01244 vec.X *= scale;
01245 vec.Y *= scale;
01246 vec.Z *= scale;
01247 return vec;
01248 }
01249
01256 public static Vector3d operator *(double scale, Vector3d vec)
01257 {
01258 vec.X *= scale;
01259 vec.Y *= scale;
01260 vec.Z *= scale;
01261 return vec;
01262 }
01263
01270 public static Vector3d operator /(Vector3d vec, double scale)
01271 {
01272 double mult = 1 / scale;
01273 vec.X *= mult;
01274 vec.Y *= mult;
01275 vec.Z *= mult;
01276 return vec;
01277 }
01278
01285 public static bool operator ==(Vector3d left, Vector3d right)
01286 {
01287 return left.Equals(right);
01288 }
01289
01296 public static bool operator !=(Vector3d left, Vector3d right)
01297 {
01298 return !left.Equals(right);
01299 }
01300
01304 public static explicit operator Vector3d(Vector3 v3)
01305 {
01306 return new Vector3d(v3.X, v3.Y, v3.Z);
01307 }
01308
01312 public static explicit operator Vector3(Vector3d v3d)
01313 {
01314 return new Vector3((float)v3d.X, (float)v3d.Y, (float)v3d.Z);
01315 }
01316
01317 #endregion
01318
01319 #region Overrides
01320
01321 #region public override string ToString()
01322
01327 public override string ToString()
01328 {
01329 return String.Format("({0}, {1}, {2})", X, Y, Z);
01330 }
01331
01332 #endregion
01333
01334 #region public override int GetHashCode()
01335
01340 public override int GetHashCode()
01341 {
01342 return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
01343 }
01344
01345 #endregion
01346
01347 #region public override bool Equals(object obj)
01348
01354 public override bool Equals(object obj)
01355 {
01356 if (!(obj is Vector3))
01357 return false;
01358
01359 return this.Equals((Vector3)obj);
01360 }
01361
01362 #endregion
01363
01364 #endregion
01365
01366 #endregion
01367
01368 #region IEquatable<Vector3> Members
01369
01373 public bool Equals(Vector3d other)
01374 {
01375 return
01376 X == other.X &&
01377 Y == other.Y &&
01378 Z == other.Z;
01379 }
01380
01381 #endregion
01382 }
01383 }