123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690 |
- #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<Matrix>
- {
- #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<Vector3> 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<Vector3> cameraForwardVector, Nullable<Vector3> 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)
- {
- return new Matrix(
- matrix1.M11 / divider, matrix1.M12 / divider, matrix1.M13 / divider, matrix1.M14 / divider,
- matrix1.M21 / divider, matrix1.M22 / divider, matrix1.M23 / divider, matrix1.M24 / divider,
- matrix1.M31 / divider, matrix1.M32 / divider, matrix1.M33 / divider, matrix1.M34 / divider,
- matrix1.M41 / divider, matrix1.M42 / divider, matrix1.M43 / divider, matrix1.M44 / divider);
- }
- 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()
- {
- return "[(" + this.M11 + ", " + this.M12 + ", " + this.M13 + ", " + this.M14 + ")\n ("
- + this.M21 + ", " + this.M22 + ", " + this.M23 + ", " + this.M24 + ")\n ("
- + this.M31 + ", " + this.M32 + ", " + this.M33 + ", " + this.M34 + ")\n ("
- + this.M41 + ", " + this.M42 + ", " + this.M43 + ", " + this.M44 + ")]";
- }
- 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
- }
- }
|