1
0
mirror of https://github.com/Halofreak1990/XFXFramework synced 2024-12-26 13:49:34 +01:00

Added missing TypeInfos to XFX namespace

Removed excess whitespace
This commit is contained in:
Tom Lint 2013-10-03 13:54:55 +02:00
parent b0dd58a08b
commit 7c5bc83237
9 changed files with 1194 additions and 1062 deletions

View File

@ -33,6 +33,7 @@
#include <System/Math.h> #include <System/Math.h>
#include <System/Single.h> #include <System/Single.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <sassert.h> #include <sassert.h>
@ -41,6 +42,7 @@ using namespace System;
namespace XFX namespace XFX
{ {
const int BoundingBox::CornerCount = 8; const int BoundingBox::CornerCount = 8;
const Type BoundingBoxTypeInfo("BoundingBox", "XFX::BoundingBox", TypeCode::Object);
BoundingBox::BoundingBox(const Vector3 min, const Vector3 max) BoundingBox::BoundingBox(const Vector3 min, const Vector3 max)
: Max(max), Min(min) : Max(max), Min(min)
@ -67,17 +69,25 @@ namespace XFX
void BoundingBox::Contains(BoundingBox box, out ContainmentType_t& result) const void BoundingBox::Contains(BoundingBox box, out ContainmentType_t& result) const
{ {
if( Max.X < box.Min.X || Min.X > box.Max.X ) if( Max.X < box.Min.X || Min.X > box.Max.X )
{
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
}
if( Max.Y < box.Min.Y || Min.Y > box.Max.Y ) if( Max.Y < box.Min.Y || Min.Y > box.Max.Y )
{
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
}
if( Max.Z < box.Min.Z || Min.Z > box.Max.Z ) if( Max.Z < box.Min.Z || Min.Z > box.Max.Z )
{
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
}
if( Min.X <= box.Min.X && box.Max.X <= Max.X && Min.Y <= box.Min.Y && if( Min.X <= box.Min.X && box.Max.X <= Max.X && Min.Y <= box.Min.Y &&
box.Max.Y <= Max.Y && Min.Z <= box.Min.Z && box.Max.Z <= Max.Z ) box.Max.Y <= Max.Y && Min.Z <= box.Min.Z && box.Max.Z <= Max.Z )
{
result = ContainmentType::Contains; result = ContainmentType::Contains;
}
result = ContainmentType::Intersects; result = ContainmentType::Intersects;
} }
@ -104,14 +114,18 @@ namespace XFX
float radius = sphere.Radius; float radius = sphere.Radius;
if(dist > (radius * radius)) if(dist > (radius * radius))
{
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
}
if(Min.X + radius <= sphere.Center.X && sphere.Center.X <= Max.X - radius && if(Min.X + radius <= sphere.Center.X && sphere.Center.X <= Max.X - radius &&
Max.X - Min.X > radius && Min.Y + radius <= sphere.Center.Y && Max.X - Min.X > radius && Min.Y + radius <= sphere.Center.Y &&
sphere.Center.Y <= Max.Y - radius && Max.Y - Min.Y > radius && sphere.Center.Y <= Max.Y - radius && Max.Y - Min.Y > radius &&
Min.Z + radius <= sphere.Center.Z && sphere.Center.Z <= Max.Z - radius && Min.Z + radius <= sphere.Center.Z && sphere.Center.Z <= Max.Z - radius &&
Max.X - Min.X > radius) Max.X - Min.X > radius)
{
result = ContainmentType::Contains; result = ContainmentType::Contains;
}
result = ContainmentType::Intersects; result = ContainmentType::Intersects;
} }
@ -120,7 +134,9 @@ namespace XFX
{ {
if(Min.X <= vector.X && vector.X <= Max.X && Min.Y <= vector.Y && if(Min.X <= vector.X && vector.X <= Max.X && Min.Y <= vector.Y &&
vector.Y <= Max.Y && Min.Z <= vector.Z && vector.Z <= Max.Z) vector.Y <= Max.Y && Min.Z <= vector.Z && vector.Z <= Max.Z)
{
return ContainmentType::Contains; return ContainmentType::Contains;
}
return ContainmentType::Disjoint; return ContainmentType::Disjoint;
} }
@ -129,7 +145,9 @@ namespace XFX
{ {
if (Min.X <= vector.X && vector.X <= Max.X && Min.Y <= vector.Y && if (Min.X <= vector.X && vector.X <= Max.X && Min.Y <= vector.Y &&
vector.Y <= Max.Y && Min.Z <= vector.Z && vector.Z <= Max.Z) vector.Y <= Max.Y && Min.Z <= vector.Z && vector.Z <= Max.Z)
{
result = ContainmentType::Contains; result = ContainmentType::Contains;
}
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
} }
@ -193,9 +211,9 @@ namespace XFX
return Min.GetHashCode() + Max.GetHashCode(); return Min.GetHashCode() + Max.GetHashCode();
} }
int BoundingBox::GetType() const Type& BoundingBox::GetType()
{ {
// TODO: implement return BoundingBoxTypeInfo;
} }
bool BoundingBox::Intersects(BoundingBox box) const bool BoundingBox::Intersects(BoundingBox box) const
@ -208,10 +226,14 @@ namespace XFX
void BoundingBox::Intersects(BoundingBox box, out bool& result) const void BoundingBox::Intersects(BoundingBox box, out bool& result) const
{ {
if (Max.X < box.Min.X || Min.X > box.Max.X) if (Max.X < box.Min.X || Min.X > box.Max.X)
{
result = false; result = false;
}
if (Max.Y < box.Min.Y || Min.Y > box.Max.Y) if (Max.Y < box.Min.Y || Min.Y > box.Max.Y)
{
result = false; result = false;
}
result = (Max.Z >= box.Min.Z && Min.Z <= box.Max.Z); result = (Max.Z >= box.Min.Z && Min.Z <= box.Max.Z);
} }

View File

@ -169,16 +169,19 @@ namespace XFX
break; break;
} }
} }
if (!flag) if (!flag)
{ {
return ContainmentType::Contains; return ContainmentType::Contains;
} }
return ContainmentType::Intersects; return ContainmentType::Intersects;
} }
ContainmentType_t BoundingFrustum::Contains(BoundingFrustum frustrum) ContainmentType_t BoundingFrustum::Contains(BoundingFrustum frustrum)
{ {
ContainmentType_t disjoint = ContainmentType::Disjoint; ContainmentType_t disjoint = ContainmentType::Disjoint;
if (Intersects(frustrum)) if (Intersects(frustrum))
{ {
disjoint = ContainmentType::Contains; disjoint = ContainmentType::Contains;
@ -190,6 +193,7 @@ namespace XFX
} }
} }
} }
return disjoint; return disjoint;
} }
@ -198,6 +202,7 @@ namespace XFX
Vector3 center = sphere.Center; Vector3 center = sphere.Center;
float radius = sphere.Radius; float radius = sphere.Radius;
int num2 = 0; int num2 = 0;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num5 = ((planes[i].Normal.X * center.X) + (planes[i].Normal.Y * center.Y)) + (planes[i].Normal.Z * center.Z); float num5 = ((planes[i].Normal.X * center.X) + (planes[i].Normal.Y * center.Y)) + (planes[i].Normal.Z * center.Z);
@ -211,10 +216,12 @@ namespace XFX
num2++; num2++;
} }
} }
if (num2 != 6) if (num2 != 6)
{ {
return ContainmentType::Intersects; return ContainmentType::Intersects;
} }
return ContainmentType::Contains; return ContainmentType::Contains;
} }
@ -223,17 +230,20 @@ namespace XFX
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num2 = (((planes[i].Normal.X * point.X) + (planes[i].Normal.Y * point.Y)) + (planes[i].Normal.Z * point.Z)) + planes[i].D; float num2 = (((planes[i].Normal.X * point.X) + (planes[i].Normal.Y * point.Y)) + (planes[i].Normal.Z * point.Z)) + planes[i].D;
if (num2 > 1E-05f) if (num2 > 1E-05f)
{ {
return ContainmentType::Disjoint; return ContainmentType::Disjoint;
} }
} }
return ContainmentType::Contains; return ContainmentType::Contains;
} }
void BoundingFrustum::Contains(BoundingBox box, out ContainmentType_t& result) void BoundingFrustum::Contains(BoundingBox box, out ContainmentType_t& result)
{ {
bool flag = false; bool flag = false;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
switch (box.Intersects(planes[i])) switch (box.Intersects(planes[i]))
@ -247,6 +257,7 @@ namespace XFX
break; break;
} }
} }
result = flag ? ContainmentType::Intersects : ContainmentType::Contains; result = flag ? ContainmentType::Intersects : ContainmentType::Contains;
} }
@ -255,20 +266,24 @@ namespace XFX
Vector3 center = sphere.Center; Vector3 center = sphere.Center;
float radius = sphere.Radius; float radius = sphere.Radius;
int num2 = 0; int num2 = 0;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num5 = ((planes[i].Normal.X * center.X) + (planes[i].Normal.Y * center.Y)) + (planes[i].Normal.Z * center.Z); float num5 = ((planes[i].Normal.X * center.X) + (planes[i].Normal.Y * center.Y)) + (planes[i].Normal.Z * center.Z);
float num3 = num5 + planes[i].D; float num3 = num5 + planes[i].D;
if (num3 > radius) if (num3 > radius)
{ {
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
return; return;
} }
if (num3 < -radius) if (num3 < -radius)
{ {
num2++; num2++;
} }
} }
result = (num2 == 6) ? ContainmentType::Contains : ContainmentType::Intersects; result = (num2 == 6) ? ContainmentType::Contains : ContainmentType::Intersects;
} }
@ -277,12 +292,14 @@ namespace XFX
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num2 = (((planes[i].Normal.X * point.X) + (planes[i].Normal.Y * point.Y)) + (planes[i].Normal.Z * point.Z)) + planes[i].D; float num2 = (((planes[i].Normal.X * point.X) + (planes[i].Normal.Y * point.Y)) + (planes[i].Normal.Z * point.Z)) + planes[i].D;
if (num2 > 1E-05f) if (num2 > 1E-05f)
{ {
result = ContainmentType::Disjoint; result = ContainmentType::Disjoint;
return; return;
} }
} }
result = ContainmentType::Contains; result = ContainmentType::Contains;
} }
@ -306,8 +323,10 @@ namespace XFX
sassert(corners != null, "corners cannot be null."); sassert(corners != null, "corners cannot be null.");
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{
corners[i] = cornerArray[i]; corners[i] = cornerArray[i];
} }
}
int BoundingFrustum::GetHashCode() const int BoundingFrustum::GetHashCode() const
{ {
@ -343,10 +362,12 @@ namespace XFX
PlaneIntersectionType_t BoundingFrustum::Intersects(Plane plane) PlaneIntersectionType_t BoundingFrustum::Intersects(Plane plane)
{ {
int num = 0; int num = 0;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
float num3 = 0; float num3 = 0;
Vector3::Dot(cornerArray[i], plane.Normal, num3); Vector3::Dot(cornerArray[i], plane.Normal, num3);
if ((num3 + plane.D) > 0) if ((num3 + plane.D) > 0)
{ {
num |= 1; num |= 1;
@ -355,15 +376,18 @@ namespace XFX
{ {
num |= 2; num |= 2;
} }
if (num == 3) if (num == 3)
{ {
return PlaneIntersectionType::Intersecting; return PlaneIntersectionType::Intersecting;
} }
} }
if (num != 1) if (num != 1)
{ {
return PlaneIntersectionType::Back; return PlaneIntersectionType::Back;
} }
return PlaneIntersectionType::Front; return PlaneIntersectionType::Front;
} }
@ -387,10 +411,12 @@ namespace XFX
void BoundingFrustum::Intersects(Plane plane, out PlaneIntersectionType_t& result) void BoundingFrustum::Intersects(Plane plane, out PlaneIntersectionType_t& result)
{ {
int num = 0; int num = 0;
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
float num3 = 0; float num3 = 0;
Vector3::Dot(cornerArray[i], plane.Normal, num3); Vector3::Dot(cornerArray[i], plane.Normal, num3);
if ((num3 + plane.D) > 0) if ((num3 + plane.D) > 0)
{ {
num |= 1; num |= 1;
@ -399,18 +425,21 @@ namespace XFX
{ {
num |= 2; num |= 2;
} }
if (num == 3) if (num == 3)
{ {
result = PlaneIntersectionType::Intersecting; result = PlaneIntersectionType::Intersecting;
return; return;
} }
} }
result = (num == 1) ? PlaneIntersectionType::Front : PlaneIntersectionType::Back; result = (num == 1) ? PlaneIntersectionType::Front : PlaneIntersectionType::Back;
} }
void BoundingFrustum::Intersects(Ray ray, out float& result) void BoundingFrustum::Intersects(Ray ray, out float& result)
{ {
ContainmentType_t type = Contains(ray.Position); ContainmentType_t type = Contains(ray.Position);
if (type == ContainmentType::Contains) if (type == ContainmentType::Contains)
{ {
result = 0.0f; result = 0.0f;
@ -420,6 +449,7 @@ namespace XFX
float minValue = Single::MinValue; float minValue = Single::MinValue;
float maxValue = Single::MaxValue; float maxValue = Single::MaxValue;
result = 0; result = 0;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num3 = 0; float num3 = 0;
@ -428,6 +458,7 @@ namespace XFX
Vector3::Dot(ray.Direction, normal, num6); Vector3::Dot(ray.Direction, normal, num6);
Vector3::Dot(ray.Position, normal, num3); Vector3::Dot(ray.Position, normal, num3);
num3 += planes[i].D; num3 += planes[i].D;
if (Math::Abs(num6) < 1E-05f) if (Math::Abs(num6) < 1E-05f)
{ {
if (num3 > 0.0f) if (num3 > 0.0f)
@ -438,12 +469,14 @@ namespace XFX
else else
{ {
float num = -num3 / num6; float num = -num3 / num6;
if (num6 < 0.0f) if (num6 < 0.0f)
{ {
if (num > maxValue) if (num > maxValue)
{ {
return; return;
} }
if (num > minValue) if (num > minValue)
{ {
minValue = num; minValue = num;
@ -455,6 +488,7 @@ namespace XFX
{ {
return; return;
} }
if (num < maxValue) if (num < maxValue)
{ {
maxValue = num; maxValue = num;
@ -462,7 +496,9 @@ namespace XFX
} }
} }
} }
float num7 = (minValue >= 0) ? minValue : maxValue; float num7 = (minValue >= 0) ? minValue : maxValue;
if (num7 >= 0) if (num7 >= 0)
{ {
result = float(num7); result = float(num7);
@ -497,12 +533,14 @@ namespace XFX
planes[1].Normal.Y = -value.M24 + value.M23; planes[1].Normal.Y = -value.M24 + value.M23;
planes[1].Normal.Z = -value.M34 + value.M33; planes[1].Normal.Z = -value.M34 + value.M33;
planes[1].D = -value.M44 + value.M43; planes[1].D = -value.M44 + value.M43;
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
float num2 = planes[i].Normal.Length(); float num2 = planes[i].Normal.Length();
planes[i].Normal = (planes[i].Normal / num2); planes[i].Normal = (planes[i].Normal / num2);
planes[i].D /= num2; planes[i].D /= num2;
} }
Ray ray = ComputeIntersectionLine(planes[0], planes[2]); Ray ray = ComputeIntersectionLine(planes[0], planes[2]);
cornerArray[0] = ComputeIntersection(planes[4], ray); cornerArray[0] = ComputeIntersection(planes[4], ray);
cornerArray[3] = ComputeIntersection(planes[5], ray); cornerArray[3] = ComputeIntersection(planes[5], ray);

View File

@ -27,9 +27,12 @@
#include <BoundingSphere.h> #include <BoundingSphere.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
namespace XFX namespace XFX
{ {
const Type BoundingSphereTypeInfo("BoundingSphere", "XFX::BoundingSphere", TypeCode::Object);
BoundingSphere::BoundingSphere(const Vector3 center, const float radius) BoundingSphere::BoundingSphere(const Vector3 center, const float radius)
: Center(center), Radius(radius) : Center(center), Radius(radius)
{ {
@ -55,6 +58,11 @@ namespace XFX
return (*this == other); return (*this == other);
} }
const Type& BoundingSphere::GetType()
{
return BoundingSphereTypeInfo;
}
int BoundingSphere::GetHashCode() const int BoundingSphere::GetHashCode() const
{ {
return Center.GetHashCode() + (int)Radius; return Center.GetHashCode() + (int)Radius;

View File

@ -27,6 +27,7 @@
#include <System/Math.h> #include <System/Math.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <MathHelper.h> #include <MathHelper.h>
#include <Matrix.h> #include <Matrix.h>
#include <Plane.h> #include <Plane.h>
@ -40,6 +41,7 @@ using namespace System;
namespace XFX namespace XFX
{ {
const Matrix Matrix::Identity = Matrix(1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f); const Matrix Matrix::Identity = Matrix(1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f, 0, 0, 0, 0, 1.0f);
const Type MatrixTypeInfo("Matrix", "XFX::Matrix", TypeCode::Object);
Matrix::Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) Matrix::Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
: M11(m11), M12(m12), M13(m13), M14(m14), : M11(m11), M12(m12), M13(m13), M14(m14),
@ -192,6 +194,7 @@ namespace XFX
vector.Y = objectPosition.Y - cameraPosition.Y; vector.Y = objectPosition.Y - cameraPosition.Y;
vector.Z = objectPosition.Z - cameraPosition.Z; vector.Z = objectPosition.Z - cameraPosition.Z;
float num = vector.LengthSquared(); float num = vector.LengthSquared();
if (num < 0.0001f) if (num < 0.0001f)
{ {
vector = (cameraForwardVector != null) ? -Vector3(cameraForwardVector->X, cameraForwardVector->Y, cameraForwardVector->Z) : Vector3::Forward; vector = (cameraForwardVector != null) ? -Vector3(cameraForwardVector->X, cameraForwardVector->Y, cameraForwardVector->Z) : Vector3::Forward;
@ -200,6 +203,7 @@ namespace XFX
{ {
Vector3::Multiply(vector, (float) (1.0f / ((float) Math::Sqrt((double) num))), vector); Vector3::Multiply(vector, (float) (1.0f / ((float) Math::Sqrt((double) num))), vector);
} }
Vector3::Cross(cameraUpVector, vector, vector3); Vector3::Cross(cameraUpVector, vector, vector3);
vector3.Normalize(); vector3.Normalize();
Vector3::Cross(vector, vector3, vector2); Vector3::Cross(vector, vector3, vector2);
@ -238,6 +242,7 @@ namespace XFX
vector2.Y = objectPosition.Y - cameraPosition.Y; vector2.Y = objectPosition.Y - cameraPosition.Y;
vector2.Z = objectPosition.Z - cameraPosition.Z; vector2.Z = objectPosition.Z - cameraPosition.Z;
float num2 = vector2.LengthSquared(); float num2 = vector2.LengthSquared();
if (num2 < 0.0001f) if (num2 < 0.0001f)
{ {
vector2 = (cameraForwardVector != null) ? -Vector3(cameraForwardVector->X, cameraForwardVector->Y, cameraForwardVector->Z) : Vector3::Forward; vector2 = (cameraForwardVector != null) ? -Vector3(cameraForwardVector->X, cameraForwardVector->Y, cameraForwardVector->Z) : Vector3::Forward;
@ -246,14 +251,17 @@ namespace XFX
{ {
Vector3::Multiply(vector2, (float) (1.0f / ((float) Math::Sqrt((double) num2))), vector2); Vector3::Multiply(vector2, (float) (1.0f / ((float) Math::Sqrt((double) num2))), vector2);
} }
Vector3 vector4 = rotateAxis; Vector3 vector4 = rotateAxis;
Vector3::Dot(rotateAxis, vector2, num); Vector3::Dot(rotateAxis, vector2, num);
if (Math::Abs(num) > 0.9982547f) if (Math::Abs(num) > 0.9982547f)
{ {
if (objectForwardVector != null) if (objectForwardVector != null)
{ {
vector = Vector3(objectForwardVector->X, objectForwardVector->Y, objectForwardVector->Z); vector = Vector3(objectForwardVector->X, objectForwardVector->Y, objectForwardVector->Z);
Vector3::Dot(rotateAxis, vector, num); Vector3::Dot(rotateAxis, vector, num);
if (Math::Abs(num) > 0.9982547f) if (Math::Abs(num) > 0.9982547f)
{ {
num = ((rotateAxis.X * Vector3::Forward.X) + (rotateAxis.Y * Vector3::Forward.Y)) + (rotateAxis.Z * Vector3::Forward.Z); num = ((rotateAxis.X * Vector3::Forward.X) + (rotateAxis.Y * Vector3::Forward.Y)) + (rotateAxis.Z * Vector3::Forward.Z);
@ -265,6 +273,7 @@ namespace XFX
num = ((rotateAxis.X * Vector3::Forward.X) + (rotateAxis.Y * Vector3::Forward.Y)) + (rotateAxis.Z * Vector3::Forward.Z); num = ((rotateAxis.X * Vector3::Forward.X) + (rotateAxis.Y * Vector3::Forward.Y)) + (rotateAxis.Z * Vector3::Forward.Z);
vector = (Math::Abs(num) > 0.9982547f) ? Vector3::Right : Vector3::Forward; vector = (Math::Abs(num) > 0.9982547f) ? Vector3::Right : Vector3::Forward;
} }
Vector3::Cross(rotateAxis, vector, vector3); Vector3::Cross(rotateAxis, vector, vector3);
vector3.Normalize(); vector3.Normalize();
Vector3::Cross(vector3, rotateAxis, vector); Vector3::Cross(vector3, rotateAxis, vector);
@ -277,6 +286,7 @@ namespace XFX
Vector3::Cross(vector3, vector4, vector); Vector3::Cross(vector3, vector4, vector);
vector.Normalize(); vector.Normalize();
} }
result.M11 = vector3.X; result.M11 = vector3.X;
result.M12 = vector3.Y; result.M12 = vector3.Y;
result.M13 = vector3.Z; result.M13 = vector3.Z;
@ -305,7 +315,9 @@ namespace XFX
void Matrix::CreateFromAxisAngle(Vector3 axis, float angle, out Matrix& result) void Matrix::CreateFromAxisAngle(Vector3 axis, float angle, out Matrix& result)
{ {
if(axis.LengthSquared() != 1.0f) if(axis.LengthSquared() != 1.0f)
{
axis.Normalize(); axis.Normalize();
}
float x = axis.X; float x = axis.X;
float y = axis.Y; float y = axis.Y;
@ -867,26 +879,44 @@ namespace XFX
translation.Y = M42; translation.Y = M42;
translation.Z = M43; translation.Z = M43;
float xs, ys, zs; float xs, ys, zs;
if (Math::Sign(M11 * M12 * M13 * M14) < 0) if (Math::Sign(M11 * M12 * M13 * M14) < 0)
{
xs = -1.0f; xs = -1.0f;
}
else else
{
xs = 1.0f; xs = 1.0f;
}
if (Math::Sign(M21 * M22 * M23 * M24) < 0) if (Math::Sign(M21 * M22 * M23 * M24) < 0)
{
ys = -1.0f; ys = -1.0f;
}
else else
{
ys = 1.0f; ys = 1.0f;
}
if (Math::Sign(M31 * M32 * M33 * M34) < 0) if (Math::Sign(M31 * M32 * M33 * M34) < 0)
{
zs = -1.0f; zs = -1.0f;
}
else else
{
zs = 1.0f; zs = 1.0f;
}
scale.X = xs * (float)Math::Sqrt(M11 * M11 + M12 * M12 + M13 * M13); scale.X = xs * (float)Math::Sqrt(M11 * M11 + M12 * M12 + M13 * M13);
scale.Y = ys * (float)Math::Sqrt(M21 * M21 + M22 * M22 + M23 * M23); scale.Y = ys * (float)Math::Sqrt(M21 * M21 + M22 * M22 + M23 * M23);
scale.Z = zs * (float)Math::Sqrt(M31 * M31 + M32 * M32 + M33 * M33); scale.Z = zs * (float)Math::Sqrt(M31 * M31 + M32 * M32 + M33 * M33);
if (scale.X == 0.0 || scale.Y == 0.0 || scale.Z == 0.0) if (scale.X == 0.0 || scale.Y == 0.0 || scale.Z == 0.0)
{ {
rotation = Quaternion::Identity; rotation = Quaternion::Identity;
return false; return false;
} }
Matrix m1 = Matrix(M11/scale.X, M12/scale.X, M13/scale.X, 0, Matrix m1 = Matrix(M11/scale.X, M12/scale.X, M13/scale.X, 0,
M21/scale.Y, M22/scale.Y, M23/scale.Y, 0, M21/scale.Y, M22/scale.Y, M23/scale.Y, 0,
M31/scale.Z, M32/scale.Z, M33/scale.Z, 0, M31/scale.Z, M32/scale.Z, M33/scale.Z, 0,
@ -966,9 +996,9 @@ namespace XFX
(int)M31 ^ (int)M32 ^ (int)M33 ^ (int)M34 ^ (int)M41 ^ (int)M42 ^ (int)M43 ^ (int)M44); (int)M31 ^ (int)M32 ^ (int)M33 ^ (int)M34 ^ (int)M41 ^ (int)M42 ^ (int)M43 ^ (int)M44);
} }
int Matrix::GetType() const Type& Matrix::GetType()
{ {
// TODO: implement return MatrixTypeInfo;
} }
void Matrix::Invert(Matrix matrix, out Matrix& result) void Matrix::Invert(Matrix matrix, out Matrix& result)

View File

@ -157,12 +157,16 @@ namespace XFX
float dot = (Normal.X * max.X) + (Normal.Y * max.Y) + (Normal.Z * max.Z); float dot = (Normal.X * max.X) + (Normal.Y * max.Y) + (Normal.Z * max.Z);
if(dot + D > 0.0f) if(dot + D > 0.0f)
{
result = PlaneIntersectionType::Front; result = PlaneIntersectionType::Front;
}
dot = (Normal.X * min.X) + (Normal.Y * min.Y) + (Normal.Z * min.Z); dot = (Normal.X * min.X) + (Normal.Y * min.Y) + (Normal.Z * min.Z);
if(dot + D < 0.0f) if(dot + D < 0.0f)
{
result = PlaneIntersectionType::Back; result = PlaneIntersectionType::Back;
}
result = PlaneIntersectionType::Intersecting; result = PlaneIntersectionType::Intersecting;
} }
@ -179,10 +183,14 @@ namespace XFX
float dot = (sphere.Center.X * Normal.X) + (sphere.Center.Y * Normal.Y) + (sphere.Center.Z * Normal.Z) + D; float dot = (sphere.Center.X * Normal.X) + (sphere.Center.Y * Normal.Y) + (sphere.Center.Z * Normal.Z) + D;
if(dot > sphere.Radius) if(dot > sphere.Radius)
{
result = PlaneIntersectionType::Front; result = PlaneIntersectionType::Front;
}
if(dot < -sphere.Radius) if(dot < -sphere.Radius)
{
result = PlaneIntersectionType::Back; result = PlaneIntersectionType::Back;
}
result = PlaneIntersectionType::Intersecting; result = PlaneIntersectionType::Intersecting;
} }

View File

@ -33,6 +33,7 @@
#include <System/FrameworkResources.h> #include <System/FrameworkResources.h>
#include <System/Math.h> #include <System/Math.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <sassert.h> #include <sassert.h>
@ -42,29 +43,26 @@ namespace XFX
{ {
const Vector2 Vector2::One = Vector2(1, 1); const Vector2 Vector2::One = Vector2(1, 1);
const Vector2 Vector2::Zero = Vector2(0, 0); const Vector2 Vector2::Zero = Vector2(0, 0);
const Type Vector2TypeInfo("Vector2", "XFX::Vector2", TypeCode::Object);
Vector2::Vector2(const float x, const float y) Vector2::Vector2(const float x, const float y)
: X(x), Y(y)
{ {
X = x;
Y = y;
} }
Vector2::Vector2(const float value) Vector2::Vector2(const float value)
: X(value), Y(value)
{ {
X = value;
Y = value;
} }
Vector2::Vector2(const Vector2 &obj) Vector2::Vector2(const Vector2 &obj)
: X(obj.X), Y(obj.Y)
{ {
X = obj.X;
Y = obj.Y;
} }
Vector2::Vector2() Vector2::Vector2()
: X(0), Y(0)
{ {
X = 0;
Y = 0;
} }
Vector2 Vector2::Add(const Vector2 value1, const Vector2 value2) Vector2 Vector2::Add(const Vector2 value1, const Vector2 value2)
@ -166,9 +164,9 @@ namespace XFX
return (int)X ^ (int)Y; return (int)X ^ (int)Y;
} }
int Vector2::GetType() const Type& Vector2::GetType()
{ {
// TODO: implement return Vector2TypeInfo;
} }
Vector2 Vector2::Hermite(const Vector2 value1, const Vector2 tangent1, const Vector2 value2, const Vector2 tangent2, const float amount) Vector2 Vector2::Hermite(const Vector2 value1, const Vector2 tangent1, const Vector2 value2, const Vector2 tangent2, const float amount)
@ -261,8 +259,12 @@ namespace XFX
void Vector2::Normalize() void Vector2::Normalize()
{ {
float length = Length(); float length = Length();
if(length == 0) if(length == 0)
{
return; return;
}
float num = 1 / length; float num = 1 / length;
X *= num; X *= num;
Y *= num; Y *= num;
@ -278,8 +280,12 @@ namespace XFX
void Vector2::Normalize(const Vector2& value, out Vector2& result) void Vector2::Normalize(const Vector2& value, out Vector2& result)
{ {
float length = value.Length(); float length = value.Length();
if (length == 0) if (length == 0)
{
return; return;
}
float num = 1 / length; float num = 1 / length;
result.X = value.X * num; result.X = value.X * num;
result.Y = value.Y * num; result.Y = value.Y * num;

View File

@ -34,6 +34,7 @@
#include <System/Array.h> #include <System/Array.h>
#include <System/Math.h> #include <System/Math.h>
#include <System/String.h> #include <System/String.h>
#include <System/Type.h>
#include <sassert.h> #include <sassert.h>
@ -52,6 +53,7 @@ namespace XFX
const Vector3 Vector3::UnitZ = Vector3(0, 0, 1); const Vector3 Vector3::UnitZ = Vector3(0, 0, 1);
const Vector3 Vector3::Up = Vector3(0, 1, 0); const Vector3 Vector3::Up = Vector3(0, 1, 0);
const Vector3 Vector3::Zero = Vector3(0, 0, 0); const Vector3 Vector3::Zero = Vector3(0, 0, 0);
const Type Vector3TypeInfo("Vector3", "XFX::Vector3", TypeCode::Object);
Vector3::Vector3(float value) Vector3::Vector3(float value)
: X(value), Y(value), Z(value) : X(value), Y(value), Z(value)
@ -243,9 +245,9 @@ namespace XFX
return ((int)X ^ (int)Y ^ (int)Z); return ((int)X ^ (int)Y ^ (int)Z);
} }
int Vector3::GetType() const Type& Vector3::GetType()
{ {
// TODO: implement return Vector3TypeInfo;
} }
Vector3 Vector3::Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount) Vector3 Vector3::Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, Vector3 tangent2, float amount)
@ -359,8 +361,12 @@ namespace XFX
void Vector3::Normalize() void Vector3::Normalize()
{ {
float length = Length(); float length = Length();
if(length == 0) if(length == 0)
{
return; return;
}
float num = 1 / length; float num = 1 / length;
X *= num; X *= num;
Y *= num; Y *= num;
@ -371,8 +377,12 @@ namespace XFX
{ {
Vector3 result; Vector3 result;
float length = value.Length(); float length = value.Length();
if(length == 0) if(length == 0)
{
return Vector3::Zero; return Vector3::Zero;
}
float num = 1 / length; float num = 1 / length;
result.X *= num; result.X *= num;
result.Y *= num; result.Y *= num;
@ -383,8 +393,12 @@ namespace XFX
void Vector3::Normalize(Vector3 value, out Vector3& result) void Vector3::Normalize(Vector3 value, out Vector3& result)
{ {
float length = value.Length(); float length = value.Length();
if(length == 0) if(length == 0)
{
return; return;
}
float num = 1 / length; float num = 1 / length;
result.X *= num; result.X *= num;
result.Y *= num; result.Y *= num;

View File

@ -33,6 +33,7 @@
#include <Vector4.h> #include <Vector4.h>
#include <System/Array.h> #include <System/Array.h>
#include <System/Math.h> #include <System/Math.h>
#include <System/Type.h>
#include <sassert.h> #include <sassert.h>
@ -46,6 +47,7 @@ namespace XFX
const Vector4 Vector4::UnitY = Vector4(0,1,0,0); const Vector4 Vector4::UnitY = Vector4(0,1,0,0);
const Vector4 Vector4::UnitZ = Vector4(0,0,1,0); const Vector4 Vector4::UnitZ = Vector4(0,0,1,0);
const Vector4 Vector4::Zero = Vector4(0,0,0,0); const Vector4 Vector4::Zero = Vector4(0,0,0,0);
const Type Vector4TypeInfo("Vector4", "XFX::Vector4", TypeCode::Object);
Vector4::Vector4(float value) Vector4::Vector4(float value)
: X(value), Y(value), Z(value), W(value) : X(value), Y(value), Z(value), W(value)
@ -209,9 +211,9 @@ namespace XFX
return ((int)X ^ (int)Y ^ (int)Z ^ (int)W); return ((int)X ^ (int)Y ^ (int)Z ^ (int)W);
} }
int Vector4::GetType() const Type& Vector4::GetType()
{ {
// TODO: implement return Vector4TypeInfo;
} }
Vector4 Vector4::Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount) Vector4 Vector4::Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount)
@ -330,8 +332,12 @@ namespace XFX
void Vector4::Normalize() void Vector4::Normalize()
{ {
float length = Length(); float length = Length();
if(length == 0) if(length == 0)
{
return; return;
}
float num = 1 / length; float num = 1 / length;
X *= num; X *= num;
Y *= num; Y *= num;