From 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 16 Jul 2007 15:40:11 +0000 Subject: changed to native line ending encoding --- .../ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs | 1366 ++++++++++---------- .../MonoXnaCompactMaths/MonoXnaCompactMaths.csproj | 100 +- .../MonoXnaCompactMaths/Properties/AssemblyInfo.cs | 66 +- .../MonoXnaCompactMaths/Quaternion.cs | 692 +++++----- .../ModifiedBulletX/MonoXnaCompactMaths/Vector3.cs | 1240 +++++++++--------- .../ModifiedBulletX/MonoXnaCompactMaths/Vector4.cs | 1260 +++++++++--------- 6 files changed, 2362 insertions(+), 2362 deletions(-) (limited to 'libraries/ModifiedBulletX/MonoXnaCompactMaths') diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs index a104d89..22842ca 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Matrix.cs @@ -1,683 +1,683 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -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 License - -using System; -using System.ComponentModel; -using System.Runtime.InteropServices; - -namespace MonoXnaCompactMaths -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - //[TypeConverter(typeof(MatrixConverter))] - public struct Matrix : IEquatable - { - #region Public Constructors - - public Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, - float m32, float m33, float m34, float m41, float m42, float m43, float m44) - { - this.M11 = m11; - this.M12 = m12; - this.M13 = m13; - this.M14 = m14; - this.M21 = m21; - this.M22 = m22; - this.M23 = m23; - this.M24 = m24; - this.M31 = m31; - this.M32 = m32; - this.M33 = m33; - this.M34 = m34; - this.M41 = m41; - this.M42 = m42; - this.M43 = m43; - this.M44 = m44; - } - - #endregion Public Constructors - - - #region Public Fields - - public float M11; - public float M12; - public float M13; - public float M14; - public float M21; - public float M22; - public float M23; - public float M24; - public float M31; - public float M32; - public float M33; - public float M34; - public float M41; - public float M42; - public float M43; - public float M44; - - #endregion Public Fields - - - #region Private Members - private static Matrix identity = new Matrix(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f); - #endregion Private Members - - - #region Public Properties - - public Vector3 Backward - { - get - { - return new Vector3(this.M31, this.M32, this.M33); - } - set - { - this.M31 = value.X; - this.M32 = value.Y; - this.M33 = value.Z; - } - } - - - public Vector3 Down - { - get - { - return new Vector3(-this.M21, -this.M22, -this.M23); - } - set - { - this.M21 = -value.X; - this.M22 = -value.Y; - this.M23 = -value.Z; - } - } - - - public Vector3 Forward - { - get - { - return new Vector3(-this.M31, -this.M32, -this.M33); - } - set - { - this.M31 = -value.X; - this.M32 = -value.Y; - this.M33 = -value.Z; - } - } - - - public static Matrix Identity - { - get { return identity; } - } - - - public Vector3 Left - { - get - { - return new Vector3(-this.M11, -this.M12, -this.M13); - } - set - { - this.M11 = -value.X; - this.M12 = -value.Y; - this.M13 = -value.Z; - } - } - - - public Vector3 Right - { - get - { - return new Vector3(this.M11, this.M12, this.M13); - } - set - { - this.M11 = value.X; - this.M12 = value.Y; - this.M13 = value.Z; - } - } - - - public Vector3 Translation - { - get - { - return new Vector3(this.M41, this.M42, this.M43); - } - set - { - this.M41 = value.X; - this.M42 = value.Y; - this.M43 = value.Z; - } - } - - - public Vector3 Up - { - get - { - return new Vector3(this.M21, this.M22, this.M23); - } - set - { - this.M21 = value.X; - this.M22 = value.Y; - this.M23 = value.Z; - } - } - #endregion Public Properties - - - #region Public Methods - - public static Matrix Add(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static void Add(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition, - Vector3 cameraUpVector, Nullable cameraForwardVector) - { - throw new NotImplementedException(); - } - - - public static void CreateBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition, - ref Vector3 cameraUpVector, Vector3? cameraForwardVector, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateConstrainedBillboard(Vector3 objectPosition, Vector3 cameraPosition, - Vector3 rotateAxis, Nullable cameraForwardVector, Nullable objectForwardVector) - { - throw new NotImplementedException(); - } - - - public static void CreateConstrainedBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition, - ref Vector3 rotateAxis, Vector3? cameraForwardVector, Vector3? objectForwardVector, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateFromAxisAngle(Vector3 axis, float angle) - { - throw new NotImplementedException(); - } - - - public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateFromQuaternion(Quaternion quaternion) - { - //--- - //http://lists.ximian.com/pipermail/mono-patches/2006-December/084667.html - float xx = quaternion.X * quaternion.X; - float xy = quaternion.X * quaternion.Y; - float xw = quaternion.X * quaternion.W; - float yy = quaternion.Y * quaternion.Y; - float yw = quaternion.Y * quaternion.W; - float yz = quaternion.Y * quaternion.Z; - float zx = quaternion.Z * quaternion.X; - float zw = quaternion.Z * quaternion.W; - float zz = quaternion.Z * quaternion.Z; - return new Matrix(1f - (2f * (yy + zz)), 2f * (xy + zw), 2f * (zx - yw), 0f, 2f * (xy - zw), - 1f - (2f * (zz + xx)), 2f * (yz + xw), 0f, 2f * (zx + yw), 2f * (yz - xw), - 1f - (2f * (yy + xx)), 0f, 0f, 0f, 0f, 1f); - //throw new NotImplementedException(); - } - - - public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector) - { - throw new NotImplementedException(); - } - - - public static void CreateLookAt(ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) - { - throw new NotImplementedException(); - } - - - public static void CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) - { - throw new NotImplementedException(); - } - - - public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, - float zNearPlane, float zFarPlane, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreatePerspective(float width, float height, float zNearPlane, float zFarPlane) - { - throw new NotImplementedException(); - } - - - public static void CreatePerspective(float width, float height, float zNearPlane, float zFarPlane, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane) - { - throw new NotImplementedException(); - } - - - public static void CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) - { - throw new NotImplementedException(); - } - - - public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlaneDistance, float farPlaneDistance, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateRotationX(float radians) - { - throw new NotImplementedException(); - } - - - public static void CreateRotationX(float radians, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateRotationY(float radians) - { - throw new NotImplementedException(); - } - - - public static void CreateRotationY(float radians, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateRotationZ(float radians) - { - throw new NotImplementedException(); - } - - - public static void CreateRotationZ(float radians, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateScale(float scale) - { - throw new NotImplementedException(); - } - - - public static void CreateScale(float scale, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateScale(float xScale, float yScale, float zScale) - { - throw new NotImplementedException(); - } - - - public static void CreateScale(float xScale, float yScale, float zScale, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateScale(Vector3 scales) - { - throw new NotImplementedException(); - } - - - public static void CreateScale(ref Vector3 scales, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateTranslation(float xPosition, float yPosition, float zPosition) - { - throw new NotImplementedException(); - } - - - public static void CreateTranslation(ref Vector3 position, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix CreateTranslation(Vector3 position) - { - throw new NotImplementedException(); - } - - - public static void CreateTranslation(float xPosition, float yPosition, float zPosition, out Matrix result) - { - throw new NotImplementedException(); - } - - - public float Determinant() - { - throw new NotImplementedException(); - } - - - public static Matrix Divide(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix Divide(Matrix matrix1, float divider) - { - throw new NotImplementedException(); - } - - - public static void Divide(ref Matrix matrix1, float divider, out Matrix result) - { - throw new NotImplementedException(); - } - - - public bool Equals(Matrix other) - { - throw new NotImplementedException(); - } - - - public override bool Equals(object obj) - { - throw new NotImplementedException(); - } - - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - - - public static Matrix Invert(Matrix matrix) - { - throw new NotImplementedException(); - } - - - public static void Invert(ref Matrix matrix, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix Lerp(Matrix matrix1, Matrix matrix2, float amount) - { - throw new NotImplementedException(); - } - - - public static void Lerp(ref Matrix matrix1, ref Matrix matrix2, float amount, out Matrix result) - { - throw new NotImplementedException(); - } - - public static Matrix Multiply(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static void Multiply(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix Multiply(Matrix matrix1, float factor) - { - throw new NotImplementedException(); - } - - - public static void Multiply(ref Matrix matrix1, float factor, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix Negate(Matrix matrix) - { - throw new NotImplementedException(); - } - - - public static void Negate(ref Matrix matrix, out Matrix result) - { - throw new NotImplementedException(); - } - - - public static Matrix operator +(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static Matrix operator /(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static Matrix operator /(Matrix matrix1, float divider) - { - throw new NotImplementedException(); - } - - - public static bool operator ==(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static bool operator !=(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static Matrix operator *(Matrix matrix1, Matrix matrix2) - { - //--- - float[, ] arrayMatrix1 = new float[4, 4]; - float[, ] arrayMatrix2 = new float[4, 4]; - float[, ] arrayMatrixProduct = new float[4, 4]; - arrayMatrix1[0, 0] = matrix1.M11; arrayMatrix1[0, 1] = matrix1.M12; arrayMatrix1[0, 2] = matrix1.M13; arrayMatrix1[0, 3] = matrix1.M14; - arrayMatrix1[1, 0] = matrix1.M21; arrayMatrix1[1, 1] = matrix1.M22; arrayMatrix1[1, 2] = matrix1.M23; arrayMatrix1[1, 3] = matrix1.M24; - arrayMatrix1[2, 0] = matrix1.M31; arrayMatrix1[2, 1] = matrix1.M32; arrayMatrix1[2, 2] = matrix1.M33; arrayMatrix1[2, 3] = matrix1.M34; - arrayMatrix1[3, 0] = matrix1.M41; arrayMatrix1[3, 1] = matrix1.M42; arrayMatrix1[3, 2] = matrix1.M43; arrayMatrix1[3, 3] = matrix1.M44; - - arrayMatrix2[0, 0] = matrix2.M11; arrayMatrix2[0, 1] = matrix2.M12; arrayMatrix2[0, 2] = matrix2.M13; arrayMatrix2[0, 3] = matrix2.M14; - arrayMatrix2[1, 0] = matrix2.M21; arrayMatrix2[1, 1] = matrix2.M22; arrayMatrix2[1, 2] = matrix2.M23; arrayMatrix2[1, 3] = matrix2.M24; - arrayMatrix2[2, 0] = matrix2.M31; arrayMatrix2[2, 1] = matrix2.M32; arrayMatrix2[2, 2] = matrix2.M33; arrayMatrix2[2, 3] = matrix2.M34; - arrayMatrix2[3, 0] = matrix2.M41; arrayMatrix2[3, 1] = matrix2.M42; arrayMatrix2[3, 2] = matrix2.M43; arrayMatrix2[3, 3] = matrix2.M44; - - int n = 4; - for (int i = 0; i < n; i++) - { - for (int j = 0; j < n; j++) - { - // (AB)[i,j] = Sum(k=0; k < 4; k++) { A[i,k] * B[k, j] } - for (int k = 0; k < n; k++) - { - arrayMatrixProduct[i, j] += arrayMatrix1[i, k] * arrayMatrix2[k, j]; - } - } - } - return new Matrix( arrayMatrixProduct[0, 0], arrayMatrixProduct[0, 1], arrayMatrixProduct[0, 2], arrayMatrixProduct[0, 3], - arrayMatrixProduct[1, 0], arrayMatrixProduct[1, 1], arrayMatrixProduct[1, 2], arrayMatrixProduct[1, 3], - arrayMatrixProduct[2, 0], arrayMatrixProduct[2, 1], arrayMatrixProduct[2, 2], arrayMatrixProduct[2, 3], - arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 2], arrayMatrixProduct[3, 3]); - //--- - //throw new NotImplementedException(); - } - - - public static Matrix operator *(Matrix matrix, float scaleFactor) - { - throw new NotImplementedException(); - } - - - public static Matrix operator -(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static Matrix operator -(Matrix matrix1) - { - throw new NotImplementedException(); - } - - - public static Matrix Subtract(Matrix matrix1, Matrix matrix2) - { - throw new NotImplementedException(); - } - - - public static void Subtract(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - throw new NotImplementedException(); - } - - - public override string ToString() - { - throw new NotImplementedException(); - } - - - public static Matrix Transpose(Matrix matrix) - { - //--- - return new Matrix( matrix.M11, matrix.M21, matrix.M31, matrix.M41, - matrix.M12, matrix.M22, matrix.M32, matrix.M42, - matrix.M13, matrix.M23, matrix.M33, matrix.M43, - matrix.M14, matrix.M24, matrix.M34, matrix.M44); - //--- - //throw new NotImplementedException(); - } - - - public static void Transpose(ref Matrix matrix, out Matrix result) - { - throw new NotImplementedException(); - } - #endregion Public Methods - } -} +#region License +/* +MIT License +Copyright © 2006 The Mono.Xna Team + +All rights reserved. + +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 License + +using System; +using System.ComponentModel; +using System.Runtime.InteropServices; + +namespace MonoXnaCompactMaths +{ + [Serializable] + [StructLayout(LayoutKind.Sequential)] + //[TypeConverter(typeof(MatrixConverter))] + public struct Matrix : IEquatable + { + #region Public Constructors + + public Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, + float m32, float m33, float m34, float m41, float m42, float m43, float m44) + { + this.M11 = m11; + this.M12 = m12; + this.M13 = m13; + this.M14 = m14; + this.M21 = m21; + this.M22 = m22; + this.M23 = m23; + this.M24 = m24; + this.M31 = m31; + this.M32 = m32; + this.M33 = m33; + this.M34 = m34; + this.M41 = m41; + this.M42 = m42; + this.M43 = m43; + this.M44 = m44; + } + + #endregion Public Constructors + + + #region Public Fields + + public float M11; + public float M12; + public float M13; + public float M14; + public float M21; + public float M22; + public float M23; + public float M24; + public float M31; + public float M32; + public float M33; + public float M34; + public float M41; + public float M42; + public float M43; + public float M44; + + #endregion Public Fields + + + #region Private Members + private static Matrix identity = new Matrix(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f); + #endregion Private Members + + + #region Public Properties + + public Vector3 Backward + { + get + { + return new Vector3(this.M31, this.M32, this.M33); + } + set + { + this.M31 = value.X; + this.M32 = value.Y; + this.M33 = value.Z; + } + } + + + public Vector3 Down + { + get + { + return new Vector3(-this.M21, -this.M22, -this.M23); + } + set + { + this.M21 = -value.X; + this.M22 = -value.Y; + this.M23 = -value.Z; + } + } + + + public Vector3 Forward + { + get + { + return new Vector3(-this.M31, -this.M32, -this.M33); + } + set + { + this.M31 = -value.X; + this.M32 = -value.Y; + this.M33 = -value.Z; + } + } + + + public static Matrix Identity + { + get { return identity; } + } + + + public Vector3 Left + { + get + { + return new Vector3(-this.M11, -this.M12, -this.M13); + } + set + { + this.M11 = -value.X; + this.M12 = -value.Y; + this.M13 = -value.Z; + } + } + + + public Vector3 Right + { + get + { + return new Vector3(this.M11, this.M12, this.M13); + } + set + { + this.M11 = value.X; + this.M12 = value.Y; + this.M13 = value.Z; + } + } + + + public Vector3 Translation + { + get + { + return new Vector3(this.M41, this.M42, this.M43); + } + set + { + this.M41 = value.X; + this.M42 = value.Y; + this.M43 = value.Z; + } + } + + + public Vector3 Up + { + get + { + return new Vector3(this.M21, this.M22, this.M23); + } + set + { + this.M21 = value.X; + this.M22 = value.Y; + this.M23 = value.Z; + } + } + #endregion Public Properties + + + #region Public Methods + + public static Matrix Add(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static void Add(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition, + Vector3 cameraUpVector, Nullable cameraForwardVector) + { + throw new NotImplementedException(); + } + + + public static void CreateBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition, + ref Vector3 cameraUpVector, Vector3? cameraForwardVector, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateConstrainedBillboard(Vector3 objectPosition, Vector3 cameraPosition, + Vector3 rotateAxis, Nullable cameraForwardVector, Nullable objectForwardVector) + { + throw new NotImplementedException(); + } + + + public static void CreateConstrainedBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition, + ref Vector3 rotateAxis, Vector3? cameraForwardVector, Vector3? objectForwardVector, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateFromAxisAngle(Vector3 axis, float angle) + { + throw new NotImplementedException(); + } + + + public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateFromQuaternion(Quaternion quaternion) + { + //--- + //http://lists.ximian.com/pipermail/mono-patches/2006-December/084667.html + float xx = quaternion.X * quaternion.X; + float xy = quaternion.X * quaternion.Y; + float xw = quaternion.X * quaternion.W; + float yy = quaternion.Y * quaternion.Y; + float yw = quaternion.Y * quaternion.W; + float yz = quaternion.Y * quaternion.Z; + float zx = quaternion.Z * quaternion.X; + float zw = quaternion.Z * quaternion.W; + float zz = quaternion.Z * quaternion.Z; + return new Matrix(1f - (2f * (yy + zz)), 2f * (xy + zw), 2f * (zx - yw), 0f, 2f * (xy - zw), + 1f - (2f * (zz + xx)), 2f * (yz + xw), 0f, 2f * (zx + yw), 2f * (yz - xw), + 1f - (2f * (yy + xx)), 0f, 0f, 0f, 0f, 1f); + //throw new NotImplementedException(); + } + + + public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector) + { + throw new NotImplementedException(); + } + + + public static void CreateLookAt(ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) + { + throw new NotImplementedException(); + } + + + public static void CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) + { + throw new NotImplementedException(); + } + + + public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, + float zNearPlane, float zFarPlane, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreatePerspective(float width, float height, float zNearPlane, float zFarPlane) + { + throw new NotImplementedException(); + } + + + public static void CreatePerspective(float width, float height, float zNearPlane, float zFarPlane, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float zNearPlane, float zFarPlane) + { + throw new NotImplementedException(); + } + + + public static void CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) + { + throw new NotImplementedException(); + } + + + public static void CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlaneDistance, float farPlaneDistance, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateRotationX(float radians) + { + throw new NotImplementedException(); + } + + + public static void CreateRotationX(float radians, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateRotationY(float radians) + { + throw new NotImplementedException(); + } + + + public static void CreateRotationY(float radians, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateRotationZ(float radians) + { + throw new NotImplementedException(); + } + + + public static void CreateRotationZ(float radians, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateScale(float scale) + { + throw new NotImplementedException(); + } + + + public static void CreateScale(float scale, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateScale(float xScale, float yScale, float zScale) + { + throw new NotImplementedException(); + } + + + public static void CreateScale(float xScale, float yScale, float zScale, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateScale(Vector3 scales) + { + throw new NotImplementedException(); + } + + + public static void CreateScale(ref Vector3 scales, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateTranslation(float xPosition, float yPosition, float zPosition) + { + throw new NotImplementedException(); + } + + + public static void CreateTranslation(ref Vector3 position, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix CreateTranslation(Vector3 position) + { + throw new NotImplementedException(); + } + + + public static void CreateTranslation(float xPosition, float yPosition, float zPosition, out Matrix result) + { + throw new NotImplementedException(); + } + + + public float Determinant() + { + throw new NotImplementedException(); + } + + + public static Matrix Divide(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix Divide(Matrix matrix1, float divider) + { + throw new NotImplementedException(); + } + + + public static void Divide(ref Matrix matrix1, float divider, out Matrix result) + { + throw new NotImplementedException(); + } + + + public bool Equals(Matrix other) + { + throw new NotImplementedException(); + } + + + public override bool Equals(object obj) + { + throw new NotImplementedException(); + } + + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + + + public static Matrix Invert(Matrix matrix) + { + throw new NotImplementedException(); + } + + + public static void Invert(ref Matrix matrix, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix Lerp(Matrix matrix1, Matrix matrix2, float amount) + { + throw new NotImplementedException(); + } + + + public static void Lerp(ref Matrix matrix1, ref Matrix matrix2, float amount, out Matrix result) + { + throw new NotImplementedException(); + } + + public static Matrix Multiply(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static void Multiply(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix Multiply(Matrix matrix1, float factor) + { + throw new NotImplementedException(); + } + + + public static void Multiply(ref Matrix matrix1, float factor, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix Negate(Matrix matrix) + { + throw new NotImplementedException(); + } + + + public static void Negate(ref Matrix matrix, out Matrix result) + { + throw new NotImplementedException(); + } + + + public static Matrix operator +(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static Matrix operator /(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static Matrix operator /(Matrix matrix1, float divider) + { + throw new NotImplementedException(); + } + + + public static bool operator ==(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static bool operator !=(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static Matrix operator *(Matrix matrix1, Matrix matrix2) + { + //--- + float[, ] arrayMatrix1 = new float[4, 4]; + float[, ] arrayMatrix2 = new float[4, 4]; + float[, ] arrayMatrixProduct = new float[4, 4]; + arrayMatrix1[0, 0] = matrix1.M11; arrayMatrix1[0, 1] = matrix1.M12; arrayMatrix1[0, 2] = matrix1.M13; arrayMatrix1[0, 3] = matrix1.M14; + arrayMatrix1[1, 0] = matrix1.M21; arrayMatrix1[1, 1] = matrix1.M22; arrayMatrix1[1, 2] = matrix1.M23; arrayMatrix1[1, 3] = matrix1.M24; + arrayMatrix1[2, 0] = matrix1.M31; arrayMatrix1[2, 1] = matrix1.M32; arrayMatrix1[2, 2] = matrix1.M33; arrayMatrix1[2, 3] = matrix1.M34; + arrayMatrix1[3, 0] = matrix1.M41; arrayMatrix1[3, 1] = matrix1.M42; arrayMatrix1[3, 2] = matrix1.M43; arrayMatrix1[3, 3] = matrix1.M44; + + arrayMatrix2[0, 0] = matrix2.M11; arrayMatrix2[0, 1] = matrix2.M12; arrayMatrix2[0, 2] = matrix2.M13; arrayMatrix2[0, 3] = matrix2.M14; + arrayMatrix2[1, 0] = matrix2.M21; arrayMatrix2[1, 1] = matrix2.M22; arrayMatrix2[1, 2] = matrix2.M23; arrayMatrix2[1, 3] = matrix2.M24; + arrayMatrix2[2, 0] = matrix2.M31; arrayMatrix2[2, 1] = matrix2.M32; arrayMatrix2[2, 2] = matrix2.M33; arrayMatrix2[2, 3] = matrix2.M34; + arrayMatrix2[3, 0] = matrix2.M41; arrayMatrix2[3, 1] = matrix2.M42; arrayMatrix2[3, 2] = matrix2.M43; arrayMatrix2[3, 3] = matrix2.M44; + + int n = 4; + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + // (AB)[i,j] = Sum(k=0; k < 4; k++) { A[i,k] * B[k, j] } + for (int k = 0; k < n; k++) + { + arrayMatrixProduct[i, j] += arrayMatrix1[i, k] * arrayMatrix2[k, j]; + } + } + } + return new Matrix( arrayMatrixProduct[0, 0], arrayMatrixProduct[0, 1], arrayMatrixProduct[0, 2], arrayMatrixProduct[0, 3], + arrayMatrixProduct[1, 0], arrayMatrixProduct[1, 1], arrayMatrixProduct[1, 2], arrayMatrixProduct[1, 3], + arrayMatrixProduct[2, 0], arrayMatrixProduct[2, 1], arrayMatrixProduct[2, 2], arrayMatrixProduct[2, 3], + arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 1], arrayMatrixProduct[3, 2], arrayMatrixProduct[3, 3]); + //--- + //throw new NotImplementedException(); + } + + + public static Matrix operator *(Matrix matrix, float scaleFactor) + { + throw new NotImplementedException(); + } + + + public static Matrix operator -(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static Matrix operator -(Matrix matrix1) + { + throw new NotImplementedException(); + } + + + public static Matrix Subtract(Matrix matrix1, Matrix matrix2) + { + throw new NotImplementedException(); + } + + + public static void Subtract(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) + { + throw new NotImplementedException(); + } + + + public override string ToString() + { + throw new NotImplementedException(); + } + + + public static Matrix Transpose(Matrix matrix) + { + //--- + return new Matrix( matrix.M11, matrix.M21, matrix.M31, matrix.M41, + matrix.M12, matrix.M22, matrix.M32, matrix.M42, + matrix.M13, matrix.M23, matrix.M33, matrix.M43, + matrix.M14, matrix.M24, matrix.M34, matrix.M44); + //--- + //throw new NotImplementedException(); + } + + + public static void Transpose(ref Matrix matrix, out Matrix result) + { + throw new NotImplementedException(); + } + #endregion Public Methods + } +} diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/MonoXnaCompactMaths.csproj b/libraries/ModifiedBulletX/MonoXnaCompactMaths/MonoXnaCompactMaths.csproj index c3ec4dd..79c5263 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/MonoXnaCompactMaths.csproj +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/MonoXnaCompactMaths.csproj @@ -1,51 +1,51 @@ - - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {121147BC-B06B-406C-84E9-907F268CF0EB} - Library - Properties - MonoXnaCompactMaths - MonoXnaCompactMaths - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - - - - - - - - + + + + Debug + AnyCPU + 8.0.50727 + 2.0 + {121147BC-B06B-406C-84E9-907F268CF0EB} + Library + Properties + MonoXnaCompactMaths + MonoXnaCompactMaths + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + \ No newline at end of file diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Properties/AssemblyInfo.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Properties/AssemblyInfo.cs index 748b94a..366f664 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Properties/AssemblyInfo.cs +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Properties/AssemblyInfo.cs @@ -1,33 +1,33 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// La información general sobre un ensamblado se controla mediante el siguiente -// conjunto de atributos. Cambie estos atributos para modificar la información -// asociada con un ensamblado. -[assembly: AssemblyTitle("MonoXnaCompactMaths")] -[assembly: AssemblyDescription("MonoXnaCompactMaths (Vector3, Vector4, Quaternion and Matrix)")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("")] -[assembly: AssemblyCopyright("Copyright 2006 - 2007 The Mono.Xna Team")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Si establece ComVisible como false hace que los tipos de este ensamblado no sean visibles -// a los componentes COM. Si necesita obtener acceso a un tipo en este ensamblado desde -// COM, establezca el atributo ComVisible como true en este tipo. -[assembly: ComVisible(false)] - -// El siguiente GUID sirve como identificador de la biblioteca de tipos si este proyecto se expone a COM -[assembly: Guid("79f9dfd1-60f8-44b8-ab08-6f6e341976b7")] - -// La información de versión de un ensamblado consta de los cuatro valores siguientes: -// -// Versión principal -// Versión secundaria -// Número de versión de compilación -// Revisión -// -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// La información general sobre un ensamblado se controla mediante el siguiente +// conjunto de atributos. Cambie estos atributos para modificar la información +// asociada con un ensamblado. +[assembly: AssemblyTitle("MonoXnaCompactMaths")] +[assembly: AssemblyDescription("MonoXnaCompactMaths (Vector3, Vector4, Quaternion and Matrix)")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright 2006 - 2007 The Mono.Xna Team")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Si establece ComVisible como false hace que los tipos de este ensamblado no sean visibles +// a los componentes COM. Si necesita obtener acceso a un tipo en este ensamblado desde +// COM, establezca el atributo ComVisible como true en este tipo. +[assembly: ComVisible(false)] + +// El siguiente GUID sirve como identificador de la biblioteca de tipos si este proyecto se expone a COM +[assembly: Guid("79f9dfd1-60f8-44b8-ab08-6f6e341976b7")] + +// La información de versión de un ensamblado consta de los cuatro valores siguientes: +// +// Versión principal +// Versión secundaria +// Número de versión de compilación +// Revisión +// +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Quaternion.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Quaternion.cs index 6ed1443..b4f1873 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Quaternion.cs +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Quaternion.cs @@ -1,346 +1,346 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -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 License - -using System; -using System.ComponentModel; - -namespace MonoXnaCompactMaths -{ - [Serializable] - //[TypeConverter(typeof(QuaternionConverter))] - public struct Quaternion : IEquatable - { - public float X; - public float Y; - public float Z; - public float W; - static Quaternion identity = new Quaternion(0, 0, 0, 1); - - - public Quaternion(float x, float y, float z, float w) - { - this.X = x; - this.Y = y; - this.Z = z; - this.W = w; - } - - - public Quaternion(Vector3 vectorPart, float scalarPart) - { - this.X = vectorPart.X; - this.Y = vectorPart.Y; - this.Z = vectorPart.Z; - this.W = scalarPart; - } - - public static Quaternion Identity - { - get{ return identity; } - } - - - public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle) - { - throw new NotImplementedException(); - } - - - public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion CreateFromRotationMatrix(Matrix matrix) - { - throw new NotImplementedException(); - } - - - public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static float Dot(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result) - { - throw new NotImplementedException(); - } - - - public override bool Equals(object obj) - { - throw new NotImplementedException(); - } - - - public bool Equals(Quaternion other) - { - throw new NotImplementedException(); - } - - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - - - public static Quaternion Inverse(Quaternion quaternion) - { - throw new NotImplementedException(); - } - - - public static void Inverse(ref Quaternion quaternion, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public float Length() - { - //--- - return (float)Math.Sqrt(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0)); - //--- - //throw new NotImplementedException(); - } - - - public float LengthSquared() - { - //--- - return (float)(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0)); - //--- - //throw new NotImplementedException(); - } - - - public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount) - { - throw new NotImplementedException(); - } - - - public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount) - { - throw new NotImplementedException(); - } - - - public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor) - { - throw new NotImplementedException(); - } - - - public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion Negate(Quaternion quaternion) - { - throw new NotImplementedException(); - } - - - public static void Negate(ref Quaternion quaternion, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public void Normalize() - { - //--- - this = Normalize(this); - //--- - //throw new NotImplementedException(); - } - - - public static Quaternion Normalize(Quaternion quaternion) - { - //--- - return quaternion / quaternion.Length(); - //--- - //throw new NotImplementedException(); - } - - - public static void Normalize(ref Quaternion quaternion, out Quaternion result) - { - throw new NotImplementedException(); - } - - - public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - public static Quaternion operator /(Quaternion quaternion, float factor) - { - quaternion.W /= factor; - quaternion.X /= factor; - quaternion.Y /= factor; - quaternion.Z /= factor; - return quaternion; - } - - public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2) - { - //--- - //Grassmann product - Quaternion quaternionProduct = new Quaternion(); - - quaternionProduct.W = quaternion1.W * quaternion2.W - quaternion1.X * quaternion2.X - quaternion1.Y * quaternion2.Y - quaternion1.Z * quaternion2.Z; - quaternionProduct.X = quaternion1.W * quaternion2.X + quaternion1.X * quaternion2.W + quaternion1.Y * quaternion2.Z - quaternion1.Z * quaternion2.Y; - quaternionProduct.Y = quaternion1.W * quaternion2.Y - quaternion1.X * quaternion2.Z + quaternion1.Y * quaternion2.W + quaternion1.Z * quaternion2.X; - quaternionProduct.Z = quaternion1.W * quaternion2.Z + quaternion1.X * quaternion2.Y - quaternion1.Y * quaternion2.X + quaternion1.Z * quaternion2.W; - return quaternionProduct; - //--- - //throw new NotImplementedException(); - } - - - public static Quaternion operator *(Quaternion quaternion1, float scaleFactor) - { - throw new NotImplementedException(); - } - - - public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2) - { - throw new NotImplementedException(); - } - - - public static Quaternion operator -(Quaternion quaternion) - { - throw new NotImplementedException(); - } - - - public override string ToString() - { - throw new NotImplementedException(); - } - - private static void Conjugate(ref Quaternion quaternion, out Quaternion result) - { - throw new NotImplementedException(); - } - } -} +#region License +/* +MIT License +Copyright © 2006 The Mono.Xna Team + +All rights reserved. + +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 License + +using System; +using System.ComponentModel; + +namespace MonoXnaCompactMaths +{ + [Serializable] + //[TypeConverter(typeof(QuaternionConverter))] + public struct Quaternion : IEquatable + { + public float X; + public float Y; + public float Z; + public float W; + static Quaternion identity = new Quaternion(0, 0, 0, 1); + + + public Quaternion(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + + + public Quaternion(Vector3 vectorPart, float scalarPart) + { + this.X = vectorPart.X; + this.Y = vectorPart.Y; + this.Z = vectorPart.Z; + this.W = scalarPart; + } + + public static Quaternion Identity + { + get{ return identity; } + } + + + public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle) + { + throw new NotImplementedException(); + } + + + public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion CreateFromRotationMatrix(Matrix matrix) + { + throw new NotImplementedException(); + } + + + public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static float Dot(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result) + { + throw new NotImplementedException(); + } + + + public override bool Equals(object obj) + { + throw new NotImplementedException(); + } + + + public bool Equals(Quaternion other) + { + throw new NotImplementedException(); + } + + + public override int GetHashCode() + { + throw new NotImplementedException(); + } + + + public static Quaternion Inverse(Quaternion quaternion) + { + throw new NotImplementedException(); + } + + + public static void Inverse(ref Quaternion quaternion, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public float Length() + { + //--- + return (float)Math.Sqrt(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0)); + //--- + //throw new NotImplementedException(); + } + + + public float LengthSquared() + { + //--- + return (float)(Math.Pow(this.W, 2.0) + Math.Pow(this.X, 2.0) + Math.Pow(this.Y, 2.0) + Math.Pow(this.Z, 2.0)); + //--- + //throw new NotImplementedException(); + } + + + public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount) + { + throw new NotImplementedException(); + } + + + public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount) + { + throw new NotImplementedException(); + } + + + public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor) + { + throw new NotImplementedException(); + } + + + public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion Negate(Quaternion quaternion) + { + throw new NotImplementedException(); + } + + + public static void Negate(ref Quaternion quaternion, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public void Normalize() + { + //--- + this = Normalize(this); + //--- + //throw new NotImplementedException(); + } + + + public static Quaternion Normalize(Quaternion quaternion) + { + //--- + return quaternion / quaternion.Length(); + //--- + //throw new NotImplementedException(); + } + + + public static void Normalize(ref Quaternion quaternion, out Quaternion result) + { + throw new NotImplementedException(); + } + + + public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + public static Quaternion operator /(Quaternion quaternion, float factor) + { + quaternion.W /= factor; + quaternion.X /= factor; + quaternion.Y /= factor; + quaternion.Z /= factor; + return quaternion; + } + + public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2) + { + //--- + //Grassmann product + Quaternion quaternionProduct = new Quaternion(); + + quaternionProduct.W = quaternion1.W * quaternion2.W - quaternion1.X * quaternion2.X - quaternion1.Y * quaternion2.Y - quaternion1.Z * quaternion2.Z; + quaternionProduct.X = quaternion1.W * quaternion2.X + quaternion1.X * quaternion2.W + quaternion1.Y * quaternion2.Z - quaternion1.Z * quaternion2.Y; + quaternionProduct.Y = quaternion1.W * quaternion2.Y - quaternion1.X * quaternion2.Z + quaternion1.Y * quaternion2.W + quaternion1.Z * quaternion2.X; + quaternionProduct.Z = quaternion1.W * quaternion2.Z + quaternion1.X * quaternion2.Y - quaternion1.Y * quaternion2.X + quaternion1.Z * quaternion2.W; + return quaternionProduct; + //--- + //throw new NotImplementedException(); + } + + + public static Quaternion operator *(Quaternion quaternion1, float scaleFactor) + { + throw new NotImplementedException(); + } + + + public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2) + { + throw new NotImplementedException(); + } + + + public static Quaternion operator -(Quaternion quaternion) + { + throw new NotImplementedException(); + } + + + public override string ToString() + { + throw new NotImplementedException(); + } + + private static void Conjugate(ref Quaternion quaternion, out Quaternion result) + { + throw new NotImplementedException(); + } + } +} diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector3.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector3.cs index fd4bcd2..f246415 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector3.cs +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector3.cs @@ -1,620 +1,620 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -Authors: - * Alan McGovern - -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 License - -using System; -using System.ComponentModel; -using System.Text; -using System.Runtime.InteropServices; - -namespace MonoXnaCompactMaths -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - //[TypeConverter(typeof(Vector3Converter))] - public struct Vector3 : IEquatable - { - #region Private Fields - - private static Vector3 zero = new Vector3(0f, 0f, 0f); - private static Vector3 one = new Vector3(1f, 1f, 1f); - private static Vector3 unitX = new Vector3(1f, 0f, 0f); - private static Vector3 unitY = new Vector3(0f, 1f, 0f); - private static Vector3 unitZ = new Vector3(0f, 0f, 1f); - private static Vector3 up = new Vector3(0f, 1f, 0f); - private static Vector3 down = new Vector3(0f, -1f, 0f); - private static Vector3 right = new Vector3(1f, 0f, 0f); - private static Vector3 left = new Vector3(-1f, 0f, 0f); - private static Vector3 forward = new Vector3(0f, 0f, -1f); - private static Vector3 backward = new Vector3(0f, 0f, 1f); - - #endregion Private Fields - - - #region Public Fields - - public float X; - public float Y; - public float Z; - - #endregion Public Fields - - - #region Properties - - public static Vector3 Zero - { - get { return zero; } - } - - public static Vector3 One - { - get { return one; } - } - - public static Vector3 UnitX - { - get { return unitX; } - } - - public static Vector3 UnitY - { - get { return unitY; } - } - - public static Vector3 UnitZ - { - get { return unitZ; } - } - - public static Vector3 Up - { - get { return up; } - } - - public static Vector3 Down - { - get { return down; } - } - - public static Vector3 Right - { - get { return right; } - } - - public static Vector3 Left - { - get { return left; } - } - - public static Vector3 Forward - { - get { return forward; } - } - - public static Vector3 Backward - { - get { return backward; } - } - - #endregion Properties - - - #region Constructors - - public Vector3(float x, float y, float z) - { - this.X = x; - this.Y = y; - this.Z = z; - } - - - public Vector3(float value) - { - this.X = value; - this.Y = value; - this.Z = value; - } - - - /*public Vector3(Vector2 value, float z) - { - this.X = value.X; - this.Y = value.Y; - this.Z = z; - }*/ - - - #endregion Constructors - - - #region Public Methods - - public static Vector3 Add(Vector3 value1, Vector3 value2) - { - value1.X += value2.X; - value1.Y += value2.Y; - value1.Z += value2.Z; - return value1; - } - - public static void Add(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result.X = value1.X + value2.X; - result.Y = value1.Y + value2.Y; - result.Z = value1.Z + value2.Z; - } - - /*public static Vector3 Barycentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2) - { - return new Vector3( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), - MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2)); - }*/ - - /*public static void Barycentric(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, float amount1, float amount2, out Vector3 result) - { - result = new Vector3( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), - MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2)); - }*/ - - /*public static Vector3 CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, Vector3 value4, float amount) - { - return new Vector3( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), - MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount)); - }*/ - - /*public static void CatmullRom(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result) - { - result = new Vector3( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), - MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount)); - }*/ - - /*public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max) - { - return new Vector3( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y), - MathHelper.Clamp(value1.Z, min.Z, max.Z)); - }*/ - - /*public static void Clamp(ref Vector3 value1, ref Vector3 min, ref Vector3 max, out Vector3 result) - { - result = new Vector3( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y), - MathHelper.Clamp(value1.Z, min.Z, max.Z)); - }*/ - - public static Vector3 Cross(Vector3 vector1, Vector3 vector2) - { - Cross(ref vector1, ref vector2, out vector1); - return vector1; - } - - public static void Cross(ref Vector3 vector1, ref Vector3 vector2, out Vector3 result) - { - result = new Vector3(vector1.Y * vector2.Z - vector2.Y * vector1.Z, - -(vector1.X * vector2.Z - vector2.X * vector1.Z), - vector1.X * vector2.Y - vector2.X * vector1.Y); - } - - public static float Distance(Vector3 vector1, Vector3 vector2) - { - float result; - DistanceSquared(ref vector1, ref vector2, out result); - return (float)Math.Sqrt(result); - } - - public static void Distance(ref Vector3 value1, ref Vector3 value2, out float result) - { - DistanceSquared(ref value1, ref value2, out result); - result = (float)Math.Sqrt(result); - } - - public static float DistanceSquared(Vector3 value1, Vector3 value2) - { - float result; - DistanceSquared(ref value1, ref value2, out result); - return result; - } - - public static void DistanceSquared(ref Vector3 value1, ref Vector3 value2, out float result) - { - result = (value1.X - value2.X) * (value1.X - value2.X) + - (value1.Y - value2.Y) * (value1.Y - value2.Y) + - (value1.Z - value2.Z) * (value1.Z - value2.Z); - } - - public static Vector3 Divide(Vector3 value1, Vector3 value2) - { - value1.X /= value2.X; - value1.Y /= value2.Y; - value1.Z /= value2.Z; - return value1; - } - - public static Vector3 Divide(Vector3 value1, float value2) - { - float factor = 1 / value2; - value1.X *= factor; - value1.Y *= factor; - value1.Z *= factor; - return value1; - } - - public static void Divide(ref Vector3 value1, float divisor, out Vector3 result) - { - float factor = 1 / divisor; - result.X = value1.X * factor; - result.Y = value1.Y * factor; - result.Z = value1.Z * factor; - } - - public static void Divide(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result.X = value1.X / value2.X; - result.Y = value1.Y / value2.Y; - result.Z = value1.Z / value2.Z; - } - - public static float Dot(Vector3 vector1, Vector3 vector2) - { - return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; - } - - public static void Dot(ref Vector3 vector1, ref Vector3 vector2, out float result) - { - result = vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; - } - - public override bool Equals(object obj) - { - return (obj is Vector3) ? this == (Vector3)obj : false; - } - - public bool Equals(Vector3 other) - { - return this == other; - } - - public override int GetHashCode() - { - return (int)(this.X + this.Y + this.Z); - } - - /*public static Vector3 Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount) - { - Vector3 result = new Vector3(); - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); - return result; - }*/ - - /*public static void Hermite(ref Vector3 value1, ref Vector3 tangent1, ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result) - { - result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); - result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); - result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); - }*/ - - public float Length() - { - float result; - DistanceSquared(ref this, ref zero, out result); - return (float)Math.Sqrt(result); - } - - public float LengthSquared() - { - float result; - DistanceSquared(ref this, ref zero, out result); - return result; - } - - /*public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount) - { - return new Vector3( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount), - MathHelper.Lerp(value1.Z, value2.Z, amount)); - }*/ - - /*public static void Lerp(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result) - { - result = new Vector3( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount), - MathHelper.Lerp(value1.Z, value2.Z, amount)); - }*/ - - /*public static Vector3 Max(Vector3 value1, Vector3 value2) - { - return new Vector3( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y), - MathHelper.Max(value1.Z, value2.Z)); - }*/ - - /*public static void Max(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result = new Vector3( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y), - MathHelper.Max(value1.Z, value2.Z)); - }*/ - - /*public static Vector3 Min(Vector3 value1, Vector3 value2) - { - return new Vector3( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y), - MathHelper.Min(value1.Z, value2.Z)); - }*/ - - /*public static void Min(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result = new Vector3( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y), - MathHelper.Min(value1.Z, value2.Z)); - }*/ - - public static Vector3 Multiply(Vector3 value1, Vector3 value2) - { - value1.X *= value2.X; - value1.Y *= value2.Y; - value1.Z *= value2.Z; - return value1; - } - - public static Vector3 Multiply(Vector3 value1, float scaleFactor) - { - value1.X *= scaleFactor; - value1.Y *= scaleFactor; - value1.Z *= scaleFactor; - return value1; - } - - public static void Multiply(ref Vector3 value1, float scaleFactor, out Vector3 result) - { - result.X = value1.X * scaleFactor; - result.Y = value1.Y * scaleFactor; - result.Z = value1.Z * scaleFactor; - } - - public static void Multiply(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result.X = value1.X * value2.X; - result.Y = value1.Y * value2.Y; - result.Z = value1.Z * value2.Z; - } - - public static Vector3 Negate(Vector3 value) - { - value = new Vector3(-value.X, -value.Y, -value.Z); - return value; - } - - public static void Negate(ref Vector3 value, out Vector3 result) - { - result = new Vector3(-value.X, -value.Y, -value.Z); - } - - public void Normalize() - { - Normalize(ref this, out this); - } - - public static Vector3 Normalize(Vector3 vector) - { - Normalize(ref vector, out vector); - return vector; - } - - public static void Normalize(ref Vector3 value, out Vector3 result) - { - float factor; - Distance(ref value, ref zero, out factor); - factor = 1f / factor; - result.X = value.X * factor; - result.Y = value.Y * factor; - result.Z = value.Z * factor; - } - - public static Vector3 Reflect(Vector3 vector, Vector3 normal) - { - throw new NotImplementedException(); - } - - public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result) - { - throw new NotImplementedException(); - } - - /*public static Vector3 SmoothStep(Vector3 value1, Vector3 value2, float amount) - { - return new Vector3( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount), - MathHelper.SmoothStep(value1.Z, value2.Z, amount)); - }*/ - - /*public static void SmoothStep(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result) - { - result = new Vector3( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount), - MathHelper.SmoothStep(value1.Z, value2.Z, amount)); - }*/ - - public static Vector3 Subtract(Vector3 value1, Vector3 value2) - { - value1.X -= value2.X; - value1.Y -= value2.Y; - value1.Z -= value2.Z; - return value1; - } - - public static void Subtract(ref Vector3 value1, ref Vector3 value2, out Vector3 result) - { - result.X = value1.X - value2.X; - result.Y = value1.Y - value2.Y; - result.Z = value1.Z - value2.Z; - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(32); - sb.Append("{X:"); - sb.Append(this.X); - sb.Append(" Y:"); - sb.Append(this.Y); - sb.Append(" Z:"); - sb.Append(this.Z); - sb.Append("}"); - return sb.ToString(); - } - - public static Vector3 Transform(Vector3 position, Matrix matrix) - { - Transform(ref position, ref matrix, out position); - return position; - } - - public static void Transform(ref Vector3 position, ref Matrix matrix, out Vector3 result) - { - result = new Vector3((position.X * matrix.M11) + (position.Y * matrix.M21) + (position.Z * matrix.M31) + matrix.M41, - (position.X * matrix.M12) + (position.Y * matrix.M22) + (position.Z * matrix.M32) + matrix.M42, - (position.X * matrix.M13) + (position.Y * matrix.M23) + (position.Z * matrix.M33) + matrix.M43); - } - - public static Vector3 TransformNormal(Vector3 normal, Matrix matrix) - { - TransformNormal(ref normal, ref matrix, out normal); - return normal; - } - - public static void TransformNormal(ref Vector3 normal, ref Matrix matrix, out Vector3 result) - { - result = new Vector3((normal.X * matrix.M11) + (normal.Y * matrix.M21) + (normal.Z * matrix.M31), - (normal.X * matrix.M12) + (normal.Y * matrix.M22) + (normal.Z * matrix.M32), - (normal.X * matrix.M13) + (normal.Y * matrix.M23) + (normal.Z * matrix.M33)); - } - - #endregion Public methods - - - #region Operators - - public static bool operator ==(Vector3 value1, Vector3 value2) - { - return value1.X == value2.X - && value1.Y == value2.Y - && value1.Z == value2.Z; - } - - public static bool operator !=(Vector3 value1, Vector3 value2) - { - return !(value1 == value2); - } - - public static Vector3 operator +(Vector3 value1, Vector3 value2) - { - value1.X += value2.X; - value1.Y += value2.Y; - value1.Z += value2.Z; - return value1; - } - - public static Vector3 operator -(Vector3 value) - { - value = new Vector3(-value.X, -value.Y, -value.Z); - return value; - } - - public static Vector3 operator -(Vector3 value1, Vector3 value2) - { - value1.X -= value2.X; - value1.Y -= value2.Y; - value1.Z -= value2.Z; - return value1; - } - - public static Vector3 operator *(Vector3 value1, Vector3 value2) - { - value1.X *= value2.X; - value1.Y *= value2.Y; - value1.Z *= value2.Z; - return value1; - } - - public static Vector3 operator *(Vector3 value, float scaleFactor) - { - value.X *= scaleFactor; - value.Y *= scaleFactor; - value.Z *= scaleFactor; - return value; - } - - public static Vector3 operator *(float scaleFactor, Vector3 value) - { - value.X *= scaleFactor; - value.Y *= scaleFactor; - value.Z *= scaleFactor; - return value; - } - - public static Vector3 operator /(Vector3 value1, Vector3 value2) - { - value1.X /= value2.X; - value1.Y /= value2.Y; - value1.Z /= value2.Z; - return value1; - } - - public static Vector3 operator /(Vector3 value, float divider) - { - float factor = 1 / divider; - value.X *= factor; - value.Y *= factor; - value.Z *= factor; - return value; - } - - #endregion - } -} +#region License +/* +MIT License +Copyright © 2006 The Mono.Xna Team + +All rights reserved. + +Authors: + * Alan McGovern + +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 License + +using System; +using System.ComponentModel; +using System.Text; +using System.Runtime.InteropServices; + +namespace MonoXnaCompactMaths +{ + [Serializable] + [StructLayout(LayoutKind.Sequential)] + //[TypeConverter(typeof(Vector3Converter))] + public struct Vector3 : IEquatable + { + #region Private Fields + + private static Vector3 zero = new Vector3(0f, 0f, 0f); + private static Vector3 one = new Vector3(1f, 1f, 1f); + private static Vector3 unitX = new Vector3(1f, 0f, 0f); + private static Vector3 unitY = new Vector3(0f, 1f, 0f); + private static Vector3 unitZ = new Vector3(0f, 0f, 1f); + private static Vector3 up = new Vector3(0f, 1f, 0f); + private static Vector3 down = new Vector3(0f, -1f, 0f); + private static Vector3 right = new Vector3(1f, 0f, 0f); + private static Vector3 left = new Vector3(-1f, 0f, 0f); + private static Vector3 forward = new Vector3(0f, 0f, -1f); + private static Vector3 backward = new Vector3(0f, 0f, 1f); + + #endregion Private Fields + + + #region Public Fields + + public float X; + public float Y; + public float Z; + + #endregion Public Fields + + + #region Properties + + public static Vector3 Zero + { + get { return zero; } + } + + public static Vector3 One + { + get { return one; } + } + + public static Vector3 UnitX + { + get { return unitX; } + } + + public static Vector3 UnitY + { + get { return unitY; } + } + + public static Vector3 UnitZ + { + get { return unitZ; } + } + + public static Vector3 Up + { + get { return up; } + } + + public static Vector3 Down + { + get { return down; } + } + + public static Vector3 Right + { + get { return right; } + } + + public static Vector3 Left + { + get { return left; } + } + + public static Vector3 Forward + { + get { return forward; } + } + + public static Vector3 Backward + { + get { return backward; } + } + + #endregion Properties + + + #region Constructors + + public Vector3(float x, float y, float z) + { + this.X = x; + this.Y = y; + this.Z = z; + } + + + public Vector3(float value) + { + this.X = value; + this.Y = value; + this.Z = value; + } + + + /*public Vector3(Vector2 value, float z) + { + this.X = value.X; + this.Y = value.Y; + this.Z = z; + }*/ + + + #endregion Constructors + + + #region Public Methods + + public static Vector3 Add(Vector3 value1, Vector3 value2) + { + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + return value1; + } + + public static void Add(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result.X = value1.X + value2.X; + result.Y = value1.Y + value2.Y; + result.Z = value1.Z + value2.Z; + } + + /*public static Vector3 Barycentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2) + { + return new Vector3( + MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), + MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), + MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2)); + }*/ + + /*public static void Barycentric(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, float amount1, float amount2, out Vector3 result) + { + result = new Vector3( + MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), + MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), + MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2)); + }*/ + + /*public static Vector3 CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, Vector3 value4, float amount) + { + return new Vector3( + MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), + MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), + MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount)); + }*/ + + /*public static void CatmullRom(ref Vector3 value1, ref Vector3 value2, ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result) + { + result = new Vector3( + MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), + MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), + MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount)); + }*/ + + /*public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max) + { + return new Vector3( + MathHelper.Clamp(value1.X, min.X, max.X), + MathHelper.Clamp(value1.Y, min.Y, max.Y), + MathHelper.Clamp(value1.Z, min.Z, max.Z)); + }*/ + + /*public static void Clamp(ref Vector3 value1, ref Vector3 min, ref Vector3 max, out Vector3 result) + { + result = new Vector3( + MathHelper.Clamp(value1.X, min.X, max.X), + MathHelper.Clamp(value1.Y, min.Y, max.Y), + MathHelper.Clamp(value1.Z, min.Z, max.Z)); + }*/ + + public static Vector3 Cross(Vector3 vector1, Vector3 vector2) + { + Cross(ref vector1, ref vector2, out vector1); + return vector1; + } + + public static void Cross(ref Vector3 vector1, ref Vector3 vector2, out Vector3 result) + { + result = new Vector3(vector1.Y * vector2.Z - vector2.Y * vector1.Z, + -(vector1.X * vector2.Z - vector2.X * vector1.Z), + vector1.X * vector2.Y - vector2.X * vector1.Y); + } + + public static float Distance(Vector3 vector1, Vector3 vector2) + { + float result; + DistanceSquared(ref vector1, ref vector2, out result); + return (float)Math.Sqrt(result); + } + + public static void Distance(ref Vector3 value1, ref Vector3 value2, out float result) + { + DistanceSquared(ref value1, ref value2, out result); + result = (float)Math.Sqrt(result); + } + + public static float DistanceSquared(Vector3 value1, Vector3 value2) + { + float result; + DistanceSquared(ref value1, ref value2, out result); + return result; + } + + public static void DistanceSquared(ref Vector3 value1, ref Vector3 value2, out float result) + { + result = (value1.X - value2.X) * (value1.X - value2.X) + + (value1.Y - value2.Y) * (value1.Y - value2.Y) + + (value1.Z - value2.Z) * (value1.Z - value2.Z); + } + + public static Vector3 Divide(Vector3 value1, Vector3 value2) + { + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + public static Vector3 Divide(Vector3 value1, float value2) + { + float factor = 1 / value2; + value1.X *= factor; + value1.Y *= factor; + value1.Z *= factor; + return value1; + } + + public static void Divide(ref Vector3 value1, float divisor, out Vector3 result) + { + float factor = 1 / divisor; + result.X = value1.X * factor; + result.Y = value1.Y * factor; + result.Z = value1.Z * factor; + } + + public static void Divide(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result.X = value1.X / value2.X; + result.Y = value1.Y / value2.Y; + result.Z = value1.Z / value2.Z; + } + + public static float Dot(Vector3 vector1, Vector3 vector2) + { + return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; + } + + public static void Dot(ref Vector3 vector1, ref Vector3 vector2, out float result) + { + result = vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z; + } + + public override bool Equals(object obj) + { + return (obj is Vector3) ? this == (Vector3)obj : false; + } + + public bool Equals(Vector3 other) + { + return this == other; + } + + public override int GetHashCode() + { + return (int)(this.X + this.Y + this.Z); + } + + /*public static Vector3 Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount) + { + Vector3 result = new Vector3(); + Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + return result; + }*/ + + /*public static void Hermite(ref Vector3 value1, ref Vector3 tangent1, ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result) + { + result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); + result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); + result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); + }*/ + + public float Length() + { + float result; + DistanceSquared(ref this, ref zero, out result); + return (float)Math.Sqrt(result); + } + + public float LengthSquared() + { + float result; + DistanceSquared(ref this, ref zero, out result); + return result; + } + + /*public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount) + { + return new Vector3( + MathHelper.Lerp(value1.X, value2.X, amount), + MathHelper.Lerp(value1.Y, value2.Y, amount), + MathHelper.Lerp(value1.Z, value2.Z, amount)); + }*/ + + /*public static void Lerp(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result) + { + result = new Vector3( + MathHelper.Lerp(value1.X, value2.X, amount), + MathHelper.Lerp(value1.Y, value2.Y, amount), + MathHelper.Lerp(value1.Z, value2.Z, amount)); + }*/ + + /*public static Vector3 Max(Vector3 value1, Vector3 value2) + { + return new Vector3( + MathHelper.Max(value1.X, value2.X), + MathHelper.Max(value1.Y, value2.Y), + MathHelper.Max(value1.Z, value2.Z)); + }*/ + + /*public static void Max(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result = new Vector3( + MathHelper.Max(value1.X, value2.X), + MathHelper.Max(value1.Y, value2.Y), + MathHelper.Max(value1.Z, value2.Z)); + }*/ + + /*public static Vector3 Min(Vector3 value1, Vector3 value2) + { + return new Vector3( + MathHelper.Min(value1.X, value2.X), + MathHelper.Min(value1.Y, value2.Y), + MathHelper.Min(value1.Z, value2.Z)); + }*/ + + /*public static void Min(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result = new Vector3( + MathHelper.Min(value1.X, value2.X), + MathHelper.Min(value1.Y, value2.Y), + MathHelper.Min(value1.Z, value2.Z)); + }*/ + + public static Vector3 Multiply(Vector3 value1, Vector3 value2) + { + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + public static Vector3 Multiply(Vector3 value1, float scaleFactor) + { + value1.X *= scaleFactor; + value1.Y *= scaleFactor; + value1.Z *= scaleFactor; + return value1; + } + + public static void Multiply(ref Vector3 value1, float scaleFactor, out Vector3 result) + { + result.X = value1.X * scaleFactor; + result.Y = value1.Y * scaleFactor; + result.Z = value1.Z * scaleFactor; + } + + public static void Multiply(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result.X = value1.X * value2.X; + result.Y = value1.Y * value2.Y; + result.Z = value1.Z * value2.Z; + } + + public static Vector3 Negate(Vector3 value) + { + value = new Vector3(-value.X, -value.Y, -value.Z); + return value; + } + + public static void Negate(ref Vector3 value, out Vector3 result) + { + result = new Vector3(-value.X, -value.Y, -value.Z); + } + + public void Normalize() + { + Normalize(ref this, out this); + } + + public static Vector3 Normalize(Vector3 vector) + { + Normalize(ref vector, out vector); + return vector; + } + + public static void Normalize(ref Vector3 value, out Vector3 result) + { + float factor; + Distance(ref value, ref zero, out factor); + factor = 1f / factor; + result.X = value.X * factor; + result.Y = value.Y * factor; + result.Z = value.Z * factor; + } + + public static Vector3 Reflect(Vector3 vector, Vector3 normal) + { + throw new NotImplementedException(); + } + + public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result) + { + throw new NotImplementedException(); + } + + /*public static Vector3 SmoothStep(Vector3 value1, Vector3 value2, float amount) + { + return new Vector3( + MathHelper.SmoothStep(value1.X, value2.X, amount), + MathHelper.SmoothStep(value1.Y, value2.Y, amount), + MathHelper.SmoothStep(value1.Z, value2.Z, amount)); + }*/ + + /*public static void SmoothStep(ref Vector3 value1, ref Vector3 value2, float amount, out Vector3 result) + { + result = new Vector3( + MathHelper.SmoothStep(value1.X, value2.X, amount), + MathHelper.SmoothStep(value1.Y, value2.Y, amount), + MathHelper.SmoothStep(value1.Z, value2.Z, amount)); + }*/ + + public static Vector3 Subtract(Vector3 value1, Vector3 value2) + { + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + public static void Subtract(ref Vector3 value1, ref Vector3 value2, out Vector3 result) + { + result.X = value1.X - value2.X; + result.Y = value1.Y - value2.Y; + result.Z = value1.Z - value2.Z; + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(32); + sb.Append("{X:"); + sb.Append(this.X); + sb.Append(" Y:"); + sb.Append(this.Y); + sb.Append(" Z:"); + sb.Append(this.Z); + sb.Append("}"); + return sb.ToString(); + } + + public static Vector3 Transform(Vector3 position, Matrix matrix) + { + Transform(ref position, ref matrix, out position); + return position; + } + + public static void Transform(ref Vector3 position, ref Matrix matrix, out Vector3 result) + { + result = new Vector3((position.X * matrix.M11) + (position.Y * matrix.M21) + (position.Z * matrix.M31) + matrix.M41, + (position.X * matrix.M12) + (position.Y * matrix.M22) + (position.Z * matrix.M32) + matrix.M42, + (position.X * matrix.M13) + (position.Y * matrix.M23) + (position.Z * matrix.M33) + matrix.M43); + } + + public static Vector3 TransformNormal(Vector3 normal, Matrix matrix) + { + TransformNormal(ref normal, ref matrix, out normal); + return normal; + } + + public static void TransformNormal(ref Vector3 normal, ref Matrix matrix, out Vector3 result) + { + result = new Vector3((normal.X * matrix.M11) + (normal.Y * matrix.M21) + (normal.Z * matrix.M31), + (normal.X * matrix.M12) + (normal.Y * matrix.M22) + (normal.Z * matrix.M32), + (normal.X * matrix.M13) + (normal.Y * matrix.M23) + (normal.Z * matrix.M33)); + } + + #endregion Public methods + + + #region Operators + + public static bool operator ==(Vector3 value1, Vector3 value2) + { + return value1.X == value2.X + && value1.Y == value2.Y + && value1.Z == value2.Z; + } + + public static bool operator !=(Vector3 value1, Vector3 value2) + { + return !(value1 == value2); + } + + public static Vector3 operator +(Vector3 value1, Vector3 value2) + { + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + return value1; + } + + public static Vector3 operator -(Vector3 value) + { + value = new Vector3(-value.X, -value.Y, -value.Z); + return value; + } + + public static Vector3 operator -(Vector3 value1, Vector3 value2) + { + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + public static Vector3 operator *(Vector3 value1, Vector3 value2) + { + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + public static Vector3 operator *(Vector3 value, float scaleFactor) + { + value.X *= scaleFactor; + value.Y *= scaleFactor; + value.Z *= scaleFactor; + return value; + } + + public static Vector3 operator *(float scaleFactor, Vector3 value) + { + value.X *= scaleFactor; + value.Y *= scaleFactor; + value.Z *= scaleFactor; + return value; + } + + public static Vector3 operator /(Vector3 value1, Vector3 value2) + { + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + public static Vector3 operator /(Vector3 value, float divider) + { + float factor = 1 / divider; + value.X *= factor; + value.Y *= factor; + value.Z *= factor; + return value; + } + + #endregion + } +} diff --git a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector4.cs b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector4.cs index c75b7c8..abb30a8 100644 --- a/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector4.cs +++ b/libraries/ModifiedBulletX/MonoXnaCompactMaths/Vector4.cs @@ -1,630 +1,630 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -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 License - -using System; -using System.ComponentModel; -using System.Text; -using System.Runtime.InteropServices; - -namespace MonoXnaCompactMaths -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - //[TypeConverter(typeof(Vector4Converter))] - public struct Vector4 : IEquatable - { - #region Private Fields - - private static Vector4 zeroVector = new Vector4(); - private static Vector4 unitVector = new Vector4(1f, 1f, 1f, 1f); - private static Vector4 unitXVector = new Vector4(1f, 0f, 0f, 0f); - private static Vector4 unitYVector = new Vector4(0f, 1f, 0f, 0f); - private static Vector4 unitZVector = new Vector4(0f, 0f, 1f, 0f); - private static Vector4 unitWVector = new Vector4(0f, 0f, 0f, 1f); - - #endregion Private Fields - - - #region Public Fields - - public float X; - public float Y; - public float Z; - public float W; - - #endregion Public Fields - - - #region Properties - - public static Vector4 Zero - { - get { return zeroVector; } - } - - public static Vector4 One - { - get { return unitVector; } - } - - public static Vector4 UnitX - { - get { return unitXVector; } - } - - public static Vector4 UnitY - { - get { return unitYVector; } - } - - public static Vector4 UnitZ - { - get { return unitZVector; } - } - - public static Vector4 UnitW - { - get { return unitWVector; } - } - - #endregion Properties - - - #region Constructors - - public Vector4(float x, float y, float z, float w) - { - this.X = x; - this.Y = y; - this.Z = z; - this.W = w; - } - - /*public Vector4(Vector2 value, float z, float w) - { - this.X = value.X; - this.Y = value.Y; - this.Z = z; - this.W = w; - }*/ - - public Vector4(Vector3 value, float w) - { - this.X = value.X; - this.Y = value.Y; - this.Z = value.Z; - this.W = w; - } - - public Vector4(float value) - { - this.X = value; - this.Y = value; - this.Z = value; - this.W = value; - } - - #endregion - - - #region Public Methods - - public static Vector4 Add(Vector4 value1, Vector4 value2) - { - value1.W += value2.W; - value1.X += value2.X; - value1.Y += value2.Y; - value1.Z += value2.Z; - return value1; - } - - public static void Add(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result.W = value1.W + value2.W; - result.X = value1.X + value2.X; - result.Y = value1.Y + value2.Y; - result.Z = value1.Z + value2.Z; - } - - /*public static Vector4 Barycentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2) - { - return new Vector4( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), - MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2), - MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2)); - }*/ - - /*public static void Barycentric(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, float amount1, float amount2, out Vector4 result) - { - result = new Vector4( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), - MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2), - MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2)); - }*/ - - /*public static Vector4 CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount) - { - return new Vector4( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), - MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount), - MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount)); - }*/ - - /*public static void CatmullRom(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, ref Vector4 value4, float amount, out Vector4 result) - { - result = new Vector4( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), - MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount), - MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount)); - }*/ - - /*public static Vector4 Clamp(Vector4 value1, Vector4 min, Vector4 max) - { - return new Vector4( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y), - MathHelper.Clamp(value1.Z, min.Z, max.Z), - MathHelper.Clamp(value1.W, min.W, max.W)); - }*/ - - /*public static void Clamp(ref Vector4 value1, ref Vector4 min, ref Vector4 max, out Vector4 result) - { - result = new Vector4( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y), - MathHelper.Clamp(value1.Z, min.Z, max.Z), - MathHelper.Clamp(value1.W, min.W, max.W)); - }*/ - - public static float Distance(Vector4 value1, Vector4 value2) - { - return (float)Math.Sqrt(DistanceSquared(value1, value2)); - } - - public static void Distance(ref Vector4 value1, ref Vector4 value2, out float result) - { - result = (float)Math.Sqrt(DistanceSquared(value1, value2)); - } - - public static float DistanceSquared(Vector4 value1, Vector4 value2) - { - float result; - DistanceSquared(ref value1, ref value2, out result); - return result; - } - - public static void DistanceSquared(ref Vector4 value1, ref Vector4 value2, out float result) - { - result = (value1.W - value2.W) * (value1.W - value2.W) + - (value1.X - value2.X) * (value1.X - value2.X) + - (value1.Y - value2.Y) * (value1.Y - value2.Y) + - (value1.Z - value2.Z) * (value1.Z - value2.Z); - } - - public static Vector4 Divide(Vector4 value1, Vector4 value2) - { - value1.W /= value2.W; - value1.X /= value2.X; - value1.Y /= value2.Y; - value1.Z /= value2.Z; - return value1; - } - - public static Vector4 Divide(Vector4 value1, float divider) - { - float factor = 1f / divider; - value1.W *= factor; - value1.X *= factor; - value1.Y *= factor; - value1.Z *= factor; - return value1; - } - - public static void Divide(ref Vector4 value1, float divider, out Vector4 result) - { - float factor = 1f / divider; - result.W = value1.W * factor; - result.X = value1.X * factor; - result.Y = value1.Y * factor; - result.Z = value1.Z * factor; - } - - public static void Divide(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result.W = value1.W / value2.W; - result.X = value1.X / value2.X; - result.Y = value1.Y / value2.Y; - result.Z = value1.Z / value2.Z; - } - - public static float Dot(Vector4 vector1, Vector4 vector2) - { - return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; - } - - public static void Dot(ref Vector4 vector1, ref Vector4 vector2, out float result) - { - result = vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; - } - - public override bool Equals(object obj) - { - return (obj is Vector4) ? this == (Vector4)obj : false; - } - - public bool Equals(Vector4 other) - { - return this.W == other.W - && this.X == other.X - && this.Y == other.Y - && this.Z == other.Z; - } - - public override int GetHashCode() - { - return (int)(this.W + this.X + this.Y + this.Y); - } - - /*public static Vector4 Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount) - { - Vector4 result = new Vector4(); - Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); - return result; - }*/ - - /*public static void Hermite(ref Vector4 value1, ref Vector4 tangent1, ref Vector4 value2, ref Vector4 tangent2, float amount, out Vector4 result) - { - result.W = MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount); - result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); - result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); - result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); - }*/ - - public float Length() - { - float result; - DistanceSquared(ref this, ref zeroVector, out result); - return (float)Math.Sqrt(result); - } - - public float LengthSquared() - { - float result; - DistanceSquared(ref this, ref zeroVector, out result); - return result; - } - - /*public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount) - { - return new Vector4( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount), - MathHelper.Lerp(value1.Z, value2.Z, amount), - MathHelper.Lerp(value1.W, value2.W, amount)); - }*/ - - /*public static void Lerp(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) - { - result = new Vector4( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount), - MathHelper.Lerp(value1.Z, value2.Z, amount), - MathHelper.Lerp(value1.W, value2.W, amount)); - }*/ - - /*public static Vector4 Max(Vector4 value1, Vector4 value2) - { - return new Vector4( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y), - MathHelper.Max(value1.Z, value2.Z), - MathHelper.Max(value1.W, value2.W)); - }*/ - - /*public static void Max(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result = new Vector4( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y), - MathHelper.Max(value1.Z, value2.Z), - MathHelper.Max(value1.W, value2.W)); - }*/ - - /*public static Vector4 Min(Vector4 value1, Vector4 value2) - { - return new Vector4( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y), - MathHelper.Min(value1.Z, value2.Z), - MathHelper.Min(value1.W, value2.W)); - }*/ - - /*public static void Min(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result = new Vector4( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y), - MathHelper.Min(value1.Z, value2.Z), - MathHelper.Min(value1.W, value2.W)); - }*/ - - public static Vector4 Multiply(Vector4 value1, Vector4 value2) - { - value1.W *= value2.W; - value1.X *= value2.X; - value1.Y *= value2.Y; - value1.Z *= value2.Z; - return value1; - } - - public static Vector4 Multiply(Vector4 value1, float scaleFactor) - { - value1.W *= scaleFactor; - value1.X *= scaleFactor; - value1.Y *= scaleFactor; - value1.Z *= scaleFactor; - return value1; - } - - public static void Multiply(ref Vector4 value1, float scaleFactor, out Vector4 result) - { - result.W = value1.W * scaleFactor; - result.X = value1.X * scaleFactor; - result.Y = value1.Y * scaleFactor; - result.Z = value1.Z * scaleFactor; - } - - public static void Multiply(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result.W = value1.W * value2.W; - result.X = value1.X * value2.X; - result.Y = value1.Y * value2.Y; - result.Z = value1.Z * value2.Z; - } - - public static Vector4 Negate(Vector4 value) - { - value = new Vector4(-value.X, -value.Y, -value.Z, -value.W); - return value; - } - - public static void Negate(ref Vector4 value, out Vector4 result) - { - result = new Vector4(-value.X, -value.Y, -value.Z,-value.W); - } - - public void Normalize() - { - Normalize(ref this, out this); - } - - public static Vector4 Normalize(Vector4 vector) - { - Normalize(ref vector, out vector); - return vector; - } - - public static void Normalize(ref Vector4 vector, out Vector4 result) - { - float factor; - DistanceSquared(ref vector, ref zeroVector, out factor); - factor = 1f / (float)Math.Sqrt(factor); - - result.W = vector.W * factor; - result.X = vector.X * factor; - result.Y = vector.Y * factor; - result.Z = vector.Z * factor; - } - - /*public static Vector4 SmoothStep(Vector4 value1, Vector4 value2, float amount) - { - return new Vector4( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount), - MathHelper.SmoothStep(value1.Z, value2.Z, amount), - MathHelper.SmoothStep(value1.W, value2.W, amount)); - }*/ - - /*public static void SmoothStep(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) - { - result = new Vector4( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount), - MathHelper.SmoothStep(value1.Z, value2.Z, amount), - MathHelper.SmoothStep(value1.W, value2.W, amount)); - }*/ - - public static Vector4 Subtract(Vector4 value1, Vector4 value2) - { - value1.W -= value2.W; - value1.X -= value2.X; - value1.Y -= value2.Y; - value1.Z -= value2.Z; - return value1; - } - - public static void Subtract(ref Vector4 value1, ref Vector4 value2, out Vector4 result) - { - result.W = value1.W - value2.W; - result.X = value1.X - value2.X; - result.Y = value1.Y - value2.Y; - result.Z = value1.Z - value2.Z; - } - - /*public static Vector4 Transform(Vector2 position, Matrix matrix) - { - Vector4 result; - Transform(ref position, ref matrix, out result); - return result; - }*/ - - public static Vector4 Transform(Vector3 position, Matrix matrix) - { - Vector4 result; - Transform(ref position, ref matrix, out result); - return result; - } - - public static Vector4 Transform(Vector4 vector, Matrix matrix) - { - Transform(ref vector, ref matrix, out vector); - return vector; - } - - /*public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector4 result) - { - result = new Vector4((position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41, - (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42, - (position.X * matrix.M13) + (position.Y * matrix.M23) + matrix.M43, - (position.X * matrix.M14) + (position.Y * matrix.M24) + matrix.M44); - }*/ - - public static void Transform(ref Vector3 position, ref Matrix matrix, out Vector4 result) - { - result = new Vector4((position.X * matrix.M11) + (position.Y * matrix.M21) + (position.Z * matrix.M31) + matrix.M41, - (position.X * matrix.M12) + (position.Y * matrix.M22) + (position.Z * matrix.M32) + matrix.M42, - (position.X * matrix.M13) + (position.Y * matrix.M23) + (position.Z * matrix.M33) + matrix.M43, - (position.X * matrix.M14) + (position.Y * matrix.M24) + (position.Z * matrix.M34) + matrix.M44); - } - - public static void Transform(ref Vector4 vector, ref Matrix matrix, out Vector4 result) - { - result = new Vector4((vector.X * matrix.M11) + (vector.Y * matrix.M21) + (vector.Z * matrix.M31) + (vector.W * matrix.M41), - (vector.X * matrix.M12) + (vector.Y * matrix.M22) + (vector.Z * matrix.M32) + (vector.W * matrix.M42), - (vector.X * matrix.M13) + (vector.Y * matrix.M23) + (vector.Z * matrix.M33) + (vector.W * matrix.M43), - (vector.X * matrix.M14) + (vector.Y * matrix.M24) + (vector.Z * matrix.M34) + (vector.W * matrix.M44)); - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(32); - sb.Append("{X:"); - sb.Append(this.X); - sb.Append(" Y:"); - sb.Append(this.Y); - sb.Append(" Z:"); - sb.Append(this.Z); - sb.Append(" W:"); - sb.Append(this.W); - sb.Append("}"); - return sb.ToString(); - } - - #endregion Public Methods - - - #region Operators - - public static Vector4 operator -(Vector4 value) - { - return new Vector4(-value.X, -value.Y, -value.Z, -value.W); - } - - public static bool operator ==(Vector4 value1, Vector4 value2) - { - return value1.W == value2.W - && value1.X == value2.X - && value1.Y == value2.Y - && value1.Z == value2.Z; - } - - public static bool operator !=(Vector4 value1, Vector4 value2) - { - return !(value1 == value2); - } - - public static Vector4 operator +(Vector4 value1, Vector4 value2) - { - value1.W += value2.W; - value1.X += value2.X; - value1.Y += value2.Y; - value1.Z += value2.Z; - return value1; - } - - public static Vector4 operator -(Vector4 value1, Vector4 value2) - { - value1.W -= value2.W; - value1.X -= value2.X; - value1.Y -= value2.Y; - value1.Z -= value2.Z; - return value1; - } - - public static Vector4 operator *(Vector4 value1, Vector4 value2) - { - value1.W *= value2.W; - value1.X *= value2.X; - value1.Y *= value2.Y; - value1.Z *= value2.Z; - return value1; - } - - public static Vector4 operator *(Vector4 value1, float scaleFactor) - { - value1.W *= scaleFactor; - value1.X *= scaleFactor; - value1.Y *= scaleFactor; - value1.Z *= scaleFactor; - return value1; - } - - public static Vector4 operator *(float scaleFactor, Vector4 value1) - { - value1.W *= scaleFactor; - value1.X *= scaleFactor; - value1.Y *= scaleFactor; - value1.Z *= scaleFactor; - return value1; - } - - public static Vector4 operator /(Vector4 value1, Vector4 value2) - { - value1.W /= value2.W; - value1.X /= value2.X; - value1.Y /= value2.Y; - value1.Z /= value2.Z; - return value1; - } - - public static Vector4 operator /(Vector4 value1, float divider) - { - float factor = 1f / divider; - value1.W *= factor; - value1.X *= factor; - value1.Y *= factor; - value1.Z *= factor; - return value1; - } - - #endregion Operators - } -} +#region License +/* +MIT License +Copyright © 2006 The Mono.Xna Team + +All rights reserved. + +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 License + +using System; +using System.ComponentModel; +using System.Text; +using System.Runtime.InteropServices; + +namespace MonoXnaCompactMaths +{ + [Serializable] + [StructLayout(LayoutKind.Sequential)] + //[TypeConverter(typeof(Vector4Converter))] + public struct Vector4 : IEquatable + { + #region Private Fields + + private static Vector4 zeroVector = new Vector4(); + private static Vector4 unitVector = new Vector4(1f, 1f, 1f, 1f); + private static Vector4 unitXVector = new Vector4(1f, 0f, 0f, 0f); + private static Vector4 unitYVector = new Vector4(0f, 1f, 0f, 0f); + private static Vector4 unitZVector = new Vector4(0f, 0f, 1f, 0f); + private static Vector4 unitWVector = new Vector4(0f, 0f, 0f, 1f); + + #endregion Private Fields + + + #region Public Fields + + public float X; + public float Y; + public float Z; + public float W; + + #endregion Public Fields + + + #region Properties + + public static Vector4 Zero + { + get { return zeroVector; } + } + + public static Vector4 One + { + get { return unitVector; } + } + + public static Vector4 UnitX + { + get { return unitXVector; } + } + + public static Vector4 UnitY + { + get { return unitYVector; } + } + + public static Vector4 UnitZ + { + get { return unitZVector; } + } + + public static Vector4 UnitW + { + get { return unitWVector; } + } + + #endregion Properties + + + #region Constructors + + public Vector4(float x, float y, float z, float w) + { + this.X = x; + this.Y = y; + this.Z = z; + this.W = w; + } + + /*public Vector4(Vector2 value, float z, float w) + { + this.X = value.X; + this.Y = value.Y; + this.Z = z; + this.W = w; + }*/ + + public Vector4(Vector3 value, float w) + { + this.X = value.X; + this.Y = value.Y; + this.Z = value.Z; + this.W = w; + } + + public Vector4(float value) + { + this.X = value; + this.Y = value; + this.Z = value; + this.W = value; + } + + #endregion + + + #region Public Methods + + public static Vector4 Add(Vector4 value1, Vector4 value2) + { + value1.W += value2.W; + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + return value1; + } + + public static void Add(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W + value2.W; + result.X = value1.X + value2.X; + result.Y = value1.Y + value2.Y; + result.Z = value1.Z + value2.Z; + } + + /*public static Vector4 Barycentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2) + { + return new Vector4( + MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), + MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), + MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2), + MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2)); + }*/ + + /*public static void Barycentric(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, float amount1, float amount2, out Vector4 result) + { + result = new Vector4( + MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), + MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2), + MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2), + MathHelper.Barycentric(value1.W, value2.W, value3.W, amount1, amount2)); + }*/ + + /*public static Vector4 CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount) + { + return new Vector4( + MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), + MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), + MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount), + MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount)); + }*/ + + /*public static void CatmullRom(ref Vector4 value1, ref Vector4 value2, ref Vector4 value3, ref Vector4 value4, float amount, out Vector4 result) + { + result = new Vector4( + MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), + MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount), + MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount), + MathHelper.CatmullRom(value1.W, value2.W, value3.W, value4.W, amount)); + }*/ + + /*public static Vector4 Clamp(Vector4 value1, Vector4 min, Vector4 max) + { + return new Vector4( + MathHelper.Clamp(value1.X, min.X, max.X), + MathHelper.Clamp(value1.Y, min.Y, max.Y), + MathHelper.Clamp(value1.Z, min.Z, max.Z), + MathHelper.Clamp(value1.W, min.W, max.W)); + }*/ + + /*public static void Clamp(ref Vector4 value1, ref Vector4 min, ref Vector4 max, out Vector4 result) + { + result = new Vector4( + MathHelper.Clamp(value1.X, min.X, max.X), + MathHelper.Clamp(value1.Y, min.Y, max.Y), + MathHelper.Clamp(value1.Z, min.Z, max.Z), + MathHelper.Clamp(value1.W, min.W, max.W)); + }*/ + + public static float Distance(Vector4 value1, Vector4 value2) + { + return (float)Math.Sqrt(DistanceSquared(value1, value2)); + } + + public static void Distance(ref Vector4 value1, ref Vector4 value2, out float result) + { + result = (float)Math.Sqrt(DistanceSquared(value1, value2)); + } + + public static float DistanceSquared(Vector4 value1, Vector4 value2) + { + float result; + DistanceSquared(ref value1, ref value2, out result); + return result; + } + + public static void DistanceSquared(ref Vector4 value1, ref Vector4 value2, out float result) + { + result = (value1.W - value2.W) * (value1.W - value2.W) + + (value1.X - value2.X) * (value1.X - value2.X) + + (value1.Y - value2.Y) * (value1.Y - value2.Y) + + (value1.Z - value2.Z) * (value1.Z - value2.Z); + } + + public static Vector4 Divide(Vector4 value1, Vector4 value2) + { + value1.W /= value2.W; + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + public static Vector4 Divide(Vector4 value1, float divider) + { + float factor = 1f / divider; + value1.W *= factor; + value1.X *= factor; + value1.Y *= factor; + value1.Z *= factor; + return value1; + } + + public static void Divide(ref Vector4 value1, float divider, out Vector4 result) + { + float factor = 1f / divider; + result.W = value1.W * factor; + result.X = value1.X * factor; + result.Y = value1.Y * factor; + result.Z = value1.Z * factor; + } + + public static void Divide(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W / value2.W; + result.X = value1.X / value2.X; + result.Y = value1.Y / value2.Y; + result.Z = value1.Z / value2.Z; + } + + public static float Dot(Vector4 vector1, Vector4 vector2) + { + return vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; + } + + public static void Dot(ref Vector4 vector1, ref Vector4 vector2, out float result) + { + result = vector1.X * vector2.X + vector1.Y * vector2.Y + vector1.Z * vector2.Z + vector1.W * vector2.W; + } + + public override bool Equals(object obj) + { + return (obj is Vector4) ? this == (Vector4)obj : false; + } + + public bool Equals(Vector4 other) + { + return this.W == other.W + && this.X == other.X + && this.Y == other.Y + && this.Z == other.Z; + } + + public override int GetHashCode() + { + return (int)(this.W + this.X + this.Y + this.Y); + } + + /*public static Vector4 Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount) + { + Vector4 result = new Vector4(); + Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result); + return result; + }*/ + + /*public static void Hermite(ref Vector4 value1, ref Vector4 tangent1, ref Vector4 value2, ref Vector4 tangent2, float amount, out Vector4 result) + { + result.W = MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount); + result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); + result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); + result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); + }*/ + + public float Length() + { + float result; + DistanceSquared(ref this, ref zeroVector, out result); + return (float)Math.Sqrt(result); + } + + public float LengthSquared() + { + float result; + DistanceSquared(ref this, ref zeroVector, out result); + return result; + } + + /*public static Vector4 Lerp(Vector4 value1, Vector4 value2, float amount) + { + return new Vector4( + MathHelper.Lerp(value1.X, value2.X, amount), + MathHelper.Lerp(value1.Y, value2.Y, amount), + MathHelper.Lerp(value1.Z, value2.Z, amount), + MathHelper.Lerp(value1.W, value2.W, amount)); + }*/ + + /*public static void Lerp(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) + { + result = new Vector4( + MathHelper.Lerp(value1.X, value2.X, amount), + MathHelper.Lerp(value1.Y, value2.Y, amount), + MathHelper.Lerp(value1.Z, value2.Z, amount), + MathHelper.Lerp(value1.W, value2.W, amount)); + }*/ + + /*public static Vector4 Max(Vector4 value1, Vector4 value2) + { + return new Vector4( + MathHelper.Max(value1.X, value2.X), + MathHelper.Max(value1.Y, value2.Y), + MathHelper.Max(value1.Z, value2.Z), + MathHelper.Max(value1.W, value2.W)); + }*/ + + /*public static void Max(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result = new Vector4( + MathHelper.Max(value1.X, value2.X), + MathHelper.Max(value1.Y, value2.Y), + MathHelper.Max(value1.Z, value2.Z), + MathHelper.Max(value1.W, value2.W)); + }*/ + + /*public static Vector4 Min(Vector4 value1, Vector4 value2) + { + return new Vector4( + MathHelper.Min(value1.X, value2.X), + MathHelper.Min(value1.Y, value2.Y), + MathHelper.Min(value1.Z, value2.Z), + MathHelper.Min(value1.W, value2.W)); + }*/ + + /*public static void Min(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result = new Vector4( + MathHelper.Min(value1.X, value2.X), + MathHelper.Min(value1.Y, value2.Y), + MathHelper.Min(value1.Z, value2.Z), + MathHelper.Min(value1.W, value2.W)); + }*/ + + public static Vector4 Multiply(Vector4 value1, Vector4 value2) + { + value1.W *= value2.W; + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + public static Vector4 Multiply(Vector4 value1, float scaleFactor) + { + value1.W *= scaleFactor; + value1.X *= scaleFactor; + value1.Y *= scaleFactor; + value1.Z *= scaleFactor; + return value1; + } + + public static void Multiply(ref Vector4 value1, float scaleFactor, out Vector4 result) + { + result.W = value1.W * scaleFactor; + result.X = value1.X * scaleFactor; + result.Y = value1.Y * scaleFactor; + result.Z = value1.Z * scaleFactor; + } + + public static void Multiply(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W * value2.W; + result.X = value1.X * value2.X; + result.Y = value1.Y * value2.Y; + result.Z = value1.Z * value2.Z; + } + + public static Vector4 Negate(Vector4 value) + { + value = new Vector4(-value.X, -value.Y, -value.Z, -value.W); + return value; + } + + public static void Negate(ref Vector4 value, out Vector4 result) + { + result = new Vector4(-value.X, -value.Y, -value.Z,-value.W); + } + + public void Normalize() + { + Normalize(ref this, out this); + } + + public static Vector4 Normalize(Vector4 vector) + { + Normalize(ref vector, out vector); + return vector; + } + + public static void Normalize(ref Vector4 vector, out Vector4 result) + { + float factor; + DistanceSquared(ref vector, ref zeroVector, out factor); + factor = 1f / (float)Math.Sqrt(factor); + + result.W = vector.W * factor; + result.X = vector.X * factor; + result.Y = vector.Y * factor; + result.Z = vector.Z * factor; + } + + /*public static Vector4 SmoothStep(Vector4 value1, Vector4 value2, float amount) + { + return new Vector4( + MathHelper.SmoothStep(value1.X, value2.X, amount), + MathHelper.SmoothStep(value1.Y, value2.Y, amount), + MathHelper.SmoothStep(value1.Z, value2.Z, amount), + MathHelper.SmoothStep(value1.W, value2.W, amount)); + }*/ + + /*public static void SmoothStep(ref Vector4 value1, ref Vector4 value2, float amount, out Vector4 result) + { + result = new Vector4( + MathHelper.SmoothStep(value1.X, value2.X, amount), + MathHelper.SmoothStep(value1.Y, value2.Y, amount), + MathHelper.SmoothStep(value1.Z, value2.Z, amount), + MathHelper.SmoothStep(value1.W, value2.W, amount)); + }*/ + + public static Vector4 Subtract(Vector4 value1, Vector4 value2) + { + value1.W -= value2.W; + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + public static void Subtract(ref Vector4 value1, ref Vector4 value2, out Vector4 result) + { + result.W = value1.W - value2.W; + result.X = value1.X - value2.X; + result.Y = value1.Y - value2.Y; + result.Z = value1.Z - value2.Z; + } + + /*public static Vector4 Transform(Vector2 position, Matrix matrix) + { + Vector4 result; + Transform(ref position, ref matrix, out result); + return result; + }*/ + + public static Vector4 Transform(Vector3 position, Matrix matrix) + { + Vector4 result; + Transform(ref position, ref matrix, out result); + return result; + } + + public static Vector4 Transform(Vector4 vector, Matrix matrix) + { + Transform(ref vector, ref matrix, out vector); + return vector; + } + + /*public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector4 result) + { + result = new Vector4((position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41, + (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42, + (position.X * matrix.M13) + (position.Y * matrix.M23) + matrix.M43, + (position.X * matrix.M14) + (position.Y * matrix.M24) + matrix.M44); + }*/ + + public static void Transform(ref Vector3 position, ref Matrix matrix, out Vector4 result) + { + result = new Vector4((position.X * matrix.M11) + (position.Y * matrix.M21) + (position.Z * matrix.M31) + matrix.M41, + (position.X * matrix.M12) + (position.Y * matrix.M22) + (position.Z * matrix.M32) + matrix.M42, + (position.X * matrix.M13) + (position.Y * matrix.M23) + (position.Z * matrix.M33) + matrix.M43, + (position.X * matrix.M14) + (position.Y * matrix.M24) + (position.Z * matrix.M34) + matrix.M44); + } + + public static void Transform(ref Vector4 vector, ref Matrix matrix, out Vector4 result) + { + result = new Vector4((vector.X * matrix.M11) + (vector.Y * matrix.M21) + (vector.Z * matrix.M31) + (vector.W * matrix.M41), + (vector.X * matrix.M12) + (vector.Y * matrix.M22) + (vector.Z * matrix.M32) + (vector.W * matrix.M42), + (vector.X * matrix.M13) + (vector.Y * matrix.M23) + (vector.Z * matrix.M33) + (vector.W * matrix.M43), + (vector.X * matrix.M14) + (vector.Y * matrix.M24) + (vector.Z * matrix.M34) + (vector.W * matrix.M44)); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder(32); + sb.Append("{X:"); + sb.Append(this.X); + sb.Append(" Y:"); + sb.Append(this.Y); + sb.Append(" Z:"); + sb.Append(this.Z); + sb.Append(" W:"); + sb.Append(this.W); + sb.Append("}"); + return sb.ToString(); + } + + #endregion Public Methods + + + #region Operators + + public static Vector4 operator -(Vector4 value) + { + return new Vector4(-value.X, -value.Y, -value.Z, -value.W); + } + + public static bool operator ==(Vector4 value1, Vector4 value2) + { + return value1.W == value2.W + && value1.X == value2.X + && value1.Y == value2.Y + && value1.Z == value2.Z; + } + + public static bool operator !=(Vector4 value1, Vector4 value2) + { + return !(value1 == value2); + } + + public static Vector4 operator +(Vector4 value1, Vector4 value2) + { + value1.W += value2.W; + value1.X += value2.X; + value1.Y += value2.Y; + value1.Z += value2.Z; + return value1; + } + + public static Vector4 operator -(Vector4 value1, Vector4 value2) + { + value1.W -= value2.W; + value1.X -= value2.X; + value1.Y -= value2.Y; + value1.Z -= value2.Z; + return value1; + } + + public static Vector4 operator *(Vector4 value1, Vector4 value2) + { + value1.W *= value2.W; + value1.X *= value2.X; + value1.Y *= value2.Y; + value1.Z *= value2.Z; + return value1; + } + + public static Vector4 operator *(Vector4 value1, float scaleFactor) + { + value1.W *= scaleFactor; + value1.X *= scaleFactor; + value1.Y *= scaleFactor; + value1.Z *= scaleFactor; + return value1; + } + + public static Vector4 operator *(float scaleFactor, Vector4 value1) + { + value1.W *= scaleFactor; + value1.X *= scaleFactor; + value1.Y *= scaleFactor; + value1.Z *= scaleFactor; + return value1; + } + + public static Vector4 operator /(Vector4 value1, Vector4 value2) + { + value1.W /= value2.W; + value1.X /= value2.X; + value1.Y /= value2.Y; + value1.Z /= value2.Z; + return value1; + } + + public static Vector4 operator /(Vector4 value1, float divider) + { + float factor = 1f / divider; + value1.W *= factor; + value1.X *= factor; + value1.Y *= factor; + value1.Z *= factor; + return value1; + } + + #endregion Operators + } +} -- cgit v1.1