+ Implemented Transform methods for Plane structure
+ Added Tests for Plane structure + Implemented quaternion transforms for Vectors
This commit is contained in:
parent
f5b655fec4
commit
f28c1d0f10
@ -17,6 +17,12 @@ using ANXVector3 = ANX.Framework.Vector3;
|
|||||||
using XNAVector4 = Microsoft.Xna.Framework.Vector4;
|
using XNAVector4 = Microsoft.Xna.Framework.Vector4;
|
||||||
using ANXVector4 = ANX.Framework.Vector4;
|
using ANXVector4 = ANX.Framework.Vector4;
|
||||||
|
|
||||||
|
using XNAMatrix = Microsoft.Xna.Framework.Matrix;
|
||||||
|
using ANXMatrix = ANX.Framework.Matrix;
|
||||||
|
|
||||||
|
using XNAQuaternion = Microsoft.Xna.Framework.Quaternion;
|
||||||
|
using ANXQuaternion = ANX.Framework.Quaternion;
|
||||||
|
|
||||||
using XNABoundingBox = Microsoft.Xna.Framework.BoundingBox;
|
using XNABoundingBox = Microsoft.Xna.Framework.BoundingBox;
|
||||||
using ANXBoundingBox = ANX.Framework.BoundingBox;
|
using ANXBoundingBox = ANX.Framework.BoundingBox;
|
||||||
|
|
||||||
@ -34,6 +40,12 @@ namespace ANX.Framework.TestCenter.Strukturen
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
class PlaneTest
|
class PlaneTest
|
||||||
{
|
{
|
||||||
|
static object[] eightfloats =
|
||||||
|
{
|
||||||
|
new object[] { 1, 2, 3, 4, 5, 6, 7, 8 },
|
||||||
|
new object[] { 8, 7, 6, 5, 4, 3, 2, 1 }
|
||||||
|
};
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IntersectsSphere()
|
public void IntersectsSphere()
|
||||||
{
|
{
|
||||||
@ -44,5 +56,251 @@ namespace ANX.Framework.TestCenter.Strukturen
|
|||||||
|
|
||||||
Assert.AreEqual(xna.Intersects(xSphere).ToString(), anx.Intersects(aSphere).ToString());
|
Assert.AreEqual(xna.Intersects(xSphere).ToString(), anx.Intersects(aSphere).ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region Dot
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotVector4(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector4 xnaVector = new XNAVector4(x1, y1, z1, w1);
|
||||||
|
float xnaResult = xnaPlane.Dot(xnaVector);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector4 anxVector = new ANXVector4(x1, y1, z1, w1);
|
||||||
|
float anxResult = anxPlane.Dot(anxVector);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotVector4");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotVector4Ref(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector4 xnaVector = new XNAVector4(x1, y1, z1, w1);
|
||||||
|
float xnaResult;
|
||||||
|
xnaPlane.Dot(ref xnaVector, out xnaResult);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector4 anxVector = new ANXVector4(x1, y1, z1, w1);
|
||||||
|
float anxResult;
|
||||||
|
anxPlane.Dot(ref anxVector, out anxResult);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotVector4Ref");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotCoordinateVector3(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector3 xnaVector = new XNAVector3(x1, y1, z1);
|
||||||
|
float xnaResult = xnaPlane.DotCoordinate(xnaVector);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector3 anxVector = new ANXVector3(x1, y1, z1);
|
||||||
|
float anxResult = anxPlane.DotCoordinate(anxVector);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotCoordinateVector3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotCoordinateVector3Ref(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector3 xnaVector = new XNAVector3(x1, y1, z1);
|
||||||
|
float xnaResult;
|
||||||
|
xnaPlane.DotCoordinate(ref xnaVector, out xnaResult);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector3 anxVector = new ANXVector3(x1, y1, z1);
|
||||||
|
float anxResult;
|
||||||
|
anxPlane.DotCoordinate(ref anxVector, out anxResult);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotCoordinateVector3Ref");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotNormalVector3(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector3 xnaVector = new XNAVector3(x1, y1, z1);
|
||||||
|
float xnaResult = xnaPlane.DotNormal(xnaVector);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector3 anxVector = new ANXVector3(x1, y1, z1);
|
||||||
|
float anxResult = anxPlane.DotNormal(anxVector);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotNormalVector3");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void DotNormalVector3Ref(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAVector3 xnaVector = new XNAVector3(x1, y1, z1);
|
||||||
|
float xnaResult;
|
||||||
|
xnaPlane.DotNormal(ref xnaVector, out xnaResult);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXVector3 anxVector = new ANXVector3(x1, y1, z1);
|
||||||
|
float anxResult;
|
||||||
|
anxPlane.DotNormal(ref anxVector, out anxResult);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "DotNormalVector3Ref");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void GetHashCode(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
int xnaResult = xnaPlane.GetHashCode();
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
int anxResult = anxPlane.GetHashCode();
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "GetHashCode");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void ToString(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaPlane.ToString(), anxPlane.ToString(), "ToString");
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Normalize
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void Normalize(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
xnaPlane.Normalize();
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
anxPlane.Normalize();
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaPlane, anxPlane, "Normalize");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void NormalizePlane(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
xnaPlane = XNAPlane.Normalize(xnaPlane);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
anxPlane = ANXPlane.Normalize(anxPlane);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaPlane, anxPlane, "NormalizePlane");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void NormalizePlaneRef(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xna = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAPlane xnaPlane;
|
||||||
|
XNAPlane.Normalize(ref xna, out xnaPlane);
|
||||||
|
|
||||||
|
ANXPlane anx = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXPlane anxPlane;
|
||||||
|
ANXPlane.Normalize(ref anx, out anxPlane);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaPlane, anxPlane, "NormalizePlaneRef");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Transform
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void TransformMatrix(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAMatrix xnaMatrix = new XNAMatrix(x1, y1, z1, w1, x2, y2, z2, w2, x1, y1, z1, w1, x2, y2, z2, w2);
|
||||||
|
XNAPlane xnaResult = XNAPlane.Transform(xnaPlane, xnaMatrix);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXMatrix anxMatrix = new ANXMatrix(x1, y1, z1, w1, x2, y2, z2, w2, x1, y1, z1, w1, x2, y2, z2, w2);
|
||||||
|
ANXPlane anxResult = ANXPlane.Transform(anxPlane, anxMatrix);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "TransformMatrix");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void TransformMatrixRef(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAMatrix xnaMatrix = new XNAMatrix(x1, y1, z1, w1, x2, y2, z2, w2, x1, y1, z1, w1, x2, y2, z2, w2);
|
||||||
|
XNAPlane xnaResult;
|
||||||
|
XNAPlane.Transform(ref xnaPlane, ref xnaMatrix, out xnaResult);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXMatrix anxMatrix = new ANXMatrix(x1, y1, z1, w1, x2, y2, z2, w2, x1, y1, z1, w1, x2, y2, z2, w2);
|
||||||
|
ANXPlane anxResult;
|
||||||
|
ANXPlane.Transform(ref anxPlane, ref anxMatrix, out anxResult);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "TransformMatrixRef");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void TransformQuaternion(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAQuaternion xnaQuat = new XNAQuaternion(x2, y2, z2, w2);
|
||||||
|
XNAPlane xnaResult = XNAPlane.Transform(xnaPlane, xnaQuat);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXQuaternion anxQuat = new ANXQuaternion(x2, y2, z2, w2);
|
||||||
|
ANXPlane anxResult = ANXPlane.Transform(anxPlane, anxQuat);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "TransformQuaternion");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("eightfloats")]
|
||||||
|
public static void TransformQuaternionRef(
|
||||||
|
float x1, float y1, float z1, float w1,
|
||||||
|
float x2, float y2, float z2, float w2)
|
||||||
|
{
|
||||||
|
XNAPlane xnaPlane = new XNAPlane(x1, y1, z1, w1);
|
||||||
|
XNAQuaternion xnaQuat = new XNAQuaternion(x2, y2, z2, w2);
|
||||||
|
XNAPlane xnaResult;
|
||||||
|
XNAPlane.Transform(ref xnaPlane, ref xnaQuat, out xnaResult);
|
||||||
|
|
||||||
|
ANXPlane anxPlane = new ANXPlane(x1, y1, z1, w1);
|
||||||
|
ANXQuaternion anxQuat = new ANXQuaternion(x2, y2, z2, w2);
|
||||||
|
ANXPlane anxResult;
|
||||||
|
ANXPlane.Transform(ref anxPlane, ref anxQuat, out anxResult);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaResult, anxResult, "TransformQuaternionRef");
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -608,6 +608,21 @@ namespace ANX.Framework.TestCenter.Strukturen
|
|||||||
AssertHelper.ConvertEquals(xnaR, anxR, "EqualsOperator");
|
AssertHelper.ConvertEquals(xnaR, anxR, "EqualsOperator");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EqualsOperatorNaN()
|
||||||
|
{
|
||||||
|
XNAVector2 xna1 = new XNAVector2(float.NaN, float.NaN);
|
||||||
|
XNAVector2 xna2 = new XNAVector2(float.NaN, float.NaN);
|
||||||
|
|
||||||
|
ANXVector2 anx1 = new ANXVector2(float.NaN, float.NaN);
|
||||||
|
ANXVector2 anx2 = new ANXVector2(float.NaN, float.NaN);
|
||||||
|
|
||||||
|
bool xnaR = (xna1 == xna2);
|
||||||
|
bool anxR = (anx1 == anx2);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xnaR, anxR, "EqualsOperator");
|
||||||
|
}
|
||||||
|
|
||||||
[Test, TestCaseSource("ninefloats")]
|
[Test, TestCaseSource("ninefloats")]
|
||||||
public void UnequalsOperator(float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float nop1)
|
public void UnequalsOperator(float x1, float y1, float z1, float w1, float x2, float y2, float z2, float w2, float nop1)
|
||||||
{
|
{
|
||||||
|
@ -689,7 +689,43 @@ namespace ANX.Framework.TestCenter.Strukturen
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Test, TestCaseSource("twentyfourFloats")]
|
[Test, TestCaseSource("twentyfourFloats")]
|
||||||
public void TransformStaticQuaternion(
|
public void TransformStaticQuaternionVector2(
|
||||||
|
float x, float y, float z, float w,
|
||||||
|
float xQ, float yQ, float zQ, float wQ,
|
||||||
|
float nop0, float nop1, float nop2, float nop3, float nop4, float nop5, float nop6, float nop7, float nop8, float nop9, float nop10, float nop11, float nop12, float nop13, float nop14, float nop15)
|
||||||
|
{
|
||||||
|
XNAVector2 xnaVector = new XNAVector2(x, y);
|
||||||
|
XNAQuaternion xnaQuaternion = new XNAQuaternion(xQ, yQ, zQ, wQ);
|
||||||
|
|
||||||
|
ANXVector2 anxVector = new ANXVector2(x, y);
|
||||||
|
ANXQuaternion anxQuaternion = new ANXQuaternion(xQ, yQ, zQ, wQ);
|
||||||
|
|
||||||
|
XNAVector4 xna = XNAVector4.Transform(xnaVector, xnaQuaternion);
|
||||||
|
ANXVector4 anx = ANXVector4.Transform(anxVector, anxQuaternion);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xna, anx, "TransformStaticQuaternion");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("twentyfourFloats")]
|
||||||
|
public void TransformStaticQuaternionVector3(
|
||||||
|
float x, float y, float z, float w,
|
||||||
|
float xQ, float yQ, float zQ, float wQ,
|
||||||
|
float nop0, float nop1, float nop2, float nop3, float nop4, float nop5, float nop6, float nop7, float nop8, float nop9, float nop10, float nop11, float nop12, float nop13, float nop14, float nop15)
|
||||||
|
{
|
||||||
|
XNAVector3 xnaVector = new XNAVector3(x, y, z);
|
||||||
|
XNAQuaternion xnaQuaternion = new XNAQuaternion(xQ, yQ, zQ, wQ);
|
||||||
|
|
||||||
|
ANXVector3 anxVector = new ANXVector3(x, y, z);
|
||||||
|
ANXQuaternion anxQuaternion = new ANXQuaternion(xQ, yQ, zQ, wQ);
|
||||||
|
|
||||||
|
XNAVector4 xna = XNAVector4.Transform(xnaVector, xnaQuaternion);
|
||||||
|
ANXVector4 anx = ANXVector4.Transform(anxVector, anxQuaternion);
|
||||||
|
|
||||||
|
AssertHelper.ConvertEquals(xna, anx, "TransformStaticQuaternion");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test, TestCaseSource("twentyfourFloats")]
|
||||||
|
public void TransformStaticQuaternionVector4(
|
||||||
float x, float y, float z, float w,
|
float x, float y, float z, float w,
|
||||||
float xQ, float yQ, float zQ, float wQ,
|
float xQ, float yQ, float zQ, float wQ,
|
||||||
float nop0, float nop1, float nop2, float nop3, float nop4, float nop5, float nop6, float nop7, float nop8, float nop9, float nop10, float nop11, float nop12, float nop13, float nop14, float nop15)
|
float nop0, float nop1, float nop2, float nop3, float nop4, float nop5, float nop6, float nop7, float nop8, float nop9, float nop10, float nop11, float nop12, float nop13, float nop14, float nop15)
|
||||||
|
@ -53,7 +53,7 @@ namespace ANX.Framework
|
|||||||
result = ContainmentType.Contains;
|
result = ContainmentType.Contains;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result = ContainmentType.Intersects;
|
result = ContainmentType.Intersects;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,17 +312,9 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public void Intersects(ref BoundingBox box, out bool result)
|
public void Intersects(ref BoundingBox box, out bool result)
|
||||||
{
|
{
|
||||||
if ((this.Max.X < box.Min.X || this.Min.X > box.Max.X) ||
|
result = (this.Max.X >= box.Min.X && this.Min.X <= box.Max.X) &&
|
||||||
(this.Max.Y < box.Min.Y || this.Min.Y > box.Max.Y) ||
|
(this.Max.Y >= box.Min.Y && this.Min.Y <= box.Max.Y) &&
|
||||||
(this.Max.Z < box.Min.Z || this.Min.Z > box.Max.Z)
|
(this.Max.Z >= box.Min.Z && this.Min.Z <= box.Max.Z);
|
||||||
)
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Intersects(BoundingFrustum frustum)
|
public bool Intersects(BoundingFrustum frustum)
|
||||||
@ -456,7 +448,7 @@ namespace ANX.Framework
|
|||||||
result = null;
|
result = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
t1 = (this.Min.Z - ray.Position.Z) - ray.Direction.Z;
|
t1 = (this.Min.Z - ray.Position.Z) - ray.Direction.Z;
|
||||||
t2 = (this.Max.Z - ray.Position.Z) - ray.Direction.Z;
|
t2 = (this.Max.Z - ray.Position.Z) - ray.Direction.Z;
|
||||||
|
|
||||||
@ -483,17 +475,11 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{Min:" + Min.ToString() +
|
return "{Min:" + Min.ToString() +
|
||||||
" Max:" + Max.ToString() + "}";
|
" Max:" + Max.ToString() + "}";
|
||||||
|
|
||||||
// return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{{Min:{0} Max:{1}}}", new object[]
|
|
||||||
//{
|
|
||||||
// this.Min.ToString(),
|
|
||||||
// this.Max.ToString()
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
// calculate 2 vectos spanning the plane and cross them to get the normal, then normalize
|
// calculate 2 vectos spanning the plane and cross them to get the normal, then normalize
|
||||||
this.Normal = Vector3.Normalize(Vector3.Cross(Vector3.Subtract(point2, point1), Vector3.Subtract(point3, point1)));
|
this.Normal = Vector3.Normalize(Vector3.Cross(Vector3.Subtract(point2, point1), Vector3.Subtract(point3, point1)));
|
||||||
// now calculate d
|
// now calculate d
|
||||||
this.D = Vector3.Dot(point1, this.Normal);
|
this.D = Vector3.Dot(point1, this.Normal);
|
||||||
}
|
}
|
||||||
public Plane(Vector4 value)
|
public Plane(Vector4 value)
|
||||||
@ -47,21 +47,16 @@ namespace ANX.Framework
|
|||||||
#region public methods
|
#region public methods
|
||||||
public float Dot(Vector4 value)
|
public float Dot(Vector4 value)
|
||||||
{
|
{
|
||||||
float result;
|
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z + this.D * value.W;
|
||||||
this.Dot(ref value, out result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
public void Dot(ref Vector4 value, out float result)
|
public void Dot(ref Vector4 value, out float result)
|
||||||
{
|
{
|
||||||
//taken from vektor
|
|
||||||
result = this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z + this.D * value.W;
|
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)
|
public float DotCoordinate(Vector3 value)
|
||||||
{
|
{
|
||||||
float result;
|
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z + this.D;
|
||||||
this.DotCoordinate(ref value, out result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
public void DotCoordinate(ref Vector3 value, out float result)
|
public void DotCoordinate(ref Vector3 value, out float result)
|
||||||
{
|
{
|
||||||
@ -70,18 +65,16 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public float DotNormal(Vector3 value)
|
public float DotNormal(Vector3 value)
|
||||||
{
|
{
|
||||||
float result;
|
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z;
|
||||||
this.DotNormal(ref value, out result);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
public void DotNormal(ref Vector3 value, out float result)
|
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 ;
|
result = this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return this.D.GetHashCode() + this.Normal.GetHashCode();
|
return this.D.GetHashCode() + this.Normal.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaneIntersectionType Intersects(BoundingBox box)
|
public PlaneIntersectionType Intersects(BoundingBox box)
|
||||||
@ -90,10 +83,38 @@ namespace ANX.Framework
|
|||||||
this.Intersects(ref box, out result);
|
this.Intersects(ref box, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Intersects(ref BoundingBox box, out PlaneIntersectionType result)
|
public void Intersects(ref BoundingBox box, out PlaneIntersectionType result)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
Vector3 p;
|
||||||
|
|
||||||
|
p.X = this.Normal.X >= 0f ? box.Min.X : box.Max.X;
|
||||||
|
p.Y = this.Normal.Y >= 0f ? box.Min.Y : box.Max.X;
|
||||||
|
p.Z = this.Normal.Z >= 0f ? box.Min.Z : box.Max.X;
|
||||||
|
|
||||||
|
float dot = this.Normal.X * p.X + this.Normal.Y * p.Y + this.Normal.Z * p.Z;
|
||||||
|
|
||||||
|
if (dot + this.D > 0f)
|
||||||
|
{
|
||||||
|
result = PlaneIntersectionType.Front;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.X = this.Normal.X >= 0f ? box.Max.X : box.Min.X;
|
||||||
|
p.Y = this.Normal.Y >= 0f ? box.Max.Y : box.Min.X;
|
||||||
|
p.Z = this.Normal.Z >= 0f ? box.Max.Z : box.Min.X;
|
||||||
|
|
||||||
|
dot = this.Normal.X * p.X + this.Normal.Y * p.Y + this.Normal.Z * p.Z;
|
||||||
|
|
||||||
|
if (dot + this.D < 0f)
|
||||||
|
{
|
||||||
|
result = PlaneIntersectionType.Back;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = PlaneIntersectionType.Intersecting;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlaneIntersectionType Intersects(BoundingFrustum frustum)
|
public PlaneIntersectionType Intersects(BoundingFrustum frustum)
|
||||||
{
|
{
|
||||||
PlaneIntersectionType result;
|
PlaneIntersectionType result;
|
||||||
@ -147,7 +168,6 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
||||||
if (distanceSquared_Sphere_Origin > distanceSquared_Plane_Origin)
|
if (distanceSquared_Sphere_Origin > distanceSquared_Plane_Origin)
|
||||||
{
|
{
|
||||||
if (distanceSquared_Sphere_Origin - sphere.Radius < distanceSquared_Plane_Origin)
|
if (distanceSquared_Sphere_Origin - sphere.Radius < distanceSquared_Plane_Origin)
|
||||||
@ -177,55 +197,149 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
//else distance sphere == distance plane
|
//else distance sphere == distance plane
|
||||||
result = PlaneIntersectionType.Intersecting;
|
result = PlaneIntersectionType.Intersecting;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Normalize()
|
public void Normalize()
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
float l = Normal.X * Normal.X + Normal.Y * Normal.Y + Normal.Z * Normal.Z;
|
||||||
|
if (Math.Abs(1.0f - l) < float.Epsilon)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
l = 1.0f / (float)Math.Sqrt(l);
|
||||||
|
Normal.X = Normal.X * l;
|
||||||
|
Normal.Y = Normal.Y * l;
|
||||||
|
Normal.Z = Normal.Z * l;
|
||||||
|
this.D = this.D * l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plane Normalize(Plane value)
|
public static Plane Normalize(Plane value)
|
||||||
{
|
{
|
||||||
|
Vector3 n = value.Normal;
|
||||||
|
float l = n.X * n.X + n.Y * n.Y + n.Z * n.Z;
|
||||||
|
if (Math.Abs(1.0f - l) < float.Epsilon)
|
||||||
|
{
|
||||||
|
return new Plane(n, value.D);
|
||||||
|
}
|
||||||
|
l = 1.0f / (float)Math.Sqrt(l);
|
||||||
Plane result;
|
Plane result;
|
||||||
Plane.Normalize(ref value, out result);
|
result.Normal.X = value.Normal.X * l;
|
||||||
|
result.Normal.Y = value.Normal.Y * l;
|
||||||
|
result.Normal.Z = value.Normal.Z * l;
|
||||||
|
result.D = value.D * l;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Normalize(ref Plane value, out Plane result)
|
public static void Normalize(ref Plane value, out Plane result)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
Vector3 n = value.Normal;
|
||||||
|
float l = n.X * n.X + n.Y * n.Y + n.Z * n.Z;
|
||||||
|
if (Math.Abs(1.0f - l) < float.Epsilon)
|
||||||
|
{
|
||||||
|
result.Normal = n;
|
||||||
|
result.D = value.D;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
l = 1.0f / (float)Math.Sqrt(l);
|
||||||
|
result.Normal.X = value.Normal.X * l;
|
||||||
|
result.Normal.Y = value.Normal.Y * l;
|
||||||
|
result.Normal.Z = value.Normal.Z * l;
|
||||||
|
result.D = value.D * l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{Normal:" + Normal.ToString() +
|
return "{Normal:" + Normal.ToString() +
|
||||||
" D:" + D.ToString(culture) + "}";
|
" D:" + D.ToString(culture) + "}";
|
||||||
|
|
||||||
//return string.Format(culture, "{{Normal:{0} D:{1}}}", new object[]
|
|
||||||
//{
|
|
||||||
// this.Normal.ToString(),
|
|
||||||
// this.D.ToString(culture)
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plane Transform(Plane plane, Matrix matrix)
|
public static Plane Transform(Plane plane, Matrix matrix)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
// multiply by the inverse transpose of the matrix
|
||||||
|
Matrix m;
|
||||||
|
Matrix.Invert(ref matrix, out m);
|
||||||
|
|
||||||
|
Vector3 n = plane.Normal;
|
||||||
|
Plane result;
|
||||||
|
result.Normal.X = n.X * m.M11 + n.Y * m.M12 + n.Z * m.M13 + plane.D * m.M14;
|
||||||
|
result.Normal.Y = n.X * m.M21 + n.Y * m.M22 + n.Z * m.M23 + plane.D * m.M24;
|
||||||
|
result.Normal.Z = n.X * m.M31 + n.Y * m.M32 + n.Z * m.M33 + plane.D * m.M34;
|
||||||
|
result.D = n.X * m.M41 + n.Y * m.M42 + n.Z * m.M43 + plane.D * m.M44;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(ref Plane plane, ref Matrix matrix, out Plane result)
|
public static void Transform(ref Plane plane, ref Matrix matrix, out Plane result)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
// multiply by the inverse transpose of the matrix
|
||||||
|
Matrix m;
|
||||||
|
Matrix.Invert(ref matrix, out m);
|
||||||
|
|
||||||
|
Vector3 n = plane.Normal;
|
||||||
|
result.Normal.X = n.X * m.M11 + n.Y * m.M12 + n.Z * m.M13 + plane.D * m.M14;
|
||||||
|
result.Normal.Y = n.X * m.M21 + n.Y * m.M22 + n.Z * m.M23 + plane.D * m.M24;
|
||||||
|
result.Normal.Z = n.X * m.M31 + n.Y * m.M32 + n.Z * m.M33 + plane.D * m.M34;
|
||||||
|
result.D = n.X * m.M41 + n.Y * m.M42 + n.Z * m.M43 + plane.D * m.M44;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Plane Transform(Plane plane, Quaternion rotation)
|
public static Plane Transform(Plane plane, Quaternion rotation)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
float twoX = rotation.X + rotation.X;
|
||||||
|
float twoY = rotation.Y + rotation.Y;
|
||||||
|
float twoZ = rotation.Z + rotation.Z;
|
||||||
|
|
||||||
|
float twoXX = twoX * rotation.X;
|
||||||
|
float twoXY = twoX * rotation.Y;
|
||||||
|
float twoXZ = twoX * rotation.Z;
|
||||||
|
float twoXW = twoX * rotation.W;
|
||||||
|
|
||||||
|
float twoYY = twoY * rotation.Y;
|
||||||
|
float twoYZ = twoY * rotation.Z;
|
||||||
|
float twoYW = twoY * rotation.W;
|
||||||
|
|
||||||
|
float twoZZ = twoZ * rotation.Z;
|
||||||
|
float twoZW = twoZ * rotation.W;
|
||||||
|
|
||||||
|
float x = plane.Normal.X;
|
||||||
|
float y = plane.Normal.Y;
|
||||||
|
float z = plane.Normal.Z;
|
||||||
|
|
||||||
|
Plane result;
|
||||||
|
result.Normal.X = x * (1.0f - twoYY - twoZZ) + y * (twoXY - twoZW) + z * (twoXZ + twoYW);
|
||||||
|
result.Normal.Y = x * (twoXY + twoZW) + y * (1.0f - twoXX - twoZZ) + z * (twoYZ - twoXW);
|
||||||
|
result.Normal.Z = x * (twoXZ - twoYW) + y * (twoYZ + twoXW) + z * (1.0f - twoXX - twoYY);
|
||||||
|
result.D = plane.D;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result)
|
public static void Transform(ref Plane plane, ref Quaternion rotation, out Plane result)
|
||||||
{
|
{
|
||||||
throw new Exception("method has not yet been implemented");
|
float twoX = rotation.X + rotation.X;
|
||||||
|
float twoY = rotation.Y + rotation.Y;
|
||||||
|
float twoZ = rotation.Z + rotation.Z;
|
||||||
|
|
||||||
|
float twoXX = twoX * rotation.X;
|
||||||
|
float twoXY = twoX * rotation.Y;
|
||||||
|
float twoXZ = twoX * rotation.Z;
|
||||||
|
float twoXW = twoX * rotation.W;
|
||||||
|
|
||||||
|
float twoYY = twoY * rotation.Y;
|
||||||
|
float twoYZ = twoY * rotation.Z;
|
||||||
|
float twoYW = twoY * rotation.W;
|
||||||
|
|
||||||
|
float twoZZ = twoZ * rotation.Z;
|
||||||
|
float twoZW = twoZ * rotation.W;
|
||||||
|
|
||||||
|
float x = plane.Normal.X;
|
||||||
|
float y = plane.Normal.Y;
|
||||||
|
float z = plane.Normal.Z;
|
||||||
|
|
||||||
|
result.Normal.X = x * (1.0f - twoYY - twoZZ) + y * (twoXY - twoZW) + z * (twoXZ + twoYW);
|
||||||
|
result.Normal.Y = x * (twoXY + twoZW) + y * (1.0f - twoXX - twoZZ) + z * (twoYZ - twoXW);
|
||||||
|
result.Normal.Z = x * (twoXZ - twoYW) + y * (twoYZ + twoXW) + z * (1.0f - twoXX - twoYY);
|
||||||
|
result.D = plane.D;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -235,6 +349,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
return (obj is Plane) ? this.Equals((Plane)obj) : false;
|
return (obj is Plane) ? this.Equals((Plane)obj) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Equals(Plane other)
|
public bool Equals(Plane other)
|
||||||
{
|
{
|
||||||
return this.D == other.D && Normal.Equals(other.Normal);
|
return this.D == other.D && Normal.Equals(other.Normal);
|
||||||
@ -247,6 +362,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
return lhs.D.Equals(rhs.D) && lhs.Normal.Equals(rhs.Normal);
|
return lhs.D.Equals(rhs.D) && lhs.Normal.Equals(rhs.Normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(Plane lhs, Plane rhs)
|
public static bool operator !=(Plane lhs, Plane rhs)
|
||||||
{
|
{
|
||||||
return !lhs.D.Equals(rhs.D) || !lhs.Normal.Equals(rhs.Normal);
|
return !lhs.D.Equals(rhs.D) || !lhs.Normal.Equals(rhs.Normal);
|
||||||
|
@ -38,6 +38,7 @@ namespace ANX.Framework
|
|||||||
this.Z = z;
|
this.Z = z;
|
||||||
this.W = w;
|
this.W = w;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Quaternion(Vector3 vectorPart, float scalarPart)
|
public Quaternion(Vector3 vectorPart, float scalarPart)
|
||||||
{
|
{
|
||||||
this.X = vectorPart.X;
|
this.X = vectorPart.X;
|
||||||
@ -51,11 +52,9 @@ namespace ANX.Framework
|
|||||||
#region public methods
|
#region public methods
|
||||||
public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2)
|
public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2)
|
||||||
{
|
{
|
||||||
|
|
||||||
Quaternion result;
|
Quaternion result;
|
||||||
Quaternion.Add(ref quaternion1, ref quaternion2, out result);
|
Quaternion.Add(ref quaternion1, ref quaternion2, out result);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
|
public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
|
||||||
@ -71,7 +70,6 @@ namespace ANX.Framework
|
|||||||
Quaternion result;
|
Quaternion result;
|
||||||
Quaternion.Concatenate(ref value1, ref value2, out result);
|
Quaternion.Concatenate(ref value1, ref value2, out result);
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result)
|
public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result)
|
||||||
@ -81,10 +79,9 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public void Conjugate()
|
public void Conjugate()
|
||||||
{
|
{
|
||||||
this.X = -this.X; //should be =this.X;
|
this.X = -this.X;
|
||||||
this.Y = -this.Y;
|
this.Y = -this.Y;
|
||||||
this.Z = -this.Z;
|
this.Z = -this.Z;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Quaternion Conjugate(Quaternion value)
|
public static Quaternion Conjugate(Quaternion value)
|
||||||
@ -372,11 +369,9 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
|
public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
|
||||||
{
|
{
|
||||||
|
|
||||||
Quaternion result;
|
Quaternion result;
|
||||||
Quaternion.Slerp(ref quaternion1, ref quaternion2, amount, out result);
|
Quaternion.Slerp(ref quaternion1, ref quaternion2, amount, out result);
|
||||||
return result; throw new NotImplementedException();
|
return result; throw new NotImplementedException();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
|
public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
|
||||||
@ -412,22 +407,12 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
return "{X:" + X.ToString(culture) +
|
||||||
// be avoided cause of it's bad performance!
|
" Y:" + Y.ToString(culture) +
|
||||||
return "{X:" + X.ToString(culture) +
|
" Z:" + Z.ToString(culture) +
|
||||||
" Y:" + Y.ToString(culture) +
|
" W:" + W.ToString(culture) + "}";
|
||||||
" Z:" + Z.ToString(culture) +
|
|
||||||
" W:" + W.ToString(culture) + "}";
|
|
||||||
|
|
||||||
//return string.Format(culture, "{{X:{0} Y:{1} Z:{2} W:{3}}}", new object[]
|
|
||||||
//{
|
|
||||||
// this.X.ToString(culture),
|
|
||||||
// this.Y.ToString(culture),
|
|
||||||
// this.Z.ToString(culture),
|
|
||||||
// this.W.ToString(culture)
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -172,17 +172,10 @@ namespace ANX.Framework
|
|||||||
/// </returns>
|
/// </returns>
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{Position:" + Position.ToString() +
|
return "{Position:" + Position.ToString() +
|
||||||
" Direction:" + Direction.ToString() + "}";
|
" Direction:" + Direction.ToString() + "}";
|
||||||
|
|
||||||
//var currentCulture = System.Globalization.CultureInfo.CurrentCulture;
|
|
||||||
//return string.Format(currentCulture, "{{Position:{0} Direction:{1}}}", new object[]
|
|
||||||
//{
|
|
||||||
// this.Position.ToString(),
|
|
||||||
// this.Direction.ToString()
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
@ -11,9 +11,9 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
#region fields
|
#region fields
|
||||||
public int X;
|
public int X;
|
||||||
public int Y;
|
public int Y;
|
||||||
public int Width;
|
public int Width;
|
||||||
public int Height;
|
public int Height;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region properties
|
#region properties
|
||||||
@ -57,13 +57,13 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Left
|
public int Left
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return this.X;
|
return this.X;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Right
|
public int Right
|
||||||
{
|
{
|
||||||
@ -81,13 +81,13 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Bottom
|
public int Bottom
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return this.Y + Height;
|
return this.Y + Height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region constructors
|
#region constructors
|
||||||
@ -123,9 +123,9 @@ namespace ANX.Framework
|
|||||||
private void Contains(ref int x, ref int y, out bool result)
|
private void Contains(ref int x, ref int y, out bool result)
|
||||||
{
|
{
|
||||||
result = x > this.X &&
|
result = x > this.X &&
|
||||||
x < this.Right &&
|
x < this.Right &&
|
||||||
y > this.Y &&
|
y > this.Y &&
|
||||||
y < this.Bottom;
|
y < this.Bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains(Rectangle value)
|
public bool Contains(Rectangle value)
|
||||||
@ -148,15 +148,12 @@ namespace ANX.Framework
|
|||||||
return this.X + this.Y + this.Width + this.Height;
|
return this.X + this.Y + this.Width + this.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Inflate(int horizontalAmount, int verticalAmount)
|
public void Inflate(int horizontalAmount, int verticalAmount)
|
||||||
{
|
{
|
||||||
this.X -= horizontalAmount;
|
this.X -= horizontalAmount;
|
||||||
this.Y -= verticalAmount;
|
this.Y -= verticalAmount;
|
||||||
this.Width += horizontalAmount * 2;
|
this.Width += horizontalAmount * 2;
|
||||||
this.Height += verticalAmount * 2;
|
this.Height += verticalAmount * 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Intersects(Rectangle value)
|
public bool Intersects(Rectangle value)
|
||||||
@ -172,9 +169,9 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
//outer
|
//outer
|
||||||
if (value.X > this.Right ||
|
if (value.X > this.Right ||
|
||||||
value.Y > this.Bottom ||
|
value.Y > this.Bottom ||
|
||||||
value.X + value.Width < this.X ||
|
value.X + value.Width < this.X ||
|
||||||
value.Y + value.Height < this.Y)
|
value.Y + value.Height < this.Y)
|
||||||
{
|
{
|
||||||
result = false;
|
result = false;
|
||||||
return;
|
return;
|
||||||
@ -186,7 +183,6 @@ namespace ANX.Framework
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result = true;
|
result = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Offset(int offsetX, int offsetY)
|
public void Offset(int offsetX, int offsetY)
|
||||||
@ -203,22 +199,14 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{X:" + X.ToString(culture) +
|
return "{X:" + X.ToString(culture) +
|
||||||
" Y:" + Y.ToString(culture) +
|
" Y:" + Y.ToString(culture) +
|
||||||
" Width:" + Width.ToString(culture) +
|
" Width:" + Width.ToString(culture) +
|
||||||
" Height:" + Height.ToString(culture) + "}";
|
" Height:" + Height.ToString(culture) + "}";
|
||||||
|
|
||||||
//return string.Format(culture, "{{X:{0} Y:{1} Width:{2} Height:{3}}}", new object[]
|
|
||||||
//{
|
|
||||||
// this.X.ToString(culture),
|
|
||||||
// this.Y.ToString(culture),
|
|
||||||
// this.Width.ToString(culture),
|
|
||||||
// this.Height.ToString(culture)
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -370,20 +358,20 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
#region operator overloading
|
#region operator overloading
|
||||||
public static bool operator ==(Rectangle a, Rectangle b)
|
public static bool operator ==(Rectangle a, Rectangle b)
|
||||||
{
|
{
|
||||||
// NOTE: Duplicated code is better than copying 4 floats around!
|
// NOTE: Duplicated code is better than copying 4 floats around!
|
||||||
return a.Height == b.Height &&
|
return a.Height == b.Height &&
|
||||||
a.Width == b.Width &&
|
a.Width == b.Width &&
|
||||||
a.X == b.X &&
|
a.X == b.X &&
|
||||||
a.Y == b.Y;
|
a.Y == b.Y;
|
||||||
}
|
}
|
||||||
public static bool operator !=(Rectangle a, Rectangle b)
|
public static bool operator !=(Rectangle a, Rectangle b)
|
||||||
{
|
{
|
||||||
// NOTE: Duplicated code is better than copying 4 floats around!
|
// NOTE: Duplicated code is better than copying 4 floats around!
|
||||||
return a.Height != b.Height ||
|
return a.Height != b.Height ||
|
||||||
a.Width != b.Width ||
|
a.Width != b.Width ||
|
||||||
a.X != b.X ||
|
a.X != b.X ||
|
||||||
a.Y != b.Y;
|
a.Y != b.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Vector2(1f, 1f);
|
return new Vector2(1f, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -36,7 +36,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Vector2(0f, 0f);
|
return new Vector2(0f, 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -49,7 +49,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Vector2(1f, 0f);
|
return new Vector2(1f, 0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -62,7 +62,7 @@ namespace ANX.Framework
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Vector2(0f, 1f);
|
return new Vector2(0f, 1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -83,8 +83,8 @@ namespace ANX.Framework
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region public methods
|
#region public methods
|
||||||
#region Add
|
#region Add
|
||||||
public static Vector2 Add(Vector2 value1, Vector2 value2)
|
public static Vector2 Add(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Add(ref value1, ref value2, out result);
|
Vector2.Add(ref value1, ref value2, out result);
|
||||||
@ -92,55 +92,49 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(ref Vector2 value1, ref Vector2 value2,
|
public static void Add(ref Vector2 value1, ref Vector2 value2,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X + value2.X;
|
result.X = value1.X + value2.X;
|
||||||
result.Y = value1.Y + value2.Y;
|
result.Y = value1.Y + value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Barycentric
|
#region Barycentric
|
||||||
public static Vector2 Barycentric(Vector2 value1, Vector2 value2,
|
public static Vector2 Barycentric(Vector2 value1, Vector2 value2,
|
||||||
Vector2 value3, float amount1, float amount2)
|
Vector2 value3, float amount1, float amount2)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Barycentric(ref value1, ref value2, ref value3, amount1,
|
Vector2.Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result);
|
||||||
amount2, out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Barycentric(ref Vector2 value1, ref Vector2 value2,
|
public static void Barycentric(ref Vector2 value1, ref Vector2 value2,
|
||||||
ref Vector2 value3, float amount1, float amount2, out Vector2 result)
|
ref Vector2 value3, float amount1, float amount2, out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X,
|
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||||
amount1, amount2);
|
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y,
|
}
|
||||||
amount1, amount2);
|
#endregion
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region CatmullRom
|
#region CatmullRom
|
||||||
public static Vector2 CatmullRom(Vector2 value1, Vector2 value2,
|
public static Vector2 CatmullRom(Vector2 value1, Vector2 value2,
|
||||||
Vector2 value3, Vector2 value4, float amount)
|
Vector2 value3, Vector2 value4, float amount)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.CatmullRom(ref value1, ref value2, ref value3, ref value4,
|
Vector2.CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
|
||||||
amount, out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CatmullRom(ref Vector2 value1, ref Vector2 value2,
|
public static void CatmullRom(ref Vector2 value1, ref Vector2 value2,
|
||||||
ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
|
ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X,
|
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||||
value4.X, amount);
|
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y,
|
}
|
||||||
value4.Y, amount);
|
#endregion
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Clamp
|
#region Clamp
|
||||||
public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
|
public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Clamp(ref value1, ref min, ref max, out result);
|
Vector2.Clamp(ref value1, ref min, ref max, out result);
|
||||||
@ -148,15 +142,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Clamp(ref Vector2 value1, ref Vector2 min,
|
public static void Clamp(ref Vector2 value1, ref Vector2 min,
|
||||||
ref Vector2 max, out Vector2 result)
|
ref Vector2 max, out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
||||||
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Distance
|
#region Distance
|
||||||
public static float Distance(Vector2 value1, Vector2 value2)
|
public static float Distance(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
float result;
|
float result;
|
||||||
Vector2.Distance(ref value1, ref value2, out result);
|
Vector2.Distance(ref value1, ref value2, out result);
|
||||||
@ -164,16 +158,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Distance(ref Vector2 value1, ref Vector2 value2,
|
public static void Distance(ref Vector2 value1, ref Vector2 value2,
|
||||||
out float result)
|
out float result)
|
||||||
{
|
{
|
||||||
Vector2 tmp;
|
Vector2 tmp;
|
||||||
Vector2.Subtract(ref value1, ref value2, out tmp);
|
Vector2.Subtract(ref value1, ref value2, out tmp);
|
||||||
result = tmp.Length();
|
result = tmp.Length();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DistanceSquared
|
#region DistanceSquared
|
||||||
public static float DistanceSquared(Vector2 value1, Vector2 value2)
|
public static float DistanceSquared(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
float result;
|
float result;
|
||||||
Vector2.DistanceSquared(ref value1, ref value2, out result);
|
Vector2.DistanceSquared(ref value1, ref value2, out result);
|
||||||
@ -181,16 +175,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void DistanceSquared(ref Vector2 value1,
|
public static void DistanceSquared(ref Vector2 value1,
|
||||||
ref Vector2 value2, out float result)
|
ref Vector2 value2, out float result)
|
||||||
{
|
{
|
||||||
Vector2 tmp;
|
Vector2 tmp;
|
||||||
Vector2.Subtract(ref value1, ref value2, out tmp);
|
Vector2.Subtract(ref value1, ref value2, out tmp);
|
||||||
result = tmp.LengthSquared();
|
result = tmp.LengthSquared();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Divide
|
#region Divide
|
||||||
public static Vector2 Divide(Vector2 value1, float divider)
|
public static Vector2 Divide(Vector2 value1, float divider)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Divide(ref value1, divider, out result);
|
Vector2.Divide(ref value1, divider, out result);
|
||||||
@ -198,7 +192,7 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(ref Vector2 value1, float divider,
|
public static void Divide(ref Vector2 value1, float divider,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
divider = 1f / divider;
|
divider = 1f / divider;
|
||||||
result.X = value1.X * divider;
|
result.X = value1.X * divider;
|
||||||
@ -213,70 +207,70 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(ref Vector2 value1, ref Vector2 value2,
|
public static void Divide(ref Vector2 value1, ref Vector2 value2,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X / value2.X;
|
result.X = value1.X / value2.X;
|
||||||
result.Y = value1.Y / value2.Y;
|
result.Y = value1.Y / value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Dot
|
#region Dot
|
||||||
public static float Dot(Vector2 value1, Vector2 value2)
|
public static float Dot(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
return value1.X * value2.X + value1.Y * value2.Y;
|
return value1.X * value2.X + value1.Y * value2.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Dot(ref Vector2 value1, ref Vector2 value2,
|
public static void Dot(ref Vector2 value1, ref Vector2 value2,
|
||||||
out float result)
|
out float result)
|
||||||
{
|
{
|
||||||
result = value1.X * value2.X + value1.Y * value2.Y;
|
result = value1.X * value2.X + value1.Y * value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetHashCode
|
#region GetHashCode
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return this.X.GetHashCode() + this.Y.GetHashCode();
|
return this.X.GetHashCode() + this.Y.GetHashCode();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Hermite
|
#region Hermite
|
||||||
public static Vector2 Hermite(Vector2 value1, Vector2 tangent1,
|
public static Vector2 Hermite(Vector2 value1, Vector2 tangent1,
|
||||||
Vector2 value2, Vector2 tangent2, float amount)
|
Vector2 value2, Vector2 tangent2, float amount)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Hermite(ref value1, ref tangent1, ref value2, ref tangent2,
|
Vector2.Hermite(ref value1, ref tangent1, ref value2, ref tangent2,
|
||||||
amount, out result);
|
amount, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Hermite(ref Vector2 value1, ref Vector2 tangent1,
|
public static void Hermite(ref Vector2 value1, ref Vector2 tangent1,
|
||||||
ref Vector2 value2, ref Vector2 tangent2, float amount,
|
ref Vector2 value2, ref Vector2 tangent2, float amount,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X,
|
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X,
|
||||||
tangent2.X, amount);
|
tangent2.X, amount);
|
||||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y,
|
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y,
|
||||||
tangent2.Y, amount);
|
tangent2.Y, amount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Length
|
#region Length
|
||||||
public float Length()
|
public float Length()
|
||||||
{
|
{
|
||||||
return (float)Math.Sqrt((this.X * this.X) + (this.Y * this.Y));
|
return (float)Math.Sqrt((this.X * this.X) + (this.Y * this.Y));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region LengthSquared
|
#region LengthSquared
|
||||||
public float LengthSquared()
|
public float LengthSquared()
|
||||||
{
|
{
|
||||||
return (this.X * this.X) + (this.Y * this.Y);
|
return (this.X * this.X) + (this.Y * this.Y);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Lerp
|
#region Lerp
|
||||||
public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
|
public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Lerp(ref value1, ref value2, amount, out result);
|
Vector2.Lerp(ref value1, ref value2, amount, out result);
|
||||||
@ -284,15 +278,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Lerp(ref Vector2 value1, ref Vector2 value2,
|
public static void Lerp(ref Vector2 value1, ref Vector2 value2,
|
||||||
float amount, out Vector2 result)
|
float amount, out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X + (value2.X - value1.X) * amount;
|
result.X = value1.X + (value2.X - value1.X) * amount;
|
||||||
result.Y = value1.Y + (value2.Y - value1.Y) * amount;
|
result.Y = value1.Y + (value2.Y - value1.Y) * amount;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Max
|
#region Max
|
||||||
public static Vector2 Max(Vector2 value1, Vector2 value2)
|
public static Vector2 Max(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Max(ref value1, ref value2, out result);
|
Vector2.Max(ref value1, ref value2, out result);
|
||||||
@ -300,15 +294,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Max(ref Vector2 value1, ref Vector2 value2,
|
public static void Max(ref Vector2 value1, ref Vector2 value2,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = (value1.X > value2.X) ? value1.X : value2.X;
|
result.X = (value1.X > value2.X) ? value1.X : value2.X;
|
||||||
result.Y = (value1.Y > value2.Y) ? value1.Y : value2.Y;
|
result.Y = (value1.Y > value2.Y) ? value1.Y : value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Min
|
#region Min
|
||||||
public static Vector2 Min(Vector2 value1, Vector2 value2)
|
public static Vector2 Min(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Min(ref value1, ref value2, out result);
|
Vector2.Min(ref value1, ref value2, out result);
|
||||||
@ -316,15 +310,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Min(ref Vector2 value1, ref Vector2 value2,
|
public static void Min(ref Vector2 value1, ref Vector2 value2,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = (value1.X < value2.X) ? value1.X : value2.X;
|
result.X = (value1.X < value2.X) ? value1.X : value2.X;
|
||||||
result.Y = (value1.Y < value2.Y) ? value1.Y : value2.Y;
|
result.Y = (value1.Y < value2.Y) ? value1.Y : value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Multiply
|
#region Multiply
|
||||||
public static Vector2 Multiply(Vector2 value1, float scaleFactor)
|
public static Vector2 Multiply(Vector2 value1, float scaleFactor)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Multiply(ref value1, scaleFactor, out result);
|
Vector2.Multiply(ref value1, scaleFactor, out result);
|
||||||
@ -332,7 +326,7 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(ref Vector2 value1, float scaleFactor,
|
public static void Multiply(ref Vector2 value1, float scaleFactor,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X * scaleFactor;
|
result.X = value1.X * scaleFactor;
|
||||||
result.Y = value1.Y * scaleFactor;
|
result.Y = value1.Y * scaleFactor;
|
||||||
@ -346,30 +340,30 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(ref Vector2 value1, ref Vector2 value2,
|
public static void Multiply(ref Vector2 value1, ref Vector2 value2,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X * value2.X;
|
result.X = value1.X * value2.X;
|
||||||
result.Y = value1.Y * value2.Y;
|
result.Y = value1.Y * value2.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Negate
|
#region Negate
|
||||||
public static Vector2 Negate(Vector2 value)
|
public static Vector2 Negate(Vector2 value)
|
||||||
{
|
{
|
||||||
// Is a bit faster than copying the vector floats to the operator method.
|
// Is a bit faster than copying the vector floats to the operator method.
|
||||||
return new Vector2(-value.X, -value.Y);
|
return new Vector2(-value.X, -value.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Negate(ref Vector2 value, out Vector2 result)
|
public static void Negate(ref Vector2 value, out Vector2 result)
|
||||||
{
|
{
|
||||||
// Is a bit faster than copying the vector floats to the operator method.
|
// Is a bit faster than copying the vector floats to the operator method.
|
||||||
result.X = -value.X;
|
result.X = -value.X;
|
||||||
result.Y = -value.Y;
|
result.Y = -value.Y;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Normalize
|
#region Normalize
|
||||||
public void Normalize()
|
public void Normalize()
|
||||||
{
|
{
|
||||||
float divider = 1f / this.Length();
|
float divider = 1f / this.Length();
|
||||||
this.X *= divider;
|
this.X *= divider;
|
||||||
@ -387,33 +381,32 @@ namespace ANX.Framework
|
|||||||
float divider = 1f / value.Length();
|
float divider = 1f / value.Length();
|
||||||
result.X = value.X * divider;
|
result.X = value.X * divider;
|
||||||
result.Y = value.Y * divider;
|
result.Y = value.Y * divider;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Vect2 = Vect1 - 2 * WallN * (WallN DOT Vect1)
|
Vect2 = Vect1 - 2 * WallN * (WallN DOT Vect1)
|
||||||
Formula from : http://www.gamedev.net/topic/165537-2d-vector-reflection-/
|
Formula from : http://www.gamedev.net/topic/165537-2d-vector-reflection-/
|
||||||
*/
|
*/
|
||||||
#region Reflect
|
#region Reflect
|
||||||
public static Vector2 Reflect(Vector2 vector, Vector2 normal)
|
public static Vector2 Reflect(Vector2 vector, Vector2 normal)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Reflect(ref vector, ref normal, out result);
|
Vector2.Reflect(ref vector, ref normal, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Reflect(ref Vector2 vector, ref Vector2 normal,
|
public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
|
||||||
out Vector2 result)
|
|
||||||
{
|
{
|
||||||
float sub = 2 * Vector2.Dot(vector, normal);
|
float sub = 2 * Vector2.Dot(vector, normal);
|
||||||
result.X = vector.X - (sub * normal.X);
|
result.X = vector.X - (sub * normal.X);
|
||||||
result.Y = vector.Y - (sub * normal.Y);
|
result.Y = vector.Y - (sub * normal.Y);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SmoothStep
|
#region SmoothStep
|
||||||
public static Vector2 SmoothStep(Vector2 value1, Vector2 value2,
|
public static Vector2 SmoothStep(Vector2 value1, Vector2 value2,
|
||||||
float amount)
|
float amount)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.SmoothStep(ref value1, ref value2, amount, out result);
|
Vector2.SmoothStep(ref value1, ref value2, amount, out result);
|
||||||
@ -421,48 +414,40 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void SmoothStep(ref Vector2 value1, ref Vector2 value2,
|
public static void SmoothStep(ref Vector2 value1, ref Vector2 value2,
|
||||||
float amount, out Vector2 result)
|
float amount, out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
||||||
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Subtract
|
#region Subtract
|
||||||
public static Vector2 Subtract(Vector2 value1, Vector2 value2)
|
public static Vector2 Subtract(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Vector2.Subtract(ref value1, ref value2, out result);
|
Vector2.Subtract(ref value1, ref value2, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(ref Vector2 value1, ref Vector2 value2,
|
public static void Subtract(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
|
||||||
out Vector2 result)
|
{
|
||||||
{
|
result.X = value1.X - value2.X;
|
||||||
result.X = value1.X - value2.X;
|
result.Y = value1.Y - value2.Y;
|
||||||
result.Y = value1.Y - value2.Y;
|
}
|
||||||
}
|
#endregion
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ToString
|
#region ToString
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{X:" + X.ToString(culture) +
|
return "{X:" + X.ToString(culture) + " Y:" + Y.ToString(culture) + "}";
|
||||||
" Y:" + Y.ToString(culture) + "}";
|
}
|
||||||
|
#endregion
|
||||||
|
|
||||||
//return string.Format(culture, "{{X:{0} Y:{1}}}", new object[]
|
#region Transform
|
||||||
//{
|
public static Vector2 Transform(Vector2 position, Matrix matrix)
|
||||||
// this.X.ToString(culture),
|
|
||||||
// this.Y.ToString(culture)
|
|
||||||
//});
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region Transform
|
|
||||||
public static Vector2 Transform(Vector2 position, Matrix matrix)
|
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
Transform(ref position, ref matrix, out result);
|
Transform(ref position, ref matrix, out result);
|
||||||
@ -470,12 +455,10 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(ref Vector2 position, ref Matrix matrix,
|
public static void Transform(ref Vector2 position, ref Matrix matrix,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = (position.X * matrix.M11) + (position.Y * matrix.M21) +
|
result.X = (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41;
|
||||||
matrix.M41;
|
result.Y = (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42;
|
||||||
result.Y = (position.X * matrix.M12) + (position.Y * matrix.M22) +
|
|
||||||
matrix.M42;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 Transform(Vector2 value, Quaternion rotation)
|
public static Vector2 Transform(Vector2 value, Quaternion rotation)
|
||||||
@ -486,7 +469,7 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(ref Vector2 value, ref Quaternion rotation,
|
public static void Transform(ref Vector2 value, ref Quaternion rotation,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
float x = 2 * (-rotation.Z * value.Y);
|
float x = 2 * (-rotation.Z * value.Y);
|
||||||
float y = 2 * (rotation.Z * value.X);
|
float y = 2 * (rotation.Z * value.X);
|
||||||
@ -497,50 +480,50 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector2[] sourceArray, int sourceIndex,
|
public static void Transform(Vector2[] sourceArray, int sourceIndex,
|
||||||
ref Matrix matrix, Vector2[] destinationArray, int destinationIndex,
|
ref Matrix matrix, Vector2[] destinationArray, int destinationIndex,
|
||||||
int length)
|
int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
{
|
{
|
||||||
Transform(ref sourceArray[i], ref matrix,
|
Transform(ref sourceArray[i], ref matrix,
|
||||||
out destinationArray[destinationIndex]);
|
out destinationArray[destinationIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector2[] sourceArray, int sourceIndex,
|
public static void Transform(Vector2[] sourceArray, int sourceIndex,
|
||||||
ref Quaternion rotation, Vector2[] destinationArray,
|
ref Quaternion rotation, Vector2[] destinationArray,
|
||||||
int destinationIndex, int length)
|
int destinationIndex, int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
{
|
{
|
||||||
Transform(ref sourceArray[i], ref rotation,
|
Transform(ref sourceArray[i], ref rotation,
|
||||||
out destinationArray[destinationIndex]);
|
out destinationArray[destinationIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector2[] sourceArray, ref Matrix matrix,
|
public static void Transform(Vector2[] sourceArray, ref Matrix matrix,
|
||||||
Vector2[] destinationArray)
|
Vector2[] destinationArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sourceArray.Length; i++)
|
for (int i = 0; i < sourceArray.Length; i++)
|
||||||
{
|
{
|
||||||
Transform(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
Transform(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector2[] sourceArray, ref Quaternion rotation,
|
public static void Transform(Vector2[] sourceArray, ref Quaternion rotation,
|
||||||
Vector2[] destinationArray)
|
Vector2[] destinationArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sourceArray.Length; i++)
|
for (int i = 0; i < sourceArray.Length; i++)
|
||||||
{
|
{
|
||||||
Transform(ref sourceArray[i], ref rotation, out destinationArray[i]);
|
Transform(ref sourceArray[i], ref rotation, out destinationArray[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region TransformNormal
|
#region TransformNormal
|
||||||
public static Vector2 TransformNormal(Vector2 normal, Matrix matrix)
|
public static Vector2 TransformNormal(Vector2 normal, Matrix matrix)
|
||||||
{
|
{
|
||||||
Vector2 result;
|
Vector2 result;
|
||||||
TransformNormal(ref normal, ref matrix, out result);
|
TransformNormal(ref normal, ref matrix, out result);
|
||||||
@ -548,34 +531,34 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformNormal(ref Vector2 normal, ref Matrix matrix,
|
public static void TransformNormal(ref Vector2 normal, ref Matrix matrix,
|
||||||
out Vector2 result)
|
out Vector2 result)
|
||||||
{
|
{
|
||||||
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||||
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformNormal(Vector2[] sourceArray,
|
public static void TransformNormal(Vector2[] sourceArray,
|
||||||
int sourceIndex, ref Matrix matrix, Vector2[] destinationArray,
|
int sourceIndex, ref Matrix matrix, Vector2[] destinationArray,
|
||||||
int destinationIndex, int length)
|
int destinationIndex, int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
{
|
{
|
||||||
TransformNormal(ref sourceArray[i], ref matrix,
|
TransformNormal(ref sourceArray[i], ref matrix,
|
||||||
out destinationArray[destinationIndex]);
|
out destinationArray[destinationIndex]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformNormal(Vector2[] sourceArray,
|
public static void TransformNormal(Vector2[] sourceArray,
|
||||||
ref Matrix matrix, Vector2[] destinationArray)
|
ref Matrix matrix, Vector2[] destinationArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sourceArray.Length; i++)
|
for (int i = 0; i < sourceArray.Length; i++)
|
||||||
{
|
{
|
||||||
TransformNormal(ref sourceArray[i], ref matrix,
|
TransformNormal(ref sourceArray[i], ref matrix,
|
||||||
out destinationArray[i]);
|
out destinationArray[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IEquatable implementation
|
#region IEquatable implementation
|
||||||
@ -607,13 +590,11 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static bool operator ==(Vector2 value1, Vector2 value2)
|
public static bool operator ==(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
return value1.X.Equals(value2.X) &&
|
return (value1.X == value2.X) && (value1.Y == value2.Y);
|
||||||
value1.Y.Equals(value2.Y);
|
|
||||||
}
|
}
|
||||||
public static bool operator !=(Vector2 value1, Vector2 value2)
|
public static bool operator !=(Vector2 value1, Vector2 value2)
|
||||||
{
|
{
|
||||||
return value1.X.Equals(value2.X) == false ||
|
return (value1.X != value2.X) || (value1.Y != value2.Y);
|
||||||
value1.Y.Equals(value2.Y) == false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 operator *(float scaleFactor, Vector2 value)
|
public static Vector2 operator *(float scaleFactor, Vector2 value)
|
||||||
|
@ -155,25 +155,24 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
#region Public Static Methods
|
#region Public Static Methods
|
||||||
|
|
||||||
#region Add
|
#region Add
|
||||||
public static Vector3 Add(Vector3 value1, Vector3 value2)
|
public static Vector3 Add(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Add(ref value1, ref value2, out result);
|
Add(ref value1, ref value2, out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Add(ref Vector3 value1, ref Vector3 value2,
|
public static void Add(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
|
||||||
out Vector3 result)
|
|
||||||
{
|
{
|
||||||
result.X = value1.X + value2.X;
|
result.X = value1.X + value2.X;
|
||||||
result.Y = value1.Y + value2.Y;
|
result.Y = value1.Y + value2.Y;
|
||||||
result.Z = value1.Z + value2.Z;
|
result.Z = value1.Z + value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Subtract
|
#region Subtract
|
||||||
public static Vector3 Subtract(Vector3 value1, Vector3 value2)
|
public static Vector3 Subtract(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Subtract(ref value1, ref value2, out result);
|
Subtract(ref value1, ref value2, out result);
|
||||||
@ -181,16 +180,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Subtract(ref Vector3 value1, ref Vector3 value2,
|
public static void Subtract(ref Vector3 value1, ref Vector3 value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X - value2.X;
|
result.X = value1.X - value2.X;
|
||||||
result.Y = value1.Y - value2.Y;
|
result.Y = value1.Y - value2.Y;
|
||||||
result.Z = value1.Z - value2.Z;
|
result.Z = value1.Z - value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Multiply
|
#region Multiply
|
||||||
public static Vector3 Multiply(Vector3 value1, float scaleFactor)
|
public static Vector3 Multiply(Vector3 value1, float scaleFactor)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Multiply(ref value1, scaleFactor, out result);
|
Multiply(ref value1, scaleFactor, out result);
|
||||||
@ -198,12 +197,12 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(ref Vector3 value1, float scaleFactor,
|
public static void Multiply(ref Vector3 value1, float scaleFactor,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X * scaleFactor;
|
result.X = value1.X * scaleFactor;
|
||||||
result.Y = value1.Y * scaleFactor;
|
result.Y = value1.Y * scaleFactor;
|
||||||
result.Z = value1.Z * scaleFactor;
|
result.Z = value1.Z * scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 Multiply(Vector3 value1, Vector3 value2)
|
public static Vector3 Multiply(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
@ -213,16 +212,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Multiply(ref Vector3 value1, ref Vector3 value2,
|
public static void Multiply(ref Vector3 value1, ref Vector3 value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X * value2.X;
|
result.X = value1.X * value2.X;
|
||||||
result.Y = value1.Y * value2.Y;
|
result.Y = value1.Y * value2.Y;
|
||||||
result.Z = value1.Z * value2.Z;
|
result.Z = value1.Z * value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Divide
|
#region Divide
|
||||||
public static Vector3 Divide(Vector3 value1, float value2)
|
public static Vector3 Divide(Vector3 value1, float value2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Divide(ref value1, value2, out result);
|
Divide(ref value1, value2, out result);
|
||||||
@ -230,7 +229,7 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(ref Vector3 value1, float value2,
|
public static void Divide(ref Vector3 value1, float value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
float factor = 1f / value2;
|
float factor = 1f / value2;
|
||||||
result.X = value1.X * factor;
|
result.X = value1.X * factor;
|
||||||
@ -246,16 +245,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Divide(ref Vector3 value1, ref Vector3 value2,
|
public static void Divide(ref Vector3 value1, ref Vector3 value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X / value2.X;
|
result.X = value1.X / value2.X;
|
||||||
result.Y = value1.Y / value2.Y;
|
result.Y = value1.Y / value2.Y;
|
||||||
result.Z = value1.Z / value2.Z;
|
result.Z = value1.Z / value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Dot
|
#region Dot
|
||||||
public static float Dot(Vector3 vector1, Vector3 vector2)
|
public static float Dot(Vector3 vector1, Vector3 vector2)
|
||||||
{
|
{
|
||||||
float result;
|
float result;
|
||||||
Dot(ref vector1, ref vector2, out result);
|
Dot(ref vector1, ref vector2, out result);
|
||||||
@ -263,15 +262,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Dot(ref Vector3 vector1, ref Vector3 vector2,
|
public static void Dot(ref Vector3 vector1, ref Vector3 vector2,
|
||||||
out float result)
|
out float result)
|
||||||
{
|
{
|
||||||
result = vector1.X * vector2.X + vector1.Y * vector2.Y +
|
result = vector1.X * vector2.X + vector1.Y * vector2.Y +
|
||||||
vector1.Z * vector2.Z;
|
vector1.Z * vector2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Cross
|
#region Cross
|
||||||
public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
|
public static Vector3 Cross(Vector3 vector1, Vector3 vector2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Cross(ref vector1, ref vector2, out result);
|
Cross(ref vector1, ref vector2, out result);
|
||||||
@ -279,16 +278,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Cross(ref Vector3 vector1, ref Vector3 vector2,
|
public static void Cross(ref Vector3 vector1, ref Vector3 vector2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
|
result.X = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
|
||||||
result.Y = vector1.Z * vector2.X - vector1.X * vector2.Z;
|
result.Y = vector1.Z * vector2.X - vector1.X * vector2.Z;
|
||||||
result.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
|
result.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Normalize
|
#region Normalize
|
||||||
public static Vector3 Normalize(Vector3 value)
|
public static Vector3 Normalize(Vector3 value)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Normalize(ref value, out result);
|
Normalize(ref value, out result);
|
||||||
@ -301,11 +300,11 @@ namespace ANX.Framework
|
|||||||
result.X = value.X * factor;
|
result.X = value.X * factor;
|
||||||
result.Y = value.Y * factor;
|
result.Y = value.Y * factor;
|
||||||
result.Z = value.Z * factor;
|
result.Z = value.Z * factor;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Distance
|
#region Distance
|
||||||
public static float Distance(Vector3 value1, Vector3 value2)
|
public static float Distance(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
float result;
|
float result;
|
||||||
Distance(ref value1, ref value2, out result);
|
Distance(ref value1, ref value2, out result);
|
||||||
@ -313,16 +312,16 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Distance(ref Vector3 value1, ref Vector3 value2,
|
public static void Distance(ref Vector3 value1, ref Vector3 value2,
|
||||||
out float result)
|
out float result)
|
||||||
{
|
{
|
||||||
Vector3 resultVector;
|
Vector3 resultVector;
|
||||||
Subtract(ref value1, ref value2, out resultVector);
|
Subtract(ref value1, ref value2, out resultVector);
|
||||||
result = resultVector.Length();
|
result = resultVector.Length();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region DistanceSquared
|
#region DistanceSquared
|
||||||
public static float DistanceSquared(Vector3 value1, Vector3 value2)
|
public static float DistanceSquared(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
float result;
|
float result;
|
||||||
DistanceSquared(ref value1, ref value2, out result);
|
DistanceSquared(ref value1, ref value2, out result);
|
||||||
@ -330,59 +329,52 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void DistanceSquared(ref Vector3 value1,
|
public static void DistanceSquared(ref Vector3 value1,
|
||||||
ref Vector3 value2, out float result)
|
ref Vector3 value2, out float result)
|
||||||
{
|
{
|
||||||
Vector3 resultVector;
|
Vector3 resultVector;
|
||||||
Subtract(ref value1, ref value2, out resultVector);
|
Subtract(ref value1, ref value2, out resultVector);
|
||||||
result = resultVector.LengthSquared();
|
result = resultVector.LengthSquared();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Barycentric
|
#region Barycentric
|
||||||
public static Vector3 Barycentric(Vector3 value1, Vector3 value2,
|
public static Vector3 Barycentric(Vector3 value1, Vector3 value2,
|
||||||
Vector3 value3, float amount1, float amount2)
|
Vector3 value3, float amount1, float amount2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Barycentric(ref value1, ref value2, ref value3, amount1, amount2,
|
Barycentric(ref value1, ref value2, ref value3, amount1, amount2,
|
||||||
out result);
|
out result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Barycentric(ref Vector3 value1, ref Vector3 value2,
|
public static void Barycentric(ref Vector3 value1, ref Vector3 value2,
|
||||||
ref Vector3 value3, float amount1, float amount2, out Vector3 result)
|
ref Vector3 value3, float amount1, float amount2, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X,
|
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||||
amount1, amount2);
|
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y,
|
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||||
amount1, amount2);
|
|
||||||
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z,
|
|
||||||
amount1, amount2);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region CatmullRom
|
#region CatmullRom
|
||||||
public static Vector3 CatmullRom(Vector3 value1, Vector3 value2,
|
public static Vector3 CatmullRom(Vector3 value1, Vector3 value2,
|
||||||
Vector3 value3, Vector3 value4, float amount)
|
Vector3 value3, Vector3 value4, float amount)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
CatmullRom(ref value1, ref value2, ref value3, ref value4, amount,
|
CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
|
||||||
out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CatmullRom(ref Vector3 value1, ref Vector3 value2,
|
public static void CatmullRom(ref Vector3 value1, ref Vector3 value2,
|
||||||
ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result)
|
ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X,
|
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||||
value4.X, amount);
|
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y,
|
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||||
value4.Y, amount);
|
|
||||||
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z,
|
|
||||||
value4.Z, amount);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Clamp
|
#region Clamp
|
||||||
public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max)
|
public static Vector3 Clamp(Vector3 value1, Vector3 min, Vector3 max)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -391,37 +383,33 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Clamp(ref Vector3 value1, ref Vector3 min,
|
public static void Clamp(ref Vector3 value1, ref Vector3 min,
|
||||||
ref Vector3 max, out Vector3 result)
|
ref Vector3 max, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
result.X = MathHelper.Clamp(value1.X, min.X, max.X);
|
||||||
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
result.Y = MathHelper.Clamp(value1.Y, min.Y, max.Y);
|
||||||
result.Z = MathHelper.Clamp(value1.Z, min.Z, max.Z);
|
result.Z = MathHelper.Clamp(value1.Z, min.Z, max.Z);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Hermite
|
#region Hermite
|
||||||
public static Vector3 Hermite(Vector3 value1, Vector3 tangent1,
|
public static Vector3 Hermite(Vector3 value1, Vector3 tangent1,
|
||||||
Vector3 value2, Vector3 tangent2, float amount)
|
Vector3 value2, Vector3 tangent2, float amount)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount,
|
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
|
||||||
out result);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Hermite(ref Vector3 value1, ref Vector3 tangent1,
|
public static void Hermite(ref Vector3 value1, ref Vector3 tangent1,
|
||||||
ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result)
|
ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X,
|
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||||
tangent2.X, amount);
|
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y,
|
result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount);
|
||||||
tangent2.Y, amount);
|
|
||||||
result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z,
|
|
||||||
tangent2.Z, amount);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Lerp
|
#region Lerp
|
||||||
public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount)
|
public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -430,15 +418,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Lerp(ref Vector3 value1, ref Vector3 value2,
|
public static void Lerp(ref Vector3 value1, ref Vector3 value2,
|
||||||
float amount, out Vector3 result)
|
float amount, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.Lerp(value1.X, value2.X, amount);
|
result.X = MathHelper.Lerp(value1.X, value2.X, amount);
|
||||||
result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount);
|
result.Y = MathHelper.Lerp(value1.Y, value2.Y, amount);
|
||||||
result.Z = MathHelper.Lerp(value1.Z, value2.Z, amount);
|
result.Z = MathHelper.Lerp(value1.Z, value2.Z, amount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Max
|
#region Max
|
||||||
public static Vector3 Max(Vector3 value1, Vector3 value2)
|
public static Vector3 Max(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -447,15 +435,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Max(ref Vector3 value1, ref Vector3 value2,
|
public static void Max(ref Vector3 value1, ref Vector3 value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X > value2.X ? value1.X : value2.X;
|
result.X = value1.X > value2.X ? value1.X : value2.X;
|
||||||
result.Y = value1.Y > value2.Y ? value1.Y : value2.Y;
|
result.Y = value1.Y > value2.Y ? value1.Y : value2.Y;
|
||||||
result.Z = value1.Z > value2.Z ? value1.Z : value2.Z;
|
result.Z = value1.Z > value2.Z ? value1.Z : value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Min
|
#region Min
|
||||||
public static Vector3 Min(Vector3 value1, Vector3 value2)
|
public static Vector3 Min(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -464,15 +452,15 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Min(ref Vector3 value1, ref Vector3 value2,
|
public static void Min(ref Vector3 value1, ref Vector3 value2,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = value1.X < value2.X ? value1.X : value2.X;
|
result.X = value1.X < value2.X ? value1.X : value2.X;
|
||||||
result.Y = value1.Y < value2.Y ? value1.Y : value2.Y;
|
result.Y = value1.Y < value2.Y ? value1.Y : value2.Y;
|
||||||
result.Z = value1.Z < value2.Z ? value1.Z : value2.Z;
|
result.Z = value1.Z < value2.Z ? value1.Z : value2.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Negate
|
#region Negate
|
||||||
public static Vector3 Negate(Vector3 value)
|
public static Vector3 Negate(Vector3 value)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -486,9 +474,9 @@ namespace ANX.Framework
|
|||||||
result.Y = -value.Y;
|
result.Y = -value.Y;
|
||||||
result.Z = -value.Z;
|
result.Z = -value.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Reflect
|
#region Reflect
|
||||||
public static Vector3 Reflect(Vector3 vector, Vector3 normal)
|
public static Vector3 Reflect(Vector3 vector, Vector3 normal)
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
@ -497,18 +485,17 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void Reflect(ref Vector3 vector, ref Vector3 normal,
|
public static void Reflect(ref Vector3 vector, ref Vector3 normal,
|
||||||
out Vector3 result)
|
out Vector3 result)
|
||||||
{
|
{
|
||||||
float scaleFactor = Vector3.Dot(vector, normal) * 2;
|
float scaleFactor = Vector3.Dot(vector, normal) * 2;
|
||||||
Vector3 tmp;
|
Vector3 tmp;
|
||||||
Multiply(ref normal, scaleFactor, out tmp);
|
Multiply(ref normal, scaleFactor, out tmp);
|
||||||
Subtract(ref vector, ref tmp, out result);
|
Subtract(ref vector, ref tmp, out result);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SmoothStep
|
#region SmoothStep
|
||||||
public static Vector3 SmoothStep(Vector3 value1, Vector3 value2,
|
public static Vector3 SmoothStep(Vector3 value1, Vector3 value2, float amount)
|
||||||
float amount)
|
|
||||||
{
|
{
|
||||||
Vector3 result;
|
Vector3 result;
|
||||||
Vector3.SmoothStep(ref value1, ref value2, amount, out result);
|
Vector3.SmoothStep(ref value1, ref value2, amount, out result);
|
||||||
@ -516,13 +503,13 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void SmoothStep(ref Vector3 value1, ref Vector3 value2,
|
public static void SmoothStep(ref Vector3 value1, ref Vector3 value2,
|
||||||
float amount, out Vector3 result)
|
float amount, out Vector3 result)
|
||||||
{
|
{
|
||||||
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
result.X = MathHelper.SmoothStep(value1.X, value2.X, amount);
|
||||||
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
result.Y = MathHelper.SmoothStep(value1.Y, value2.Y, amount);
|
||||||
result.Z = MathHelper.SmoothStep(value1.Z, value2.Z, amount);
|
result.Z = MathHelper.SmoothStep(value1.Z, value2.Z, amount);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Transformations
|
#region Transformations
|
||||||
public static Vector3 Transform(Vector3 position, Matrix matrix)
|
public static Vector3 Transform(Vector3 position, Matrix matrix)
|
||||||
@ -549,35 +536,39 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector3 result)
|
public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector3 result)
|
||||||
{
|
{
|
||||||
float x = 2* (rotation.Y * value.Z - rotation.Z * value.Y);
|
float x = 2 * (rotation.Y * value.Z - rotation.Z * value.Y);
|
||||||
float y = 2* (rotation.Z * value.X - rotation.X * value.Z);
|
float y = 2 * (rotation.Z * value.X - rotation.X * value.Z);
|
||||||
float z = 2* (rotation.X * value.Y - rotation.Y * value.X);
|
float z = 2 * (rotation.X * value.Y - rotation.Y * value.X);
|
||||||
|
|
||||||
result.X = value.X + x * rotation.W + (rotation.Y * z - rotation.Z * y);
|
result.X = value.X + x * rotation.W + (rotation.Y * z - rotation.Z * y);
|
||||||
result.Y = value.Y + y * rotation.W + (rotation.Z * x - rotation.X * z);
|
result.Y = value.Y + y * rotation.W + (rotation.Z * x - rotation.X * z);
|
||||||
result.Z = value.Z + z * rotation.W + (rotation.X * y - rotation.Y * x);
|
result.Z = value.Z + z * rotation.W + (rotation.X * y - rotation.Y * x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector3[] sourceArray, ref Matrix matrix, Vector3[] destinationArray)
|
public static void Transform(Vector3[] sourceArray, ref Matrix matrix,
|
||||||
|
Vector3[] destinationArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sourceArray.Length; i++)
|
for (int i = 0; i < sourceArray.Length; i++)
|
||||||
Transform(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
Transform(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector3[] sourceArray, ref Quaternion rotation, Vector3[] destinationArray)
|
public static void Transform(Vector3[] sourceArray, ref Quaternion rotation,
|
||||||
|
Vector3[] destinationArray)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < sourceArray.Length; i++)
|
for (int i = 0; i < sourceArray.Length; i++)
|
||||||
Transform(ref sourceArray[i], ref rotation, out destinationArray[i]);
|
Transform(ref sourceArray[i], ref rotation, out destinationArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix, Vector3[] destinationArray, int destinationIndex, int length)
|
public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix,
|
||||||
|
Vector3[] destinationArray, int destinationIndex, int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
Transform(ref sourceArray[i], ref matrix, out destinationArray[destinationIndex]);
|
Transform(ref sourceArray[i], ref matrix, out destinationArray[destinationIndex]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector3[] destinationArray, int destinationIndex, int length)
|
public static void Transform(Vector3[] sourceArray, int sourceIndex, ref Quaternion rotation,
|
||||||
|
Vector3[] destinationArray, int destinationIndex, int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
@ -604,7 +595,8 @@ namespace ANX.Framework
|
|||||||
TransformNormal(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
TransformNormal(ref sourceArray[i], ref matrix, out destinationArray[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void TransformNormal(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix, Vector3[] destinationArray, int destinationIndex, int length)
|
public static void TransformNormal(Vector3[] sourceArray, int sourceIndex, ref Matrix matrix,
|
||||||
|
Vector3[] destinationArray, int destinationIndex, int length)
|
||||||
{
|
{
|
||||||
length += sourceIndex;
|
length += sourceIndex;
|
||||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||||
@ -618,120 +610,113 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static Vector3 operator +(Vector3 value1, Vector3 value2)
|
public static Vector3 operator +(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return new Vector3(value1.X + value2.X, value1.Y + value2.Y,
|
return new Vector3(value1.X + value2.X, value1.Y + value2.Y, value1.Z + value2.Z);
|
||||||
value1.Z + value2.Z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator /(Vector3 value1, float divider)
|
public static Vector3 operator /(Vector3 value1, float divider)
|
||||||
{
|
{
|
||||||
float factor = 1f / divider;
|
float factor = 1f / divider;
|
||||||
return new Vector3(value1.X * factor, value1.Y * factor,
|
return new Vector3(value1.X * factor, value1.Y * factor,
|
||||||
value1.Z * factor);
|
value1.Z * factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator /(Vector3 value1, Vector3 value2)
|
public static Vector3 operator /(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return new Vector3(value1.X / value2.X, value1.Y / value2.Y,
|
return new Vector3(value1.X / value2.X, value1.Y / value2.Y,
|
||||||
value1.Z / value2.Z);
|
value1.Z / value2.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator ==(Vector3 value1, Vector3 value2)
|
public static bool operator ==(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return value1.X == value2.X &&
|
return value1.X == value2.X &&
|
||||||
value1.Y == value2.Y &&
|
value1.Y == value2.Y &&
|
||||||
value1.Z == value2.Z;
|
value1.Z == value2.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator !=(Vector3 value1, Vector3 value2)
|
public static bool operator !=(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return value1.X != value2.X ||
|
return value1.X != value2.X ||
|
||||||
value1.Y != value2.Y ||
|
value1.Y != value2.Y ||
|
||||||
value1.Z != value2.Z;
|
value1.Z != value2.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator *(Vector3 value, float scaleFactor)
|
public static Vector3 operator *(Vector3 value, float scaleFactor)
|
||||||
{
|
{
|
||||||
return new Vector3(value.X * scaleFactor, value.Y * scaleFactor,
|
return new Vector3(value.X * scaleFactor, value.Y * scaleFactor,
|
||||||
value.Z * scaleFactor);
|
value.Z * scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator *(float scaleFactor, Vector3 value)
|
public static Vector3 operator *(float scaleFactor, Vector3 value)
|
||||||
{
|
{
|
||||||
return new Vector3(value.X * scaleFactor, value.Y * scaleFactor,
|
return new Vector3(value.X * scaleFactor, value.Y * scaleFactor,
|
||||||
value.Z * scaleFactor);
|
value.Z * scaleFactor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator *(Vector3 value1, Vector3 value2)
|
public static Vector3 operator *(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return new Vector3(value1.X * value2.X, value1.Y * value2.Y,
|
return new Vector3(value1.X * value2.X, value1.Y * value2.Y,
|
||||||
value1.Z * value2.Z);
|
value1.Z * value2.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator -(Vector3 value1, Vector3 value2)
|
public static Vector3 operator -(Vector3 value1, Vector3 value2)
|
||||||
{
|
{
|
||||||
return new Vector3(value1.X - value2.X, value1.Y - value2.Y,
|
return new Vector3(value1.X - value2.X, value1.Y - value2.Y,
|
||||||
value1.Z - value2.Z);
|
value1.Z - value2.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 operator -(Vector3 value)
|
public static Vector3 operator -(Vector3 value)
|
||||||
{
|
{
|
||||||
return new Vector3(-value.X, -value.Y, -value.Z);
|
return new Vector3(-value.X, -value.Y, -value.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
|
|
||||||
#region Length
|
#region Length
|
||||||
public float Length()
|
public float Length()
|
||||||
{
|
{
|
||||||
return (float)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
|
return (float)Math.Sqrt(this.X * this.X + this.Y * this.Y + this.Z * this.Z);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region LengthSquared
|
#region LengthSquared
|
||||||
public float LengthSquared()
|
public float LengthSquared()
|
||||||
{
|
{
|
||||||
return this.X * this.X + this.Y * this.Y + this.Z * this.Z;
|
return this.X * this.X + this.Y * this.Y + this.Z * this.Z;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Normalize
|
#region Normalize
|
||||||
public void Normalize()
|
public void Normalize()
|
||||||
{
|
{
|
||||||
float factor = 1f / this.Length();
|
float factor = 1f / this.Length();
|
||||||
this.X *= factor;
|
this.X *= factor;
|
||||||
this.Y *= factor;
|
this.Y *= factor;
|
||||||
this.Z *= factor;
|
this.Z *= factor;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region GetHashCode
|
#region GetHashCode
|
||||||
public override int GetHashCode()
|
public override int GetHashCode()
|
||||||
{
|
{
|
||||||
return this.X.GetHashCode() + this.Y.GetHashCode() +
|
return this.X.GetHashCode() +
|
||||||
this.Z.GetHashCode();
|
this.Y.GetHashCode() +
|
||||||
|
this.Z.GetHashCode();
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ToString
|
#region ToString
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{X:" + X.ToString(culture) +
|
return "{X:" + X.ToString(culture) +
|
||||||
" Y:" + Y.ToString(culture) +
|
" Y:" + Y.ToString(culture) +
|
||||||
" Z:" + Z.ToString(culture) + "}";
|
" Z:" + Z.ToString(culture) + "}";
|
||||||
|
}
|
||||||
//return string.Format(culture, "{{X:{0} Y:{1} Z:{2}}}", new object[]
|
#endregion
|
||||||
//{
|
|
||||||
// this.X.ToString(culture),
|
|
||||||
// this.Y.ToString(culture),
|
|
||||||
// this.Z.ToString(culture)
|
|
||||||
//});
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -745,8 +730,8 @@ namespace ANX.Framework
|
|||||||
public bool Equals(Vector3 other)
|
public bool Equals(Vector3 other)
|
||||||
{
|
{
|
||||||
return this.X == other.X &&
|
return this.X == other.X &&
|
||||||
this.Y == other.Y &&
|
this.Y == other.Y &&
|
||||||
this.Z == other.Z;
|
this.Z == other.Z;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -433,7 +433,26 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector4 result)
|
public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector4 result)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
float twoX = rotation.X + rotation.X;
|
||||||
|
float twoY = rotation.Y + rotation.Y;
|
||||||
|
float twoZ = rotation.Z + rotation.Z;
|
||||||
|
|
||||||
|
float twoXX = twoX * rotation.X;
|
||||||
|
float twoXY = twoX * rotation.Y;
|
||||||
|
float twoXZ = twoX * rotation.Z;
|
||||||
|
float twoXW = twoX * rotation.W;
|
||||||
|
|
||||||
|
float twoYY = twoY * rotation.Y;
|
||||||
|
float twoYZ = twoY * rotation.Z;
|
||||||
|
float twoYW = twoY * rotation.W;
|
||||||
|
|
||||||
|
float twoZZ = twoZ * rotation.Z;
|
||||||
|
float twoZW = twoZ * rotation.W;
|
||||||
|
|
||||||
|
result.X = value.X * (1.0f - twoYY - twoZZ) + value.Y * (twoXY - twoZW);
|
||||||
|
result.Y = value.X * (twoXY + twoZW) + value.Y * (1.0f - twoXX - twoZZ);
|
||||||
|
result.Z = value.X * (twoXZ - twoYW) + value.Y * (twoYZ + twoXW);
|
||||||
|
result.W = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector4 Transform(Vector3 position, Matrix matrix)
|
public static Vector4 Transform(Vector3 position, Matrix matrix)
|
||||||
@ -460,7 +479,26 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector4 result)
|
public static void Transform(ref Vector3 value, ref Quaternion rotation, out Vector4 result)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
float twoX = rotation.X + rotation.X;
|
||||||
|
float twoY = rotation.Y + rotation.Y;
|
||||||
|
float twoZ = rotation.Z + rotation.Z;
|
||||||
|
|
||||||
|
float twoXX = twoX * rotation.X;
|
||||||
|
float twoXY = twoX * rotation.Y;
|
||||||
|
float twoXZ = twoX * rotation.Z;
|
||||||
|
float twoXW = twoX * rotation.W;
|
||||||
|
|
||||||
|
float twoYY = twoY * rotation.Y;
|
||||||
|
float twoYZ = twoY * rotation.Z;
|
||||||
|
float twoYW = twoY * rotation.W;
|
||||||
|
|
||||||
|
float twoZZ = twoZ * rotation.Z;
|
||||||
|
float twoZW = twoZ * rotation.W;
|
||||||
|
|
||||||
|
result.X = value.X * (1.0f - twoYY - twoZZ) + value.Y * (twoXY - twoZW) + value.Z * (twoXZ + twoYW);
|
||||||
|
result.Y = value.X * (twoXY + twoZW) + value.Y * (1.0f - twoXX - twoZZ) + value.Z * (twoYZ - twoXW);
|
||||||
|
result.Z = value.X * (twoXZ - twoYW) + value.Y * (twoYZ + twoXW) + value.Z * (1.0f - twoXX - twoYY);
|
||||||
|
result.W = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector4 Transform(Vector4 vector, Matrix matrix)
|
public static Vector4 Transform(Vector4 vector, Matrix matrix)
|
||||||
@ -487,13 +525,25 @@ namespace ANX.Framework
|
|||||||
|
|
||||||
public static void Transform(ref Vector4 value, ref Quaternion rotation, out Vector4 result)
|
public static void Transform(ref Vector4 value, ref Quaternion rotation, out Vector4 result)
|
||||||
{
|
{
|
||||||
float x = 2 * (rotation.Y * value.Z - rotation.Z * value.Y);
|
float twoX = rotation.X + rotation.X;
|
||||||
float y = 2 * (rotation.Z * value.X - rotation.X * value.Z);
|
float twoY = rotation.Y + rotation.Y;
|
||||||
float z = 2 * (rotation.X * value.Y - rotation.Y * value.X);
|
float twoZ = rotation.Z + rotation.Z;
|
||||||
|
|
||||||
result.X = value.X + x * rotation.W + (rotation.Y * z - rotation.Z * y);
|
float twoXX = twoX * rotation.X;
|
||||||
result.Y = value.Y + y * rotation.W + (rotation.Z * x - rotation.X * z);
|
float twoXY = twoX * rotation.Y;
|
||||||
result.Z = value.Z + z * rotation.W + (rotation.X * y - rotation.Y * x);
|
float twoXZ = twoX * rotation.Z;
|
||||||
|
float twoXW = twoX * rotation.W;
|
||||||
|
|
||||||
|
float twoYY = twoY * rotation.Y;
|
||||||
|
float twoYZ = twoY * rotation.Z;
|
||||||
|
float twoYW = twoY * rotation.W;
|
||||||
|
|
||||||
|
float twoZZ = twoZ * rotation.Z;
|
||||||
|
float twoZW = twoZ * rotation.W;
|
||||||
|
|
||||||
|
result.X = value.X * (1.0f - twoYY - twoZZ) + value.Y * (twoXY - twoZW) + value.Z * (twoXZ + twoYW);
|
||||||
|
result.Y = value.X * (twoXY + twoZW) + value.Y * (1.0f - twoXX - twoZZ) + value.Z * (twoYZ - twoXW);
|
||||||
|
result.Z = value.X * (twoXZ - twoYW) + value.Y * (twoYZ + twoXW) + value.Z * (1.0f - twoXX - twoYY);
|
||||||
result.W = value.W;
|
result.W = value.W;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,22 +591,22 @@ namespace ANX.Framework
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var culture = CultureInfo.CurrentCulture;
|
var culture = CultureInfo.CurrentCulture;
|
||||||
// This may look a bit more ugly, but String.Format should
|
// This may look a bit more ugly, but String.Format should
|
||||||
// be avoided cause of it's bad performance!
|
// be avoided cause of it's bad performance!
|
||||||
return "{X:" + X.ToString(culture) +
|
return "{X:" + X.ToString(culture) +
|
||||||
" Y:" + Y.ToString(culture) +
|
" Y:" + Y.ToString(culture) +
|
||||||
" Z:" + Z.ToString(culture) +
|
" Z:" + Z.ToString(culture) +
|
||||||
" W:" + W.ToString(culture) + "}";
|
" W:" + W.ToString(culture) + "}";
|
||||||
|
|
||||||
//return string.Format(culture, "{{X:{0} Y:{1} Z:{2} W:{3}}}", new object[]
|
//return string.Format(culture, "{{X:{0} Y:{1} Z:{2} W:{3}}}", new object[]
|
||||||
//{
|
//{
|
||||||
// this.X.ToString(culture),
|
// this.X.ToString(culture),
|
||||||
// this.Y.ToString(culture),
|
// this.Y.ToString(culture),
|
||||||
// this.Z.ToString(culture),
|
// this.Z.ToString(culture),
|
||||||
// this.W.ToString(culture)
|
// this.W.ToString(culture)
|
||||||
//});
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
public float Length()
|
public float Length()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user