use openTK for graphics math types, even if, hypothetically, we make a d3d BizwareGL driver.
This commit is contained in:
parent
d4c8b75de4
commit
c6997c49c8
|
@ -78,6 +78,10 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\References\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="PresentationFramework" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -34,6 +34,10 @@
|
|||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\References\OpenTK.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Drawing" />
|
||||
|
@ -67,23 +71,6 @@
|
|||
<Compile Include="TexAtlas.cs" />
|
||||
<Compile Include="Art.cs" />
|
||||
<Compile Include="Texture2d.cs" />
|
||||
<Compile Include="Types\BoundingBox.cs" />
|
||||
<Compile Include="Types\BoundingFrustum.cs" />
|
||||
<Compile Include="Types\BoundingSphere.cs" />
|
||||
<Compile Include="Types\Enums.cs" />
|
||||
<Compile Include="Types\MathHelper.cs" />
|
||||
<Compile Include="Types\Matrix.cs" />
|
||||
<Compile Include="Types\Plane.cs" />
|
||||
<Compile Include="Types\PlaneHelper.cs" />
|
||||
<Compile Include="Types\Point.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Types\Quaternion.cs" />
|
||||
<Compile Include="Types\Ray.cs" />
|
||||
<Compile Include="Types\Rectangle.cs" />
|
||||
<Compile Include="Types\Vector2.cs" />
|
||||
<Compile Include="Types\Vector3.cs" />
|
||||
<Compile Include="Types\Vector4.cs" />
|
||||
<Compile Include="UniformInfo.cs" />
|
||||
<Compile Include="VertexLayout.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
using System;
|
||||
using sd=System.Drawing;
|
||||
|
||||
using OpenTK;
|
||||
|
||||
namespace BizHawk.Bizware.BizwareGL
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Sets a uniform value
|
||||
/// </summary>
|
||||
void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix mat, bool transpose);
|
||||
void SetPipelineUniformMatrix(PipelineUniform uniform, Matrix4 mat, bool transpose);
|
||||
|
||||
/// <summary>
|
||||
/// Sets a uniform value
|
||||
/// </summary>
|
||||
void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix mat, bool transpose);
|
||||
void SetPipelineUniformMatrix(PipelineUniform uniform, ref Matrix4 mat, bool transpose);
|
||||
|
||||
/// <summary>
|
||||
/// sets a uniform value
|
||||
|
@ -193,12 +195,12 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
/// <summary>
|
||||
/// generates a proper 2d othographic projection for the given destination size, suitable for use in a GUI
|
||||
/// </summary>
|
||||
Matrix CreateGuiProjectionMatrix(int w, int h);
|
||||
Matrix4 CreateGuiProjectionMatrix(int w, int h);
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// </summary>
|
||||
Matrix CreateGuiViewMatrix(int w, int h);
|
||||
Matrix4 CreateGuiViewMatrix(int w, int h);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Matrix> stack = new Stack<Matrix>();
|
||||
Stack<Matrix4> stack = new Stack<Matrix4>();
|
||||
|
||||
/// <summary>
|
||||
/// This is made public for performance reasons, to avoid lame copies of the matrix when necessary. Don't mess it up!
|
||||
/// </summary>
|
||||
public Matrix Top;
|
||||
public Matrix4 Top;
|
||||
|
||||
/// <summary>
|
||||
/// Resets the matrix stack to an empty identity matrix stack
|
||||
|
@ -38,40 +41,40 @@ namespace BizHawk.Bizware.BizwareGL
|
|||
/// <summary>
|
||||
/// Clears the matrix stack and loads the specified value
|
||||
/// </summary>
|
||||
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; }
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<BoundingBox>
|
||||
{
|
||||
|
||||
#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<Vector3> 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<float> Intersects(Ray ray)
|
||||
{
|
||||
return ray.Intersects(this);
|
||||
}
|
||||
|
||||
public void Intersects(ref Ray ray, out Nullable<float> 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
|
||||
}
|
||||
}
|
|
@ -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<BoundingFrustum>
|
||||
{
|
||||
#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<float> Intersects(Ray ray)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Intersects(ref Ray ray, out Nullable<float> 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
|
||||
}
|
||||
}
|
|
@ -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<BoundingSphere>
|
||||
{
|
||||
#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<Vector3> 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<float> Intersects(Ray ray)
|
||||
{
|
||||
return ray.Intersects(this);
|
||||
}
|
||||
|
||||
public void Intersects(ref Ray ray, out Nullable<float> 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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -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<Plane>
|
||||
{
|
||||
#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
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Bizware.BizwareGL
|
||||
{
|
||||
internal class PlaneHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a value indicating what side (positive/negative) of a plane a point is
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check with</param>
|
||||
/// <param name="plane">The plane to check against</param>
|
||||
/// <returns>Greater than zero if on the positive side, less than zero if on the negative size, 0 otherwise</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the perpendicular distance from a point to a plane
|
||||
/// </summary>
|
||||
/// <param name="point">The point to check</param>
|
||||
/// <param name="plane">The place to check</param>
|
||||
/// <returns>The perpendicular distance from the point to the plane</returns>
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Point>
|
||||
{
|
||||
#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
|
||||
|
||||
/// <summary>
|
||||
/// Makes new Point with integer accurate
|
||||
/// </summary>
|
||||
/// <param name="x">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
/// <param name="y">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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<Quaternion>
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<Ray>
|
||||
{
|
||||
#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
|
||||
}
|
||||
}
|
|
@ -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<Rectangle>
|
||||
{
|
||||
#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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves Rectangle for both Point values.
|
||||
/// </summary>
|
||||
/// <param name="offset">
|
||||
/// A <see cref="Point"/>
|
||||
/// </param>
|
||||
public void Offset(Point offset)
|
||||
{
|
||||
X += offset.X;
|
||||
Y += offset.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Moves rectangle for both values.
|
||||
/// </summary>
|
||||
/// <param name="offsetX">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
/// <param name="offsetY">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
public void Offset(int offsetX, int offsetY)
|
||||
{
|
||||
X += offsetX;
|
||||
Y += offsetY;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Grows the Rectangle. Down right point is in the same position.
|
||||
/// </summary>
|
||||
/// <param name="horizontalValue">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
/// <param name="verticalValue">
|
||||
/// A <see cref="System.Int32"/>
|
||||
/// </param>
|
||||
public void Inflate(int horizontalValue, int verticalValue)
|
||||
{
|
||||
X -= horizontalValue;
|
||||
Y -= verticalValue;
|
||||
Width += horizontalValue * 2;
|
||||
Height += verticalValue * 2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It checks if two rectangle intersects.
|
||||
/// </summary>
|
||||
/// <param name="rect">
|
||||
/// A <see cref="Rectangle"/>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.Boolean"/>
|
||||
/// </returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if recangles are same
|
||||
/// </summary>
|
||||
/// <param name="obj">
|
||||
/// A <see cref="System.Object"/>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.Boolean"/>
|
||||
/// </returns>
|
||||
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
|
||||
}
|
||||
}
|
|
@ -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
|
||||
// -----------------------
|
||||
|
||||
/// <summary>
|
||||
/// Empty Shared Field
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// An uninitialized Size Structure.
|
||||
/// </remarks>
|
||||
|
||||
public static readonly Size Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Ceiling Shared Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Produces a Size structure from a SizeF structure by
|
||||
/// taking the ceiling of the Width and Height properties.
|
||||
/// </remarks>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Round Shared Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Produces a Size structure from a SizeF structure by
|
||||
/// rounding the Width and Height properties.
|
||||
/// </remarks>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Truncate Shared Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Produces a Size structure from a SizeF structure by
|
||||
/// truncating the Width and Height properties.
|
||||
/// </remarks>
|
||||
|
||||
public static Size Truncate(SizeF value)
|
||||
{
|
||||
int w, h;
|
||||
checked
|
||||
{
|
||||
w = (int)value.Width;
|
||||
h = (int)value.Height;
|
||||
}
|
||||
|
||||
return new Size(w, h);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Addition Operator
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Addition of two Size structures.
|
||||
/// </remarks>
|
||||
|
||||
public static Size operator +(Size sz1, Size sz2)
|
||||
{
|
||||
return new Size(sz1.Width + sz2.Width,
|
||||
sz1.Height + sz2.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equality Operator
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Compares two Size objects. The return value is
|
||||
/// based on the equivalence of the Width and Height
|
||||
/// properties of the two Sizes.
|
||||
/// </remarks>
|
||||
|
||||
public static bool operator ==(Size sz1, Size sz2)
|
||||
{
|
||||
return ((sz1.Width == sz2.Width) &&
|
||||
(sz1.Height == sz2.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Inequality Operator
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Compares two Size objects. The return value is
|
||||
/// based on the equivalence of the Width and Height
|
||||
/// properties of the two Sizes.
|
||||
/// </remarks>
|
||||
|
||||
public static bool operator !=(Size sz1, Size sz2)
|
||||
{
|
||||
return ((sz1.Width != sz2.Width) ||
|
||||
(sz1.Height != sz2.Height));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subtraction Operator
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Subtracts two Size structures.
|
||||
/// </remarks>
|
||||
|
||||
public static Size operator -(Size sz1, Size sz2)
|
||||
{
|
||||
return new Size(sz1.Width - sz2.Width,
|
||||
sz1.Height - sz2.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Size to Point Conversion
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Returns a Point based on the dimensions of a given
|
||||
/// Size. Requires explicit cast.
|
||||
/// </remarks>
|
||||
|
||||
public static explicit operator Point(Size size)
|
||||
{
|
||||
return new Point(size.Width, size.Height);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Size to SizeF Conversion
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Creates a SizeF based on the dimensions of a given
|
||||
/// Size. No explicit cast is required.
|
||||
/// </remarks>
|
||||
|
||||
public static implicit operator SizeF(Size p)
|
||||
{
|
||||
return new SizeF(p.Width, p.Height);
|
||||
}
|
||||
|
||||
|
||||
// -----------------------
|
||||
// Public Constructors
|
||||
// -----------------------
|
||||
|
||||
/// <summary>
|
||||
/// Size Constructor
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Creates a Size from a Point value.
|
||||
/// </remarks>
|
||||
|
||||
public Size(Point pt)
|
||||
{
|
||||
width = pt.X;
|
||||
height = pt.Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Size Constructor
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Creates a Size from specified dimensions.
|
||||
/// </remarks>
|
||||
|
||||
public Size(int width, int height)
|
||||
{
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
// -----------------------
|
||||
// Public Instance Members
|
||||
// -----------------------
|
||||
|
||||
/// <summary>
|
||||
/// IsEmpty Property
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Indicates if both Width and Height are zero.
|
||||
/// </remarks>
|
||||
|
||||
[Browsable(false)]
|
||||
public bool IsEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return ((width == 0) && (height == 0));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width Property
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// The Width coordinate of the Size.
|
||||
/// </remarks>
|
||||
|
||||
public int Width
|
||||
{
|
||||
get
|
||||
{
|
||||
return width;
|
||||
}
|
||||
set
|
||||
{
|
||||
width = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Height Property
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// The Height coordinate of the Size.
|
||||
/// </remarks>
|
||||
|
||||
public int Height
|
||||
{
|
||||
get
|
||||
{
|
||||
return height;
|
||||
}
|
||||
set
|
||||
{
|
||||
height = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Equals Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Checks equivalence of this Size and another object.
|
||||
/// </remarks>
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Size))
|
||||
return false;
|
||||
|
||||
return (this == (Size)obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// GetHashCode Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Calculates a hashing value.
|
||||
/// </remarks>
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return width ^ height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ToString Method
|
||||
/// </summary>
|
||||
///
|
||||
/// <remarks>
|
||||
/// Formats the Size as a string in coordinate notation.
|
||||
/// </remarks>
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
}
|
|
@ -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<Vector2>
|
||||
{
|
||||
#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
|
||||
|
||||
/// <summary>
|
||||
/// Constructor foe standard 2D vector.
|
||||
/// </summary>
|
||||
/// <param name="x">
|
||||
/// A <see cref="System.Single"/>
|
||||
/// </param>
|
||||
/// <param name="y">
|
||||
/// A <see cref="System.Single"/>
|
||||
/// </param>
|
||||
public Vector2(float x, float y)
|
||||
{
|
||||
this.X = x;
|
||||
this.Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor for "square" vector.
|
||||
/// </summary>
|
||||
/// <param name="value">
|
||||
/// A <see cref="System.Single"/>
|
||||
/// </param>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns float precison distanve between two vectors
|
||||
/// </summary>
|
||||
/// <param name="value1">
|
||||
/// A <see cref="Vector2"/>
|
||||
/// </param>
|
||||
/// <param name="value2">
|
||||
/// A <see cref="Vector2"/>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A <see cref="System.Single"/>
|
||||
/// </returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Devide first vector with the secund vector
|
||||
/// </summary>
|
||||
/// <param name="value1">
|
||||
/// A <see cref="Vector2"/>
|
||||
/// </param>
|
||||
/// <param name="value2">
|
||||
/// A <see cref="Vector2"/>
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// A <see cref="Vector2"/>
|
||||
/// </returns>
|
||||
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
|
||||
}
|
||||
}
|
|
@ -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<Vector3>
|
||||
{
|
||||
#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
|
||||
}
|
||||
}
|
|
@ -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<Vector4>
|
||||
{
|
||||
#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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue