From c6997c49c849f67bf3e6f62f086fda4ed00ebf6c Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 27 Jan 2014 00:38:10 +0000 Subject: [PATCH] use openTK for graphics math types, even if, hypothetically, we make a d3d BizwareGL driver. --- .../BizHawk.Client.EmuHawk.csproj | 4 + .../IGL_TK.cs | 14 +- .../BizHawk.Bizware.BizwareGL.csproj | 21 +- .../BizHawk.Bizware.BizwareGL/GuiRenderer.cs | 2 + Bizware/BizHawk.Bizware.BizwareGL/IGL.cs | 10 +- .../BizHawk.Bizware.BizwareGL/MatrixStack.cs | 41 +- .../PipelineUniform.cs | 6 +- .../Types/BoundingBox.cs | 426 ----- .../Types/BoundingFrustum.cs | 513 ------ .../Types/BoundingSphere.cs | 363 ---- .../BizHawk.Bizware.BizwareGL/Types/Enums.cs | 76 - .../Types/MathHelper.cs | 150 -- .../BizHawk.Bizware.BizwareGL/Types/Matrix.cs | 1515 ----------------- .../BizHawk.Bizware.BizwareGL/Types/Plane.cs | 212 --- .../Types/PlaneHelper.cs | 33 - .../BizHawk.Bizware.BizwareGL/Types/Point.cs | 119 -- .../Types/Quaternion.cs | 687 -------- .../BizHawk.Bizware.BizwareGL/Types/Ray.cs | 233 --- .../Types/Rectangle.cs | 312 ---- .../BizHawk.Bizware.BizwareGL/Types/Size.cs | 368 ---- .../Types/Vector2.cs | 599 ------- .../Types/Vector3.cs | 679 -------- .../Types/Vector4.cs | 709 -------- 23 files changed, 49 insertions(+), 7043 deletions(-) delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingBox.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingFrustum.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingSphere.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Enums.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/MathHelper.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Matrix.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Plane.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/PlaneHelper.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Point.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Quaternion.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Ray.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Rectangle.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Size.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Vector2.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Vector3.cs delete mode 100644 Bizware/BizHawk.Bizware.BizwareGL/Types/Vector4.cs diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj index a9e451eda0..af1ca76e1e 100644 --- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj +++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj @@ -78,6 +78,10 @@ False ..\Newtonsoft.Json.dll + + False + ..\References\OpenTK.dll + diff --git a/Bizware/BizHawk.Bizware.BizwareGL.OpenTK/IGL_TK.cs b/Bizware/BizHawk.Bizware.BizwareGL.OpenTK/IGL_TK.cs index 9e8afd9a38..81932e3f2d 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL.OpenTK/IGL_TK.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL.OpenTK/IGL_TK.cs @@ -281,14 +281,14 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK GL.UseProgram(pipeline.Id.ToInt32()); } - unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, Matrix mat, bool transpose) + unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose) { GL.UniformMatrix4(uniform.Id.ToInt32(), 1, transpose, (float*)&mat); } - unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix mat, bool transpose) + unsafe void IGL.SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose) { - fixed(Matrix* pMat = &mat) + fixed(Matrix4* pMat = &mat) GL.UniformMatrix4(uniform.Id.ToInt32(), 1, transpose, (float*)pMat); } @@ -373,17 +373,17 @@ namespace BizHawk.Bizware.BizwareGL.Drivers.OpenTK return (this as IGL).LoadTexture(fs); } - Matrix IGL.CreateGuiProjectionMatrix(int w, int h) + Matrix4 IGL.CreateGuiProjectionMatrix(int w, int h) { - Matrix ret = Matrix.Identity; + Matrix4 ret = Matrix4.Identity; ret.M11 = 2.0f / (float)w; ret.M22 = 2.0f / (float)h; return ret; } - Matrix IGL.CreateGuiViewMatrix(int w, int h) + Matrix4 IGL.CreateGuiViewMatrix(int w, int h) { - Matrix ret = Matrix.Identity; + Matrix4 ret = Matrix4.Identity; ret.M22 = -1.0f; ret.M41 = -w * 0.5f; // -0.5f; ret.M42 = h * 0.5f; // +0.5f; diff --git a/Bizware/BizHawk.Bizware.BizwareGL/BizHawk.Bizware.BizwareGL.csproj b/Bizware/BizHawk.Bizware.BizwareGL/BizHawk.Bizware.BizwareGL.csproj index 316b1c473c..989e85ae47 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL/BizHawk.Bizware.BizwareGL.csproj +++ b/Bizware/BizHawk.Bizware.BizwareGL/BizHawk.Bizware.BizwareGL.csproj @@ -34,6 +34,10 @@ true + + False + ..\..\References\OpenTK.dll + @@ -67,23 +71,6 @@ - - - - - - - - - - Code - - - - - - - diff --git a/Bizware/BizHawk.Bizware.BizwareGL/GuiRenderer.cs b/Bizware/BizHawk.Bizware.BizwareGL/GuiRenderer.cs index 98caddda1b..313dad3bff 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL/GuiRenderer.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL/GuiRenderer.cs @@ -3,6 +3,8 @@ using System; using sd=System.Drawing; +using OpenTK; + namespace BizHawk.Bizware.BizwareGL { /// diff --git a/Bizware/BizHawk.Bizware.BizwareGL/IGL.cs b/Bizware/BizHawk.Bizware.BizwareGL/IGL.cs index 3e6f739d6f..94d8d8072b 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL/IGL.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL/IGL.cs @@ -3,6 +3,8 @@ using System.IO; using sd=System.Drawing; using swf=System.Windows.Forms; +using OpenTK; + namespace BizHawk.Bizware.BizwareGL { @@ -73,12 +75,12 @@ namespace BizHawk.Bizware.BizwareGL /// /// Sets a uniform value /// - void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix mat, bool transpose); + void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose); /// /// Sets a uniform value /// - void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix mat, bool transpose); + void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose); /// /// sets a uniform value @@ -193,12 +195,12 @@ namespace BizHawk.Bizware.BizwareGL /// /// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI /// - Matrix CreateGuiProjectionMatrix(int w, int h); + Matrix4 CreateGuiProjectionMatrix(int w, int h); /// /// generates a proper view transform for a standard 2d ortho projection, including half-pixel jitter if necessary and /// re-establishing of a normal 2d graphics top-left origin. suitable for use in a GUI /// - Matrix CreateGuiViewMatrix(int w, int h); + Matrix4 CreateGuiViewMatrix(int w, int h); } } diff --git a/Bizware/BizHawk.Bizware.BizwareGL/MatrixStack.cs b/Bizware/BizHawk.Bizware.BizwareGL/MatrixStack.cs index a24ee4c4e5..b86183cef3 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL/MatrixStack.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL/MatrixStack.cs @@ -1,6 +1,9 @@ using System; +using System.Drawing; using System.Collections.Generic; +using OpenTK; + namespace BizHawk.Bizware.BizwareGL { public class MatrixStack @@ -11,19 +14,19 @@ namespace BizHawk.Bizware.BizwareGL IsDirty = false; } - public static implicit operator Matrix(MatrixStack ms) { return ms.Top; } - public static implicit operator MatrixStack(Matrix m) { return new MatrixStack(m); } + public static implicit operator Matrix4(MatrixStack ms) { return ms.Top; } + public static implicit operator MatrixStack(Matrix4 m) { return new MatrixStack(m); } - public MatrixStack(Matrix matrix) { LoadMatrix(matrix); } + public MatrixStack(Matrix4 matrix) { LoadMatrix(matrix); } public bool IsDirty; - Stack stack = new Stack(); + Stack stack = new Stack(); /// /// This is made public for performance reasons, to avoid lame copies of the matrix when necessary. Don't mess it up! /// - public Matrix Top; + public Matrix4 Top; /// /// Resets the matrix stack to an empty identity matrix stack @@ -38,40 +41,40 @@ namespace BizHawk.Bizware.BizwareGL /// /// Clears the matrix stack and loads the specified value /// - public void Clear(Matrix value) + public void Clear(Matrix4 value) { stack.Clear(); Top = value; IsDirty = true; } - public void LoadMatrix(Matrix value) { Top = value; IsDirty = true; } + public void LoadMatrix(Matrix4 value) { Top = value; IsDirty = true; } - public void LoadIdentity() { Top = Matrix.Identity; IsDirty = true; } + public void LoadIdentity() { Top = Matrix4.Identity; IsDirty = true; } public void Pop() { Top = stack.Pop(); IsDirty = true; } public void Push() { stack.Push(Top); IsDirty = true; } - public void RotateAxis(Vector3 axisRotation, float angle) { Top = Matrix.CreateFromAxisAngle(axisRotation, angle) * Top; IsDirty = true; } + public void RotateAxis(Vector3 axisRotation, float angle) { Top = Matrix4.CreateFromAxisAngle(axisRotation, angle) * Top; IsDirty = true; } - public void Scale(Vector3 scale) { Top = Matrix.CreateScale(scale) * Top; IsDirty = true; } - public void Scale(Vector2 scale) { Top = Matrix.CreateScale(scale.X, scale.Y, 1) * Top; IsDirty = true; } - public void Scale(float x, float y, float z) { Top = Matrix.CreateScale(x, y, z) * Top; IsDirty = true; } + public void Scale(Vector3 scale) { Top = Matrix4.CreateScale(scale) * Top; IsDirty = true; } + public void Scale(Vector2 scale) { Top = Matrix4.CreateScale(scale.X, scale.Y, 1) * Top; IsDirty = true; } + public void Scale(float x, float y, float z) { Top = Matrix4.CreateScale(x, y, z) * Top; IsDirty = true; } public void Scale(float ratio) { Scale(ratio, ratio, ratio); IsDirty = true; } public void Scale(float x, float y) { Scale(x, y, 1); IsDirty = true; } - public void RotateAxis(float x, float y, float z, float degrees) { MultiplyMatrix(Matrix.CreateFromAxisAngle(new Vector3(x, y, z), degrees)); IsDirty = true; } - public void RotateY(float degrees) { MultiplyMatrix(Matrix.CreateRotationY(degrees)); IsDirty = true; } - public void RotateX(float degrees) { MultiplyMatrix(Matrix.CreateRotationX(degrees)); IsDirty = true; } - public void RotateZ(float degrees) { MultiplyMatrix(Matrix.CreateRotationZ(degrees)); IsDirty = true; } + public void RotateAxis(float x, float y, float z, float degrees) { MultiplyMatrix(Matrix4.CreateFromAxisAngle(new Vector3(x, y, z), degrees)); IsDirty = true; } + public void RotateY(float degrees) { MultiplyMatrix(Matrix4.CreateRotationY(degrees)); IsDirty = true; } + public void RotateX(float degrees) { MultiplyMatrix(Matrix4.CreateRotationX(degrees)); IsDirty = true; } + public void RotateZ(float degrees) { MultiplyMatrix(Matrix4.CreateRotationZ(degrees)); IsDirty = true; } public void Translate(Vector2 v) { Translate(v.X, v.Y, 0); IsDirty = true; } - public void Translate(Vector3 trans) { Top = Matrix.CreateTranslation(trans) * Top; IsDirty = true; } - public void Translate(float x, float y, float z) { Top = Matrix.CreateTranslation(x, y, z) * Top; IsDirty = true; } + public void Translate(Vector3 trans) { Top = Matrix4.CreateTranslation(trans) * Top; IsDirty = true; } + public void Translate(float x, float y, float z) { Top = Matrix4.CreateTranslation(x, y, z) * Top; IsDirty = true; } public void Translate(float x, float y) { Translate(x, y, 0); IsDirty = true; } public void Translate(Point pt) { Translate(pt.X, pt.Y, 0); IsDirty = true; } public void MultiplyMatrix(MatrixStack ms) { MultiplyMatrix(ms.Top); IsDirty = true; } - public void MultiplyMatrix(Matrix value) { Top = value * Top; IsDirty = true; } + public void MultiplyMatrix(Matrix4 value) { Top = value * Top; IsDirty = true; } } } \ No newline at end of file diff --git a/Bizware/BizHawk.Bizware.BizwareGL/PipelineUniform.cs b/Bizware/BizHawk.Bizware.BizwareGL/PipelineUniform.cs index 282b8144bc..5c76c849f1 100644 --- a/Bizware/BizHawk.Bizware.BizwareGL/PipelineUniform.cs +++ b/Bizware/BizHawk.Bizware.BizwareGL/PipelineUniform.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using OpenTK; + namespace BizHawk.Bizware.BizwareGL { public class PipelineUniform @@ -16,7 +18,7 @@ namespace BizHawk.Bizware.BizwareGL public IntPtr Id { get; private set; } public int SamplerIndex { get; private set; } - public void Set(Matrix mat, bool transpose = false) + public void Set(Matrix4 mat, bool transpose = false) { Owner.Owner.SetPipelineUniformMatrix(this, mat, transpose); } @@ -26,7 +28,7 @@ namespace BizHawk.Bizware.BizwareGL Owner.Owner.SetPipelineUniform(this, vec); } - public void Set(ref Matrix mat, bool transpose = false) + public void Set(ref Matrix4 mat, bool transpose = false) { Owner.Owner.SetPipelineUniformMatrix(this, ref mat, transpose); } diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingBox.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingBox.cs deleted file mode 100644 index cf917f3ee4..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingBox.cs +++ /dev/null @@ -1,426 +0,0 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -Authors: -Olivier Dufour (Duff) - -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.Collections.Generic; -using System.ComponentModel; - -namespace BizHawk.Bizware.BizwareGL -{ - public struct BoundingBox : IEquatable - { - - #region Public Fields - - public Vector3 Min; - public Vector3 Max; - public const int CornerCount = 8; - - #endregion Public Fields - - - #region Public Constructors - - public BoundingBox(Vector3 min, Vector3 max) - { - this.Min = min; - this.Max = max; - } - - #endregion Public Constructors - - - #region Public Methods - - public ContainmentType Contains(BoundingBox box) - { - //test if all corner is in the same side of a face by just checking min and max - if (box.Max.X < Min.X - || box.Min.X > Max.X - || box.Max.Y < Min.Y - || box.Min.Y > Max.Y - || box.Max.Z < Min.Z - || box.Min.Z > Max.Z) - return ContainmentType.Disjoint; - - - if (box.Min.X >= Min.X - && box.Max.X <= Max.X - && box.Min.Y >= Min.Y - && box.Max.Y <= Max.Y - && box.Min.Z >= Min.Z - && box.Max.Z <= Max.Z) - return ContainmentType.Contains; - - return ContainmentType.Intersects; - } - - public void Contains(ref BoundingBox box, out ContainmentType result) - { - result = Contains(box); - } - - public ContainmentType Contains(BoundingFrustum frustum) - { - //TODO: bad done here need a fix. - //Because question is not frustum contain box but reverse and this is not the same - int i; - ContainmentType contained; - Vector3[] corners = frustum.GetCorners(); - - // First we check if frustum is in box - for (i = 0; i < corners.Length; i++) - { - this.Contains(ref corners[i], out contained); - if (contained == ContainmentType.Disjoint) - break; - } - - if (i == corners.Length) // This means we checked all the corners and they were all contain or instersect - return ContainmentType.Contains; - - if (i != 0) // if i is not equal to zero, we can fastpath and say that this box intersects - return ContainmentType.Intersects; - - - // If we get here, it means the first (and only) point we checked was actually contained in the frustum. - // So we assume that all other points will also be contained. If one of the points is disjoint, we can - // exit immediately saying that the result is Intersects - i++; - for (; i < corners.Length; i++) - { - this.Contains(ref corners[i], out contained); - if (contained != ContainmentType.Contains) - return ContainmentType.Intersects; - - } - - // If we get here, then we know all the points were actually contained, therefore result is Contains - return ContainmentType.Contains; - } - - public ContainmentType Contains(BoundingSphere sphere) - { - if (sphere.Center.X - Min.X > sphere.Radius - && sphere.Center.Y - Min.Y > sphere.Radius - && sphere.Center.Z - Min.Z > sphere.Radius - && Max.X - sphere.Center.X > sphere.Radius - && Max.Y - sphere.Center.Y > sphere.Radius - && Max.Z - sphere.Center.Z > sphere.Radius) - return ContainmentType.Contains; - - double dmin = 0; - - if (sphere.Center.X - Min.X <= sphere.Radius) - dmin += (sphere.Center.X - Min.X) * (sphere.Center.X - Min.X); - else if (Max.X - sphere.Center.X <= sphere.Radius) - dmin += (sphere.Center.X - Max.X) * (sphere.Center.X - Max.X); - if (sphere.Center.Y - Min.Y <= sphere.Radius) - dmin += (sphere.Center.Y - Min.Y) * (sphere.Center.Y - Min.Y); - else if (Max.Y - sphere.Center.Y <= sphere.Radius) - dmin += (sphere.Center.Y - Max.Y) * (sphere.Center.Y - Max.Y); - if (sphere.Center.Z - Min.Z <= sphere.Radius) - dmin += (sphere.Center.Z - Min.Z) * (sphere.Center.Z - Min.Z); - else if (Max.Z - sphere.Center.Z <= sphere.Radius) - dmin += (sphere.Center.Z - Max.Z) * (sphere.Center.Z - Max.Z); - - if (dmin <= sphere.Radius * sphere.Radius) - return ContainmentType.Intersects; - - return ContainmentType.Disjoint; - } - - public void Contains(ref BoundingSphere sphere, out ContainmentType result) - { - result = this.Contains(sphere); - } - - public ContainmentType Contains(Vector3 point) - { - ContainmentType result; - this.Contains(ref point, out result); - return result; - } - - public void Contains(ref Vector3 point, out ContainmentType result) - { - //first we get if point is out of box - if (point.X < this.Min.X - || point.X > this.Max.X - || point.Y < this.Min.Y - || point.Y > this.Max.Y - || point.Z < this.Min.Z - || point.Z > this.Max.Z) - { - result = ContainmentType.Disjoint; - }//or if point is on box because coordonate of point is lesser or equal - else if (point.X == this.Min.X - || point.X == this.Max.X - || point.Y == this.Min.Y - || point.Y == this.Max.Y - || point.Z == this.Min.Z - || point.Z == this.Max.Z) - result = ContainmentType.Intersects; - else - result = ContainmentType.Contains; - - - } - - public static BoundingBox CreateFromPoints(IEnumerable points) - { - if (points == null) - throw new ArgumentNullException(); - - // TODO: Just check that Count > 0 - bool empty = true; - Vector3 vector2 = new Vector3(float.MaxValue); - Vector3 vector1 = new Vector3(float.MinValue); - foreach (Vector3 vector3 in points) - { - vector2 = Vector3.Min(vector2, vector3); - vector1 = Vector3.Max(vector1, vector3); - empty = false; - } - if (empty) - throw new ArgumentException(); - - return new BoundingBox(vector2, vector1); - } - - public static BoundingBox CreateFromSphere(BoundingSphere sphere) - { - Vector3 vector1 = new Vector3(sphere.Radius); - return new BoundingBox(sphere.Center - vector1, sphere.Center + vector1); - } - - public static void CreateFromSphere(ref BoundingSphere sphere, out BoundingBox result) - { - result = BoundingBox.CreateFromSphere(sphere); - } - - public static BoundingBox CreateMerged(BoundingBox original, BoundingBox additional) - { - return new BoundingBox( - Vector3.Min(original.Min, additional.Min), Vector3.Max(original.Max, additional.Max)); - } - - public static void CreateMerged(ref BoundingBox original, ref BoundingBox additional, out BoundingBox result) - { - result = BoundingBox.CreateMerged(original, additional); - } - - public bool Equals(BoundingBox other) - { - return (this.Min == other.Min) && (this.Max == other.Max); - } - - public override bool Equals(object obj) - { - return (obj is BoundingBox) ? this.Equals((BoundingBox)obj) : false; - } - - public Vector3[] GetCorners() - { - return new Vector3[] { - new Vector3(this.Min.X, this.Max.Y, this.Max.Z), - new Vector3(this.Max.X, this.Max.Y, this.Max.Z), - new Vector3(this.Max.X, this.Min.Y, this.Max.Z), - new Vector3(this.Min.X, this.Min.Y, this.Max.Z), - new Vector3(this.Min.X, this.Max.Y, this.Min.Z), - new Vector3(this.Max.X, this.Max.Y, this.Min.Z), - new Vector3(this.Max.X, this.Min.Y, this.Min.Z), - new Vector3(this.Min.X, this.Min.Y, this.Min.Z) - }; - } - - public void GetCorners(Vector3[] corners) - { - if (corners == null) - { - throw new ArgumentNullException("corners"); - } - if (corners.Length < 8) - { - throw new ArgumentOutOfRangeException("corners", "Not Enought Corners"); - } - corners[0].X = this.Min.X; - corners[0].Y = this.Max.Y; - corners[0].Z = this.Max.Z; - corners[1].X = this.Max.X; - corners[1].Y = this.Max.Y; - corners[1].Z = this.Max.Z; - corners[2].X = this.Max.X; - corners[2].Y = this.Min.Y; - corners[2].Z = this.Max.Z; - corners[3].X = this.Min.X; - corners[3].Y = this.Min.Y; - corners[3].Z = this.Max.Z; - corners[4].X = this.Min.X; - corners[4].Y = this.Max.Y; - corners[4].Z = this.Min.Z; - corners[5].X = this.Max.X; - corners[5].Y = this.Max.Y; - corners[5].Z = this.Min.Z; - corners[6].X = this.Max.X; - corners[6].Y = this.Min.Y; - corners[6].Z = this.Min.Z; - corners[7].X = this.Min.X; - corners[7].Y = this.Min.Y; - corners[7].Z = this.Min.Z; - } - - public override int GetHashCode() - { - return this.Min.GetHashCode() + this.Max.GetHashCode(); - } - - public bool Intersects(BoundingBox box) - { - bool result; - Intersects(ref box, out result); - return result; - } - - public void Intersects(ref BoundingBox box, out bool result) - { - if ((this.Max.X >= box.Min.X) && (this.Min.X <= box.Max.X)) - { - if ((this.Max.Y < box.Min.Y) || (this.Min.Y > box.Max.Y)) - { - result = false; - return; - } - - result = (this.Max.Z >= box.Min.Z) && (this.Min.Z <= box.Max.Z); - return; - } - - result = false; - return; - } - - public bool Intersects(BoundingFrustum frustum) - { - return frustum.Intersects(this); - } - - public bool Intersects(BoundingSphere sphere) - { - if (sphere.Center.X - Min.X > sphere.Radius - && sphere.Center.Y - Min.Y > sphere.Radius - && sphere.Center.Z - Min.Z > sphere.Radius - && Max.X - sphere.Center.X > sphere.Radius - && Max.Y - sphere.Center.Y > sphere.Radius - && Max.Z - sphere.Center.Z > sphere.Radius) - return true; - - double dmin = 0; - - if (sphere.Center.X - Min.X <= sphere.Radius) - dmin += (sphere.Center.X - Min.X) * (sphere.Center.X - Min.X); - else if (Max.X - sphere.Center.X <= sphere.Radius) - dmin += (sphere.Center.X - Max.X) * (sphere.Center.X - Max.X); - - if (sphere.Center.Y - Min.Y <= sphere.Radius) - dmin += (sphere.Center.Y - Min.Y) * (sphere.Center.Y - Min.Y); - else if (Max.Y - sphere.Center.Y <= sphere.Radius) - dmin += (sphere.Center.Y - Max.Y) * (sphere.Center.Y - Max.Y); - - if (sphere.Center.Z - Min.Z <= sphere.Radius) - dmin += (sphere.Center.Z - Min.Z) * (sphere.Center.Z - Min.Z); - else if (Max.Z - sphere.Center.Z <= sphere.Radius) - dmin += (sphere.Center.Z - Max.Z) * (sphere.Center.Z - Max.Z); - - if (dmin <= sphere.Radius * sphere.Radius) - return true; - - return false; - } - - public void Intersects(ref BoundingSphere sphere, out bool result) - { - result = Intersects(sphere); - } - - public PlaneIntersectionType Intersects(Plane plane) - { - //check all corner side of plane - Vector3[] corners = this.GetCorners(); - float lastdistance = Vector3.Dot(plane.Normal, corners[0]) + plane.D; - - for (int i = 1; i < corners.Length; i++) - { - float distance = Vector3.Dot(plane.Normal, corners[i]) + plane.D; - if ((distance <= 0.0f && lastdistance > 0.0f) || (distance >= 0.0f && lastdistance < 0.0f)) - return PlaneIntersectionType.Intersecting; - lastdistance = distance; - } - - if (lastdistance > 0.0f) - return PlaneIntersectionType.Front; - - return PlaneIntersectionType.Back; - - } - - public void Intersects(ref Plane plane, out PlaneIntersectionType result) - { - result = Intersects(plane); - } - - public Nullable Intersects(Ray ray) - { - return ray.Intersects(this); - } - - public void Intersects(ref Ray ray, out Nullable result) - { - result = Intersects(ray); - } - - public static bool operator ==(BoundingBox a, BoundingBox b) - { - return a.Equals(b); - } - - public static bool operator !=(BoundingBox a, BoundingBox b) - { - return !a.Equals(b); - } - - public override string ToString() - { - return string.Format("{{Min:{0} Max:{1}}}", this.Min.ToString(), this.Max.ToString()); - } - - #endregion Public Methods - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingFrustum.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingFrustum.cs deleted file mode 100644 index 463bfc0b9a..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingFrustum.cs +++ /dev/null @@ -1,513 +0,0 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -Authors: -Olivier Dufour (Duff) - -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.Collections.Generic; -using System.ComponentModel; -using System.Runtime.InteropServices; -using System.Text; - -namespace BizHawk.Bizware.BizwareGL -{ - [Serializable, TypeConverter(typeof(ExpandableObjectConverter))] - public class BoundingFrustum : IEquatable - { - #region Private Fields - - private Matrix matrix; - private Plane bottom; - private Plane far; - private Plane left; - private Plane right; - private Plane near; - private Plane top; - private Vector3[] corners; - - #endregion Private Fields - - #region Public Fields - public const int CornerCount = 8; - #endregion - - #region Public Constructors - - public BoundingFrustum(Matrix value) - { - this.matrix = value; - CreatePlanes(); - CreateCorners(); - } - - #endregion Public Constructors - - - #region Public Properties - - public Plane Bottom - { - get { return this.bottom; } - } - - public Plane Far - { - get { return this.far; } - } - - public Plane Left - { - get { return this.left; } - } - - public Matrix Matrix - { - get { return this.matrix; } - set - { - this.matrix = value; - this.CreatePlanes(); // FIXME: The odds are the planes will be used a lot more often than the matrix - this.CreateCorners(); // is updated, so this should help performance. I hope ;) - } - } - - public Plane Near - { - get { return this.near; } - } - - public Plane Right - { - get { return this.right; } - } - - public Plane Top - { - get { return this.top; } - } - - #endregion Public Properties - - - #region Public Methods - - public static bool operator ==(BoundingFrustum a, BoundingFrustum b) - { - if (object.Equals(a, null)) - return (object.Equals(b, null)); - - if (object.Equals(b, null)) - return (object.Equals(a, null)); - - return a.matrix == (b.matrix); - } - - public static bool operator !=(BoundingFrustum a, BoundingFrustum b) - { - return !(a == b); - } - - public ContainmentType Contains(BoundingBox box) - { - ContainmentType result; - this.Contains(ref box, out result); - return result; - } - - public void GetCorners(Vector3[] corners) - { - throw new NotImplementedException(); - } - - public void Contains(ref BoundingBox box, out ContainmentType result) - { - // FIXME: Is this a bug? - // If the bounding box is of W * D * H = 0, then return disjoint - if (box.Min == box.Max) - { - result = ContainmentType.Disjoint; - return; - } - - int i; - ContainmentType contained; - Vector3[] corners = box.GetCorners(); - - // First we assume completely disjoint. So if we find a point that is contained, we break out of this loop - for (i = 0; i < corners.Length; i++) - { - this.Contains(ref corners[i], out contained); - if (contained != ContainmentType.Disjoint) - break; - } - - if (i == corners.Length) // This means we checked all the corners and they were all disjoint - { - result = ContainmentType.Disjoint; - return; - } - - if (i != 0) // if i is not equal to zero, we can fastpath and say that this box intersects - { // because we know at least one point is outside and one is inside. - result = ContainmentType.Intersects; - return; - } - - // If we get here, it means the first (and only) point we checked was actually contained in the frustum. - // So we assume that all other points will also be contained. If one of the points is disjoint, we can - // exit immediately saying that the result is Intersects - i++; - for (; i < corners.Length; i++) - { - this.Contains(ref corners[i], out contained); - if (contained != ContainmentType.Contains) - { - result = ContainmentType.Intersects; - return; - } - } - - // If we get here, then we know all the points were actually contained, therefore result is Contains - result = ContainmentType.Contains; - return; - } - - // TODO: Implement this - public ContainmentType Contains(BoundingFrustum frustum) - { - if (this == frustum) // We check to see if the two frustums are equal - return ContainmentType.Contains;// If they are, there's no need to go any further. - - throw new NotImplementedException(); - } - - public ContainmentType Contains(BoundingSphere sphere) - { - ContainmentType result; - this.Contains(ref sphere, out result); - return result; - } - - public void Contains(ref BoundingSphere sphere, out ContainmentType result) - { - float val; - ContainmentType contained; - - // We first check if the sphere is inside the frustum - this.Contains(ref sphere.Center, out contained); - - // The sphere is inside. Now we need to check if it's fully contained or not - // So we see if the perpendicular distance to each plane is less than or equal to the sphere's radius. - // If the perpendicular distance is less, just return Intersects. - if (contained == ContainmentType.Contains) - { - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.bottom); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.far); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.left); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.near); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.right); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - val = PlaneHelper.PerpendicularDistance(ref sphere.Center, ref this.top); - if (val < sphere.Radius) - { - result = ContainmentType.Intersects; - return; - } - - // If we get here, the sphere is fully contained - result = ContainmentType.Contains; - return; - } - //duff idea : test if all corner is in same side of a plane if yes and outside it is disjoint else intersect - // issue is that we can have some times when really close aabb - - - - // If we're here, the the sphere's centre was outside of the frustum. This makes things hard :( - // We can't use perpendicular distance anymore. I'm not sure how to code this. - throw new NotImplementedException(); - } - - public ContainmentType Contains(Vector3 point) - { - ContainmentType result; - this.Contains(ref point, out result); - return result; - } - - public void Contains(ref Vector3 point, out ContainmentType result) - { - float val; - // If a point is on the POSITIVE side of the plane, then the point is not contained within the frustum - - // Check the top - val = PlaneHelper.ClassifyPoint(ref point, ref this.top); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // Check the bottom - val = PlaneHelper.ClassifyPoint(ref point, ref this.bottom); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // Check the left - val = PlaneHelper.ClassifyPoint(ref point, ref this.left); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // Check the right - val = PlaneHelper.ClassifyPoint(ref point, ref this.right); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // Check the near - val = PlaneHelper.ClassifyPoint(ref point, ref this.near); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // Check the far - val = PlaneHelper.ClassifyPoint(ref point, ref this.far); - if (val > 0) - { - result = ContainmentType.Disjoint; - return; - } - - // If we get here, it means that the point was on the correct side of each plane to be - // contained. Therefore this point is contained - result = ContainmentType.Contains; - } - - public bool Equals(BoundingFrustum other) - { - return (this == other); - } - - public override bool Equals(object obj) - { - BoundingFrustum f = obj as BoundingFrustum; - return (object.Equals(f, null)) ? false : (this == f); - } - - public Vector3[] GetCorners() - { - return corners; - } - - public override int GetHashCode() - { - return this.matrix.GetHashCode(); - } - - public bool Intersects(BoundingBox box) - { - throw new NotImplementedException(); - } - - public void Intersects(ref BoundingBox box, out bool result) - { - throw new NotImplementedException(); - } - - public bool Intersects(BoundingFrustum frustum) - { - throw new NotImplementedException(); - } - - public bool Intersects(BoundingSphere sphere) - { - throw new NotImplementedException(); - } - - public void Intersects(ref BoundingSphere sphere, out bool result) - { - throw new NotImplementedException(); - } - - public PlaneIntersectionType Intersects(Plane plane) - { - throw new NotImplementedException(); - } - - public void Intersects(ref Plane plane, out PlaneIntersectionType result) - { - throw new NotImplementedException(); - } - - public Nullable Intersects(Ray ray) - { - throw new NotImplementedException(); - } - - public void Intersects(ref Ray ray, out Nullable result) - { - throw new NotImplementedException(); - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(256); - sb.Append("{Near:"); - sb.Append(this.near.ToString()); - sb.Append(" Far:"); - sb.Append(this.far.ToString()); - sb.Append(" Left:"); - sb.Append(this.left.ToString()); - sb.Append(" Right:"); - sb.Append(this.right.ToString()); - sb.Append(" Top:"); - sb.Append(this.top.ToString()); - sb.Append(" Bottom:"); - sb.Append(this.bottom.ToString()); - sb.Append("}"); - return sb.ToString(); - } - - #endregion Public Methods - - - #region Private Methods - - private void CreateCorners() - { - this.corners = new Vector3[8]; - this.corners[0] = IntersectionPoint(ref this.near, ref this.left, ref this.top); - this.corners[1] = IntersectionPoint(ref this.near, ref this.right, ref this.top); - this.corners[2] = IntersectionPoint(ref this.near, ref this.right, ref this.bottom); - this.corners[3] = IntersectionPoint(ref this.near, ref this.left, ref this.bottom); - this.corners[4] = IntersectionPoint(ref this.far, ref this.left, ref this.top); - this.corners[5] = IntersectionPoint(ref this.far, ref this.right, ref this.top); - this.corners[6] = IntersectionPoint(ref this.far, ref this.right, ref this.bottom); - this.corners[7] = IntersectionPoint(ref this.far, ref this.left, ref this.bottom); - } - - private void CreatePlanes() - { - // Pre-calculate the different planes needed - this.left = new Plane(-this.matrix.M14 - this.matrix.M11, -this.matrix.M24 - this.matrix.M21, - -this.matrix.M34 - this.matrix.M31, -this.matrix.M44 - this.matrix.M41); - - this.right = new Plane(this.matrix.M11 - this.matrix.M14, this.matrix.M21 - this.matrix.M24, - this.matrix.M31 - this.matrix.M34, this.matrix.M41 - this.matrix.M44); - - this.top = new Plane(this.matrix.M12 - this.matrix.M14, this.matrix.M22 - this.matrix.M24, - this.matrix.M32 - this.matrix.M34, this.matrix.M42 - this.matrix.M44); - - this.bottom = new Plane(-this.matrix.M14 - this.matrix.M12, -this.matrix.M24 - this.matrix.M22, - -this.matrix.M34 - this.matrix.M32, -this.matrix.M44 - this.matrix.M42); - - this.near = new Plane(-this.matrix.M13, -this.matrix.M23, -this.matrix.M33, -this.matrix.M43); - - - this.far = new Plane(this.matrix.M13 - this.matrix.M14, this.matrix.M23 - this.matrix.M24, - this.matrix.M33 - this.matrix.M34, this.matrix.M43 - this.matrix.M44); - - this.NormalizePlane(ref this.left); - this.NormalizePlane(ref this.right); - this.NormalizePlane(ref this.top); - this.NormalizePlane(ref this.bottom); - this.NormalizePlane(ref this.near); - this.NormalizePlane(ref this.far); - } - - private static Vector3 IntersectionPoint(ref Plane a, ref Plane b, ref Plane c) - { - // Formula used - // d1 ( N2 * N3 ) + d2 ( N3 * N1 ) + d3 ( N1 * N2 ) - //P = ------------------------------------------------------------------------- - // N1 . ( N2 * N3 ) - // - // Note: N refers to the normal, d refers to the displacement. '.' means dot product. '*' means cross product - - Vector3 v1, v2, v3; - float f = -Vector3.Dot(a.Normal, Vector3.Cross(b.Normal, c.Normal)); - - v1 = (a.D * (Vector3.Cross(b.Normal, c.Normal))); - v2 = (b.D * (Vector3.Cross(c.Normal, a.Normal))); - v3 = (c.D * (Vector3.Cross(a.Normal, b.Normal))); - - Vector3 vec = new Vector3(v1.X + v2.X + v3.X, v1.Y + v2.Y + v3.Y, v1.Z + v2.Z + v3.Z); - return vec / f; - } - - private void NormalizePlane(ref Plane p) - { - float factor = 1f / p.Normal.Length(); - p.Normal.X *= factor; - p.Normal.Y *= factor; - p.Normal.Z *= factor; - p.D *= factor; - } - - #endregion - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingSphere.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingSphere.cs deleted file mode 100644 index b1895286db..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/BoundingSphere.cs +++ /dev/null @@ -1,363 +0,0 @@ -#region License -/* -MIT License -Copyright © 2006 The Mono.Xna Team - -All rights reserved. - -Authors: -Olivier Dufour (Duff) - -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.Collections.Generic; -using System.Globalization; -using System.ComponentModel; - -namespace BizHawk.Bizware.BizwareGL -{ - public struct BoundingSphere : IEquatable - { - #region Public Fields - - public Vector3 Center; - public float Radius; - - #endregion Public Fields - - - #region Constructors - - public BoundingSphere(Vector3 center, float radius) - { - this.Center = center; - this.Radius = radius; - } - - #endregion Constructors - - - #region Public Methods - - public BoundingSphere Transform(Matrix matrix) - { - BoundingSphere sphere = new BoundingSphere(); - sphere.Center = Vector3.Transform(this.Center, matrix); - sphere.Radius = this.Radius * ((float)Math.Sqrt((double)Math.Max(((matrix.M11 * matrix.M11) + (matrix.M12 * matrix.M12)) + (matrix.M13 * matrix.M13), Math.Max(((matrix.M21 * matrix.M21) + (matrix.M22 * matrix.M22)) + (matrix.M23 * matrix.M23), ((matrix.M31 * matrix.M31) + (matrix.M32 * matrix.M32)) + (matrix.M33 * matrix.M33))))); - return sphere; - } - - public void Transform(ref Matrix matrix, out BoundingSphere result) - { - result.Center = Vector3.Transform(this.Center, matrix); - result.Radius = this.Radius * ((float)Math.Sqrt((double)Math.Max(((matrix.M11 * matrix.M11) + (matrix.M12 * matrix.M12)) + (matrix.M13 * matrix.M13), Math.Max(((matrix.M21 * matrix.M21) + (matrix.M22 * matrix.M22)) + (matrix.M23 * matrix.M23), ((matrix.M31 * matrix.M31) + (matrix.M32 * matrix.M32)) + (matrix.M33 * matrix.M33))))); - } - - public ContainmentType Contains(BoundingBox box) - { - //check if all corner is in sphere - bool inside = true; - foreach (Vector3 corner in box.GetCorners()) - { - if (this.Contains(corner) == ContainmentType.Disjoint) - { - inside = false; - break; - } - } - - if (inside) - return ContainmentType.Contains; - - //check if the distance from sphere center to cube face < radius - double dmin = 0; - - if (Center.X < box.Min.X) - dmin += (Center.X - box.Min.X) * (Center.X - box.Min.X); - - else if (Center.X > box.Max.X) - dmin += (Center.X - box.Max.X) * (Center.X - box.Max.X); - - if (Center.Y < box.Min.Y) - dmin += (Center.Y - box.Min.Y) * (Center.Y - box.Min.Y); - - else if (Center.Y > box.Max.Y) - dmin += (Center.Y - box.Max.Y) * (Center.Y - box.Max.Y); - - if (Center.Z < box.Min.Z) - dmin += (Center.Z - box.Min.Z) * (Center.Z - box.Min.Z); - - else if (Center.Z > box.Max.Z) - dmin += (Center.Z - box.Max.Z) * (Center.Z - box.Max.Z); - - if (dmin <= Radius * Radius) - return ContainmentType.Intersects; - - //else disjoint - return ContainmentType.Disjoint; - - } - - public void Contains(ref BoundingBox box, out ContainmentType result) - { - result = this.Contains(box); - } - - public ContainmentType Contains(BoundingFrustum frustum) - { - //check if all corner is in sphere - bool inside = true; - - Vector3[] corners = frustum.GetCorners(); - foreach (Vector3 corner in corners) - { - if (this.Contains(corner) == ContainmentType.Disjoint) - { - inside = false; - break; - } - } - if (inside) - return ContainmentType.Contains; - - //check if the distance from sphere center to frustrum face < radius - double dmin = 0; - //TODO : calcul dmin - - if (dmin <= Radius * Radius) - return ContainmentType.Intersects; - - //else disjoint - return ContainmentType.Disjoint; - } - - public ContainmentType Contains(BoundingSphere sphere) - { - float val = Vector3.Distance(sphere.Center, Center); - - if (val > sphere.Radius + Radius) - return ContainmentType.Disjoint; - - else if (val <= Radius - sphere.Radius) - return ContainmentType.Contains; - - else - return ContainmentType.Intersects; - } - - public void Contains(ref BoundingSphere sphere, out ContainmentType result) - { - result = Contains(sphere); - } - - public ContainmentType Contains(Vector3 point) - { - float distance = Vector3.Distance(point, Center); - - if (distance > this.Radius) - return ContainmentType.Disjoint; - - else if (distance < this.Radius) - return ContainmentType.Contains; - - return ContainmentType.Intersects; - } - - public void Contains(ref Vector3 point, out ContainmentType result) - { - result = Contains(point); - } - - public static BoundingSphere CreateFromBoundingBox(BoundingBox box) - { - // Find the center of the box. - Vector3 center = new Vector3((box.Min.X + box.Max.X) / 2.0f, - (box.Min.Y + box.Max.Y) / 2.0f, - (box.Min.Z + box.Max.Z) / 2.0f); - - // Find the distance between the center and one of the corners of the box. - float radius = Vector3.Distance(center, box.Max); - - return new BoundingSphere(center, radius); - } - - public static void CreateFromBoundingBox(ref BoundingBox box, out BoundingSphere result) - { - result = CreateFromBoundingBox(box); - } - - public static BoundingSphere CreateFromFrustum(BoundingFrustum frustum) - { - return BoundingSphere.CreateFromPoints(frustum.GetCorners()); - } - - public static BoundingSphere CreateFromPoints(IEnumerable points) - { - if (points == null) - throw new ArgumentNullException("points"); - - float radius = 0; - Vector3 center = new Vector3(); - // First, we'll find the center of gravity for the point 'cloud'. - int num_points = 0; // The number of points (there MUST be a better way to get this instead of counting the number of points one by one?) - - foreach (Vector3 v in points) - { - center += v; // If we actually knew the number of points, we'd get better accuracy by adding v / num_points. - ++num_points; - } - - center /= (float)num_points; - - // Calculate the radius of the needed sphere (it equals the distance between the center and the point further away). - foreach (Vector3 v in points) - { - float distance = ((Vector3)(v - center)).Length(); - - if (distance > radius) - radius = distance; - } - - return new BoundingSphere(center, radius); - } - - public static BoundingSphere CreateMerged(BoundingSphere original, BoundingSphere additional) - { - Vector3 ocenterToaCenter = Vector3.Subtract(additional.Center, original.Center); - float distance = ocenterToaCenter.Length(); - if (distance <= original.Radius + additional.Radius)//intersect - { - if (distance <= original.Radius - additional.Radius)//original contain additional - return original; - if (distance <= additional.Radius - original.Radius)//additional contain original - return additional; - } - - //else find center of new sphere and radius - float leftRadius = Math.Max(original.Radius - distance, additional.Radius); - float Rightradius = Math.Max(original.Radius + distance, additional.Radius); - ocenterToaCenter = ocenterToaCenter + (((leftRadius - Rightradius) / (2 * ocenterToaCenter.Length())) * ocenterToaCenter);//oCenterToResultCenter - - BoundingSphere result = new BoundingSphere(); - result.Center = original.Center + ocenterToaCenter; - result.Radius = (leftRadius + Rightradius) / 2; - return result; - } - - public static void CreateMerged(ref BoundingSphere original, ref BoundingSphere additional, out BoundingSphere result) - { - result = BoundingSphere.CreateMerged(original, additional); - } - - public bool Equals(BoundingSphere other) - { - return this.Center == other.Center && this.Radius == other.Radius; - } - - public override bool Equals(object obj) - { - if (obj is BoundingSphere) - return this.Equals((BoundingSphere)obj); - - return false; - } - - public override int GetHashCode() - { - return this.Center.GetHashCode() + this.Radius.GetHashCode(); - } - - public bool Intersects(BoundingBox box) - { - return box.Intersects(this); - } - - public void Intersects(ref BoundingBox box, out bool result) - { - result = Intersects(box); - } - - public bool Intersects(BoundingFrustum frustum) - { - if (frustum == null) - throw new NullReferenceException(); - - throw new NotImplementedException(); - } - - public bool Intersects(BoundingSphere sphere) - { - float val = Vector3.Distance(sphere.Center, Center); - if (val > sphere.Radius + Radius) - return false; - return true; - } - - public void Intersects(ref BoundingSphere sphere, out bool result) - { - result = Intersects(sphere); - } - - public PlaneIntersectionType Intersects(Plane plane) - { - float distance = Vector3.Dot(plane.Normal, this.Center) + plane.D; - if (distance > this.Radius) - return PlaneIntersectionType.Front; - if (distance < -this.Radius) - return PlaneIntersectionType.Back; - //else it intersect - return PlaneIntersectionType.Intersecting; - } - - public void Intersects(ref Plane plane, out PlaneIntersectionType result) - { - result = Intersects(plane); - } - - public Nullable Intersects(Ray ray) - { - return ray.Intersects(this); - } - - public void Intersects(ref Ray ray, out Nullable result) - { - result = Intersects(ray); - } - - public static bool operator == (BoundingSphere a, BoundingSphere b) - { - return a.Equals(b); - } - - public static bool operator != (BoundingSphere a, BoundingSphere b) - { - return !a.Equals(b); - } - - public override string ToString() - { - return string.Format(CultureInfo.CurrentCulture, "{{Center:{0} Radius:{1}}}", this.Center.ToString(), this.Radius.ToString()); - } - - #endregion Public Methods - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Enums.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Enums.cs deleted file mode 100644 index 493e3abf00..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Enums.cs +++ /dev/null @@ -1,76 +0,0 @@ -#region License -/* -MIT License -Copyright © 2006 - 2007 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; - -namespace BizHawk.Bizware.BizwareGL -{ - - public enum CurveLoopType - { - Constant, - Cycle, - CycleOffset, - Oscillate, - Linear - } - - public enum CurveContinuity - { - Smooth, - Step - } - - public enum CurveTangent - { - Flat, - Linear, - Smooth - } - - public enum TargetPlatform - { - Unknown, - Windows, - Xbox360, - Zune - } - - public enum PlaneIntersectionType - { - Front, - Back, - Intersecting - } - - public enum ContainmentType - { - Disjoint, - Contains, - Intersects - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/MathHelper.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/MathHelper.cs deleted file mode 100644 index 2b5022292d..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/MathHelper.cs +++ /dev/null @@ -1,150 +0,0 @@ -#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.Collections.Generic; -using System.Text; - -namespace BizHawk.Bizware.BizwareGL -{ - public static class MathHelper - { - public const float E = (float)Math.E; - public const float Log10E = 0.4342945f; - public const float Log2E = 1.442695f; - public const float Pi = (float)Math.PI; - public const float PiOver2 = (float)(Math.PI / 2.0); - public const float PiOver4 = (float)(Math.PI / 4.0); - public const float TwoPi = (float)(Math.PI * 2.0); - - public static float Barycentric(float value1, float value2, float value3, float amount1, float amount2) - { - return value1 + (value2 - value1) * amount1 + (value3 - value1) * amount2; - } - - public static float CatmullRom(float value1, float value2, float value3, float value4, float amount) - { - // Using formula from http://www.mvps.org/directx/articles/catmull/ - // Internally using doubles not to lose precission - double amountSquared = amount * amount; - double amountCubed = amountSquared * amount; - return (float)(0.5f * (2.0f * value2 + - (value3 - value1) * amount + - (2.0f * value1 - 5.0f * value2 + 4.0f * value3 - value4) * amountSquared + - (3.0f * value2 - value1 - 3.0f * value3 + value4) * amountCubed)); - } - - public static float Clamp(float value, float min, float max) - { - return value > max ? max : (value < min ? min : value); - } - - public static float Distance(float value1, float value2) - { - return Math.Abs(value1 - value2); - } - - public static float Hermite(float value1, float tangent1, float value2, float tangent2, float amount) - { - // All transformed to double not to lose precission - // Otherwise, for high numbers of param:amount the result is NaN instead of Infinity - double v1 = value1, v2 = value2, t1 = tangent1, t2 = tangent2, s = amount, result; - double sCubed = s * s * s; - double sSquared = s * s; - - if (amount == 0f) - result = value1; - else if (amount == 1f) - result = value2; - else - result = (2.0f * v1 - 2.0f * v2 + t2 + t1) * sCubed + - (3.0f * v2 - 3.0f * v1 - 2.0f * t1 - t2) * sSquared + - t1 * s + - v1; - return (float)result; - } - - - public static float Lerp(float value1, float value2, float amount) - { - return value1 + (value2 - value1) * amount; - } - - public static float Max(float value1, float value2) - { - return Math.Max(value1, value2); - } - - public static float Min(float value1, float value2) - { - return Math.Min(value1, value2); - } - - public static float SmoothStep(float value1, float value2, float amount) - { - // It is expected that 0 < amount < 1 - // If amount < 0, return value1 - // If amount > 1, return value2 - float result = MathHelper.Clamp(amount, 0f, 1f); - result = MathHelper.Hermite(value1, 0f, value2, 0f, result); - return result; - } - - public static float ToDegrees(float radians) - { - // This method uses double precission internally, - // though it returns single float - // Factor = 180 / pi - return (float)(radians * 57.295779513082320876798154814105); - } - - public static float ToRadians(float degrees) - { - // This method uses double precission internally, - // though it returns single float - // Factor = pi / 180 - return (float)(degrees * 0.017453292519943295769236907684886); - } - - - public static float WrapAngle(float angle) - { - angle = (float)Math.IEEERemainder((double)angle, 6.2831854820251465); //2xPi precission is double - if (angle <= -3.141593f) - { - angle += 6.283185f; - return angle; - } - if (angle > 3.141593f) - { - angle -= 6.283185f; - } - return angle; - } - - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Matrix.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Matrix.cs deleted file mode 100644 index 9238029847..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Matrix.cs +++ /dev/null @@ -1,1515 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - - public struct Matrix : IEquatable - { - #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 Static Properties - - private static Matrix identity = new Matrix(1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 1f); - public static Matrix Identity { - get { return identity; } - } - - #endregion Static Properties - - - #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 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 Constructors - /// - /// Constructor for 4x4 Matrix - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - 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 Constructors - - #region Public Static Methods - - public static Matrix CreateWorld(Vector3 position, Vector3 forward, Vector3 up) - { - Matrix ret; - CreateWorld(ref position, ref forward, ref up, out ret); - return ret; - } - - public static void CreateWorld(ref Vector3 position, ref Vector3 forward, ref Vector3 up, out Matrix result) - { - Vector3 x, y, z; - Vector3.Normalize(ref forward, out z); - Vector3.Cross(ref forward, ref up, out x); - Vector3.Cross(ref x, ref forward, out y); - x.Normalize(); - y.Normalize(); - - result = new Matrix(); - result.Right = x; - result.Up = y; - result.Forward = z; - result.Translation = position; - result.M44 = 1f; - } - - public static Matrix CreateShadow(Vector3 lightDirection, Plane plane) - { - Matrix ret; - CreateShadow(ref lightDirection, ref plane, out ret); - return ret; - } - - public static void CreateShadow(ref Vector3 lightDirection, ref Plane plane, out Matrix result) - { - // Formula: - // http://msdn.microsoft.com/en-us/library/bb205364(v=VS.85).aspx - - Plane p = Plane.Normalize(plane); - float d = Vector3.Dot(p.Normal, lightDirection); - - result.M11 = -1 * p.Normal.X * lightDirection.X + d; - result.M12 = -1 * p.Normal.X * lightDirection.Y; - result.M13 = -1 * p.Normal.X * lightDirection.Z; - result.M14 = 0; - result.M21 = -1 * p.Normal.Y * lightDirection.X; - result.M22 = -1 * p.Normal.Y * lightDirection.Y + d; - result.M23 = -1 * p.Normal.Y * lightDirection.Z; - result.M24 = 0; - result.M31 = -1 * p.Normal.Z * lightDirection.X; - result.M32 = -1 * p.Normal.Z * lightDirection.Y; - result.M33 = -1 * p.Normal.Z * lightDirection.Z + d; - result.M34 = 0; - result.M41 = -1 * p.D * lightDirection.X; - result.M42 = -1 * p.D * lightDirection.Y; - result.M43 = -1 * p.D * lightDirection.Z; - result.M44 = d; - } - - public static void CreateReflection(ref Plane value, out Matrix result) - { - // Formula: - // http://msdn.microsoft.com/en-us/library/bb205356(v=VS.85).aspx - - Plane p = Plane.Normalize(value); - - result.M11 = -2 * p.Normal.X * p.Normal.X + 1; - result.M12 = -2 * p.Normal.X * p.Normal.Y; - result.M13 = -2 * p.Normal.X * p.Normal.Z; - result.M14 = 0; - result.M21 = -2 * p.Normal.Y * p.Normal.X; - result.M22 = -2 * p.Normal.Y * p.Normal.Y + 1; - result.M23 = -2 * p.Normal.Y * p.Normal.Z; - result.M24 = 0; - result.M31 = -2 * p.Normal.Z * p.Normal.X; - result.M32 = -2 * p.Normal.Z * p.Normal.Y; - result.M33 = -2 * p.Normal.Z * p.Normal.Z + 1; - result.M34 = 0; - result.M41 = -2 * p.D * p.Normal.X; - result.M42 = -2 * p.D * p.Normal.Y; - result.M43 = -2 * p.D * p.Normal.Z; - result.M44 = 1; - } - - public static Matrix CreateReflection(Plane value) - { - Matrix ret; - CreateReflection(ref value, out ret); - return ret; - } - - public static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll) - { - Matrix matrix; - Quaternion quaternion; - Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion); - CreateFromQuaternion(ref quaternion, out matrix); - return matrix; - } - - public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Matrix result) - { - Quaternion quaternion; - Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll, out quaternion); - CreateFromQuaternion(ref quaternion, out result); - } - - public static void Transform(ref Matrix value, ref Quaternion rotation, out Matrix result) - { - Matrix matrix = CreateFromQuaternion(rotation); - Matrix.Multiply(ref value, ref matrix, out result); - } - - public static Matrix Transform(Matrix value, Quaternion rotation) - { - Matrix ret; - Transform(ref value, ref rotation, out ret); - return ret; - } - - public bool Decompose(out Vector3 scale, out Quaternion rotation, out Vector3 translation) - { - translation.X = this.M41; - translation.Y = this.M42; - translation.Z = this.M43; - float xs, ys, zs; - - if (Math.Sign(M11 * M12 * M13 * M14) < 0) - xs = -1f; - else - xs = 1f; - - if (Math.Sign(M21 * M22 * M23 * M24) < 0) - ys = -1f; - else - ys = 1f; - - if (Math.Sign(M31 * M32 * M33 * M34) < 0) - zs = -1f; - else - zs = 1f; - - scale.X = xs * (float)Math.Sqrt(this.M11 * this.M11 + this.M12 * this.M12 + this.M13 * this.M13); - scale.Y = ys * (float)Math.Sqrt(this.M21 * this.M21 + this.M22 * this.M22 + this.M23 * this.M23); - scale.Z = zs * (float)Math.Sqrt(this.M31 * this.M31 + this.M32 * this.M32 + this.M33 * this.M33); - - if (scale.X == 0.0 || scale.Y == 0.0 || scale.Z == 0.0) - { - rotation = Quaternion.Identity; - return false; - } - - Matrix m1 = new Matrix(this.M11/scale.X, M12/scale.X, M13/scale.X, 0, - this.M21/scale.Y, M22/scale.Y, M23/scale.Y, 0, - this.M31/scale.Z, M32/scale.Z, M33/scale.Z, 0, - 0, 0, 0, 1); - - rotation = Quaternion.CreateFromRotationMatrix(m1); - return true; - } - - /// - /// Adds second matrix to the first. - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - public static Matrix Add(Matrix matrix1, Matrix matrix2) - { - matrix1.M11 += matrix2.M11; - matrix1.M12 += matrix2.M12; - matrix1.M13 += matrix2.M13; - matrix1.M14 += matrix2.M14; - matrix1.M21 += matrix2.M21; - matrix1.M22 += matrix2.M22; - matrix1.M23 += matrix2.M23; - matrix1.M24 += matrix2.M24; - matrix1.M31 += matrix2.M31; - matrix1.M32 += matrix2.M32; - matrix1.M33 += matrix2.M33; - matrix1.M34 += matrix2.M34; - matrix1.M41 += matrix2.M41; - matrix1.M42 += matrix2.M42; - matrix1.M43 += matrix2.M43; - matrix1.M44 += matrix2.M44; - return matrix1; - } - - - /// - /// Adds two Matrix and save to the result Matrix - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - public static void Add(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - result.M11 = matrix1.M11 + matrix2.M11; - result.M12 = matrix1.M12 + matrix2.M12; - result.M13 = matrix1.M13 + matrix2.M13; - result.M14 = matrix1.M14 + matrix2.M14; - result.M21 = matrix1.M21 + matrix2.M21; - result.M22 = matrix1.M22 + matrix2.M22; - result.M23 = matrix1.M23 + matrix2.M23; - result.M24 = matrix1.M24 + matrix2.M24; - result.M31 = matrix1.M31 + matrix2.M31; - result.M32 = matrix1.M32 + matrix2.M32; - result.M33 = matrix1.M33 + matrix2.M33; - result.M34 = matrix1.M34 + matrix2.M34; - result.M41 = matrix1.M41 + matrix2.M41; - result.M42 = matrix1.M42 + matrix2.M42; - result.M43 = matrix1.M43 + matrix2.M43; - result.M44 = matrix1.M44 + matrix2.M44; - } - - - public static Matrix CreateBillboard(Vector3 objectPosition, Vector3 cameraPosition, - Vector3 cameraUpVector, Nullable cameraForwardVector) - { - Matrix ret; - CreateBillboard(ref objectPosition, ref cameraPosition, ref cameraUpVector, cameraForwardVector, out ret); - return ret; - } - - public static void CreateBillboard(ref Vector3 objectPosition, ref Vector3 cameraPosition, - ref Vector3 cameraUpVector, Vector3? cameraForwardVector, out Matrix result) - { - Vector3 translation = objectPosition - cameraPosition; - Vector3 backwards, right, up; - Vector3.Normalize(ref translation, out backwards); - Vector3.Normalize(ref cameraUpVector, out up); - Vector3.Cross(ref backwards, ref up, out right); - Vector3.Cross(ref backwards, ref right, out up); - result = Matrix.Identity; - result.Backward = backwards; - result.Right = right; - result.Up = up; - result.Translation = translation; - } - - 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) - { - Matrix ret; - CreateFromQuaternion(ref quaternion, out ret); - return ret; - } - - - public static void CreateFromQuaternion(ref Quaternion quaternion, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = 1 - 2 * (quaternion.Y * quaternion.Y + quaternion.Z * quaternion.Z); - result.M12 = 2 * (quaternion.X * quaternion.Y + quaternion.W * quaternion.Z); - result.M13 = 2 * (quaternion.X * quaternion.Z - quaternion.W * quaternion.Y); - result.M21 = 2 * (quaternion.X * quaternion.Y - quaternion.W * quaternion.Z); - result.M22 = 1 - 2 * (quaternion.X * quaternion.X + quaternion.Z * quaternion.Z); - result.M23 = 2 * (quaternion.Y * quaternion.Z + quaternion.W * quaternion.X); - result.M31 = 2 * (quaternion.X * quaternion.Z + quaternion.W * quaternion.Y); - result.M32 = 2 * (quaternion.Y * quaternion.Z - quaternion.W * quaternion.X); - result.M33 = 1 - 2 * (quaternion.X * quaternion.X + quaternion.Y * quaternion.Y); - } - - - public static Matrix CreateLookAt(Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector) - { - Matrix ret; - CreateLookAt(ref cameraPosition, ref cameraTarget, ref cameraUpVector, out ret); - return ret; - } - - - public static void CreateLookAt(ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result) - { - // http://msdn.microsoft.com/en-us/library/bb205343(v=VS.85).aspx - - Vector3 vz = Vector3.Normalize(cameraPosition - cameraTarget); - Vector3 vx = Vector3.Normalize(Vector3.Cross(cameraUpVector, vz)); - Vector3 vy = Vector3.Cross(vz, vx); - result = Matrix.Identity; - result.M11 = vx.X; - result.M12 = vy.X; - result.M13 = vz.X; - result.M21 = vx.Y; - result.M22 = vy.Y; - result.M23 = vz.Y; - result.M31 = vx.Z; - result.M32 = vy.Z; - result.M33 = vz.Z; - result.M41 = -Vector3.Dot(vx, cameraPosition); - result.M42 = -Vector3.Dot(vy, cameraPosition); - result.M43 = -Vector3.Dot(vz, cameraPosition); - } - - public static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) - { - Matrix ret; - CreateOrthographic(width, height, zNearPlane, zFarPlane, out ret); - return ret; - } - - - public static void CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane, out Matrix result) - { - result.M11 = 2 / width; - result.M12 = 0; - result.M13 = 0; - result.M14 = 0; - result.M21 = 0; - result.M22 = 2 / height; - result.M23 = 0; - result.M24 = 0; - result.M31 = 0; - result.M32 = 0; - result.M33 = 1 / (zNearPlane - zFarPlane); - result.M34 = 0; - result.M41 = 0; - result.M42 = 0; - result.M43 = zNearPlane / (zNearPlane - zFarPlane); - result.M44 = 1; - } - - - public static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) - { - Matrix ret; - CreateOrthographicOffCenter(left, right, bottom, top, zNearPlane, zFarPlane, out ret); - return ret; - } - - - public static void CreateOrthographicOffCenter(float left, float right, float bottom, float top, - float zNearPlane, float zFarPlane, out Matrix result) - { - result.M11 = 2 / (right - left); - result.M12 = 0; - result.M13 = 0; - result.M14 = 0; - result.M21 = 0; - result.M22 = 2 / (top - bottom); - result.M23 = 0; - result.M24 = 0; - result.M31 = 0; - result.M32 = 0; - result.M33 = 1 / (zNearPlane - zFarPlane); - result.M34 = 0; - result.M41 = (left + right) / (left - right); - result.M42 = (bottom + top) / (bottom - top); - result.M43 = zNearPlane / (zNearPlane - zFarPlane); - result.M44 = 1; - } - - - 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 nearPlaneDistance, float farPlaneDistance) - { - Matrix ret; - CreatePerspectiveFieldOfView(fieldOfView, aspectRatio, nearPlaneDistance, farPlaneDistance, out ret); - return ret; - } - - - public static void CreatePerspectiveFieldOfView(float fieldOfView, float aspectRatio, float nearPlaneDistance, float farPlaneDistance, out Matrix result) - { - // http://msdn.microsoft.com/en-us/library/bb205351(v=VS.85).aspx - // http://msdn.microsoft.com/en-us/library/bb195665.aspx - - result = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); - - if (fieldOfView < 0 || fieldOfView > 3.14159262f) - throw new ArgumentOutOfRangeException("fieldOfView", "fieldOfView takes a value between 0 and Pi (180 degrees) in radians."); - - if (nearPlaneDistance <= 0.0f) - throw new ArgumentOutOfRangeException("nearPlaneDistance", "You should specify positive value for nearPlaneDistance."); - - if (farPlaneDistance <= 0.0f) - throw new ArgumentOutOfRangeException("farPlaneDistance", "You should specify positive value for farPlaneDistance."); - - if (farPlaneDistance <= nearPlaneDistance) - throw new ArgumentOutOfRangeException("nearPlaneDistance", "Near plane distance is larger than Far plane distance. Near plane distance must be smaller than Far plane distance."); - - float yscale = (float)1 / (float)Math.Tan(fieldOfView / 2); - float xscale = yscale / aspectRatio; - - result.M11 = xscale; - result.M22 = yscale; - result.M33 = farPlaneDistance / (nearPlaneDistance - farPlaneDistance); - result.M34 = -1; - result.M43 = nearPlaneDistance * farPlaneDistance / (nearPlaneDistance - farPlaneDistance); - } - - - 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) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M22 = (float)Math.Cos(radians); - returnMatrix.M23 = (float)Math.Sin(radians); - returnMatrix.M32 = -returnMatrix.M23; - returnMatrix.M33 = returnMatrix.M22; - - return returnMatrix; - } - - - public static void CreateRotationX(float radians, out Matrix result) - { - result = Matrix.Identity; - - result.M22 = (float)Math.Cos(radians); - result.M23 = (float)Math.Sin(radians); - result.M32 = -result.M23; - result.M33 = result.M22; - } - - - public static Matrix CreateRotationY(float radians) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M11 = (float)Math.Cos(radians); - returnMatrix.M13 = (float)Math.Sin(radians); - returnMatrix.M31 = -returnMatrix.M13; - returnMatrix.M33 = returnMatrix.M11; - - return returnMatrix; - } - - - public static void CreateRotationY(float radians, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = (float)Math.Cos(radians); - result.M13 = (float)Math.Sin(radians); - result.M31 = -result.M13; - result.M33 = result.M11; - } - - - public static Matrix CreateRotationZ(float radians) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M11 = (float)Math.Cos(radians); - returnMatrix.M12 = (float)Math.Sin(radians); - returnMatrix.M21 = -returnMatrix.M12; - returnMatrix.M22 = returnMatrix.M11; - - return returnMatrix; - } - - - public static void CreateRotationZ(float radians, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = (float)Math.Cos(radians); - result.M12 = (float)Math.Sin(radians); - result.M21 = -result.M12; - result.M22 = result.M11; - } - - - public static Matrix CreateScale(float scale) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M11 = scale; - returnMatrix.M22 = scale; - returnMatrix.M33 = scale; - - return returnMatrix; - } - - - public static void CreateScale(float scale, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = scale; - result.M22 = scale; - result.M33 = scale; - } - - - public static Matrix CreateScale(float xScale, float yScale, float zScale) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M11 = xScale; - returnMatrix.M22 = yScale; - returnMatrix.M33 = zScale; - - return returnMatrix; - } - - - public static void CreateScale(float xScale, float yScale, float zScale, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = xScale; - result.M22 = yScale; - result.M33 = zScale; - } - - - public static Matrix CreateScale(Vector3 scales) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M11 = scales.X; - returnMatrix.M22 = scales.Y; - returnMatrix.M33 = scales.Z; - - return returnMatrix; - } - - - public static void CreateScale(ref Vector3 scales, out Matrix result) - { - result = Matrix.Identity; - - result.M11 = scales.X; - result.M22 = scales.Y; - result.M33 = scales.Z; - } - - - public static Matrix CreateTranslation(float xPosition, float yPosition, float zPosition) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M41 = xPosition; - returnMatrix.M42 = yPosition; - returnMatrix.M43 = zPosition; - - return returnMatrix; - } - - - public static void CreateTranslation(float xPosition, float yPosition, float zPosition, out Matrix result) - { - result = Matrix.Identity; - - result.M41 = xPosition; - result.M42 = yPosition; - result.M43 = zPosition; - } - - - public static Matrix CreateTranslation(Vector3 position) - { - Matrix returnMatrix = Matrix.Identity; - - returnMatrix.M41 = position.X; - returnMatrix.M42 = position.Y; - returnMatrix.M43 = position.Z; - - return returnMatrix; - } - - - public static void CreateTranslation(ref Vector3 position, out Matrix result) - { - result = Matrix.Identity; - - result.M41 = position.X; - result.M42 = position.Y; - result.M43 = position.Z; - } - - public static Matrix Divide(Matrix matrix1, Matrix matrix2) - { - Matrix inverse = Matrix.Invert(matrix2), result; - - result.M11 = matrix1.M11 * inverse.M11 + matrix1.M12 * inverse.M21 + matrix1.M13 * inverse.M31 + matrix1.M14 * inverse.M41; - result.M12 = matrix1.M11 * inverse.M12 + matrix1.M12 * inverse.M22 + matrix1.M13 * inverse.M32 + matrix1.M14 * inverse.M42; - result.M13 = matrix1.M11 * inverse.M13 + matrix1.M12 * inverse.M23 + matrix1.M13 * inverse.M33 + matrix1.M14 * inverse.M43; - result.M14 = matrix1.M11 * inverse.M14 + matrix1.M12 * inverse.M24 + matrix1.M13 * inverse.M34 + matrix1.M14 * inverse.M44; - - result.M21 = matrix1.M21 * inverse.M11 + matrix1.M22 * inverse.M21 + matrix1.M23 * inverse.M31 + matrix1.M24 * inverse.M41; - result.M22 = matrix1.M21 * inverse.M12 + matrix1.M22 * inverse.M22 + matrix1.M23 * inverse.M32 + matrix1.M24 * inverse.M42; - result.M23 = matrix1.M21 * inverse.M13 + matrix1.M22 * inverse.M23 + matrix1.M23 * inverse.M33 + matrix1.M24 * inverse.M43; - result.M24 = matrix1.M21 * inverse.M14 + matrix1.M22 * inverse.M24 + matrix1.M23 * inverse.M34 + matrix1.M24 * inverse.M44; - - result.M31 = matrix1.M31 * inverse.M11 + matrix1.M32 * inverse.M21 + matrix1.M33 * inverse.M31 + matrix1.M34 * inverse.M41; - result.M32 = matrix1.M31 * inverse.M12 + matrix1.M32 * inverse.M22 + matrix1.M33 * inverse.M32 + matrix1.M34 * inverse.M42; - result.M33 = matrix1.M31 * inverse.M13 + matrix1.M32 * inverse.M23 + matrix1.M33 * inverse.M33 + matrix1.M34 * inverse.M43; - result.M34 = matrix1.M31 * inverse.M14 + matrix1.M32 * inverse.M24 + matrix1.M33 * inverse.M34 + matrix1.M34 * inverse.M44; - - result.M41 = matrix1.M41 * inverse.M11 + matrix1.M42 * inverse.M21 + matrix1.M43 * inverse.M31 + matrix1.M44 * inverse.M41; - result.M42 = matrix1.M41 * inverse.M12 + matrix1.M42 * inverse.M22 + matrix1.M43 * inverse.M32 + matrix1.M44 * inverse.M42; - result.M43 = matrix1.M41 * inverse.M13 + matrix1.M42 * inverse.M23 + matrix1.M43 * inverse.M33 + matrix1.M44 * inverse.M43; - result.M44 = matrix1.M41 * inverse.M14 + matrix1.M42 * inverse.M24 + matrix1.M43 * inverse.M34 + matrix1.M44 * inverse.M44; - - return result; - } - - - public static void Divide(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - Matrix inverse = Matrix.Invert(matrix2); - result.M11 = matrix1.M11 * inverse.M11 + matrix1.M12 * inverse.M21 + matrix1.M13 * inverse.M31 + matrix1.M14 * inverse.M41; - result.M12 = matrix1.M11 * inverse.M12 + matrix1.M12 * inverse.M22 + matrix1.M13 * inverse.M32 + matrix1.M14 * inverse.M42; - result.M13 = matrix1.M11 * inverse.M13 + matrix1.M12 * inverse.M23 + matrix1.M13 * inverse.M33 + matrix1.M14 * inverse.M43; - result.M14 = matrix1.M11 * inverse.M14 + matrix1.M12 * inverse.M24 + matrix1.M13 * inverse.M34 + matrix1.M14 * inverse.M44; - - result.M21 = matrix1.M21 * inverse.M11 + matrix1.M22 * inverse.M21 + matrix1.M23 * inverse.M31 + matrix1.M24 * inverse.M41; - result.M22 = matrix1.M21 * inverse.M12 + matrix1.M22 * inverse.M22 + matrix1.M23 * inverse.M32 + matrix1.M24 * inverse.M42; - result.M23 = matrix1.M21 * inverse.M13 + matrix1.M22 * inverse.M23 + matrix1.M23 * inverse.M33 + matrix1.M24 * inverse.M43; - result.M24 = matrix1.M21 * inverse.M14 + matrix1.M22 * inverse.M24 + matrix1.M23 * inverse.M34 + matrix1.M24 * inverse.M44; - - result.M31 = matrix1.M31 * inverse.M11 + matrix1.M32 * inverse.M21 + matrix1.M33 * inverse.M31 + matrix1.M34 * inverse.M41; - result.M32 = matrix1.M31 * inverse.M12 + matrix1.M32 * inverse.M22 + matrix1.M33 * inverse.M32 + matrix1.M34 * inverse.M42; - result.M33 = matrix1.M31 * inverse.M13 + matrix1.M32 * inverse.M23 + matrix1.M33 * inverse.M33 + matrix1.M34 * inverse.M43; - result.M34 = matrix1.M31 * inverse.M14 + matrix1.M32 * inverse.M24 + matrix1.M33 * inverse.M34 + matrix1.M34 * inverse.M44; - - result.M41 = matrix1.M41 * inverse.M11 + matrix1.M42 * inverse.M21 + matrix1.M43 * inverse.M31 + matrix1.M44 * inverse.M41; - result.M42 = matrix1.M41 * inverse.M12 + matrix1.M42 * inverse.M22 + matrix1.M43 * inverse.M32 + matrix1.M44 * inverse.M42; - result.M43 = matrix1.M41 * inverse.M13 + matrix1.M42 * inverse.M23 + matrix1.M43 * inverse.M33 + matrix1.M44 * inverse.M43; - result.M44 = matrix1.M41 * inverse.M14 + matrix1.M42 * inverse.M24 + matrix1.M43 * inverse.M34 + matrix1.M44 * inverse.M44; - } - - - public static Matrix Divide(Matrix matrix1, float divider) - { - float inverseDivider = 1.0f / divider; - - matrix1.M11 = matrix1.M11 * inverseDivider; - matrix1.M12 = matrix1.M12 * inverseDivider; - matrix1.M13 = matrix1.M13 * inverseDivider; - matrix1.M14 = matrix1.M14 * inverseDivider; - matrix1.M21 = matrix1.M21 * inverseDivider; - matrix1.M22 = matrix1.M22 * inverseDivider; - matrix1.M23 = matrix1.M23 * inverseDivider; - matrix1.M24 = matrix1.M24 * inverseDivider; - matrix1.M31 = matrix1.M31 * inverseDivider; - matrix1.M32 = matrix1.M32 * inverseDivider; - matrix1.M33 = matrix1.M33 * inverseDivider; - matrix1.M34 = matrix1.M34 * inverseDivider; - matrix1.M41 = matrix1.M41 * inverseDivider; - matrix1.M42 = matrix1.M42 * inverseDivider; - matrix1.M43 = matrix1.M43 * inverseDivider; - matrix1.M44 = matrix1.M44 * inverseDivider; - - return matrix1; - } - - - public static void Divide(ref Matrix matrix1, float divider, out Matrix result) - { - float inverseDivider = 1.0f / divider; - result.M11 = matrix1.M11 * inverseDivider; - result.M12 = matrix1.M12 * inverseDivider; - result.M13 = matrix1.M13 * inverseDivider; - result.M14 = matrix1.M14 * inverseDivider; - result.M21 = matrix1.M21 * inverseDivider; - result.M22 = matrix1.M22 * inverseDivider; - result.M23 = matrix1.M23 * inverseDivider; - result.M24 = matrix1.M24 * inverseDivider; - result.M31 = matrix1.M31 * inverseDivider; - result.M32 = matrix1.M32 * inverseDivider; - result.M33 = matrix1.M33 * inverseDivider; - result.M34 = matrix1.M34 * inverseDivider; - result.M41 = matrix1.M41 * inverseDivider; - result.M42 = matrix1.M42 * inverseDivider; - result.M43 = matrix1.M43 * inverseDivider; - result.M44 = matrix1.M44 * inverseDivider; - } - - public static Matrix Invert(Matrix matrix) - { - Invert(ref matrix, out matrix); - return matrix; - } - - - public static void Invert(ref Matrix matrix, out Matrix result) - { - // - // Use Laplace expansion theorem to calculate the inverse of a 4x4 matrix - // - // 1. Calculate the 2x2 determinants needed and the 4x4 determinant based on the 2x2 determinants - // 2. Create the adjugate matrix, which satisfies: A * adj(A) = det(A) * I - // 3. Divide adjugate matrix with the determinant to find the inverse - - float det1 = matrix.M11 * matrix.M22 - matrix.M12 * matrix.M21; - float det2 = matrix.M11 * matrix.M23 - matrix.M13 * matrix.M21; - float det3 = matrix.M11 * matrix.M24 - matrix.M14 * matrix.M21; - float det4 = matrix.M12 * matrix.M23 - matrix.M13 * matrix.M22; - float det5 = matrix.M12 * matrix.M24 - matrix.M14 * matrix.M22; - float det6 = matrix.M13 * matrix.M24 - matrix.M14 * matrix.M23; - float det7 = matrix.M31 * matrix.M42 - matrix.M32 * matrix.M41; - float det8 = matrix.M31 * matrix.M43 - matrix.M33 * matrix.M41; - float det9 = matrix.M31 * matrix.M44 - matrix.M34 * matrix.M41; - float det10 = matrix.M32 * matrix.M43 - matrix.M33 * matrix.M42; - float det11 = matrix.M32 * matrix.M44 - matrix.M34 * matrix.M42; - float det12 = matrix.M33 * matrix.M44 - matrix.M34 * matrix.M43; - - float detMatrix = (float)(det1*det12 - det2*det11 + det3*det10 + det4*det9 - det5*det8 + det6*det7); - - float invDetMatrix = 1f / detMatrix; - - Matrix ret; // Allow for matrix and result to point to the same structure - - ret.M11 = (matrix.M22*det12 - matrix.M23*det11 + matrix.M24*det10) * invDetMatrix; - ret.M12 = (-matrix.M12*det12 + matrix.M13*det11 - matrix.M14*det10) * invDetMatrix; - ret.M13 = (matrix.M42*det6 - matrix.M43*det5 + matrix.M44*det4) * invDetMatrix; - ret.M14 = (-matrix.M32*det6 + matrix.M33*det5 - matrix.M34*det4) * invDetMatrix; - ret.M21 = (-matrix.M21*det12 + matrix.M23*det9 - matrix.M24*det8) * invDetMatrix; - ret.M22 = (matrix.M11*det12 - matrix.M13*det9 + matrix.M14*det8) * invDetMatrix; - ret.M23 = (-matrix.M41*det6 + matrix.M43*det3 - matrix.M44*det2) * invDetMatrix; - ret.M24 = (matrix.M31*det6 - matrix.M33*det3 + matrix.M34*det2) * invDetMatrix; - ret.M31 = (matrix.M21*det11 - matrix.M22*det9 + matrix.M24*det7) * invDetMatrix; - ret.M32 = (-matrix.M11*det11 + matrix.M12*det9 - matrix.M14*det7) * invDetMatrix; - ret.M33 = (matrix.M41*det5 - matrix.M42*det3 + matrix.M44*det1) * invDetMatrix; - ret.M34 = (-matrix.M31*det5 + matrix.M32*det3 - matrix.M34*det1) * invDetMatrix; - ret.M41 = (-matrix.M21*det10 + matrix.M22*det8 - matrix.M23*det7) * invDetMatrix; - ret.M42 = (matrix.M11*det10 - matrix.M12*det8 + matrix.M13*det7) * invDetMatrix; - ret.M43 = (-matrix.M41*det4 + matrix.M42*det2 - matrix.M43*det1) * invDetMatrix; - ret.M44 = (matrix.M31*det4 - matrix.M32*det2 + matrix.M33*det1) * invDetMatrix; - - result = ret; - } - - - 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) - { - Matrix result; - - result.M11 = matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21 + matrix1.M13 * matrix2.M31 + matrix1.M14 * matrix2.M41; - result.M12 = matrix1.M11 * matrix2.M12 + matrix1.M12 * matrix2.M22 + matrix1.M13 * matrix2.M32 + matrix1.M14 * matrix2.M42; - result.M13 = matrix1.M11 * matrix2.M13 + matrix1.M12 * matrix2.M23 + matrix1.M13 * matrix2.M33 + matrix1.M14 * matrix2.M43; - result.M14 = matrix1.M11 * matrix2.M14 + matrix1.M12 * matrix2.M24 + matrix1.M13 * matrix2.M34 + matrix1.M14 * matrix2.M44; - - result.M21 = matrix1.M21 * matrix2.M11 + matrix1.M22 * matrix2.M21 + matrix1.M23 * matrix2.M31 + matrix1.M24 * matrix2.M41; - result.M22 = matrix1.M21 * matrix2.M12 + matrix1.M22 * matrix2.M22 + matrix1.M23 * matrix2.M32 + matrix1.M24 * matrix2.M42; - result.M23 = matrix1.M21 * matrix2.M13 + matrix1.M22 * matrix2.M23 + matrix1.M23 * matrix2.M33 + matrix1.M24 * matrix2.M43; - result.M24 = matrix1.M21 * matrix2.M14 + matrix1.M22 * matrix2.M24 + matrix1.M23 * matrix2.M34 + matrix1.M24 * matrix2.M44; - - result.M31 = matrix1.M31 * matrix2.M11 + matrix1.M32 * matrix2.M21 + matrix1.M33 * matrix2.M31 + matrix1.M34 * matrix2.M41; - result.M32 = matrix1.M31 * matrix2.M12 + matrix1.M32 * matrix2.M22 + matrix1.M33 * matrix2.M32 + matrix1.M34 * matrix2.M42; - result.M33 = matrix1.M31 * matrix2.M13 + matrix1.M32 * matrix2.M23 + matrix1.M33 * matrix2.M33 + matrix1.M34 * matrix2.M43; - result.M34 = matrix1.M31 * matrix2.M14 + matrix1.M32 * matrix2.M24 + matrix1.M33 * matrix2.M34 + matrix1.M34 * matrix2.M44; - - result.M41 = matrix1.M41 * matrix2.M11 + matrix1.M42 * matrix2.M21 + matrix1.M43 * matrix2.M31 + matrix1.M44 * matrix2.M41; - result.M42 = matrix1.M41 * matrix2.M12 + matrix1.M42 * matrix2.M22 + matrix1.M43 * matrix2.M32 + matrix1.M44 * matrix2.M42; - result.M43 = matrix1.M41 * matrix2.M13 + matrix1.M42 * matrix2.M23 + matrix1.M43 * matrix2.M33 + matrix1.M44 * matrix2.M43; - result.M44 = matrix1.M41 * matrix2.M14 + matrix1.M42 * matrix2.M24 + matrix1.M43 * matrix2.M34 + matrix1.M44 * matrix2.M44; - - return result; - } - - - public static void Multiply(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - result.M11 = matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21 + matrix1.M13 * matrix2.M31 + matrix1.M14 * matrix2.M41; - result.M12 = matrix1.M11 * matrix2.M12 + matrix1.M12 * matrix2.M22 + matrix1.M13 * matrix2.M32 + matrix1.M14 * matrix2.M42; - result.M13 = matrix1.M11 * matrix2.M13 + matrix1.M12 * matrix2.M23 + matrix1.M13 * matrix2.M33 + matrix1.M14 * matrix2.M43; - result.M14 = matrix1.M11 * matrix2.M14 + matrix1.M12 * matrix2.M24 + matrix1.M13 * matrix2.M34 + matrix1.M14 * matrix2.M44; - - result.M21 = matrix1.M21 * matrix2.M11 + matrix1.M22 * matrix2.M21 + matrix1.M23 * matrix2.M31 + matrix1.M24 * matrix2.M41; - result.M22 = matrix1.M21 * matrix2.M12 + matrix1.M22 * matrix2.M22 + matrix1.M23 * matrix2.M32 + matrix1.M24 * matrix2.M42; - result.M23 = matrix1.M21 * matrix2.M13 + matrix1.M22 * matrix2.M23 + matrix1.M23 * matrix2.M33 + matrix1.M24 * matrix2.M43; - result.M24 = matrix1.M21 * matrix2.M14 + matrix1.M22 * matrix2.M24 + matrix1.M23 * matrix2.M34 + matrix1.M24 * matrix2.M44; - - result.M31 = matrix1.M31 * matrix2.M11 + matrix1.M32 * matrix2.M21 + matrix1.M33 * matrix2.M31 + matrix1.M34 * matrix2.M41; - result.M32 = matrix1.M31 * matrix2.M12 + matrix1.M32 * matrix2.M22 + matrix1.M33 * matrix2.M32 + matrix1.M34 * matrix2.M42; - result.M33 = matrix1.M31 * matrix2.M13 + matrix1.M32 * matrix2.M23 + matrix1.M33 * matrix2.M33 + matrix1.M34 * matrix2.M43; - result.M34 = matrix1.M31 * matrix2.M14 + matrix1.M32 * matrix2.M24 + matrix1.M33 * matrix2.M34 + matrix1.M34 * matrix2.M44; - - result.M41 = matrix1.M41 * matrix2.M11 + matrix1.M42 * matrix2.M21 + matrix1.M43 * matrix2.M31 + matrix1.M44 * matrix2.M41; - result.M42 = matrix1.M41 * matrix2.M12 + matrix1.M42 * matrix2.M22 + matrix1.M43 * matrix2.M32 + matrix1.M44 * matrix2.M42; - result.M43 = matrix1.M41 * matrix2.M13 + matrix1.M42 * matrix2.M23 + matrix1.M43 * matrix2.M33 + matrix1.M44 * matrix2.M43; - result.M44 = matrix1.M41 * matrix2.M14 + matrix1.M42 * matrix2.M24 + matrix1.M43 * matrix2.M34 + matrix1.M44 * matrix2.M44; - } - - - public static Matrix Multiply(Matrix matrix1, float factor) - { - matrix1.M11 *= factor; - matrix1.M12 *= factor; - matrix1.M13 *= factor; - matrix1.M14 *= factor; - matrix1.M21 *= factor; - matrix1.M22 *= factor; - matrix1.M23 *= factor; - matrix1.M24 *= factor; - matrix1.M31 *= factor; - matrix1.M32 *= factor; - matrix1.M33 *= factor; - matrix1.M34 *= factor; - matrix1.M41 *= factor; - matrix1.M42 *= factor; - matrix1.M43 *= factor; - matrix1.M44 *= factor; - return matrix1; - } - - - public static void Multiply(ref Matrix matrix1, float factor, out Matrix result) - { - result.M11 = matrix1.M11 * factor; - result.M12 = matrix1.M12 * factor; - result.M13 = matrix1.M13 * factor; - result.M14 = matrix1.M14 * factor; - result.M21 = matrix1.M21 * factor; - result.M22 = matrix1.M22 * factor; - result.M23 = matrix1.M23 * factor; - result.M24 = matrix1.M24 * factor; - result.M31 = matrix1.M31 * factor; - result.M32 = matrix1.M32 * factor; - result.M33 = matrix1.M33 * factor; - result.M34 = matrix1.M34 * factor; - result.M41 = matrix1.M41 * factor; - result.M42 = matrix1.M42 * factor; - result.M43 = matrix1.M43 * factor; - result.M44 = matrix1.M44 * factor; - } - - - public static Matrix Negate(Matrix matrix) - { - matrix.M11 = -matrix.M11; - matrix.M12 = -matrix.M12; - matrix.M13 = -matrix.M13; - matrix.M14 = -matrix.M14; - matrix.M21 = -matrix.M21; - matrix.M22 = -matrix.M22; - matrix.M23 = -matrix.M23; - matrix.M24 = -matrix.M24; - matrix.M31 = -matrix.M31; - matrix.M32 = -matrix.M32; - matrix.M33 = -matrix.M33; - matrix.M34 = -matrix.M34; - matrix.M41 = -matrix.M41; - matrix.M42 = -matrix.M42; - matrix.M43 = -matrix.M43; - matrix.M44 = -matrix.M44; - return matrix; - } - - - public static void Negate(ref Matrix matrix, out Matrix result) - { - result.M11 = matrix.M11; - result.M12 = matrix.M12; - result.M13 = matrix.M13; - result.M14 = matrix.M14; - result.M21 = matrix.M21; - result.M22 = matrix.M22; - result.M23 = matrix.M23; - result.M24 = matrix.M24; - result.M31 = matrix.M31; - result.M32 = matrix.M32; - result.M33 = matrix.M33; - result.M34 = matrix.M34; - result.M41 = matrix.M41; - result.M42 = matrix.M42; - result.M43 = matrix.M43; - result.M44 = matrix.M44; - } - - public static Matrix Subtract(Matrix matrix1, Matrix matrix2) - { - matrix1.M11 -= matrix2.M11; - matrix1.M12 -= matrix2.M12; - matrix1.M13 -= matrix2.M13; - matrix1.M14 -= matrix2.M14; - matrix1.M21 -= matrix2.M21; - matrix1.M22 -= matrix2.M22; - matrix1.M23 -= matrix2.M23; - matrix1.M24 -= matrix2.M24; - matrix1.M31 -= matrix2.M31; - matrix1.M32 -= matrix2.M32; - matrix1.M33 -= matrix2.M33; - matrix1.M34 -= matrix2.M34; - matrix1.M41 -= matrix2.M41; - matrix1.M42 -= matrix2.M42; - matrix1.M43 -= matrix2.M43; - matrix1.M44 -= matrix2.M44; - return matrix1; - } - - public static void Subtract(ref Matrix matrix1, ref Matrix matrix2, out Matrix result) - { - result.M11 = matrix1.M11 - matrix2.M11; - result.M12 = matrix1.M12 - matrix2.M12; - result.M13 = matrix1.M13 - matrix2.M13; - result.M14 = matrix1.M14 - matrix2.M14; - result.M21 = matrix1.M21 - matrix2.M21; - result.M22 = matrix1.M22 - matrix2.M22; - result.M23 = matrix1.M23 - matrix2.M23; - result.M24 = matrix1.M24 - matrix2.M24; - result.M31 = matrix1.M31 - matrix2.M31; - result.M32 = matrix1.M32 - matrix2.M32; - result.M33 = matrix1.M33 - matrix2.M33; - result.M34 = matrix1.M34 - matrix2.M34; - result.M41 = matrix1.M41 - matrix2.M41; - result.M42 = matrix1.M42 - matrix2.M42; - result.M43 = matrix1.M43 - matrix2.M43; - result.M44 = matrix1.M44 - matrix2.M44; - } - - public static Matrix Transpose(Matrix matrix) - { - Matrix result; - - result.M11 = matrix.M11; - result.M12 = matrix.M21; - result.M13 = matrix.M31; - result.M14 = matrix.M41; - - result.M21 = matrix.M12; - result.M22 = matrix.M22; - result.M23 = matrix.M32; - result.M24 = matrix.M42; - - result.M31 = matrix.M13; - result.M32 = matrix.M23; - result.M33 = matrix.M33; - result.M34 = matrix.M43; - - result.M41 = matrix.M14; - result.M42 = matrix.M24; - result.M43 = matrix.M34; - result.M44 = matrix.M44; - - return result; - } - - - public static void Transpose(ref Matrix matrix, out Matrix result) - { - result.M11 = matrix.M11; - result.M12 = matrix.M21; - result.M13 = matrix.M31; - result.M14 = matrix.M41; - - result.M21 = matrix.M12; - result.M22 = matrix.M22; - result.M23 = matrix.M32; - result.M24 = matrix.M42; - - result.M31 = matrix.M13; - result.M32 = matrix.M23; - result.M33 = matrix.M33; - result.M34 = matrix.M43; - - result.M41 = matrix.M14; - result.M42 = matrix.M24; - result.M43 = matrix.M34; - result.M44 = matrix.M44; - } - - #endregion Public Static Methods - - #region Public Methods - - public float Determinant() - { - float minor1, minor2, minor3, minor4, minor5, minor6; - - minor1 = M31 * M42 - M32 * M41; - minor2 = M31 * M43 - M33 * M41; - minor3 = M31 * M44 - M34 * M41; - minor4 = M32 * M43 - M33 * M42; - minor5 = M32 * M44 - M34 * M42; - minor6 = M33 * M44 - M34 * M43; - - return M11 * (M22 * minor6 - M23 * minor5 + M24 * minor4) - - M12 * (M21 * minor6 - M23 * minor3 + M24 * minor2) + - M13 * (M21 * minor5 - M22 * minor3 + M24 * minor1) - - M14 * (M21 * minor4 - M22 * minor2 + M23 * minor1); - } - - public bool Equals(Matrix other) - { - return (this.M11 == other.M11) && (this.M12 == other.M12) && - (this.M13 == other.M13) && (this.M14 == other.M14) && - (this.M21 == other.M21) && (this.M22 == other.M22) && - (this.M23 == other.M23) && (this.M24 == other.M24) && - (this.M31 == other.M31) && (this.M32 == other.M32) && - (this.M33 == other.M33) && (this.M34 == other.M34) && - (this.M41 == other.M41) && (this.M42 == other.M42) && - (this.M43 == other.M43) && (this.M44 == other.M44); - } - - #endregion Public Methods - - #region Operators - - public static Matrix operator +(Matrix matrix1, Matrix matrix2) - { - matrix1.M11 += matrix2.M11; - matrix1.M12 += matrix2.M12; - matrix1.M13 += matrix2.M13; - matrix1.M14 += matrix2.M14; - matrix1.M21 += matrix2.M21; - matrix1.M22 += matrix2.M22; - matrix1.M23 += matrix2.M23; - matrix1.M24 += matrix2.M24; - matrix1.M31 += matrix2.M31; - matrix1.M32 += matrix2.M32; - matrix1.M33 += matrix2.M33; - matrix1.M34 += matrix2.M34; - matrix1.M41 += matrix2.M41; - matrix1.M42 += matrix2.M42; - matrix1.M43 += matrix2.M43; - matrix1.M44 += matrix2.M44; - return matrix1; - } - - public static Matrix operator /(Matrix matrix1, Matrix matrix2) - { - Matrix inverse = Matrix.Invert(matrix2), result; - - result.M11 = matrix1.M11 * inverse.M11 + matrix1.M12 * inverse.M21 + matrix1.M13 * inverse.M31 + matrix1.M14 * inverse.M41; - result.M12 = matrix1.M11 * inverse.M12 + matrix1.M12 * inverse.M22 + matrix1.M13 * inverse.M32 + matrix1.M14 * inverse.M42; - result.M13 = matrix1.M11 * inverse.M13 + matrix1.M12 * inverse.M23 + matrix1.M13 * inverse.M33 + matrix1.M14 * inverse.M43; - result.M14 = matrix1.M11 * inverse.M14 + matrix1.M12 * inverse.M24 + matrix1.M13 * inverse.M34 + matrix1.M14 * inverse.M44; - - result.M21 = matrix1.M21 * inverse.M11 + matrix1.M22 * inverse.M21 + matrix1.M23 * inverse.M31 + matrix1.M24 * inverse.M41; - result.M22 = matrix1.M21 * inverse.M12 + matrix1.M22 * inverse.M22 + matrix1.M23 * inverse.M32 + matrix1.M24 * inverse.M42; - result.M23 = matrix1.M21 * inverse.M13 + matrix1.M22 * inverse.M23 + matrix1.M23 * inverse.M33 + matrix1.M24 * inverse.M43; - result.M24 = matrix1.M21 * inverse.M14 + matrix1.M22 * inverse.M24 + matrix1.M23 * inverse.M34 + matrix1.M24 * inverse.M44; - - result.M31 = matrix1.M31 * inverse.M11 + matrix1.M32 * inverse.M21 + matrix1.M33 * inverse.M31 + matrix1.M34 * inverse.M41; - result.M32 = matrix1.M31 * inverse.M12 + matrix1.M32 * inverse.M22 + matrix1.M33 * inverse.M32 + matrix1.M34 * inverse.M42; - result.M33 = matrix1.M31 * inverse.M13 + matrix1.M32 * inverse.M23 + matrix1.M33 * inverse.M33 + matrix1.M34 * inverse.M43; - result.M34 = matrix1.M31 * inverse.M14 + matrix1.M32 * inverse.M24 + matrix1.M33 * inverse.M34 + matrix1.M34 * inverse.M44; - - result.M41 = matrix1.M41 * inverse.M11 + matrix1.M42 * inverse.M21 + matrix1.M43 * inverse.M31 + matrix1.M44 * inverse.M41; - result.M42 = matrix1.M41 * inverse.M12 + matrix1.M42 * inverse.M22 + matrix1.M43 * inverse.M32 + matrix1.M44 * inverse.M42; - result.M43 = matrix1.M41 * inverse.M13 + matrix1.M42 * inverse.M23 + matrix1.M43 * inverse.M33 + matrix1.M44 * inverse.M43; - result.M44 = matrix1.M41 * inverse.M14 + matrix1.M42 * inverse.M24 + matrix1.M43 * inverse.M34 + matrix1.M44 * inverse.M44; - - return result; - } - - public static Matrix operator /(Matrix matrix1, float divider) - { - float inverseDivider = 1.0f / divider; - - matrix1.M11 = matrix1.M11 * inverseDivider; - matrix1.M12 = matrix1.M12 * inverseDivider; - matrix1.M13 = matrix1.M13 * inverseDivider; - matrix1.M14 = matrix1.M14 * inverseDivider; - matrix1.M21 = matrix1.M21 * inverseDivider; - matrix1.M22 = matrix1.M22 * inverseDivider; - matrix1.M23 = matrix1.M23 * inverseDivider; - matrix1.M24 = matrix1.M24 * inverseDivider; - matrix1.M31 = matrix1.M31 * inverseDivider; - matrix1.M32 = matrix1.M32 * inverseDivider; - matrix1.M33 = matrix1.M33 * inverseDivider; - matrix1.M34 = matrix1.M34 * inverseDivider; - matrix1.M41 = matrix1.M41 * inverseDivider; - matrix1.M42 = matrix1.M42 * inverseDivider; - matrix1.M43 = matrix1.M43 * inverseDivider; - matrix1.M44 = matrix1.M44 * inverseDivider; - - return matrix1; - } - - public static bool operator ==(Matrix matrix1, Matrix matrix2) - { - return (matrix1.M11 == matrix2.M11) && (matrix1.M12 == matrix2.M12) && - (matrix1.M13 == matrix2.M13) && (matrix1.M14 == matrix2.M14) && - (matrix1.M21 == matrix2.M21) && (matrix1.M22 == matrix2.M22) && - (matrix1.M23 == matrix2.M23) && (matrix1.M24 == matrix2.M24) && - (matrix1.M31 == matrix2.M31) && (matrix1.M32 == matrix2.M32) && - (matrix1.M33 == matrix2.M33) && (matrix1.M34 == matrix2.M34) && - (matrix1.M41 == matrix2.M41) && (matrix1.M42 == matrix2.M42) && - (matrix1.M43 == matrix2.M43) && (matrix1.M44 == matrix2.M44); - } - - public static bool operator !=(Matrix matrix1, Matrix matrix2) - { - return (matrix1.M11 != matrix2.M11) || (matrix1.M12 != matrix2.M12) || - (matrix1.M13 != matrix2.M13) || (matrix1.M14 != matrix2.M14) || - (matrix1.M21 != matrix2.M21) || (matrix1.M22 != matrix2.M22) || - (matrix1.M23 != matrix2.M23) || (matrix1.M24 != matrix2.M24) || - (matrix1.M31 != matrix2.M31) || (matrix1.M32 != matrix2.M32) || - (matrix1.M33 != matrix2.M33) || (matrix1.M34 != matrix2.M34) || - (matrix1.M41 != matrix2.M41) || (matrix1.M42 != matrix2.M42) || - (matrix1.M43 != matrix2.M43) || (matrix1.M44 != matrix2.M44); - } - - public static Matrix operator *(Matrix matrix1, Matrix matrix2) - { - Matrix result; - - result.M11 = matrix1.M11 * matrix2.M11 + matrix1.M12 * matrix2.M21 + matrix1.M13 * matrix2.M31 + matrix1.M14 * matrix2.M41; - result.M12 = matrix1.M11 * matrix2.M12 + matrix1.M12 * matrix2.M22 + matrix1.M13 * matrix2.M32 + matrix1.M14 * matrix2.M42; - result.M13 = matrix1.M11 * matrix2.M13 + matrix1.M12 * matrix2.M23 + matrix1.M13 * matrix2.M33 + matrix1.M14 * matrix2.M43; - result.M14 = matrix1.M11 * matrix2.M14 + matrix1.M12 * matrix2.M24 + matrix1.M13 * matrix2.M34 + matrix1.M14 * matrix2.M44; - - result.M21 = matrix1.M21 * matrix2.M11 + matrix1.M22 * matrix2.M21 + matrix1.M23 * matrix2.M31 + matrix1.M24 * matrix2.M41; - result.M22 = matrix1.M21 * matrix2.M12 + matrix1.M22 * matrix2.M22 + matrix1.M23 * matrix2.M32 + matrix1.M24 * matrix2.M42; - result.M23 = matrix1.M21 * matrix2.M13 + matrix1.M22 * matrix2.M23 + matrix1.M23 * matrix2.M33 + matrix1.M24 * matrix2.M43; - result.M24 = matrix1.M21 * matrix2.M14 + matrix1.M22 * matrix2.M24 + matrix1.M23 * matrix2.M34 + matrix1.M24 * matrix2.M44; - - result.M31 = matrix1.M31 * matrix2.M11 + matrix1.M32 * matrix2.M21 + matrix1.M33 * matrix2.M31 + matrix1.M34 * matrix2.M41; - result.M32 = matrix1.M31 * matrix2.M12 + matrix1.M32 * matrix2.M22 + matrix1.M33 * matrix2.M32 + matrix1.M34 * matrix2.M42; - result.M33 = matrix1.M31 * matrix2.M13 + matrix1.M32 * matrix2.M23 + matrix1.M33 * matrix2.M33 + matrix1.M34 * matrix2.M43; - result.M34 = matrix1.M31 * matrix2.M14 + matrix1.M32 * matrix2.M24 + matrix1.M33 * matrix2.M34 + matrix1.M34 * matrix2.M44; - - result.M41 = matrix1.M41 * matrix2.M11 + matrix1.M42 * matrix2.M21 + matrix1.M43 * matrix2.M31 + matrix1.M44 * matrix2.M41; - result.M42 = matrix1.M41 * matrix2.M12 + matrix1.M42 * matrix2.M22 + matrix1.M43 * matrix2.M32 + matrix1.M44 * matrix2.M42; - result.M43 = matrix1.M41 * matrix2.M13 + matrix1.M42 * matrix2.M23 + matrix1.M43 * matrix2.M33 + matrix1.M44 * matrix2.M43; - result.M44 = matrix1.M41 * matrix2.M14 + matrix1.M42 * matrix2.M24 + matrix1.M43 * matrix2.M34 + matrix1.M44 * matrix2.M44; - - return result; - } - - public static Matrix operator *(Matrix matrix, float scaleFactor) - { - matrix.M11 = matrix.M11 * scaleFactor; - matrix.M12 = matrix.M12 * scaleFactor; - matrix.M13 = matrix.M13 * scaleFactor; - matrix.M14 = matrix.M14 * scaleFactor; - matrix.M21 = matrix.M21 * scaleFactor; - matrix.M22 = matrix.M22 * scaleFactor; - matrix.M23 = matrix.M23 * scaleFactor; - matrix.M24 = matrix.M24 * scaleFactor; - matrix.M31 = matrix.M31 * scaleFactor; - matrix.M32 = matrix.M32 * scaleFactor; - matrix.M33 = matrix.M33 * scaleFactor; - matrix.M34 = matrix.M34 * scaleFactor; - matrix.M41 = matrix.M41 * scaleFactor; - matrix.M42 = matrix.M42 * scaleFactor; - matrix.M43 = matrix.M43 * scaleFactor; - matrix.M44 = matrix.M44 * scaleFactor; - return matrix; - } - - public static Matrix operator *(float scaleFactor, Matrix matrix) - { - matrix.M11 = matrix.M11 * scaleFactor; - matrix.M12 = matrix.M12 * scaleFactor; - matrix.M13 = matrix.M13 * scaleFactor; - matrix.M14 = matrix.M14 * scaleFactor; - matrix.M21 = matrix.M21 * scaleFactor; - matrix.M22 = matrix.M22 * scaleFactor; - matrix.M23 = matrix.M23 * scaleFactor; - matrix.M24 = matrix.M24 * scaleFactor; - matrix.M31 = matrix.M31 * scaleFactor; - matrix.M32 = matrix.M32 * scaleFactor; - matrix.M33 = matrix.M33 * scaleFactor; - matrix.M34 = matrix.M34 * scaleFactor; - matrix.M41 = matrix.M41 * scaleFactor; - matrix.M42 = matrix.M42 * scaleFactor; - matrix.M43 = matrix.M43 * scaleFactor; - matrix.M44 = matrix.M44 * scaleFactor; - return matrix; - } - - public static Matrix operator -(Matrix matrix1, Matrix matrix2) - { - matrix1.M11 -= matrix2.M11; - matrix1.M12 -= matrix2.M12; - matrix1.M13 -= matrix2.M13; - matrix1.M14 -= matrix2.M14; - matrix1.M21 -= matrix2.M21; - matrix1.M22 -= matrix2.M22; - matrix1.M23 -= matrix2.M23; - matrix1.M24 -= matrix2.M24; - matrix1.M31 -= matrix2.M31; - matrix1.M32 -= matrix2.M32; - matrix1.M33 -= matrix2.M33; - matrix1.M34 -= matrix2.M34; - matrix1.M41 -= matrix2.M41; - matrix1.M42 -= matrix2.M42; - matrix1.M43 -= matrix2.M43; - matrix1.M44 -= matrix2.M44; - return matrix1; - } - - - public static Matrix operator -(Matrix matrix) - { - matrix.M11 = -matrix.M11; - matrix.M12 = -matrix.M12; - matrix.M13 = -matrix.M13; - matrix.M14 = -matrix.M14; - matrix.M21 = -matrix.M21; - matrix.M22 = -matrix.M22; - matrix.M23 = -matrix.M23; - matrix.M24 = -matrix.M24; - matrix.M31 = -matrix.M31; - matrix.M32 = -matrix.M32; - matrix.M33 = -matrix.M33; - matrix.M34 = -matrix.M34; - matrix.M41 = -matrix.M41; - matrix.M42 = -matrix.M42; - matrix.M43 = -matrix.M43; - matrix.M44 = -matrix.M44; - return matrix; - } - - #endregion - - #region Object Overrides - - public override bool Equals(object obj) - { - if (obj is Matrix) - return this == (Matrix)obj; - return false; - } - - public override int GetHashCode() - { - throw new NotImplementedException(); - } - - public override string ToString() - { - return "{ {M11:" + M11 + " M12:" + M12 + " M13:" + M13 + " M14:" + M14 + "}" + - " {M21:" + M21 + " M22:" + M22 + " M23:" + M23 + " M24:" + M24 + "}" + - " {M31:" + M31 + " M32:" + M32 + " M33:" + M33 + " M34:" + M34 + "}" + - " {M41:" + M41 + " M42:" + M42 + " M43:" + M43 + " M44:" + M44 + "} }"; - } - - #endregion - - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Plane.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Plane.cs deleted file mode 100644 index 9970380f34..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Plane.cs +++ /dev/null @@ -1,212 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - - [Serializable] - public struct Plane : IEquatable - { - #region Public Fields - - public float D; - public Vector3 Normal; - - #endregion Public Fields - - - #region Constructors - - public Plane(Vector4 value) - : this(new Vector3(value.X, value.Y, value.Z), value.W) - { - - } - - public Plane(Vector3 normal, float d) - { - Normal = normal; - D = d; - } - - public Plane(Vector3 a, Vector3 b, Vector3 c) - { - Vector3 ab = b - a; - Vector3 ac = c - a; - - Vector3 cross = Vector3.Cross(ab, ac); - Normal = Vector3.Normalize(cross); - D = -(Vector3.Dot(cross, a)); - } - - public Plane(float a, float b, float c, float d) - : this(new Vector3(a, b, c), d) - { - - } - - #endregion Constructors - - - #region Public Methods - - public float Dot(Vector4 value) - { - return ((((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z)) + (this.D * value.W)); - } - - public void Dot(ref Vector4 value, out float result) - { - result = (((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z)) + (this.D * value.W); - } - - public float DotCoordinate(Vector3 value) - { - return ((((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z)) + this.D); - } - - public void DotCoordinate(ref Vector3 value, out float result) - { - result = (((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z)) + this.D; - } - - public float DotNormal(Vector3 value) - { - return (((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z)); - } - - public void DotNormal(ref Vector3 value, out float result) - { - result = ((this.Normal.X * value.X) + (this.Normal.Y * value.Y)) + (this.Normal.Z * value.Z); - } - - public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Plane plane, ref Matrix matrix, out Plane result) - { - throw new NotImplementedException(); - } - - public static Plane Transform(Plane plane, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static Plane Transform(Plane plane, Matrix matrix) - { - throw new NotImplementedException(); - } - - public void Normalize() - { - float factor; - Vector3 normal = Normal; - Normal = Vector3.Normalize(Normal); - factor = (float)Math.Sqrt(Normal.X * Normal.X + Normal.Y * Normal.Y + Normal.Z * Normal.Z) / - (float)Math.Sqrt(normal.X * normal.X + normal.Y * normal.Y + normal.Z * normal.Z); - D = D * factor; - } - - public static Plane Normalize(Plane value) - { - Plane ret; - Normalize(ref value, out ret); - return ret; - } - - public static void Normalize(ref Plane value, out Plane result) - { - float factor; - result.Normal = Vector3.Normalize(value.Normal); - factor = (float)Math.Sqrt(result.Normal.X * result.Normal.X + result.Normal.Y * result.Normal.Y + result.Normal.Z * result.Normal.Z) / - (float)Math.Sqrt(value.Normal.X * value.Normal.X + value.Normal.Y * value.Normal.Y + value.Normal.Z * value.Normal.Z); - result.D = value.D * factor; - } - - public static bool operator !=(Plane plane1, Plane plane2) - { - return !plane1.Equals(plane2); - } - - public static bool operator ==(Plane plane1, Plane plane2) - { - return plane1.Equals(plane2); - } - - public override bool Equals(object other) - { - return (other is Plane) ? this.Equals((Plane)other) : false; - } - - public bool Equals(Plane other) - { - return ((Normal == other.Normal) && (D == other.D)); - } - - public override int GetHashCode() - { - return Normal.GetHashCode() ^ D.GetHashCode(); - } - - public PlaneIntersectionType Intersects(BoundingBox box) - { - return box.Intersects(this); - } - - public void Intersects(ref BoundingBox box, out PlaneIntersectionType result) - { - result = Intersects(box); - } - - public PlaneIntersectionType Intersects(BoundingFrustum frustum) - { - return frustum.Intersects(this); - } - - public PlaneIntersectionType Intersects(BoundingSphere sphere) - { - return sphere.Intersects(this); - } - - public void Intersects(ref BoundingSphere sphere, out PlaneIntersectionType result) - { - result = Intersects(sphere); - } - - public override string ToString() - { - return string.Format("{{Normal:{0} D:{1}}}", Normal, D); - } - - #endregion - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/PlaneHelper.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/PlaneHelper.cs deleted file mode 100644 index 533ad89e72..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/PlaneHelper.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BizHawk.Bizware.BizwareGL -{ - internal class PlaneHelper - { - /// - /// Returns a value indicating what side (positive/negative) of a plane a point is - /// - /// The point to check with - /// The plane to check against - /// Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise - public static float ClassifyPoint(ref Vector3 point, ref Plane plane) - { - return point.X * plane.Normal.X + point.Y * plane.Normal.Y + point.Z * plane.Normal.Z + plane.D; - } - - /// - /// Returns the perpendicular distance from a point to a plane - /// - /// The point to check - /// The place to check - /// The perpendicular distance from the point to the plane - public static float PerpendicularDistance(ref Vector3 point, ref Plane plane) - { - // dist = (ax + by + cz + d) / sqrt(a*a + b*b + c*c) - return (float)Math.Abs((plane.Normal.X * point.X + plane.Normal.Y * point.Y + plane.Normal.Z * point.Z) - / Math.Sqrt(plane.Normal.X * plane.Normal.X + plane.Normal.Y * plane.Normal.Y + plane.Normal.Z * plane.Normal.Z)); - } - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Point.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Point.cs deleted file mode 100644 index 10fa723fa1..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Point.cs +++ /dev/null @@ -1,119 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - - public struct Point : IEquatable - { - #region Private Fields - - private static Point zeroPoint = new Point(); - - #endregion Private Fields - - - #region Public Fields - - public int X; - public int Y; - - #endregion Public Fields - - - #region Properties - - public static Point Zero - { - get { return zeroPoint; } - } - - #endregion Properties - - - #region Constructors - - /// - /// Makes new Point with integer accurate - /// - /// - /// A - /// - /// - /// A - /// - public Point(int x, int y) - { - this.X = x; - this.Y = y; - } - - #endregion Constructors - - - #region Public methods - - public static bool operator ==(Point a, Point b) - { - return a.Equals(b); - } - - public static bool operator !=(Point a, Point b) - { - return !a.Equals(b); - } - - public bool Equals(Point other) - { - return ((X == other.X) && (Y == other.Y)); - } - - public override bool Equals(object obj) - { - return (obj is Point) ? Equals((Point)obj) : false; - } - - public override int GetHashCode() - { - return X ^ Y; - } - - public override string ToString() - { - return string.Format("{{X:{0} Y:{1}}}", X, Y); - } - - #endregion - } -} - - diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Quaternion.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Quaternion.cs deleted file mode 100644 index 1edd9befbf..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Quaternion.cs +++ /dev/null @@ -1,687 +0,0 @@ -#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; - -namespace BizHawk.Bizware.BizwareGL -{ - [Serializable] - 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) - { - quaternion1.X += quaternion2.X; - quaternion1.Y += quaternion2.Y; - quaternion1.Z += quaternion2.Z; - quaternion1.W += quaternion2.W; - return quaternion1; - } - - - public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - result.W = quaternion1.W + quaternion2.W; - result.X = quaternion1.X + quaternion2.X; - result.Y = quaternion1.Y + quaternion2.Y; - result.Z = quaternion1.Z + quaternion2.Z; - } - - public static Quaternion Concatenate(Quaternion value1, Quaternion value2) - { - Quaternion quaternion; - quaternion.X = ((value2.X * value1.W) + (value1.X * value2.W)) + (value2.Y * value1.Z) - (value2.Z * value1.Y); - quaternion.Y = ((value2.Y * value1.W) + (value1.Y * value2.W)) + (value2.Z * value1.X) - (value2.X * value1.Z); - quaternion.Z = ((value2.Z * value1.W) + (value1.Z * value2.W)) + (value2.X * value1.Y) - (value2.Y * value1.X); - quaternion.W = (value2.W * value1.W) - ((value2.X * value1.X) + (value2.Y * value1.Y)) + (value2.Z * value1.Z); - return quaternion; - } - - public void Conjugate() - { - this.X = -this.X; - this.Y = -this.Y; - this.Z = -this.Z; - } - - public static Quaternion Conjugate(Quaternion value) - { - Quaternion quaternion; - quaternion.X = -value.X; - quaternion.Y = -value.Y; - quaternion.Z = -value.Z; - quaternion.W = value.W; - return quaternion; - } - - public static void Conjugate(ref Quaternion value, out Quaternion result) - { - result.X = -value.X; - result.Y = -value.Y; - result.Z = -value.Z; - result.W = value.W; - } - - public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result) - { - result.X = ((value2.X * value1.W) + (value1.X * value2.W)) + (value2.Y * value1.Z) - (value2.Z * value1.Y); - result.Y = ((value2.Y * value1.W) + (value1.Y * value2.W)) + (value2.Z * value1.X) - (value2.X * value1.Z); - result.Z = ((value2.Z * value1.W) + (value1.Z * value2.W)) + (value2.X * value1.Y) - (value2.Y * value1.X); - result.W = (value2.W * value1.W) - ((value2.X * value1.X) + (value2.Y * value1.Y)) + (value2.Z * value1.Z); - } - - public static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll) - { - Quaternion quaternion; - quaternion.X = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) + (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - quaternion.Y = (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) - (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - quaternion.Z = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))) - (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))); - quaternion.W = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) + (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - return quaternion; - } - - public static void CreateFromYawPitchRoll(float yaw, float pitch, float roll, out Quaternion result) - { - result.X = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) + (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - result.Y = (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) - (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - result.Z = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))) - (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))); - result.W = (((float)Math.Cos((double)(yaw * 0.5f)) * (float)Math.Cos((double)(pitch * 0.5f))) * (float)Math.Cos((double)(roll * 0.5f))) + (((float)Math.Sin((double)(yaw * 0.5f)) * (float)Math.Sin((double)(pitch * 0.5f))) * (float)Math.Sin((double)(roll * 0.5f))); - } - - public static Quaternion CreateFromAxisAngle(Vector3 axis, float angle) - { - float sin_a = (float)Math.Sin(angle / 2.0f); - return new Quaternion(axis.X * sin_a,axis.Y * sin_a,axis.Z * sin_a,(float)Math.Cos(angle / 2.0f)); - } - - - public static void CreateFromAxisAngle(ref Vector3 axis, float angle, out Quaternion result) - { - float sin_a = (float)Math.Sin(angle / 2.0f); - result.X = axis.X * sin_a; - result.Y = axis.Y * sin_a; - result.Z = axis.Z * sin_a; - result.W = (float)Math.Cos(angle / 2.0f); - } - - - public static Quaternion CreateFromRotationMatrix(Matrix matrix) - { - Quaternion result; - if ((matrix.M11 + matrix.M22 + matrix.M33) > 0.0F) - { - float M1 = (float)System.Math.Sqrt((double)(matrix.M11 + matrix.M22 + matrix.M33 + 1.0F)); - result.W = M1 * 0.5F; - M1 = 0.5F / M1; - result.X = (matrix.M23 - matrix.M32) * M1; - result.Y = (matrix.M31 - matrix.M13) * M1; - result.Z = (matrix.M12 - matrix.M21) * M1; - return result; - } - if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) - { - float M2 = (float)System.Math.Sqrt((double)(1.0F + matrix.M11 - matrix.M22 - matrix.M33)); - float M3 = 0.5F / M2; - result.X = 0.5F * M2; - result.Y = (matrix.M12 + matrix.M21) * M3; - result.Z = (matrix.M13 + matrix.M31) * M3; - result.W = (matrix.M23 - matrix.M32) * M3; - return result; - } - if (matrix.M22 > matrix.M33) - { - float M4 = (float)System.Math.Sqrt((double)(1.0F + matrix.M22 - matrix.M11 - matrix.M33)); - float M5 = 0.5F / M4; - result.X = (matrix.M21 + matrix.M12) * M5; - result.Y = 0.5F * M4; - result.Z = (matrix.M32 + matrix.M23) * M5; - result.W = (matrix.M31 - matrix.M13) * M5; - return result; - } - float M6 = (float)System.Math.Sqrt((double)(1.0F + matrix.M33 - matrix.M11 - matrix.M22)); - float M7 = 0.5F / M6; - result.X = (matrix.M31 + matrix.M13) * M7; - result.Y = (matrix.M32 + matrix.M23) * M7; - result.Z = 0.5F * M6; - result.W = (matrix.M12 - matrix.M21) * M7; - return result; - } - - - public static void CreateFromRotationMatrix(ref Matrix matrix, out Quaternion result) - { - if ((matrix.M11 + matrix.M22 + matrix.M33) > 0.0F) - { - float M1 = (float)System.Math.Sqrt((double)(matrix.M11 + matrix.M22 + matrix.M33 + 1.0F)); - result.W = M1 * 0.5F; - M1 = 0.5F / M1; - result.X = (matrix.M23 - matrix.M32) * M1; - result.Y = (matrix.M31 - matrix.M13) * M1; - result.Z = (matrix.M12 - matrix.M21) * M1; - return; - } - if ((matrix.M11 >= matrix.M22) && (matrix.M11 >= matrix.M33)) - { - float M2 = (float)System.Math.Sqrt((double)(1.0F + matrix.M11 - matrix.M22 - matrix.M33)); - float M3 = 0.5F / M2; - result.X = 0.5F * M2; - result.Y = (matrix.M12 + matrix.M21) * M3; - result.Z = (matrix.M13 + matrix.M31) * M3; - result.W = (matrix.M23 - matrix.M32) * M3; - return; - } - if (matrix.M22 > matrix.M33) - { - float M4 = (float)System.Math.Sqrt((double)(1.0F + matrix.M22 - matrix.M11 - matrix.M33)); - float M5 = 0.5F / M4; - result.X = (matrix.M21 + matrix.M12) * M5; - result.Y = 0.5F * M4; - result.Z = (matrix.M32 + matrix.M23) * M5; - result.W = (matrix.M31 - matrix.M13) * M5; - return; - } - float M6 = (float)System.Math.Sqrt((double)(1.0F + matrix.M33 - matrix.M11 - matrix.M22)); - float M7 = 0.5F / M6; - result.X = (matrix.M31 + matrix.M13) * M7; - result.Y = (matrix.M32 + matrix.M23) * M7; - result.Z = 0.5F * M6; - result.W = (matrix.M12 - matrix.M21) * M7; - } - - - public static Quaternion Divide(Quaternion quaternion1, Quaternion quaternion2) - { - Quaternion result; - - float w5 = 1.0F / ((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y) + (quaternion2.Z * quaternion2.Z) + (quaternion2.W * quaternion2.W)); - float w4 = -quaternion2.X * w5; - float w3 = -quaternion2.Y * w5; - float w2 = -quaternion2.Z * w5; - float w1 = quaternion2.W * w5; - - result.X = (quaternion1.X * w1) + (w4 * quaternion1.W) + ((quaternion1.Y * w2) - (quaternion1.Z * w3)); - result.Y = (quaternion1.Y * w1) + (w3 * quaternion1.W) + ((quaternion1.Z * w4) - (quaternion1.X * w2)); - result.Z = (quaternion1.Z * w1) + (w2 * quaternion1.W) + ((quaternion1.X * w3) - (quaternion1.Y * w4)); - result.W = (quaternion1.W * quaternion2.W * w5) - ((quaternion1.X * w4) + (quaternion1.Y * w3) + (quaternion1.Z * w2)); - return result; - } - - - public static void Divide(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - float w5 = 1.0F / ((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y) + (quaternion2.Z * quaternion2.Z) + (quaternion2.W * quaternion2.W)); - float w4 = -quaternion2.X * w5; - float w3 = -quaternion2.Y * w5; - float w2 = -quaternion2.Z * w5; - float w1 = quaternion2.W * w5; - - result.X = (quaternion1.X * w1) + (w4 * quaternion1.W) + ((quaternion1.Y * w2) - (quaternion1.Z * w3)); - result.Y = (quaternion1.Y * w1) + (w3 * quaternion1.W) + ((quaternion1.Z * w4) - (quaternion1.X * w2)); - result.Z = (quaternion1.Z * w1) + (w2 * quaternion1.W) + ((quaternion1.X * w3) - (quaternion1.Y * w4)); - result.W = (quaternion1.W * quaternion2.W * w5) - ((quaternion1.X * w4) + (quaternion1.Y * w3) + (quaternion1.Z * w2)); - } - - - public static float Dot(Quaternion quaternion1, Quaternion quaternion2) - { - return (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W); - } - - - public static void Dot(ref Quaternion quaternion1, ref Quaternion quaternion2, out float result) - { - result = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W); - } - - - public override bool Equals(object obj) - { - return (obj is Quaternion) ? this == (Quaternion)obj : false; - } - - - public bool Equals(Quaternion other) - { - if ((X == other.X) && (Y == other.Y) && (Z == other.Z)) - return W == other.W; - return false; - } - - - public override int GetHashCode() - { - return X.GetHashCode() + Y.GetHashCode() + Z.GetHashCode() + W.GetHashCode(); - } - - - public static Quaternion Inverse(Quaternion quaternion) - { - Quaternion result; - float m1 = 1.0F / ((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W)); - result.X = -quaternion.X * m1; - result.Y = -quaternion.Y * m1; - result.Z = -quaternion.Z * m1; - result.W = quaternion.W * m1; - return result; - } - - - public static void Inverse(ref Quaternion quaternion, out Quaternion result) - { - float m1 = 1.0F / ((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W)); - result.X = -quaternion.X * m1; - result.Y = -quaternion.Y * m1; - result.Z = -quaternion.Z * m1; - result.W = quaternion.W * m1; - } - - - public float Length() - { - return (float)System.Math.Sqrt((double)((X * X) + (Y * Y) + (Z * Z) + (W * W))); - } - - - public float LengthSquared() - { - return (X * X) + (Y * Y) + (Z * Z) + (W * W); - } - - - public static Quaternion Lerp(Quaternion quaternion1, Quaternion quaternion2, float amount) - { - Quaternion result; - float f2 = 1.0F - amount; - if (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W)) >= 0.0F) - { - result.X = (f2 * quaternion1.X) + (amount * quaternion2.X); - result.Y = (f2 * quaternion1.Y) + (amount * quaternion2.Y); - result.Z = (f2 * quaternion1.Z) + (amount * quaternion2.Z); - result.W = (f2 * quaternion1.W) + (amount * quaternion2.W); - } - else - { - result.X = (f2 * quaternion1.X) - (amount * quaternion2.X); - result.Y = (f2 * quaternion1.Y) - (amount * quaternion2.Y); - result.Z = (f2 * quaternion1.Z) - (amount * quaternion2.Z); - result.W = (f2 * quaternion1.W) - (amount * quaternion2.W); - } - float f4 = (result.X * result.X) + (result.Y * result.Y) + (result.Z * result.Z) + (result.W * result.W); - float f3 = 1.0F / (float)System.Math.Sqrt((double)f4); - result.X *= f3; - result.Y *= f3; - result.Z *= f3; - result.W *= f3; - return result; - } - - - public static void Lerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) - { - float m2 = 1.0F - amount; - if (((quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W)) >= 0.0F) - { - result.X = (m2 * quaternion1.X) + (amount * quaternion2.X); - result.Y = (m2 * quaternion1.Y) + (amount * quaternion2.Y); - result.Z = (m2 * quaternion1.Z) + (amount * quaternion2.Z); - result.W = (m2 * quaternion1.W) + (amount * quaternion2.W); - } - else - { - result.X = (m2 * quaternion1.X) - (amount * quaternion2.X); - result.Y = (m2 * quaternion1.Y) - (amount * quaternion2.Y); - result.Z = (m2 * quaternion1.Z) - (amount * quaternion2.Z); - result.W = (m2 * quaternion1.W) - (amount * quaternion2.W); - } - float m4 = (result.X * result.X) + (result.Y * result.Y) + (result.Z * result.Z) + (result.W * result.W); - float m3 = 1.0F / (float)System.Math.Sqrt((double)m4); - result.X *= m3; - result.Y *= m3; - result.Z *= m3; - result.W *= m3; - } - - - public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount) - { - Quaternion result; - float q2, q3; - - float q4 = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W); - bool flag = false; - if (q4 < 0.0F) - { - flag = true; - q4 = -q4; - } - if (q4 > 0.999999F) - { - q3 = 1.0F - amount; - q2 = flag ? -amount : amount; - } - else - { - float q5 = (float)System.Math.Acos((double)q4); - float q6 = (float)(1.0 / System.Math.Sin((double)q5)); - q3 = (float)System.Math.Sin((double)((1.0F - amount) * q5)) * q6; - q2 = flag ? (float)-System.Math.Sin((double)(amount * q5)) * q6 : (float)System.Math.Sin((double)(amount * q5)) * q6; - } - result.X = (q3 * quaternion1.X) + (q2 * quaternion2.X); - result.Y = (q3 * quaternion1.Y) + (q2 * quaternion2.Y); - result.Z = (q3 * quaternion1.Z) + (q2 * quaternion2.Z); - result.W = (q3 * quaternion1.W) + (q2 * quaternion2.W); - return result; - } - - - public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result) - { - float q2, q3; - - float q4 = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z) + (quaternion1.W * quaternion2.W); - bool flag = false; - if (q4 < 0.0F) - { - flag = true; - q4 = -q4; - } - if (q4 > 0.999999F) - { - q3 = 1.0F - amount; - q2 = flag ? -amount : amount; - } - else - { - float q5 = (float)System.Math.Acos((double)q4); - float q6 = (float)(1.0 / System.Math.Sin((double)q5)); - q3 = (float)System.Math.Sin((double)((1.0F - amount) * q5)) * q6; - q2 = flag ? (float)-System.Math.Sin((double)(amount * q5)) * q6 : (float)System.Math.Sin((double)(amount * q5)) * q6; - } - result.X = (q3 * quaternion1.X) + (q2 * quaternion2.X); - result.Y = (q3 * quaternion1.Y) + (q2 * quaternion2.Y); - result.Z = (q3 * quaternion1.Z) + (q2 * quaternion2.Z); - result.W = (q3 * quaternion1.W) + (q2 * quaternion2.W); - } - - - public static Quaternion Subtract(Quaternion quaternion1, Quaternion quaternion2) - { - quaternion1.X -= quaternion2.X; - quaternion1.Y -= quaternion2.Y; - quaternion1.Z -= quaternion2.Z; - quaternion1.W -= quaternion2.W; - return quaternion1; - } - - - public static void Subtract(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - result.X = quaternion1.X - quaternion2.X; - result.Y = quaternion1.Y - quaternion2.Y; - result.Z = quaternion1.Z - quaternion2.Z; - result.W = quaternion1.W - quaternion2.W; - } - - - public static Quaternion Multiply(Quaternion quaternion1, Quaternion quaternion2) - { - Quaternion result; - float f12 = (quaternion1.Y * quaternion2.Z) - (quaternion1.Z * quaternion2.Y); - float f11 = (quaternion1.Z * quaternion2.X) - (quaternion1.X * quaternion2.Z); - float f10 = (quaternion1.X * quaternion2.Y) - (quaternion1.Y * quaternion2.X); - float f9 = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z); - result.X = (quaternion1.X * quaternion2.W) + (quaternion2.X * quaternion1.W) + f12; - result.Y = (quaternion1.Y * quaternion2.W) + (quaternion2.Y * quaternion1.W) + f11; - result.Z = (quaternion1.Z * quaternion2.W) + (quaternion2.Z * quaternion1.W) + f10; - result.W = (quaternion1.W * quaternion2.W) - f9; - return result; - } - - - public static Quaternion Multiply(Quaternion quaternion1, float scaleFactor) - { - quaternion1.X *= scaleFactor; - quaternion1.Y *= scaleFactor; - quaternion1.Z *= scaleFactor; - quaternion1.W *= scaleFactor; - return quaternion1; - } - - - public static void Multiply(ref Quaternion quaternion1, float scaleFactor, out Quaternion result) - { - result.X = quaternion1.X * scaleFactor; - result.Y = quaternion1.Y * scaleFactor; - result.Z = quaternion1.Z * scaleFactor; - result.W = quaternion1.W * scaleFactor; - } - - - public static void Multiply(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result) - { - float f12 = (quaternion1.Y * quaternion2.Z) - (quaternion1.Z * quaternion2.Y); - float f11 = (quaternion1.Z * quaternion2.X) - (quaternion1.X * quaternion2.Z); - float f10 = (quaternion1.X * quaternion2.Y) - (quaternion1.Y * quaternion2.X); - float f9 = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z); - result.X = (quaternion1.X * quaternion2.W) + (quaternion2.X * quaternion1.W) + f12; - result.Y = (quaternion1.Y * quaternion2.W) + (quaternion2.Y * quaternion1.W) + f11; - result.Z = (quaternion1.Z * quaternion2.W) + (quaternion2.Z * quaternion1.W) + f10; - result.W = (quaternion1.W * quaternion2.W) - f9; - } - - - public static Quaternion Negate(Quaternion quaternion) - { - Quaternion result; - result.X = -quaternion.X; - result.Y = -quaternion.Y; - result.Z = -quaternion.Z; - result.W = -quaternion.W; - return result; - } - - - public static void Negate(ref Quaternion quaternion, out Quaternion result) - { - result.X = -quaternion.X; - result.Y = -quaternion.Y; - result.Z = -quaternion.Z; - result.W = -quaternion.W; - } - - - public void Normalize() - { - float f1 = 1.0F / (float)System.Math.Sqrt((double)((this.X * this.X) + (this.Y * this.Y) + (this.Z * this.Z) + (this.W * this.W))); - this.X *= f1; - this.Y *= f1; - this.Z *= f1; - this.W *= f1; - } - - - public static Quaternion Normalize(Quaternion quaternion) - { - Quaternion result; - float f1 = 1.0F / (float)System.Math.Sqrt((double)((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); - result.X = quaternion.X * f1; - result.Y = quaternion.Y * f1; - result.Z = quaternion.Z * f1; - result.W = quaternion.W * f1; - return result; - } - - - public static void Normalize(ref Quaternion quaternion, out Quaternion result) - { - float f1 = 1.0F / (float)System.Math.Sqrt((double)((quaternion.X * quaternion.X) + (quaternion.Y * quaternion.Y) + (quaternion.Z * quaternion.Z) + (quaternion.W * quaternion.W))); - result.X = quaternion.X * f1; - result.Y = quaternion.Y * f1; - result.Z = quaternion.Z * f1; - result.W = quaternion.W * f1; - } - - - public static Quaternion operator +(Quaternion quaternion1, Quaternion quaternion2) - { - quaternion1.X += quaternion2.X; - quaternion1.Y += quaternion2.Y; - quaternion1.Z += quaternion2.Z; - quaternion1.W += quaternion2.W; - return quaternion1; - } - - - public static Quaternion operator /(Quaternion quaternion1, Quaternion quaternion2) - { - Quaternion result; - - float w5 = 1.0F / ((quaternion2.X * quaternion2.X) + (quaternion2.Y * quaternion2.Y) + (quaternion2.Z * quaternion2.Z) + (quaternion2.W * quaternion2.W)); - float w4 = -quaternion2.X * w5; - float w3 = -quaternion2.Y * w5; - float w2 = -quaternion2.Z * w5; - float w1 = quaternion2.W * w5; - - result.X = (quaternion1.X * w1) + (w4 * quaternion1.W) + ((quaternion1.Y * w2) - (quaternion1.Z * w3)); - result.Y = (quaternion1.Y * w1) + (w3 * quaternion1.W) + ((quaternion1.Z * w4) - (quaternion1.X * w2)); - result.Z = (quaternion1.Z * w1) + (w2 * quaternion1.W) + ((quaternion1.X * w3) - (quaternion1.Y * w4)); - result.W = (quaternion1.W * quaternion2.W * w5) - ((quaternion1.X * w4) + (quaternion1.Y * w3) + (quaternion1.Z * w2)); - return result; - } - - - public static bool operator ==(Quaternion quaternion1, Quaternion quaternion2) - { - return quaternion1.X == quaternion2.X - && quaternion1.Y == quaternion2.Y - && quaternion1.Z == quaternion2.Z - && quaternion1.W == quaternion2.W; - } - - - public static bool operator !=(Quaternion quaternion1, Quaternion quaternion2) - { - return quaternion1.X != quaternion2.X - || quaternion1.Y != quaternion2.Y - || quaternion1.Z != quaternion2.Z - || quaternion1.W != quaternion2.W; - } - - - public static Quaternion operator *(Quaternion quaternion1, Quaternion quaternion2) - { - Quaternion result; - float f12 = (quaternion1.Y * quaternion2.Z) - (quaternion1.Z * quaternion2.Y); - float f11 = (quaternion1.Z * quaternion2.X) - (quaternion1.X * quaternion2.Z); - float f10 = (quaternion1.X * quaternion2.Y) - (quaternion1.Y * quaternion2.X); - float f9 = (quaternion1.X * quaternion2.X) + (quaternion1.Y * quaternion2.Y) + (quaternion1.Z * quaternion2.Z); - result.X = (quaternion1.X * quaternion2.W) + (quaternion2.X * quaternion1.W) + f12; - result.Y = (quaternion1.Y * quaternion2.W) + (quaternion2.Y * quaternion1.W) + f11; - result.Z = (quaternion1.Z * quaternion2.W) + (quaternion2.Z * quaternion1.W) + f10; - result.W = (quaternion1.W * quaternion2.W) - f9; - return result; - } - - - public static Quaternion operator *(Quaternion quaternion1, float scaleFactor) - { - quaternion1.X *= scaleFactor; - quaternion1.Y *= scaleFactor; - quaternion1.Z *= scaleFactor; - quaternion1.W *= scaleFactor; - return quaternion1; - } - - - public static Quaternion operator -(Quaternion quaternion1, Quaternion quaternion2) - { - quaternion1.X -= quaternion2.X; - quaternion1.Y -= quaternion2.Y; - quaternion1.Z -= quaternion2.Z; - quaternion1.W -= quaternion2.W; - return quaternion1; - } - - - public static Quaternion operator -(Quaternion quaternion) - { - quaternion.X = -quaternion.X; - quaternion.Y = -quaternion.Y; - quaternion.Z = -quaternion.Z; - quaternion.W = -quaternion.W; - return quaternion; - } - - - 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(); - } - - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Ray.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Ray.cs deleted file mode 100644 index ecfdb39c26..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Ray.cs +++ /dev/null @@ -1,233 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - public struct Ray : IEquatable - { - #region Public Fields - - public Vector3 Direction; - public Vector3 Position; - - #endregion - - - #region Public Constructors - - public Ray(Vector3 position, Vector3 direction) - { - this.Position = position; - this.Direction = direction; - } - - #endregion - - - #region Public Methods - - public override bool Equals(object obj) - { - return (obj is Ray) ? this.Equals((Ray)obj) : false; - } - - - public bool Equals(Ray other) - { - return this.Position.Equals(other.Position) && this.Direction.Equals(other.Direction); - } - - - public override int GetHashCode() - { - return Position.GetHashCode() ^ Direction.GetHashCode(); - } - - - public float? Intersects(BoundingBox box) - { - //first test if start in box - if (Position.X >= box.Min.X - && Position.X <= box.Max.X - && Position.Y >= box.Min.Y - && Position.Y <= box.Max.Y - && Position.Z >= box.Min.Z - && Position.Z <= box.Max.Z) - return 0.0f;// here we concidere cube is full and origine is in cube so intersect at origine - - //Second we check each face - Vector3 maxT = new Vector3(-1.0f); - //Vector3 minT = new Vector3(-1.0f); - //calcul intersection with each faces - if (Position.X < box.Min.X && Direction.X != 0.0f) - maxT.X = (box.Min.X - Position.X) / Direction.X; - else if (Position.X > box.Max.X && Direction.X != 0.0f) - maxT.X = (box.Max.X - Position.X) / Direction.X; - if (Position.Y < box.Min.Y && Direction.Y != 0.0f) - maxT.Y = (box.Min.Y - Position.Y) / Direction.Y; - else if (Position.Y > box.Max.Y && Direction.Y != 0.0f) - maxT.Y = (box.Max.Y - Position.Y) / Direction.Y; - if (Position.Z < box.Min.Z && Direction.Z != 0.0f) - maxT.Z = (box.Min.Z - Position.Z) / Direction.Z; - else if (Position.Z > box.Max.Z && Direction.Z != 0.0f) - maxT.Z = (box.Max.Z - Position.Z) / Direction.Z; - - //get the maximum maxT - if (maxT.X > maxT.Y && maxT.X > maxT.Z) - { - if (maxT.X < 0.0f) - return null;// ray go on opposite of face - //coordonate of hit point of face of cube - float coord = Position.Z + maxT.X * Direction.Z; - // if hit point coord ( intersect face with ray) is out of other plane coord it miss - if (coord < box.Min.Z || coord > box.Max.Z) - return null; - coord = Position.Y + maxT.X * Direction.Y; - if (coord < box.Min.Y || coord > box.Max.Y) - return null; - return maxT.X; - } - if (maxT.Y > maxT.X && maxT.Y > maxT.Z) - { - if (maxT.Y < 0.0f) - return null;// ray go on opposite of face - //coordonate of hit point of face of cube - float coord = Position.Z + maxT.Y * Direction.Z; - // if hit point coord ( intersect face with ray) is out of other plane coord it miss - if (coord < box.Min.Z || coord > box.Max.Z) - return null; - coord = Position.X + maxT.Y * Direction.X; - if (coord < box.Min.X || coord > box.Max.X) - return null; - return maxT.Y; - } - else //Z - { - if (maxT.Z < 0.0f) - return null;// ray go on opposite of face - //coordonate of hit point of face of cube - float coord = Position.X + maxT.Z * Direction.X; - // if hit point coord ( intersect face with ray) is out of other plane coord it miss - if (coord < box.Min.X || coord > box.Max.X) - return null; - coord = Position.Y + maxT.Z * Direction.Y; - if (coord < box.Min.Y || coord > box.Max.Y) - return null; - return maxT.Z; - } - } - - - public void Intersects(ref BoundingBox box, out float? result) - { - result = Intersects(box); - } - - - public float? Intersects(BoundingFrustum frustum) - { - throw new NotImplementedException(); - } - - - public float? Intersects(BoundingSphere sphere) - { - float? result; - Intersects(ref sphere, out result); - return result; - } - - public float? Intersects(Plane plane) - { - throw new NotImplementedException(); - } - - public void Intersects(ref Plane plane, out float? result) - { - throw new NotImplementedException(); - } - - public void Intersects(ref BoundingSphere sphere, out float? result) - { - // Find the vector between where the ray starts the the sphere's centre - Vector3 difference = sphere.Center - this.Position; - - float differenceLengthSquared = difference.LengthSquared(); - float sphereRadiusSquared = sphere.Radius * sphere.Radius; - - float distanceAlongRay; - - // If the distance between the ray start and the sphere's centre is less than - // the radius of the sphere, it means we've intersected. N.B. checking the LengthSquared is faster. - if (differenceLengthSquared < sphereRadiusSquared) - { - result = 0.0f; - return; - } - - Vector3.Dot(ref this.Direction, ref difference, out distanceAlongRay); - // If the ray is pointing away from the sphere then we don't ever intersect - if (distanceAlongRay < 0) - { - result = null; - return; - } - - // Next we kinda use Pythagoras to check if we are within the bounds of the sphere - // if x = radius of sphere - // if y = distance between ray position and sphere centre - // if z = the distance we've travelled along the ray - // if x^2 + z^2 - y^2 < 0, we do not intersect - float dist = sphereRadiusSquared + distanceAlongRay * distanceAlongRay - differenceLengthSquared; - - result = (dist < 0) ? null : distanceAlongRay - (float?)Math.Sqrt(dist); - } - - - public static bool operator !=(Ray a, Ray b) - { - return !a.Equals(b); - } - - - public static bool operator ==(Ray a, Ray b) - { - return a.Equals(b); - } - - - public override string ToString() - { - return string.Format("{{Position:{0} Direction:{1}}}", Position.ToString(), Direction.ToString()); - } - #endregion - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Rectangle.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Rectangle.cs deleted file mode 100644 index 69924053e0..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Rectangle.cs +++ /dev/null @@ -1,312 +0,0 @@ -#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.Globalization; -using System.ComponentModel; - - -namespace BizHawk.Bizware.BizwareGL -{ - - - public struct Rectangle : IEquatable - { - #region Private Fields - - private static Rectangle emptyRectangle = new Rectangle(); - - #endregion Private Fields - - - #region Public Fields - - public int X; - public int Y; - public int Width; - public int Height; - - #endregion Public Fields - - - #region Public Properties - - public Point Center - { - get - { - return new Point(this.X + (this.Width / 2), this.Y + (this.Height / 2)); - } - } - - public Point Location - { - get - { - return new Point(this.X, this.Y); - } - set - { - this.X = value.X; - this.Y = value.Y; - } - } - - public bool IsEmpty - { - get - { - return ((((this.Width == 0) && (this.Height == 0)) && (this.X == 0)) && (this.Y == 0)); - } - } - - public static Rectangle Empty - { - get { return emptyRectangle; } - } - - public int Left - { - get { return this.X; } - } - - public int Right - { - get { return (this.X + this.Width); } - } - - public int Top - { - get { return this.Y; } - } - - public int Bottom - { - get { return (this.Y + this.Height); } - } - - #endregion Public Properties - - - #region Constructors - - public Rectangle(int x, int y, int width, int height) - { - this.X = x; - this.Y = y; - this.Width = width; - this.Height = height; - } - - #endregion Constructors - - - #region Public Methods - - public static Rectangle Union(Rectangle value1, Rectangle value2) - { - throw new NotImplementedException(); - } - - public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result) - { - throw new NotImplementedException(); - } - - public static Rectangle Intersect(Rectangle value1, Rectangle value2) - { - throw new NotImplementedException(); - } - - public void Intersects(ref Rectangle value, out bool result) - { - result = (((value.X < (this.X + this.Width)) && (this.X < (value.X + value.Width))) && (value.Y < (this.Y + this.Height))) && (this.Y < (value.Y + value.Height)); - } - - public bool Contains(Point value) - { - return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height))); - } - - public bool Contains(Rectangle value) - { - return ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height))); - } - - public void Contains(ref Rectangle value, out bool result) - { - result = (((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height)); - } - - public bool Contains(int x, int y) - { - return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height))); - } - - public void Contains(ref Point value, out bool result) - { - result = (((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)); - } - - public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result) - { - throw new NotImplementedException(); - } - - public static bool operator ==(Rectangle a, Rectangle b) - { - return ((a.X == b.X) && (a.Y == b.Y) && (a.Width == b.Width) && (a.Height == b.Height)); - } - - public static bool operator !=(Rectangle a, Rectangle b) - { - return !(a == b); - } - - /// - /// Moves Rectangle for both Point values. - /// - /// - /// A - /// - public void Offset(Point offset) - { - X += offset.X; - Y += offset.Y; - } - - /// - /// Moves rectangle for both values. - /// - /// - /// A - /// - /// - /// A - /// - public void Offset(int offsetX, int offsetY) - { - X += offsetX; - Y += offsetY; - } - - /// - /// Grows the Rectangle. Down right point is in the same position. - /// - /// - /// A - /// - /// - /// A - /// - public void Inflate(int horizontalValue, int verticalValue) - { - X -= horizontalValue; - Y -= verticalValue; - Width += horizontalValue * 2; - Height += verticalValue * 2; - } - - /// - /// It checks if two rectangle intersects. - /// - /// - /// A - /// - /// - /// A - /// - public bool Intersects(Rectangle rect) - { - if(this.X <= rect.X) - { - if((this.X + this.Width) > rect.X) - { - if(this.Y < rect.Y) - { - if((this.Y + this.Height) > rect.Y) - return true; - } - else - { - if((rect.Y + rect.Height) > this.Y) - return true; - } - } - } - else - { - if((rect.X + rect.Width) > this.X) - { - if(this.Y < rect.Y) - { - if((this.Y + this.Height) > rect.Y) - return true; - } - else - { - if((rect.Y + rect.Height) > this.Y) - return true; - } - } - } - return false; - } - - - public bool Equals(Rectangle other) - { - return this == other; - } - - /// - /// Returns true if recangles are same - /// - /// - /// A - /// - /// - /// A - /// - public override bool Equals(object obj) - { - return (obj is Rectangle) ? this == ((Rectangle)obj) : false; - } - - public override string ToString() - { - return string.Format("{{X:{0} Y:{1} Width:{2} Height:{3}}}", X, Y, Width, Height); - } - - public override int GetHashCode() - { - return (this.X ^ this.Y ^ this.Width ^ this.Height); - } - - #endregion Public Methods - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Size.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Size.cs deleted file mode 100644 index 0524e0e10e..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Size.cs +++ /dev/null @@ -1,368 +0,0 @@ -// -// System.Drawing.Size.cs -// -// Author: -// Mike Kestner (mkestner@speakeasy.net) -// -// Copyright (C) 2001 Mike Kestner -// Copyright (C) 2004 Novell, Inc. http://www.novell.com -// - -//The MIT license: - -// -// Copyright (C) 2004 Novell, Inc (http://www.novell.com) -// -// 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. -// - -using System; -using System.Runtime.Serialization; -using System.Runtime.InteropServices; -using System.ComponentModel; - -namespace BizHawk.Bizware.BizwareGL -{ - [Serializable] - [ComVisible(true)] - public struct Size - { - - // Private Height and width fields. - private int width, height; - - // ----------------------- - // Public Shared Members - // ----------------------- - - /// - /// Empty Shared Field - /// - /// - /// - /// An uninitialized Size Structure. - /// - - public static readonly Size Empty; - - /// - /// Ceiling Shared Method - /// - /// - /// - /// Produces a Size structure from a SizeF structure by - /// taking the ceiling of the Width and Height properties. - /// - - public static Size Ceiling(SizeF value) - { - int w, h; - checked - { - w = (int)Math.Ceiling(value.Width); - h = (int)Math.Ceiling(value.Height); - } - - return new Size(w, h); - } - - /// - /// Round Shared Method - /// - /// - /// - /// Produces a Size structure from a SizeF structure by - /// rounding the Width and Height properties. - /// - - public static Size Round(SizeF value) - { - int w, h; - checked - { - w = (int)Math.Round(value.Width); - h = (int)Math.Round(value.Height); - } - - return new Size(w, h); - } - - /// - /// Truncate Shared Method - /// - /// - /// - /// Produces a Size structure from a SizeF structure by - /// truncating the Width and Height properties. - /// - - public static Size Truncate(SizeF value) - { - int w, h; - checked - { - w = (int)value.Width; - h = (int)value.Height; - } - - return new Size(w, h); - } - - /// - /// Addition Operator - /// - /// - /// - /// Addition of two Size structures. - /// - - public static Size operator +(Size sz1, Size sz2) - { - return new Size(sz1.Width + sz2.Width, - sz1.Height + sz2.Height); - } - - /// - /// Equality Operator - /// - /// - /// - /// Compares two Size objects. The return value is - /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// - - public static bool operator ==(Size sz1, Size sz2) - { - return ((sz1.Width == sz2.Width) && - (sz1.Height == sz2.Height)); - } - - /// - /// Inequality Operator - /// - /// - /// - /// Compares two Size objects. The return value is - /// based on the equivalence of the Width and Height - /// properties of the two Sizes. - /// - - public static bool operator !=(Size sz1, Size sz2) - { - return ((sz1.Width != sz2.Width) || - (sz1.Height != sz2.Height)); - } - - /// - /// Subtraction Operator - /// - /// - /// - /// Subtracts two Size structures. - /// - - public static Size operator -(Size sz1, Size sz2) - { - return new Size(sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } - - /// - /// Size to Point Conversion - /// - /// - /// - /// Returns a Point based on the dimensions of a given - /// Size. Requires explicit cast. - /// - - public static explicit operator Point(Size size) - { - return new Point(size.Width, size.Height); - } - - /// - /// Size to SizeF Conversion - /// - /// - /// - /// Creates a SizeF based on the dimensions of a given - /// Size. No explicit cast is required. - /// - - public static implicit operator SizeF(Size p) - { - return new SizeF(p.Width, p.Height); - } - - - // ----------------------- - // Public Constructors - // ----------------------- - - /// - /// Size Constructor - /// - /// - /// - /// Creates a Size from a Point value. - /// - - public Size(Point pt) - { - width = pt.X; - height = pt.Y; - } - - /// - /// Size Constructor - /// - /// - /// - /// Creates a Size from specified dimensions. - /// - - public Size(int width, int height) - { - this.width = width; - this.height = height; - } - - // ----------------------- - // Public Instance Members - // ----------------------- - - /// - /// IsEmpty Property - /// - /// - /// - /// Indicates if both Width and Height are zero. - /// - - [Browsable(false)] - public bool IsEmpty - { - get - { - return ((width == 0) && (height == 0)); - } - } - - /// - /// Width Property - /// - /// - /// - /// The Width coordinate of the Size. - /// - - public int Width - { - get - { - return width; - } - set - { - width = value; - } - } - - /// - /// Height Property - /// - /// - /// - /// The Height coordinate of the Size. - /// - - public int Height - { - get - { - return height; - } - set - { - height = value; - } - } - - /// - /// Equals Method - /// - /// - /// - /// Checks equivalence of this Size and another object. - /// - - public override bool Equals(object obj) - { - if (!(obj is Size)) - return false; - - return (this == (Size)obj); - } - - /// - /// GetHashCode Method - /// - /// - /// - /// Calculates a hashing value. - /// - - public override int GetHashCode() - { - return width ^ height; - } - - /// - /// ToString Method - /// - /// - /// - /// Formats the Size as a string in coordinate notation. - /// - - public override string ToString() - { - return String.Format("{{Width={0}, Height={1}}}", width, height); - } - -#if NET_2_0 - public static Size Add (Size sz1, Size sz2) - { - return new Size (sz1.Width + sz2.Width, - sz1.Height + sz2.Height); - - } - - public static Size Subtract (Size sz1, Size sz2) - { - return new Size (sz1.Width - sz2.Width, - sz1.Height - sz2.Height); - } -#endif - - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector2.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector2.cs deleted file mode 100644 index b03b511b1c..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector2.cs +++ /dev/null @@ -1,599 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - - public struct Vector2 : IEquatable - { - #region Private Fields - - private static Vector2 zeroVector = new Vector2(0f, 0f); - private static Vector2 unitVector = new Vector2(1f, 1f); - private static Vector2 unitXVector = new Vector2(1f, 0f); - private static Vector2 unitYVector = new Vector2(0f, 1f); - - #endregion Private Fields - - - #region Public Fields - - public float X; - public float Y; - - #endregion Public Fields - - - #region Properties - - public static Vector2 Zero - { - get { return zeroVector; } - } - - public static Vector2 One - { - get { return unitVector; } - } - - public static Vector2 UnitX - { - get { return unitXVector; } - } - - public static Vector2 UnitY - { - get { return unitYVector; } - } - - #endregion Properties - - - #region Constructors - - /// - /// Constructor foe standard 2D vector. - /// - /// - /// A - /// - /// - /// A - /// - public Vector2(float x, float y) - { - this.X = x; - this.Y = y; - } - - /// - /// Constructor for "square" vector. - /// - /// - /// A - /// - public Vector2(float value) - { - this.X = value; - this.Y = value; - } - - #endregion Constructors - - - #region Public Methods - - public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result) - { - float dot = Dot(vector, normal); - result.X = vector.X - ((2f * dot) * normal.X); - result.Y = vector.Y - ((2f * dot) * normal.Y); - } - - public static Vector2 Reflect(Vector2 vector, Vector2 normal) - { - Vector2 result; - Reflect(ref vector, ref normal, out result); - return result; - } - - public static Vector2 Add(Vector2 value1, Vector2 value2) - { - value1.X += value2.X; - value1.Y += value2.Y; - return value1; - } - - public static void Add(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result.X = value1.X + value2.X; - result.Y = value1.Y + value2.Y; - } - - public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2) - { - return new Vector2( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2)); - } - - public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result) - { - result = new Vector2( - MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2), - MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2)); - } - - public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount) - { - return new Vector2( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount)); - } - - public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result) - { - result = new Vector2( - MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount), - MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount)); - } - - public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max) - { - return new Vector2( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y)); - } - - public static void Clamp(ref Vector2 value1, ref Vector2 min, ref Vector2 max, out Vector2 result) - { - result = new Vector2( - MathHelper.Clamp(value1.X, min.X, max.X), - MathHelper.Clamp(value1.Y, min.Y, max.Y)); - } - - /// - /// Returns float precison distanve between two vectors - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - public static float Distance(Vector2 value1, Vector2 value2) - { - return (float)Math.Sqrt((value1.X - value2.X) * (value1.X - value2.X) + (value1.Y - value2.Y) * (value1.Y - value2.Y)); - } - - - public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result) - { - result = (float)Math.Sqrt((value1.X - value2.X) * (value1.X - value2.X) + (value1.Y - value2.Y) * (value1.Y - value2.Y)); - } - - public static float DistanceSquared(Vector2 value1, Vector2 value2) - { - return (value1.X - value2.X) * (value1.X - value2.X) + (value1.Y - value2.Y) * (value1.Y - value2.Y); - } - - public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result) - { - result = (value1.X - value2.X) * (value1.X - value2.X) + (value1.Y - value2.Y) * (value1.Y - value2.Y); - } - - /// - /// Devide first vector with the secund vector - /// - /// - /// A - /// - /// - /// A - /// - /// - /// A - /// - public static Vector2 Divide(Vector2 value1, Vector2 value2) - { - value1.X /= value2.X; - value1.Y /= value2.Y; - return value1; - } - - public static void Divide(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result.X = value1.X / value2.X; - result.Y = value1.Y / value2.Y; - } - - public static Vector2 Divide(Vector2 value1, float divider) - { - float factor = 1.0f / divider; - value1.X *= factor; - value1.Y *= factor; - return value1; - } - - public static void Divide(ref Vector2 value1, float divider, out Vector2 result) - { - float factor = 1.0f / divider; - result.X = value1.X * factor; - result.Y = value1.Y * factor; - } - - public static float Dot(Vector2 value1, Vector2 value2) - { - return value1.X * value2.X + value1.Y * value2.Y; - } - - public static void Dot(ref Vector2 value1, ref Vector2 value2, out float result) - { - result = value1.X * value2.X + value1.Y * value2.Y; - } - - public override bool Equals(object obj) - { - return (obj is Vector2) ? this == ((Vector2)obj) : false; - } - - public bool Equals(Vector2 other) - { - return this == other; - } - - public override int GetHashCode() - { - return (int)(this.X + this.Y); - } - - public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount) - { - value1.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); - value1.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); - return value1; - } - - public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 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); - } - - public float Length() - { - return (float)Math.Sqrt((double)(X * X + Y * Y)); - } - - public float LengthSquared() - { - return X * X + Y * Y; - } - - public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount) - { - return new Vector2( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount)); - } - - public static void Lerp(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result) - { - result = new Vector2( - MathHelper.Lerp(value1.X, value2.X, amount), - MathHelper.Lerp(value1.Y, value2.Y, amount)); - } - - public static Vector2 Max(Vector2 value1, Vector2 value2) - { - return new Vector2( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y)); - } - - public static void Max(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result = new Vector2( - MathHelper.Max(value1.X, value2.X), - MathHelper.Max(value1.Y, value2.Y)); - } - - public static Vector2 Min(Vector2 value1, Vector2 value2) - { - return new Vector2( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y)); - } - - public static void Min(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result = new Vector2( - MathHelper.Min(value1.X, value2.X), - MathHelper.Min(value1.Y, value2.Y)); - } - - public static Vector2 Multiply(Vector2 value1, Vector2 value2) - { - value1.X *= value2.X; - value1.Y *= value2.Y; - return value1; - } - - public static Vector2 Multiply(Vector2 value1, float scaleFactor) - { - value1.X *= scaleFactor; - value1.Y *= scaleFactor; - return value1; - } - - public static void Multiply(ref Vector2 value1, float scaleFactor, out Vector2 result) - { - result.X = value1.X * scaleFactor; - result.Y = value1.Y * scaleFactor; - } - - public static void Multiply(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result.X = value1.X * value2.X; - result.Y = value1.Y * value2.Y; - } - - public static Vector2 Negate(Vector2 value) - { - value.X = -value.X; - value.Y = -value.Y; - return value; - } - - public static void Negate(ref Vector2 value, out Vector2 result) - { - result.X = -value.X; - result.Y = -value.Y; - } - - public void Normalize() - { - float factor = 1f / (float)Math.Sqrt((double)(X * X + Y * Y)); - X *= factor; - Y *= factor; - } - - public static Vector2 Normalize(Vector2 value) - { - float factor = 1f / (float)Math.Sqrt((double)(value.X * value.X + value.Y * value.Y)); - value.X *= factor; - value.Y *= factor; - return value; - } - - public static void Normalize(ref Vector2 value, out Vector2 result) - { - float factor = 1f / (float)Math.Sqrt((double)(value.X * value.X + value.Y * value.Y)); - result.X = value.X * factor; - result.Y = value.Y * factor; - } - - public static Vector2 SmoothStep(Vector2 value1, Vector2 value2, float amount) - { - return new Vector2( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount)); - } - - public static void SmoothStep(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result) - { - result = new Vector2( - MathHelper.SmoothStep(value1.X, value2.X, amount), - MathHelper.SmoothStep(value1.Y, value2.Y, amount)); - } - - public static Vector2 Subtract(Vector2 value1, Vector2 value2) - { - value1.X -= value2.X; - value1.Y -= value2.Y; - return value1; - } - - public static void Subtract(ref Vector2 value1, ref Vector2 value2, out Vector2 result) - { - result.X = value1.X - value2.X; - result.Y = value1.Y - value2.Y; - } - - public static Vector2 Transform(Vector2 position, Matrix matrix) - { - Transform(ref position, ref matrix, out position); - return position; - } - - public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector2 result) - { - result = new Vector2((position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41, - (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42); - } - - public static Vector2 Transform(Vector2 value, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector2 result) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector2[] sourceArray, ref Matrix matrix, Vector2[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector2[] sourceArray, ref Quaternion rotation, Vector2[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector2[] sourceArray, int sourceIndex, ref Matrix matrix, Vector2[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector2[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector2[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public static Vector2 TransformNormal(Vector2 normal, Matrix matrix) - { - Vector2.TransformNormal(ref normal, ref matrix, out normal); - return normal; - } - - public static void TransformNormal(ref Vector2 normal, ref Matrix matrix, out Vector2 result) - { - result = new Vector2((normal.X * matrix.M11) + (normal.Y * matrix.M21), - (normal.X * matrix.M12) + (normal.Y * matrix.M22)); - } - - public static void TransformNormal(Vector2[] sourceArray, ref Matrix matrix, Vector2[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void TransformNormal(Vector2[] sourceArray, int sourceIndex, ref Matrix matrix, Vector2[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public override string ToString() - { - StringBuilder sb = new StringBuilder(24); - sb.Append("{X:"); - sb.Append(this.X); - sb.Append(" Y:"); - sb.Append(this.Y); - sb.Append("}"); - return sb.ToString(); - } - - #endregion Public Methods - - - #region Operators - - public static Vector2 operator -(Vector2 value) - { - value.X = -value.X; - value.Y = -value.Y; - return value; - } - - - public static bool operator ==(Vector2 value1, Vector2 value2) - { - return value1.X == value2.X && value1.Y == value2.Y; - } - - - public static bool operator !=(Vector2 value1, Vector2 value2) - { - return value1.X != value2.X || value1.Y != value2.Y; - } - - - public static Vector2 operator +(Vector2 value1, Vector2 value2) - { - value1.X += value2.X; - value1.Y += value2.Y; - return value1; - } - - - public static Vector2 operator -(Vector2 value1, Vector2 value2) - { - value1.X -= value2.X; - value1.Y -= value2.Y; - return value1; - } - - - public static Vector2 operator *(Vector2 value1, Vector2 value2) - { - value1.X *= value2.X; - value1.Y *= value2.Y; - return value1; - } - - - public static Vector2 operator *(Vector2 value, float scaleFactor) - { - value.X *= scaleFactor; - value.Y *= scaleFactor; - return value; - } - - - public static Vector2 operator *(float scaleFactor, Vector2 value) - { - value.X *= scaleFactor; - value.Y *= scaleFactor; - return value; - } - - - public static Vector2 operator /(Vector2 value1, Vector2 value2) - { - value1.X /= value2.X; - value1.Y /= value2.Y; - return value1; - } - - - public static Vector2 operator /(Vector2 value1, float divider) - { - float factor = 1 / divider; - value1.X *= factor; - value1.Y *= factor; - return value1; - } - - #endregion Operators - } -} diff --git a/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector3.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector3.cs deleted file mode 100644 index 7a93a379fc..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector3.cs +++ /dev/null @@ -1,679 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - - 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) - { - Vector3 result; - result.X = vector1.Y * vector2.Z - vector2.Y * vector1.Z; - result.Y = vector2.X * vector1.Z - vector1.X * vector2.Z; - result.Z = vector1.X * vector2.Y - vector2.X * vector1.Y; - return result; - } - - public static void Cross(ref Vector3 vector1, ref Vector3 vector2, out Vector3 result) - { - result.X = vector1.Y * vector2.Z - vector2.Y * vector1.Z; - result.Y = vector2.X * vector1.Z - vector1.X * vector2.Z; - result.Z = vector1.X * vector2.Y - vector2.X * vector1.Y; - } - - public static float Distance(Vector3 value1, Vector3 value2) - { - return (float)Math.Sqrt((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 void Distance(ref Vector3 value1, ref Vector3 value2, out float result) - { - result = (float)Math.Sqrt((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 float DistanceSquared(Vector3 value1, Vector3 value2) - { - return (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 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.0f / 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.0f / 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) - { - value1.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); - value1.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); - value1.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); - return value1; - } - - 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() - { - return (float)Math.Sqrt((double)(X * X + Y * Y + Z * Z)); - } - - public float LengthSquared() - { - return X * X + Y * Y + Z * Z; - } - - 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.X = -value.X; - value.Y = -value.Y; - value.Z = -value.Z; - return value; - } - - public static void Negate(ref Vector3 value, out Vector3 result) - { - result.X = -value.X; - result.Y = -value.Y; - result.Z = -value.Z; - } - - public void Normalize() - { - float factor = 1f / (float)Math.Sqrt((double)(X * X + Y * Y + Z * Z)); - X *= factor; - Y *= factor; - Z *= factor; - } - - public static Vector3 Normalize(Vector3 value) - { - float factor = 1f / (float)Math.Sqrt((double)(value.X * value.X + value.Y * value.Y + value.Z * value.Z)); - value.X *= factor; - value.Y *= factor; - value.Z *= factor; - return value; - } - - public static void Normalize(ref Vector3 value, out Vector3 result) - { - float factor = 1f / (float)Math.Sqrt((double)(value.X * value.X + value.Y * value.Y + value.Z * value.Z)); - result.X = value.X * factor; - result.Y = value.Y * factor; - result.Z = value.Z * factor; - } - - public static Vector3 Reflect(Vector3 vector, Vector3 normal) - { - float dotTimesTwo = 2f * Dot(vector, normal); - vector.X = vector.X - dotTimesTwo * normal.X; - vector.Y = vector.Y - dotTimesTwo * normal.Y; - vector.Z = vector.Z - dotTimesTwo * normal.Z; - return vector; - } - - public static void Reflect(ref Vector3 vector, ref Vector3 normal, out Vector3 result) - { - float dotTimesTwo = 2f * Dot(vector, normal); - result.X = vector.X - dotTimesTwo * normal.X; - result.Y = vector.Y - dotTimesTwo * normal.Y; - result.Z = vector.Z - dotTimesTwo * normal.Z; - } - - 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 Transform(Vector3 value, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector3[] sourceArray, ref Matrix matrix, Vector3[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector3[] sourceArray, ref Quaternion rotation, Vector3[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix, Vector3[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector3[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector3 result) - { - throw new NotImplementedException(); - } - - public static void TransformNormal(Vector3[] sourceArray, ref Matrix matrix, Vector3[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void TransformNormal(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix, Vector3[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - 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.X != value2.X - || value1.Y != value2.Y - || value1.Z != value2.Z; - } - - 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/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector4.cs b/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector4.cs deleted file mode 100644 index feef9703fb..0000000000 --- a/Bizware/BizHawk.Bizware.BizwareGL/Types/Vector4.cs +++ /dev/null @@ -1,709 +0,0 @@ -#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 BizHawk.Bizware.BizwareGL -{ - [Serializable] - [StructLayout(LayoutKind.Sequential)] - - 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((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 void Distance(ref Vector4 value1, ref Vector4 value2, out float result) - { - result = (float)Math.Sqrt((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 float DistanceSquared(Vector4 value1, Vector4 value2) - { - return (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 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) - { - value1.W = MathHelper.Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount); - value1.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount); - value1.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount); - value1.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount); - - return value1; - } - - 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() - { - return (float)Math.Sqrt((double)(X * X + Y * Y + Z * Z + W * W)); - } - - public float LengthSquared() - { - return X * X + Y * Y + Z * Z + W * W; - } - - 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.X = -value.X; - value.Y = -value.Y; - value.Z = -value.Z; - value.W = -value.W; - return value; - } - - public static void Negate(ref Vector4 value, out Vector4 result) - { - result.X = -value.X; - result.Y = -value.Y; - result.Z = -value.Z; - result.W = -value.W; - } - - public void Normalize() - { - float factor = 1f / (float)Math.Sqrt((double)(X * X + Y * Y + Z * Z + W * W)); - - W = W * factor; - X = X * factor; - Y = Y * factor; - Z = Z * factor; - } - - public static Vector4 Normalize(Vector4 vector) - { - float factor = 1f / (float)Math.Sqrt((double)(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W)); - - vector.W = vector.W * factor; - vector.X = vector.X * factor; - vector.Y = vector.Y * factor; - vector.Z = vector.Z * factor; - - return vector; - } - - public static void Normalize(ref Vector4 vector, out Vector4 result) - { - float factor = 1f / (float)Math.Sqrt((double)(vector.X * vector.X + vector.Y * vector.Y + vector.Z * vector.Z + vector.W * vector.W)); - - 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(Vector2 value, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static Vector4 Transform(Vector3 value, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static Vector4 Transform(Vector4 value, Quaternion rotation) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector4 result) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector4 result) - { - throw new NotImplementedException(); - } - - public static void Transform(ref Vector4 value, ref Quaternion rotation, out Vector4 result) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector4[] sourceArray, ref Quaternion rotation, Vector4[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector4[] sourceArray, ref Matrix matrix, Vector4[] destinationArray) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector4[] sourceArray, int sourceIndex, ref Matrix matrix, Vector4[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - public static void Transform(Vector4[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector4[] destinationArray, int destinationIndex, int length) - { - throw new NotImplementedException(); - } - - 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) - { - value.X = -value.X; - value.Y = -value.Y; - value.Z = -value.Z; - value.W = -value.W; - return value; - } - - 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.W != value2.W - || value1.X != value2.X - || value1.Y != value2.Y - || value1.Z != value2.Z; - } - - 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 - } -}