+ 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 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 ANXBoundingBox = ANX.Framework.BoundingBox;
|
||||
|
||||
@ -34,6 +40,12 @@ namespace ANX.Framework.TestCenter.Strukturen
|
||||
[TestFixture]
|
||||
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]
|
||||
public void IntersectsSphere()
|
||||
{
|
||||
@ -44,5 +56,251 @@ namespace ANX.Framework.TestCenter.Strukturen
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
[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")]
|
||||
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")]
|
||||
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 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)
|
||||
|
@ -312,17 +312,9 @@ namespace ANX.Framework
|
||||
|
||||
public void Intersects(ref BoundingBox box, out bool result)
|
||||
{
|
||||
if ((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.Z < box.Min.Z || this.Min.Z > box.Max.Z)
|
||||
)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
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.Z >= box.Min.Z && this.Min.Z <= box.Max.Z);
|
||||
}
|
||||
|
||||
public bool Intersects(BoundingFrustum frustum)
|
||||
@ -488,12 +480,6 @@ namespace ANX.Framework
|
||||
// be avoided cause of it's bad performance!
|
||||
return "{Min:" + Min.ToString() +
|
||||
" Max:" + Max.ToString() + "}";
|
||||
|
||||
// return string.Format(System.Globalization.CultureInfo.CurrentCulture, "{{Min:{0} Max:{1}}}", new object[]
|
||||
//{
|
||||
// this.Min.ToString(),
|
||||
// this.Max.ToString()
|
||||
//});
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -47,21 +47,16 @@ namespace ANX.Framework
|
||||
#region public methods
|
||||
public float Dot(Vector4 value)
|
||||
{
|
||||
float result;
|
||||
this.Dot(ref value, out result);
|
||||
return result;
|
||||
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z + this.D * value.W;
|
||||
}
|
||||
public void Dot(ref Vector4 value, out float result)
|
||||
{
|
||||
//taken from vektor
|
||||
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)
|
||||
{
|
||||
float result;
|
||||
this.DotCoordinate(ref value, out result);
|
||||
return result;
|
||||
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z + this.D;
|
||||
}
|
||||
public void DotCoordinate(ref Vector3 value, out float result)
|
||||
{
|
||||
@ -70,13 +65,11 @@ namespace ANX.Framework
|
||||
|
||||
public float DotNormal(Vector3 value)
|
||||
{
|
||||
float result;
|
||||
this.DotNormal(ref value, out result);
|
||||
return result;
|
||||
return this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z;
|
||||
}
|
||||
public void DotNormal(ref Vector3 value, out float result)
|
||||
{
|
||||
result = this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z ;
|
||||
result = this.Normal.X * value.X + this.Normal.Y * value.Y + this.Normal.Z * value.Z;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
@ -90,10 +83,38 @@ namespace ANX.Framework
|
||||
this.Intersects(ref box, out result);
|
||||
return 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)
|
||||
{
|
||||
PlaneIntersectionType result;
|
||||
@ -147,7 +168,6 @@ namespace ANX.Framework
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (distanceSquared_Sphere_Origin > distanceSquared_Plane_Origin)
|
||||
{
|
||||
if (distanceSquared_Sphere_Origin - sphere.Radius < distanceSquared_Plane_Origin)
|
||||
@ -177,23 +197,54 @@ namespace ANX.Framework
|
||||
}
|
||||
//else distance sphere == distance plane
|
||||
result = PlaneIntersectionType.Intersecting;
|
||||
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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.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;
|
||||
}
|
||||
|
||||
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()
|
||||
@ -203,29 +254,92 @@ namespace ANX.Framework
|
||||
// be avoided cause of it's bad performance!
|
||||
return "{Normal:" + Normal.ToString() +
|
||||
" 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
|
||||
@ -235,6 +349,7 @@ namespace ANX.Framework
|
||||
{
|
||||
return (obj is Plane) ? this.Equals((Plane)obj) : false;
|
||||
}
|
||||
|
||||
public bool Equals(Plane other)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public static bool operator !=(Plane lhs, Plane rhs)
|
||||
{
|
||||
return !lhs.D.Equals(rhs.D) || !lhs.Normal.Equals(rhs.Normal);
|
||||
|
@ -38,6 +38,7 @@ namespace ANX.Framework
|
||||
this.Z = z;
|
||||
this.W = w;
|
||||
}
|
||||
|
||||
public Quaternion(Vector3 vectorPart, float scalarPart)
|
||||
{
|
||||
this.X = vectorPart.X;
|
||||
@ -51,11 +52,9 @@ namespace ANX.Framework
|
||||
#region public methods
|
||||
public static Quaternion Add(Quaternion quaternion1, Quaternion quaternion2)
|
||||
{
|
||||
|
||||
Quaternion result;
|
||||
Quaternion.Add(ref quaternion1, ref quaternion2, out result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static void Add(ref Quaternion quaternion1, ref Quaternion quaternion2, out Quaternion result)
|
||||
@ -71,7 +70,6 @@ namespace ANX.Framework
|
||||
Quaternion result;
|
||||
Quaternion.Concatenate(ref value1, ref value2, out result);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static void Concatenate(ref Quaternion value1, ref Quaternion value2, out Quaternion result)
|
||||
@ -81,10 +79,9 @@ namespace ANX.Framework
|
||||
|
||||
public void Conjugate()
|
||||
{
|
||||
this.X = -this.X; //should be =this.X;
|
||||
this.X = -this.X;
|
||||
this.Y = -this.Y;
|
||||
this.Z = -this.Z;
|
||||
|
||||
}
|
||||
|
||||
public static Quaternion Conjugate(Quaternion value)
|
||||
@ -372,11 +369,9 @@ namespace ANX.Framework
|
||||
|
||||
public static Quaternion Slerp(Quaternion quaternion1, Quaternion quaternion2, float amount)
|
||||
{
|
||||
|
||||
Quaternion result;
|
||||
Quaternion.Slerp(ref quaternion1, ref quaternion2, amount, out result);
|
||||
return result; throw new NotImplementedException();
|
||||
|
||||
}
|
||||
|
||||
public static void Slerp(ref Quaternion quaternion1, ref Quaternion quaternion2, float amount, out Quaternion result)
|
||||
@ -414,20 +409,10 @@ namespace ANX.Framework
|
||||
public override string ToString()
|
||||
{
|
||||
var culture = CultureInfo.CurrentCulture;
|
||||
// This may look a bit more ugly, but String.Format should
|
||||
// be avoided cause of it's bad performance!
|
||||
return "{X:" + X.ToString(culture) +
|
||||
" Y:" + Y.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
|
||||
|
||||
|
@ -176,13 +176,6 @@ namespace ANX.Framework
|
||||
// be avoided cause of it's bad performance!
|
||||
return "{Position:" + Position.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
|
||||
|
||||
|
@ -148,15 +148,12 @@ namespace ANX.Framework
|
||||
return this.X + this.Y + this.Width + this.Height;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void Inflate(int horizontalAmount, int verticalAmount)
|
||||
{
|
||||
this.X -= horizontalAmount;
|
||||
this.Y -= verticalAmount;
|
||||
this.Width += horizontalAmount * 2;
|
||||
this.Height += verticalAmount * 2;
|
||||
|
||||
}
|
||||
|
||||
public bool Intersects(Rectangle value)
|
||||
@ -186,7 +183,6 @@ namespace ANX.Framework
|
||||
return;
|
||||
}
|
||||
result = true;
|
||||
|
||||
}
|
||||
|
||||
public void Offset(int offsetX, int offsetY)
|
||||
@ -211,14 +207,6 @@ namespace ANX.Framework
|
||||
" Y:" + Y.ToString(culture) +
|
||||
" Width:" + Width.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
|
||||
|
@ -104,18 +104,15 @@ namespace ANX.Framework
|
||||
Vector2 value3, float amount1, float amount2)
|
||||
{
|
||||
Vector2 result;
|
||||
Vector2.Barycentric(ref value1, ref value2, ref value3, amount1,
|
||||
amount2, out result);
|
||||
Vector2.Barycentric(ref value1, ref value2, ref value3, amount1, amount2, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Barycentric(ref Vector2 value1, ref Vector2 value2,
|
||||
ref Vector2 value3, float amount1, float amount2, out Vector2 result)
|
||||
{
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X,
|
||||
amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y,
|
||||
amount1, amount2);
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -124,18 +121,15 @@ namespace ANX.Framework
|
||||
Vector2 value3, Vector2 value4, float amount)
|
||||
{
|
||||
Vector2 result;
|
||||
Vector2.CatmullRom(ref value1, ref value2, ref value3, ref value4,
|
||||
amount, out result);
|
||||
Vector2.CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void CatmullRom(ref Vector2 value1, ref Vector2 value2,
|
||||
ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
|
||||
{
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X,
|
||||
value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y,
|
||||
value4.Y, amount);
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -402,8 +396,7 @@ namespace ANX.Framework
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Reflect(ref Vector2 vector, ref Vector2 normal,
|
||||
out Vector2 result)
|
||||
public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
|
||||
{
|
||||
float sub = 2 * Vector2.Dot(vector, normal);
|
||||
result.X = vector.X - (sub * normal.X);
|
||||
@ -436,8 +429,7 @@ namespace ANX.Framework
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Subtract(ref Vector2 value1, ref Vector2 value2,
|
||||
out Vector2 result)
|
||||
public static void Subtract(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
|
||||
{
|
||||
result.X = value1.X - value2.X;
|
||||
result.Y = value1.Y - value2.Y;
|
||||
@ -450,14 +442,7 @@ namespace ANX.Framework
|
||||
var culture = CultureInfo.CurrentCulture;
|
||||
// This may look a bit more ugly, but String.Format should
|
||||
// be avoided cause of it's bad performance!
|
||||
return "{X:" + X.ToString(culture) +
|
||||
" Y:" + Y.ToString(culture) + "}";
|
||||
|
||||
//return string.Format(culture, "{{X:{0} Y:{1}}}", new object[]
|
||||
//{
|
||||
// this.X.ToString(culture),
|
||||
// this.Y.ToString(culture)
|
||||
//});
|
||||
return "{X:" + X.ToString(culture) + " Y:" + Y.ToString(culture) + "}";
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -472,10 +457,8 @@ namespace ANX.Framework
|
||||
public static void Transform(ref Vector2 position, ref Matrix matrix,
|
||||
out Vector2 result)
|
||||
{
|
||||
result.X = (position.X * matrix.M11) + (position.Y * matrix.M21) +
|
||||
matrix.M41;
|
||||
result.Y = (position.X * matrix.M12) + (position.Y * matrix.M22) +
|
||||
matrix.M42;
|
||||
result.X = (position.X * matrix.M11) + (position.Y * matrix.M21) + matrix.M41;
|
||||
result.Y = (position.X * matrix.M12) + (position.Y * matrix.M22) + matrix.M42;
|
||||
}
|
||||
|
||||
public static Vector2 Transform(Vector2 value, Quaternion rotation)
|
||||
@ -607,13 +590,11 @@ namespace ANX.Framework
|
||||
|
||||
public static bool operator ==(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
return value1.X.Equals(value2.X) &&
|
||||
value1.Y.Equals(value2.Y);
|
||||
return (value1.X == value2.X) && (value1.Y == value2.Y);
|
||||
}
|
||||
public static bool operator !=(Vector2 value1, Vector2 value2)
|
||||
{
|
||||
return value1.X.Equals(value2.X) == false ||
|
||||
value1.Y.Equals(value2.Y) == false;
|
||||
return (value1.X != value2.X) || (value1.Y != value2.Y);
|
||||
}
|
||||
|
||||
public static Vector2 operator *(float scaleFactor, Vector2 value)
|
||||
|
@ -163,8 +163,7 @@ namespace ANX.Framework
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Add(ref Vector3 value1, ref Vector3 value2,
|
||||
out Vector3 result)
|
||||
public static void Add(ref Vector3 value1, ref Vector3 value2, out Vector3 result)
|
||||
{
|
||||
result.X = value1.X + value2.X;
|
||||
result.Y = value1.Y + value2.Y;
|
||||
@ -351,12 +350,9 @@ namespace ANX.Framework
|
||||
public static void Barycentric(ref Vector3 value1, ref Vector3 value2,
|
||||
ref Vector3 value3, float amount1, float amount2, out Vector3 result)
|
||||
{
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X,
|
||||
amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y,
|
||||
amount1, amount2);
|
||||
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z,
|
||||
amount1, amount2);
|
||||
result.X = MathHelper.Barycentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper.Barycentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
result.Z = MathHelper.Barycentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -365,20 +361,16 @@ namespace ANX.Framework
|
||||
Vector3 value3, Vector3 value4, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
CatmullRom(ref value1, ref value2, ref value3, ref value4, amount,
|
||||
out result);
|
||||
CatmullRom(ref value1, ref value2, ref value3, ref value4, amount, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void CatmullRom(ref Vector3 value1, ref Vector3 value2,
|
||||
ref Vector3 value3, ref Vector3 value4, float amount, out Vector3 result)
|
||||
{
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X,
|
||||
value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y,
|
||||
value4.Y, amount);
|
||||
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z,
|
||||
value4.Z, amount);
|
||||
result.X = MathHelper.CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
result.Y = MathHelper.CatmullRom(value1.Y, value2.Y, value3.Y, value4.Y, amount);
|
||||
result.Z = MathHelper.CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -404,20 +396,16 @@ namespace ANX.Framework
|
||||
Vector3 value2, Vector3 tangent2, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount,
|
||||
out result);
|
||||
Hermite(ref value1, ref tangent1, ref value2, ref tangent2, amount, out result);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void Hermite(ref Vector3 value1, ref Vector3 tangent1,
|
||||
ref Vector3 value2, ref Vector3 tangent2, float amount, out Vector3 result)
|
||||
{
|
||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X,
|
||||
tangent2.X, amount);
|
||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y,
|
||||
tangent2.Y, amount);
|
||||
result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z,
|
||||
tangent2.Z, amount);
|
||||
result.X = MathHelper.Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper.Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
result.Z = MathHelper.Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount);
|
||||
}
|
||||
#endregion
|
||||
|
||||
@ -507,8 +495,7 @@ namespace ANX.Framework
|
||||
#endregion
|
||||
|
||||
#region SmoothStep
|
||||
public static Vector3 SmoothStep(Vector3 value1, Vector3 value2,
|
||||
float amount)
|
||||
public static Vector3 SmoothStep(Vector3 value1, Vector3 value2, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
Vector3.SmoothStep(ref value1, ref value2, amount, out result);
|
||||
@ -549,35 +536,39 @@ namespace ANX.Framework
|
||||
|
||||
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 y = 2* (rotation.Z * value.X - rotation.X * value.Z);
|
||||
float z = 2* (rotation.X * value.Y - rotation.Y * value.X);
|
||||
float x = 2 * (rotation.Y * value.Z - rotation.Z * value.Y);
|
||||
float y = 2 * (rotation.Z * value.X - rotation.X * value.Z);
|
||||
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.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);
|
||||
}
|
||||
|
||||
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++)
|
||||
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++)
|
||||
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;
|
||||
for (int i = sourceIndex; i < length; i++, 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;
|
||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||
@ -604,7 +595,8 @@ namespace ANX.Framework
|
||||
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;
|
||||
for (int i = sourceIndex; i < length; i++, destinationIndex++)
|
||||
@ -618,8 +610,7 @@ namespace ANX.Framework
|
||||
|
||||
public static Vector3 operator +(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return new Vector3(value1.X + value2.X, value1.Y + value2.Y,
|
||||
value1.Z + value2.Z);
|
||||
return new Vector3(value1.X + value2.X, value1.Y + value2.Y, value1.Z + value2.Z);
|
||||
}
|
||||
|
||||
public static Vector3 operator /(Vector3 value1, float divider)
|
||||
@ -709,7 +700,8 @@ namespace ANX.Framework
|
||||
#region GetHashCode
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.X.GetHashCode() + this.Y.GetHashCode() +
|
||||
return this.X.GetHashCode() +
|
||||
this.Y.GetHashCode() +
|
||||
this.Z.GetHashCode();
|
||||
}
|
||||
#endregion
|
||||
@ -723,13 +715,6 @@ namespace ANX.Framework
|
||||
return "{X:" + X.ToString(culture) +
|
||||
" Y:" + Y.ToString(culture) +
|
||||
" Z:" + Z.ToString(culture) + "}";
|
||||
|
||||
//return string.Format(culture, "{{X:{0} Y:{1} Z:{2}}}", new object[]
|
||||
//{
|
||||
// this.X.ToString(culture),
|
||||
// this.Y.ToString(culture),
|
||||
// this.Z.ToString(culture)
|
||||
//});
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
@ -433,7 +433,26 @@ namespace ANX.Framework
|
||||
|
||||
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)
|
||||
@ -460,7 +479,26 @@ namespace ANX.Framework
|
||||
|
||||
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)
|
||||
@ -487,13 +525,25 @@ namespace ANX.Framework
|
||||
|
||||
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 y = 2 * (rotation.Z * value.X - rotation.X * value.Z);
|
||||
float z = 2 * (rotation.X * value.Y - rotation.Y * value.X);
|
||||
float twoX = rotation.X + rotation.X;
|
||||
float twoY = rotation.Y + rotation.Y;
|
||||
float twoZ = rotation.Z + rotation.Z;
|
||||
|
||||
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.Z = value.Z + z * rotation.W + (rotation.X * y - rotation.Y * x);
|
||||
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 = value.W;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user