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:
parent
b0dd58a08b
commit
7c5bc83237
@ -33,6 +33,7 @@
|
||||
#include <System/Math.h>
|
||||
#include <System/Single.h>
|
||||
#include <System/String.h>
|
||||
#include <System/Type.h>
|
||||
|
||||
#include <sassert.h>
|
||||
|
||||
@ -41,6 +42,7 @@ using namespace System;
|
||||
namespace XFX
|
||||
{
|
||||
const int BoundingBox::CornerCount = 8;
|
||||
const Type BoundingBoxTypeInfo("BoundingBox", "XFX::BoundingBox", TypeCode::Object);
|
||||
|
||||
BoundingBox::BoundingBox(const Vector3 min, const Vector3 max)
|
||||
: Max(max), Min(min)
|
||||
@ -66,20 +68,28 @@ namespace XFX
|
||||
|
||||
void BoundingBox::Contains(BoundingBox box, out ContainmentType_t& result) const
|
||||
{
|
||||
if( Max.X < box.Min.X || Min.X > box.Max.X )
|
||||
result = ContainmentType::Disjoint;
|
||||
|
||||
if( Max.Y < box.Min.Y || Min.Y > box.Max.Y )
|
||||
result = ContainmentType::Disjoint;
|
||||
|
||||
if( Max.Z < box.Min.Z || Min.Z > box.Max.Z )
|
||||
result = ContainmentType::Disjoint;
|
||||
|
||||
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 )
|
||||
result = ContainmentType::Contains;
|
||||
|
||||
result = ContainmentType::Intersects;
|
||||
if( Max.X < box.Min.X || Min.X > box.Max.X )
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
if( Max.Y < box.Min.Y || Min.Y > box.Max.Y )
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
if( Max.Z < box.Min.Z || Min.Z > box.Max.Z )
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
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 )
|
||||
{
|
||||
result = ContainmentType::Contains;
|
||||
}
|
||||
|
||||
result = ContainmentType::Intersects;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingBox::Contains(BoundingSphere sphere) const
|
||||
@ -92,90 +102,98 @@ namespace XFX
|
||||
void BoundingBox::Contains(BoundingSphere sphere, out ContainmentType_t& result) const
|
||||
{
|
||||
float dist;
|
||||
Vector3 clamped;
|
||||
|
||||
Vector3::Clamp(sphere.Center, Min, Max, clamped);
|
||||
|
||||
float x = sphere.Center.X - clamped.X;
|
||||
float y = sphere.Center.Y - clamped.Y;
|
||||
float z = sphere.Center.Z - clamped.Z;
|
||||
|
||||
dist = (x * x) + (y * y) + (z * z);
|
||||
float radius = sphere.Radius;
|
||||
|
||||
if(dist > (radius * radius))
|
||||
result = ContainmentType::Disjoint;
|
||||
|
||||
if(Min.X + radius <= sphere.Center.X && sphere.Center.X <= Max.X - radius &&
|
||||
Max.X - Min.X > radius && Min.Y + radius <= sphere.Center.Y &&
|
||||
sphere.Center.Y <= Max.Y - radius && Max.Y - Min.Y > radius &&
|
||||
Min.Z + radius <= sphere.Center.Z && sphere.Center.Z <= Max.Z - radius &&
|
||||
Max.X - Min.X > radius)
|
||||
result = ContainmentType::Contains;
|
||||
|
||||
result = ContainmentType::Intersects;
|
||||
Vector3 clamped;
|
||||
|
||||
Vector3::Clamp(sphere.Center, Min, Max, clamped);
|
||||
|
||||
float x = sphere.Center.X - clamped.X;
|
||||
float y = sphere.Center.Y - clamped.Y;
|
||||
float z = sphere.Center.Z - clamped.Z;
|
||||
|
||||
dist = (x * x) + (y * y) + (z * z);
|
||||
float radius = sphere.Radius;
|
||||
|
||||
if(dist > (radius * radius))
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
if(Min.X + radius <= sphere.Center.X && sphere.Center.X <= Max.X - radius &&
|
||||
Max.X - Min.X > radius && Min.Y + radius <= sphere.Center.Y &&
|
||||
sphere.Center.Y <= Max.Y - radius && Max.Y - Min.Y > radius &&
|
||||
Min.Z + radius <= sphere.Center.Z && sphere.Center.Z <= Max.Z - radius &&
|
||||
Max.X - Min.X > radius)
|
||||
{
|
||||
result = ContainmentType::Contains;
|
||||
}
|
||||
|
||||
result = ContainmentType::Intersects;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingBox::Contains(const Vector3 vector) const
|
||||
{
|
||||
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)
|
||||
return ContainmentType::Contains;
|
||||
|
||||
return ContainmentType::Disjoint;
|
||||
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)
|
||||
{
|
||||
return ContainmentType::Contains;
|
||||
}
|
||||
|
||||
return ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
void BoundingBox::Contains(Vector3 vector, out ContainmentType_t& result) const
|
||||
{
|
||||
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)
|
||||
result = ContainmentType::Contains;
|
||||
|
||||
result = ContainmentType::Disjoint;
|
||||
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)
|
||||
{
|
||||
result = ContainmentType::Contains;
|
||||
}
|
||||
|
||||
result = ContainmentType::Disjoint;
|
||||
}
|
||||
|
||||
BoundingBox BoundingBox::CreateFromPoints(Vector3 points[], int startIndex, int length)
|
||||
{
|
||||
sassert(points != null, String::Format("points; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
|
||||
Vector3 min = Single::MinValue;
|
||||
Vector3 max = Single::MaxValue;
|
||||
|
||||
Vector3 min = Single::MinValue;
|
||||
Vector3 max = Single::MaxValue;
|
||||
|
||||
for(int i = startIndex; i < length; i++)
|
||||
{
|
||||
Vector3::Min(min, points[i], min);
|
||||
Vector3::Max(max, points[i], max);
|
||||
}
|
||||
|
||||
return BoundingBox(min, max);
|
||||
{
|
||||
Vector3::Min(min, points[i], min);
|
||||
Vector3::Max(max, points[i], max);
|
||||
}
|
||||
|
||||
return BoundingBox(min, max);
|
||||
}
|
||||
|
||||
BoundingBox BoundingBox::CreateFromSphere(BoundingSphere sphere)
|
||||
{
|
||||
BoundingBox result;
|
||||
result.Min = Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius );
|
||||
result.Max = Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius );
|
||||
return result;
|
||||
BoundingBox result;
|
||||
result.Min = Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius );
|
||||
result.Max = Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius );
|
||||
return result;
|
||||
}
|
||||
|
||||
void BoundingBox::CreateFromSphere(BoundingSphere sphere, out BoundingBox& result)
|
||||
{
|
||||
result.Min = Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius );
|
||||
result.Max = Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius );
|
||||
result.Min = Vector3(sphere.Center.X - sphere.Radius, sphere.Center.Y - sphere.Radius, sphere.Center.Z - sphere.Radius );
|
||||
result.Max = Vector3(sphere.Center.X + sphere.Radius, sphere.Center.Y + sphere.Radius, sphere.Center.Z + sphere.Radius );
|
||||
}
|
||||
|
||||
BoundingBox BoundingBox::CreateMerged(BoundingBox box1, BoundingBox box2)
|
||||
{
|
||||
BoundingBox result;
|
||||
Vector3::Min(box1.Min, box2.Min, result.Min);
|
||||
Vector3::Max(box1.Max, box2.Max, result.Max);
|
||||
return result;
|
||||
Vector3::Min(box1.Min, box2.Min, result.Min);
|
||||
Vector3::Max(box1.Max, box2.Max, result.Max);
|
||||
return result;
|
||||
}
|
||||
|
||||
void BoundingBox::CreateMerged(BoundingBox box1, BoundingBox box2, out BoundingBox& result)
|
||||
{
|
||||
Vector3::Min(box1.Min, box2.Min, result.Min);
|
||||
Vector3::Max(box1.Max, box2.Max, result.Max);
|
||||
Vector3::Min(box1.Min, box2.Min, result.Min);
|
||||
Vector3::Max(box1.Max, box2.Max, result.Max);
|
||||
}
|
||||
|
||||
bool BoundingBox::Equals(Object const * const obj) const
|
||||
@ -192,10 +210,10 @@ namespace XFX
|
||||
{
|
||||
return Min.GetHashCode() + Max.GetHashCode();
|
||||
}
|
||||
|
||||
int BoundingBox::GetType()
|
||||
|
||||
const Type& BoundingBox::GetType()
|
||||
{
|
||||
// TODO: implement
|
||||
return BoundingBoxTypeInfo;
|
||||
}
|
||||
|
||||
bool BoundingBox::Intersects(BoundingBox box) const
|
||||
@ -207,13 +225,17 @@ namespace XFX
|
||||
|
||||
void BoundingBox::Intersects(BoundingBox box, out bool& result) const
|
||||
{
|
||||
if (Max.X < box.Min.X || Min.X > box.Max.X)
|
||||
result = false;
|
||||
|
||||
if (Max.Y < box.Min.Y || Min.Y > box.Max.Y)
|
||||
result = false;
|
||||
|
||||
result = (Max.Z >= box.Min.Z && Min.Z <= box.Max.Z);
|
||||
if (Max.X < box.Min.X || Min.X > box.Max.X)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
if (Max.Y < box.Min.Y || Min.Y > box.Max.Y)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
result = (Max.Z >= box.Min.Z && Min.Z <= box.Max.Z);
|
||||
}
|
||||
|
||||
bool BoundingBox::Intersects(BoundingSphere sphere) const
|
||||
@ -225,18 +247,18 @@ namespace XFX
|
||||
|
||||
void BoundingBox::Intersects(BoundingSphere sphere, out bool& result) const
|
||||
{
|
||||
float dist;
|
||||
Vector3 clamped;
|
||||
|
||||
Vector3::Clamp(sphere.Center, Min, Max, clamped);
|
||||
|
||||
float x = sphere.Center.X - clamped.X;
|
||||
float y = sphere.Center.Y - clamped.Y;
|
||||
float z = sphere.Center.Z - clamped.Z;
|
||||
|
||||
dist = (x * x) + (y * y) + (z * z);
|
||||
|
||||
result = (dist <= (sphere.Radius * sphere.Radius));
|
||||
float dist;
|
||||
Vector3 clamped;
|
||||
|
||||
Vector3::Clamp(sphere.Center, Min, Max, clamped);
|
||||
|
||||
float x = sphere.Center.X - clamped.X;
|
||||
float y = sphere.Center.Y - clamped.Y;
|
||||
float z = sphere.Center.Z - clamped.Z;
|
||||
|
||||
dist = (x * x) + (y * y) + (z * z);
|
||||
|
||||
result = (dist <= (sphere.Radius * sphere.Radius));
|
||||
}
|
||||
|
||||
PlaneIntersectionType_t BoundingBox::Intersects(Plane plane) const
|
||||
|
@ -142,147 +142,164 @@ namespace XFX
|
||||
Vector3 BoundingFrustum::ComputeIntersection(Plane plane, Ray ray)
|
||||
{
|
||||
float num = (-plane.D - Vector3::Dot(plane.Normal, ray.Position)) / Vector3::Dot(plane.Normal, ray.Direction);
|
||||
return (ray.Position + (ray.Direction * num));
|
||||
return (ray.Position + (ray.Direction * num));
|
||||
}
|
||||
|
||||
Ray BoundingFrustum::ComputeIntersectionLine(Plane p1, Plane p2)
|
||||
{
|
||||
Ray ray = Ray();
|
||||
ray.Direction = Vector3::Cross(p1.Normal, p2.Normal);
|
||||
float num = ray.Direction.LengthSquared();
|
||||
float num = ray.Direction.LengthSquared();
|
||||
ray.Position = (Vector3::Cross(((p2.Normal * -p1.D) + (p1.Normal * p2.D)), ray.Direction) / num);
|
||||
return ray;
|
||||
return ray;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingFrustum::Contains(BoundingBox box)
|
||||
{
|
||||
bool flag = false;
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
switch (box.Intersects(planes[i]))
|
||||
{
|
||||
for(int i = 0; i < 6; i++)
|
||||
{
|
||||
switch (box.Intersects(planes[i]))
|
||||
{
|
||||
case PlaneIntersectionType::Front:
|
||||
return ContainmentType::Disjoint;
|
||||
|
||||
case PlaneIntersectionType::Intersecting:
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!flag)
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
return ContainmentType::Contains;
|
||||
}
|
||||
}
|
||||
|
||||
return ContainmentType::Intersects;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingFrustum::Contains(BoundingFrustum frustrum)
|
||||
{
|
||||
ContainmentType_t disjoint = ContainmentType::Disjoint;
|
||||
if (Intersects(frustrum))
|
||||
{
|
||||
|
||||
if (Intersects(frustrum))
|
||||
{
|
||||
disjoint = ContainmentType::Contains;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
{
|
||||
if (Contains(frustrum.cornerArray[i]) == ContainmentType::Disjoint)
|
||||
{
|
||||
{
|
||||
return ContainmentType::Intersects;
|
||||
}
|
||||
}
|
||||
}
|
||||
return disjoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return disjoint;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingFrustum::Contains(BoundingSphere sphere)
|
||||
{
|
||||
Vector3 center = sphere.Center;
|
||||
float radius = sphere.Radius;
|
||||
int num2 = 0;
|
||||
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 num3 = num5 + planes[i].D;
|
||||
if (num3 > radius)
|
||||
{
|
||||
float radius = sphere.Radius;
|
||||
int num2 = 0;
|
||||
|
||||
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 num3 = num5 + planes[i].D;
|
||||
if (num3 > radius)
|
||||
{
|
||||
return ContainmentType::Disjoint;
|
||||
}
|
||||
if (num3 < -radius)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
if (num2 != 6)
|
||||
{
|
||||
}
|
||||
if (num3 < -radius)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
|
||||
if (num2 != 6)
|
||||
{
|
||||
return ContainmentType::Intersects;
|
||||
}
|
||||
}
|
||||
|
||||
return ContainmentType::Contains;
|
||||
}
|
||||
|
||||
ContainmentType_t BoundingFrustum::Contains(Vector3 point)
|
||||
{
|
||||
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;
|
||||
if (num2 > 1E-05f)
|
||||
{
|
||||
{
|
||||
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)
|
||||
{
|
||||
return ContainmentType::Disjoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ContainmentType::Contains;
|
||||
}
|
||||
|
||||
void BoundingFrustum::Contains(BoundingBox box, out ContainmentType_t& result)
|
||||
{
|
||||
bool flag = false;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
switch (box.Intersects(planes[i]))
|
||||
{
|
||||
{
|
||||
switch (box.Intersects(planes[i]))
|
||||
{
|
||||
case PlaneIntersectionType::Front:
|
||||
result = ContainmentType::Disjoint;
|
||||
return;
|
||||
return;
|
||||
|
||||
case PlaneIntersectionType::Intersecting:
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = flag ? ContainmentType::Intersects : ContainmentType::Contains;
|
||||
}
|
||||
|
||||
void BoundingFrustum::Contains(BoundingSphere sphere, out ContainmentType_t& result)
|
||||
{
|
||||
Vector3 center = sphere.Center;
|
||||
float radius = sphere.Radius;
|
||||
int num2 = 0;
|
||||
float radius = sphere.Radius;
|
||||
int num2 = 0;
|
||||
|
||||
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 num3 = num5 + planes[i].D;
|
||||
if (num3 > radius)
|
||||
{
|
||||
{
|
||||
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;
|
||||
|
||||
if (num3 > radius)
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
return;
|
||||
}
|
||||
if (num3 < -radius)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (num3 < -radius)
|
||||
{
|
||||
num2++;
|
||||
}
|
||||
}
|
||||
|
||||
result = (num2 == 6) ? ContainmentType::Contains : ContainmentType::Intersects;
|
||||
}
|
||||
|
||||
void BoundingFrustum::Contains(Vector3 point, out ContainmentType_t& result)
|
||||
{
|
||||
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;
|
||||
if (num2 > 1E-05f)
|
||||
{
|
||||
{
|
||||
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)
|
||||
{
|
||||
result = ContainmentType::Disjoint;
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
result = ContainmentType::Contains;
|
||||
}
|
||||
|
||||
@ -306,7 +323,9 @@ namespace XFX
|
||||
sassert(corners != null, "corners cannot be null.");
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
corners[i] = cornerArray[i];
|
||||
}
|
||||
}
|
||||
|
||||
int BoundingFrustum::GetHashCode() const
|
||||
@ -322,8 +341,8 @@ namespace XFX
|
||||
bool BoundingFrustum::Intersects(BoundingBox box)
|
||||
{
|
||||
bool flag = false;
|
||||
Intersects(box, flag);
|
||||
return flag;
|
||||
Intersects(box, flag);
|
||||
return flag;
|
||||
}
|
||||
|
||||
bool BoundingFrustum::Intersects(BoundingFrustum frustrum)
|
||||
@ -343,10 +362,12 @@ namespace XFX
|
||||
PlaneIntersectionType_t BoundingFrustum::Intersects(Plane plane)
|
||||
{
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
float num3 = 0;
|
||||
Vector3::Dot(cornerArray[i], plane.Normal, num3);
|
||||
|
||||
if ((num3 + plane.D) > 0)
|
||||
{
|
||||
num |= 1;
|
||||
@ -355,15 +376,18 @@ namespace XFX
|
||||
{
|
||||
num |= 2;
|
||||
}
|
||||
|
||||
if (num == 3)
|
||||
{
|
||||
return PlaneIntersectionType::Intersecting;
|
||||
}
|
||||
}
|
||||
|
||||
if (num != 1)
|
||||
{
|
||||
return PlaneIntersectionType::Back;
|
||||
}
|
||||
|
||||
return PlaneIntersectionType::Front;
|
||||
}
|
||||
|
||||
@ -387,10 +411,12 @@ namespace XFX
|
||||
void BoundingFrustum::Intersects(Plane plane, out PlaneIntersectionType_t& result)
|
||||
{
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
float num3 = 0;
|
||||
Vector3::Dot(cornerArray[i], plane.Normal, num3);
|
||||
|
||||
if ((num3 + plane.D) > 0)
|
||||
{
|
||||
num |= 1;
|
||||
@ -399,18 +425,21 @@ namespace XFX
|
||||
{
|
||||
num |= 2;
|
||||
}
|
||||
|
||||
if (num == 3)
|
||||
{
|
||||
result = PlaneIntersectionType::Intersecting;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
result = (num == 1) ? PlaneIntersectionType::Front : PlaneIntersectionType::Back;
|
||||
}
|
||||
|
||||
void BoundingFrustum::Intersects(Ray ray, out float& result)
|
||||
{
|
||||
ContainmentType_t type = Contains(ray.Position);
|
||||
|
||||
if (type == ContainmentType::Contains)
|
||||
{
|
||||
result = 0.0f;
|
||||
@ -420,6 +449,7 @@ namespace XFX
|
||||
float minValue = Single::MinValue;
|
||||
float maxValue = Single::MaxValue;
|
||||
result = 0;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float num3 = 0;
|
||||
@ -428,6 +458,7 @@ namespace XFX
|
||||
Vector3::Dot(ray.Direction, normal, num6);
|
||||
Vector3::Dot(ray.Position, normal, num3);
|
||||
num3 += planes[i].D;
|
||||
|
||||
if (Math::Abs(num6) < 1E-05f)
|
||||
{
|
||||
if (num3 > 0.0f)
|
||||
@ -438,12 +469,14 @@ namespace XFX
|
||||
else
|
||||
{
|
||||
float num = -num3 / num6;
|
||||
|
||||
if (num6 < 0.0f)
|
||||
{
|
||||
if (num > maxValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (num > minValue)
|
||||
{
|
||||
minValue = num;
|
||||
@ -455,6 +488,7 @@ namespace XFX
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (num < maxValue)
|
||||
{
|
||||
maxValue = num;
|
||||
@ -462,7 +496,9 @@ namespace XFX
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float num7 = (minValue >= 0) ? minValue : maxValue;
|
||||
|
||||
if (num7 >= 0)
|
||||
{
|
||||
result = float(num7);
|
||||
@ -497,12 +533,14 @@ namespace XFX
|
||||
planes[1].Normal.Y = -value.M24 + value.M23;
|
||||
planes[1].Normal.Z = -value.M34 + value.M33;
|
||||
planes[1].D = -value.M44 + value.M43;
|
||||
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
float num2 = planes[i].Normal.Length();
|
||||
planes[i].Normal = (planes[i].Normal / num2);
|
||||
planes[i].D /= num2;
|
||||
}
|
||||
|
||||
Ray ray = ComputeIntersectionLine(planes[0], planes[2]);
|
||||
cornerArray[0] = ComputeIntersection(planes[4], ray);
|
||||
cornerArray[3] = ComputeIntersection(planes[5], ray);
|
||||
|
@ -27,9 +27,12 @@
|
||||
|
||||
#include <BoundingSphere.h>
|
||||
#include <System/String.h>
|
||||
#include <System/Type.h>
|
||||
|
||||
namespace XFX
|
||||
{
|
||||
const Type BoundingSphereTypeInfo("BoundingSphere", "XFX::BoundingSphere", TypeCode::Object);
|
||||
|
||||
BoundingSphere::BoundingSphere(const Vector3 center, const float radius)
|
||||
: Center(center), Radius(radius)
|
||||
{
|
||||
@ -55,6 +58,11 @@ namespace XFX
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
const Type& BoundingSphere::GetType()
|
||||
{
|
||||
return BoundingSphereTypeInfo;
|
||||
}
|
||||
|
||||
int BoundingSphere::GetHashCode() const
|
||||
{
|
||||
return Center.GetHashCode() + (int)Radius;
|
||||
|
@ -47,9 +47,9 @@ namespace XFX
|
||||
float squared = amount * amount;
|
||||
float cubed = amount * squared;
|
||||
|
||||
return 0.5f * ((((2.0f * value2) + ((-value1 + value3) * amount)) +
|
||||
(((((2.0f * value1) - (5.0f * value2)) + (4.0f * value3)) - value4) * squared)) +
|
||||
((((-value1 + (3.0f * value2)) - (3.0f * value3)) + value4) * cubed));
|
||||
return 0.5f * ((((2.0f * value2) + ((-value1 + value3) * amount)) +
|
||||
(((((2.0f * value1) - (5.0f * value2)) + (4.0f * value3)) - value4) * squared)) +
|
||||
((((-value1 + (3.0f * value2)) - (3.0f * value3)) + value4) * cubed));
|
||||
}
|
||||
|
||||
float MathHelper::Clamp(const float value, const float min, const float max)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -157,12 +157,16 @@ namespace XFX
|
||||
float dot = (Normal.X * max.X) + (Normal.Y * max.Y) + (Normal.Z * max.Z);
|
||||
|
||||
if(dot + D > 0.0f)
|
||||
{
|
||||
result = PlaneIntersectionType::Front;
|
||||
}
|
||||
|
||||
dot = (Normal.X * min.X) + (Normal.Y * min.Y) + (Normal.Z * min.Z);
|
||||
|
||||
if(dot + D < 0.0f)
|
||||
{
|
||||
result = PlaneIntersectionType::Back;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if(dot > sphere.Radius)
|
||||
{
|
||||
result = PlaneIntersectionType::Front;
|
||||
}
|
||||
|
||||
if(dot < -sphere.Radius)
|
||||
{
|
||||
result = PlaneIntersectionType::Back;
|
||||
}
|
||||
|
||||
result = PlaneIntersectionType::Intersecting;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <System/FrameworkResources.h>
|
||||
#include <System/Math.h>
|
||||
#include <System/String.h>
|
||||
#include <System/Type.h>
|
||||
|
||||
#include <sassert.h>
|
||||
|
||||
@ -42,29 +43,26 @@ namespace XFX
|
||||
{
|
||||
const Vector2 Vector2::One = Vector2(1, 1);
|
||||
const Vector2 Vector2::Zero = Vector2(0, 0);
|
||||
const Type Vector2TypeInfo("Vector2", "XFX::Vector2", TypeCode::Object);
|
||||
|
||||
Vector2::Vector2(const float x, const float y)
|
||||
: X(x), Y(y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
Vector2::Vector2(const float value)
|
||||
: X(value), Y(value)
|
||||
{
|
||||
X = value;
|
||||
Y = value;
|
||||
}
|
||||
|
||||
|
||||
Vector2::Vector2(const Vector2 &obj)
|
||||
: X(obj.X), Y(obj.Y)
|
||||
{
|
||||
X = obj.X;
|
||||
Y = obj.Y;
|
||||
}
|
||||
|
||||
|
||||
Vector2::Vector2()
|
||||
: X(0), Y(0)
|
||||
{
|
||||
X = 0;
|
||||
Y = 0;
|
||||
}
|
||||
|
||||
Vector2 Vector2::Add(const Vector2 value1, const Vector2 value2)
|
||||
@ -112,40 +110,40 @@ namespace XFX
|
||||
result.X = MathHelper::Clamp(value.X, min.X, max.X);
|
||||
result.Y = MathHelper::Clamp(value.Y, min.Y, max.Y);
|
||||
}
|
||||
|
||||
|
||||
float Vector2::Distance(const Vector2 value1, const Vector2 value2)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
return Math::Sqrt((x * x) + (y * y));
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
return Math::Sqrt((x * x) + (y * y));
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Distance(const Vector2& value1, const Vector2& value2, out float& result)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
result = Math::Sqrt((x * x) + (y * y));
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
result = Math::Sqrt((x * x) + (y * y));
|
||||
}
|
||||
|
||||
|
||||
float Vector2::DistanceSquared(const Vector2 value1, const Vector2 value2)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
return (x * x) + (y * y);
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
return (x * x) + (y * y);
|
||||
}
|
||||
|
||||
|
||||
void Vector2::DistanceSquared(const Vector2& value1, const Vector2& value2, out float& result)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
result = (x * x) + (y * y);
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
result = (x * x) + (y * y);
|
||||
}
|
||||
|
||||
|
||||
float Vector2::Dot(const Vector2 value1, const Vector2 value2)
|
||||
{
|
||||
return (value1.X * value2.X + value1.Y * value2.Y);
|
||||
return (value1.X * value2.X + value1.Y * value2.Y);
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Dot(const Vector2& value1, const Vector2& value2, out float& result)
|
||||
{
|
||||
result = (value1.X * value2.X + value1.Y * value2.Y);
|
||||
@ -160,65 +158,65 @@ namespace XFX
|
||||
{
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
int Vector2::GetHashCode() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
return Vector2(MathHelper::Hermite(value1.X,tangent1.X,value2.X,tangent2.X,amount), MathHelper::Hermite(value1.Y,tangent1.Y,value2.Y,tangent2.Y,amount));
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Hermite(const Vector2& value1, const Vector2& tangent1, const Vector2& value2, const Vector2& tangent2, const float amount, out Vector2& result)
|
||||
{
|
||||
result.X = MathHelper::Hermite(value1.X,tangent1.X,value2.X,tangent2.X,amount);
|
||||
result.Y = MathHelper::Hermite(value1.Y,tangent1.Y,value2.Y,tangent2.Y,amount);
|
||||
}
|
||||
|
||||
|
||||
float Vector2::Length() const
|
||||
{
|
||||
return Math::Sqrt((X * X) + (Y * Y));
|
||||
}
|
||||
|
||||
|
||||
float Vector2::LengthSquared() const
|
||||
{
|
||||
return (X * X) + (Y * Y);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Lerp(const Vector2 value1, const Vector2 value2, const float amount)
|
||||
{
|
||||
return Vector2(MathHelper::Lerp(value1.X, value2.X, amount), MathHelper::Lerp(value1.Y, value2.Y, amount));
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Lerp(const Vector2& value1, const Vector2& value2, const float amount, out Vector2& result)
|
||||
{
|
||||
result.X = MathHelper::Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper::Lerp(value1.Y, value2.Y, amount);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Max(const Vector2 value1, const Vector2 value2)
|
||||
{
|
||||
return Vector2((value1.X > value2.X) ? value1.X : value2.X,(value1.Y > value2.Y) ? value1.Y : value2.Y);
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Max(const Vector2& value1, const Vector2& value2, out Vector2& result)
|
||||
{
|
||||
result.X = (value1.X > value2.X) ? value1.X : value2.X;
|
||||
result.Y = (value1.Y > value2.Y) ? value1.Y : value2.Y;
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Min(const Vector2 value1, const Vector2 value2)
|
||||
{
|
||||
return Vector2((value1.X < value2.X) ? value1.X : value2.X, (value1.Y < value2.Y) ? value1.Y : value2.Y);
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Min(const Vector2& value1, const Vector2& value2, out Vector2& result)
|
||||
{
|
||||
result.X = (value1.X < value2.X) ? value1.X : value2.X;
|
||||
@ -257,34 +255,42 @@ namespace XFX
|
||||
result.X = -value.X;
|
||||
result.Y = -value.Y;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
if(length == 0)
|
||||
return;
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Normalize(const Vector2 value)
|
||||
{
|
||||
Vector2 result;
|
||||
Normalize(value, result);
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Normalize(const Vector2& value, out Vector2& result)
|
||||
{
|
||||
float length = value.Length();
|
||||
if (length == 0)
|
||||
return;
|
||||
float num = 1 / length;
|
||||
result.X = value.X * num;
|
||||
result.Y = value.Y * num;
|
||||
float length = value.Length();
|
||||
|
||||
if (length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
result.X = value.X * num;
|
||||
result.Y = value.Y * num;
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Reflect(const Vector2 vector, const Vector2 normal)
|
||||
{
|
||||
Vector2 result;
|
||||
@ -298,14 +304,14 @@ namespace XFX
|
||||
result.X = vector.X - normal.X * dp;
|
||||
result.Y = vector.Y - normal.Y * dp;
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::SmoothStep(const Vector2 value1, const Vector2 value2, const float amount)
|
||||
{
|
||||
Vector2 result;
|
||||
SmoothStep(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::SmoothStep(const Vector2& value1, const Vector2& value2, const float amount, out Vector2& result)
|
||||
{
|
||||
result.X = MathHelper::SmoothStep(value1.X, value2.X, amount);
|
||||
@ -318,7 +324,7 @@ namespace XFX
|
||||
Subtract(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Subtract(const Vector2& value1, const Vector2& value2, out Vector2& result)
|
||||
{
|
||||
result.X = value1.X - value2.X;
|
||||
@ -329,90 +335,90 @@ namespace XFX
|
||||
{
|
||||
return String::Format("{X:%f Y:%f}", X, Y);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Transform(const Vector2 position, const Matrix matrix)
|
||||
{
|
||||
Vector2 result;
|
||||
Vector2 result;
|
||||
Transform(position, matrix, result);
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Transform(const Vector2& position, const Matrix& matrix, out Vector2& result)
|
||||
{
|
||||
Vector4 vector;
|
||||
|
||||
vector.X = (vector.X * matrix.M11) + (vector.Y * matrix.M21) + matrix.M41;
|
||||
vector.Y = (vector.X * matrix.M12) + (vector.Y * matrix.M22) + matrix.M42;
|
||||
vector.Z = (vector.X * matrix.M13) + (vector.Y * matrix.M23) + matrix.M43;
|
||||
vector.W = 1 / ((vector.X * matrix.M14) + (vector.Y * matrix.M24) + matrix.M44);
|
||||
|
||||
result.X = vector.X * vector.W;
|
||||
result.Y = vector.Y * vector.W;
|
||||
Vector4 vector;
|
||||
|
||||
vector.X = (vector.X * matrix.M11) + (vector.Y * matrix.M21) + matrix.M41;
|
||||
vector.Y = (vector.X * matrix.M12) + (vector.Y * matrix.M22) + matrix.M42;
|
||||
vector.Z = (vector.X * matrix.M13) + (vector.Y * matrix.M23) + matrix.M43;
|
||||
vector.W = 1 / ((vector.X * matrix.M14) + (vector.Y * matrix.M24) + matrix.M44);
|
||||
|
||||
result.X = vector.X * vector.W;
|
||||
result.Y = vector.Y * vector.W;
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::Transform(const Vector2 position, const Quaternion rotation)
|
||||
{
|
||||
Vector2 result;
|
||||
Transform(position, rotation, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Transform(const Vector2& position, const Quaternion& rotation, out Vector2& result)
|
||||
{
|
||||
Quaternion quat = Quaternion(position.X, position.Y, 0, 0), i, t;
|
||||
Quaternion::Inverse(rotation, i);
|
||||
Quaternion::Multiply(rotation, quat, t);
|
||||
Quaternion::Multiply(t, i, quat);
|
||||
|
||||
|
||||
result.X = quat.X;
|
||||
result.Y = quat.Y;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Transform(const Vector2 sourceArray[], const int sourceIndex, const Matrix& matrix, Vector2 destinationArray[], const int destinationIndex, const int length)
|
||||
{
|
||||
sassert(sourceArray != null, "sourceArray cannot be null.");
|
||||
|
||||
sassert(destinationArray != null, "destinationArray cannot be null.");
|
||||
|
||||
|
||||
for(int i = sourceIndex, j = destinationIndex; i < (sourceIndex + length); i++, j++)
|
||||
{
|
||||
TransformNormal(sourceArray[i], matrix, destinationArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Vector2::Transform(const Vector2 sourceArray[], const int sourceIndex, const Quaternion& rotation, Vector2 destinationArray[], const int destinationIndex, const int length)
|
||||
{
|
||||
sassert(sourceArray != null, String::Format("sourceArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
|
||||
sassert(destinationArray != null, String::Format("destinationArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
|
||||
|
||||
for(int i = sourceIndex, j = destinationIndex; i < (sourceIndex + length); i++, j++)
|
||||
{
|
||||
Transform(sourceArray[i], rotation, destinationArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::TransformNormal(const Vector2 normal, const Matrix matrix)
|
||||
{
|
||||
Vector2 result;
|
||||
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||
|
||||
return result;
|
||||
Vector2 result;
|
||||
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector2::TransformNormal(const Vector2& normal, const Matrix& matrix, out Vector2& result)
|
||||
{
|
||||
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||
result.X = (normal.X * matrix.M11) + (normal.Y * matrix.M21);
|
||||
result.Y = (normal.X * matrix.M12) + (normal.Y * matrix.M22);
|
||||
}
|
||||
|
||||
|
||||
void Vector2::TransformNormal(const Vector2 sourceArray[], const int sourceIndex, const Matrix& matrix, Vector2 destinationArray[], const int destinationIndex, const int length)
|
||||
{
|
||||
sassert(sourceArray != null, String::Format("sourceArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
|
||||
sassert(destinationArray != null, String::Format("destinationArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
|
||||
|
||||
for(int i = sourceIndex, j = destinationIndex; i < (sourceIndex + length); i++, j++)
|
||||
{
|
||||
TransformNormal(sourceArray[i], matrix, destinationArray[j]);
|
||||
@ -423,17 +429,17 @@ namespace XFX
|
||||
{
|
||||
return Vector2(X + other.X, Y + other.Y);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::operator/(const float divider) const
|
||||
{
|
||||
return Vector2(X / divider, Y / divider);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::operator/(const Vector2& other) const
|
||||
{
|
||||
return Vector2(X / other.X, Y / other.Y);
|
||||
}
|
||||
|
||||
|
||||
bool Vector2::operator==(const Vector2& other) const
|
||||
{
|
||||
return ((X == other.X) && (Y == other.Y));
|
||||
@ -448,7 +454,7 @@ namespace XFX
|
||||
{
|
||||
return Vector2(X * scaleFactor, Y * scaleFactor);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::operator*(const Vector2& other) const
|
||||
{
|
||||
return Vector2(X * other.X, Y * other.Y);
|
||||
@ -458,7 +464,7 @@ namespace XFX
|
||||
{
|
||||
return Vector2(X - other.X, Y - other.Y);
|
||||
}
|
||||
|
||||
|
||||
Vector2 Vector2::operator-() const
|
||||
{
|
||||
return Vector2(-X, -Y);
|
||||
|
@ -34,13 +34,14 @@
|
||||
#include <System/Array.h>
|
||||
#include <System/Math.h>
|
||||
#include <System/String.h>
|
||||
#include <System/Type.h>
|
||||
|
||||
#include <sassert.h>
|
||||
|
||||
using namespace System;
|
||||
|
||||
namespace XFX
|
||||
{
|
||||
{
|
||||
const Vector3 Vector3::Backward = Vector3(0, 0, 1);
|
||||
const Vector3 Vector3::Down = Vector3(0, -1, 0);
|
||||
const Vector3 Vector3::Forward = Vector3(0, 0, -1);
|
||||
@ -52,17 +53,18 @@ namespace XFX
|
||||
const Vector3 Vector3::UnitZ = Vector3(0, 0, 1);
|
||||
const Vector3 Vector3::Up = Vector3(0, 1, 0);
|
||||
const Vector3 Vector3::Zero = Vector3(0, 0, 0);
|
||||
|
||||
const Type Vector3TypeInfo("Vector3", "XFX::Vector3", TypeCode::Object);
|
||||
|
||||
Vector3::Vector3(float value)
|
||||
: X(value), Y(value), Z(value)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Vector3::Vector3(float x, float y, float z)
|
||||
: X(x), Y(y), Z(z)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Vector3::Vector3(Vector2 value, float z)
|
||||
: X(value.X), Y(value.Y), Z(z)
|
||||
{
|
||||
@ -89,7 +91,7 @@ namespace XFX
|
||||
result.Y = value1.Y + value2.Y;
|
||||
result.Z = value1.Z + value2.Z;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Baricentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -98,14 +100,14 @@ namespace XFX
|
||||
result.X = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Baricentric(Vector3 value1, Vector3 value2, Vector3 value3, float amount1, float amount2, out Vector3& result)
|
||||
{
|
||||
result.X = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Z = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.X = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, Vector3 value4, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -114,14 +116,14 @@ namespace XFX
|
||||
result.Z = MathHelper::CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::CatmullRom(Vector3 value1, Vector3 value2, Vector3 value3, 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);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Clamp(Vector3 value1, Vector3 min, Vector3 max)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -130,14 +132,14 @@ namespace XFX
|
||||
result.Z = MathHelper::Clamp(value1.Z, min.Z, max.Z);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Clamp(Vector3 value1, Vector3 min, Vector3 max, out Vector3& result)
|
||||
{
|
||||
result.X = MathHelper::Clamp(value1.X, min.X, max.X);
|
||||
result.Y = MathHelper::Clamp(value1.Y, min.Y, max.Y);
|
||||
result.Z = MathHelper::Clamp(value1.Z, min.Z, max.Z);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Cross(Vector3 vector1, Vector3 vector2)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -146,62 +148,62 @@ namespace XFX
|
||||
result.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Cross(Vector3 vector1, Vector3 vector2, out Vector3& result)
|
||||
{
|
||||
result.X = vector1.Y * vector2.Z - vector1.Z * vector2.Y;
|
||||
result.Y = vector1.Z * vector2.X - vector1.X * vector2.Z;
|
||||
result.Z = vector1.X * vector2.Y - vector1.Y * vector2.X;
|
||||
}
|
||||
|
||||
|
||||
float Vector3::Distance(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
return Math::Sqrt((x*x) + (y*y) + (z*z));
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Distance(Vector3 value1, Vector3 value2, out float& result)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
result = Math::Sqrt((x*x) + (y*y) + (z*z));
|
||||
}
|
||||
|
||||
|
||||
float Vector3::DistanceSquared(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
return (x*x) + (y*y) + (z*z);
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
return (x*x) + (y*y) + (z*z);
|
||||
}
|
||||
|
||||
|
||||
void Vector3::DistanceSquared(Vector3 value1, Vector3 value2, out float& result)
|
||||
{
|
||||
float x = value1.X - value2.X;
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
float y = value1.Y - value2.Y;
|
||||
float z = value1.Z - value2.Z;
|
||||
|
||||
result = (x*x) + (y*y) + (z*z);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Divide(Vector3 value1, float value2)
|
||||
{
|
||||
return Vector3(value1.X / value2, value1.Y / value2, value1.Z / value2);
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Divide(Vector3 value1, float value2, out Vector3& result)
|
||||
{
|
||||
result.X = value1.X / value2;
|
||||
result.Y = value1.Y / value2;
|
||||
result.Z = value1.Z / value2;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Divide(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -210,19 +212,19 @@ namespace XFX
|
||||
result.Z = value1.Z / value2.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Divide(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
{
|
||||
result.X = value1.X / value2.X;
|
||||
result.Y = value1.Y / value2.Y;
|
||||
result.Z = value1.Z / value2.Z;
|
||||
}
|
||||
|
||||
|
||||
float Vector3::Dot(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
return (value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z);
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Dot(Vector3 value1, Vector3 value2, out float& result)
|
||||
{
|
||||
result = (value1.X * value2.X + value1.Y * value2.Y + value1.Z * value2.Z);
|
||||
@ -237,237 +239,249 @@ namespace XFX
|
||||
{
|
||||
return (*this == other);
|
||||
}
|
||||
|
||||
|
||||
int Vector3::GetHashCode() const
|
||||
{
|
||||
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 result;
|
||||
Hermite(value1, tangent1, value2, tangent2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Hermite(Vector3 value1, Vector3 tangent1, Vector3 value2, 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);
|
||||
}
|
||||
|
||||
|
||||
float Vector3::Length() const
|
||||
{
|
||||
return Math::Sqrt((X * X) + (Y * Y) + (Z * Z));
|
||||
}
|
||||
|
||||
|
||||
float Vector3::LengthSquared() const
|
||||
{
|
||||
return (X * X) + (Y * Y) + (Z * Z);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Lerp(Vector3 value1, Vector3 value2, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
Lerp(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Lerp(Vector3 value1, Vector3 value2, float amount, out Vector3& result)
|
||||
{
|
||||
result.X = MathHelper::Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper::Lerp(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper::Lerp(value1.Z, value2.Z, amount);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Max(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
Max(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Max(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
{
|
||||
result.X = (value1.X > value2.X) ? value1.X : value2.X;
|
||||
result.Y = (value1.Y > value2.Y) ? value1.Y : value2.Y;
|
||||
result.Z = (value1.Z > value2.Z) ? value1.Z : value2.Z;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Min(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
Min(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Min(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
{
|
||||
result.X = (value1.X < value2.X) ? value1.X : value2.X;
|
||||
result.Y = (value1.Y < value2.Y) ? value1.Y : value2.Y;
|
||||
result.Z = (value1.Z < value2.Z) ? value1.Z : value2.Z;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Multiply(Vector3 value1, float scaleFactor)
|
||||
{
|
||||
Vector3 result;
|
||||
Multiply(value1, scaleFactor, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Multiply(Vector3 value1, float scaleFactor, out Vector3& result)
|
||||
{
|
||||
result.X = value1.X * scaleFactor;
|
||||
result.Y = value1.Y * scaleFactor;
|
||||
result.Z = value1.Z * scaleFactor;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Multiply(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
Multiply(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Multiply(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
{
|
||||
result.X = value1.X * value2.X;
|
||||
result.Y = value1.Y * value2.Y;
|
||||
result.Z = value1.Z * value2.Z;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Negate(Vector3 value)
|
||||
{
|
||||
Vector3 result;
|
||||
Negate(value, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Negate(Vector3 value, out Vector3& result)
|
||||
{
|
||||
result.X = -value.X;
|
||||
result.Y = -value.Y;
|
||||
result.Z = -value.Z;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
if(length == 0)
|
||||
return;
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
Z *= num;
|
||||
float length = Length();
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
Z *= num;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Normalize(Vector3 value)
|
||||
{
|
||||
Vector3 result;
|
||||
float length = value.Length();
|
||||
if(length == 0)
|
||||
return Vector3::Zero;
|
||||
float num = 1 / length;
|
||||
result.X *= num;
|
||||
result.Y *= num;
|
||||
result.Z *= num;
|
||||
return result;
|
||||
float length = value.Length();
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
return Vector3::Zero;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
result.X *= num;
|
||||
result.Y *= num;
|
||||
result.Z *= num;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Normalize(Vector3 value, out Vector3& result)
|
||||
{
|
||||
float length = value.Length();
|
||||
if(length == 0)
|
||||
return;
|
||||
float num = 1 / length;
|
||||
result.X *= num;
|
||||
result.Y *= num;
|
||||
result.Z *= num;
|
||||
float length = value.Length();
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
result.X *= num;
|
||||
result.Y *= num;
|
||||
result.Z *= num;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Reflect(Vector3 vector, Vector3 normal)
|
||||
{
|
||||
Vector3 result;
|
||||
Reflect(vector, normal, result);
|
||||
return result;
|
||||
Vector3 result;
|
||||
Reflect(vector, normal, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Reflect(Vector3 vector, Vector3 normal, out Vector3& result)
|
||||
{
|
||||
float dot = ((vector.X * normal.X) + (vector.Y * normal.Y)) + (vector.Z * normal.Z);
|
||||
|
||||
result.X = vector.X - ((2.0f * dot) * normal.X);
|
||||
result.Y = vector.Y - ((2.0f * dot) * normal.Y);
|
||||
result.Z = vector.Z - ((2.0f * dot) * normal.Z);
|
||||
}
|
||||
|
||||
Vector3 Vector3::SmoothStep(Vector3 value1, Vector3 value2, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
SmoothStep(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector3::SmoothStep(Vector3 value1, Vector3 value2, float amount, out Vector3& result)
|
||||
{
|
||||
result.X = MathHelper::SmoothStep(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper::SmoothStep(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper::SmoothStep(value1.Z, value2.Z, amount);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Subtract(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
Subtract(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector3::Subtract(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
|
||||
result.X = vector.X - ((2.0f * dot) * normal.X);
|
||||
result.Y = vector.Y - ((2.0f * dot) * normal.Y);
|
||||
result.Z = vector.Z - ((2.0f * dot) * normal.Z);
|
||||
}
|
||||
|
||||
Vector3 Vector3::SmoothStep(Vector3 value1, Vector3 value2, float amount)
|
||||
{
|
||||
Vector3 result;
|
||||
SmoothStep(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector3::SmoothStep(Vector3 value1, Vector3 value2, float amount, out Vector3& result)
|
||||
{
|
||||
result.X = MathHelper::SmoothStep(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper::SmoothStep(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper::SmoothStep(value1.Z, value2.Z, amount);
|
||||
}
|
||||
|
||||
Vector3 Vector3::Subtract(Vector3 value1, Vector3 value2)
|
||||
{
|
||||
Vector3 result;
|
||||
Subtract(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector3::Subtract(Vector3 value1, Vector3 value2, out Vector3& result)
|
||||
{
|
||||
result.X = value1.X - value2.X;
|
||||
result.Y = value1.Y - value2.Y;
|
||||
result.Z = value1.Z - value2.Z;
|
||||
result.Y = value1.Y - value2.Y;
|
||||
result.Z = value1.Z - value2.Z;
|
||||
}
|
||||
|
||||
const String Vector3::ToString() const
|
||||
{
|
||||
return String::Format("{X:%f Y:%f Z:%f}", X, Y, Z);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Transform(Vector3 position, Matrix matrix)
|
||||
{
|
||||
Vector3 result;
|
||||
Transform(position, matrix, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Transform(Vector3 position, Matrix matrix, out Vector3& result)
|
||||
{
|
||||
Vector4 vector;
|
||||
|
||||
vector.X = (((vector.X * matrix.M11) + (vector.Y * matrix.M21)) + (vector.Z * matrix.M31)) + matrix.M41;
|
||||
vector.Y = (((vector.X * matrix.M12) + (vector.Y * matrix.M22)) + (vector.Z * matrix.M32)) + matrix.M42;
|
||||
vector.Z = (((vector.X * matrix.M13) + (vector.Y * matrix.M23)) + (vector.Z * matrix.M33)) + matrix.M43;
|
||||
vector.W = 1 / ((((vector.X * matrix.M14) + (vector.Y * matrix.M24)) + (vector.Z * matrix.M34)) + matrix.M44);
|
||||
|
||||
result.X = vector.X * vector.W;
|
||||
result.Y = vector.Y * vector.W;
|
||||
result.Z = vector.Z * vector.W;
|
||||
Vector4 vector;
|
||||
|
||||
vector.X = (((vector.X * matrix.M11) + (vector.Y * matrix.M21)) + (vector.Z * matrix.M31)) + matrix.M41;
|
||||
vector.Y = (((vector.X * matrix.M12) + (vector.Y * matrix.M22)) + (vector.Z * matrix.M32)) + matrix.M42;
|
||||
vector.Z = (((vector.X * matrix.M13) + (vector.Y * matrix.M23)) + (vector.Z * matrix.M33)) + matrix.M43;
|
||||
vector.W = 1 / ((((vector.X * matrix.M14) + (vector.Y * matrix.M24)) + (vector.Z * matrix.M34)) + matrix.M44);
|
||||
|
||||
result.X = vector.X * vector.W;
|
||||
result.Y = vector.Y * vector.W;
|
||||
result.Z = vector.Z * vector.W;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::Transform(Vector3 position, Quaternion rotation)
|
||||
{
|
||||
Vector3 result;
|
||||
Transform(position, rotation, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Transform(Vector3 position, Quaternion rotation, out Vector3& result)
|
||||
{
|
||||
Vector3 xyz = Vector3(rotation.X,rotation.Y, rotation.Z), temp, temp2;
|
||||
@ -478,7 +492,7 @@ namespace XFX
|
||||
Multiply(temp, 2, temp);
|
||||
Add(position, temp, result);
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Transform(const Vector3 sourceArray[], const int sourceIndex, const Matrix matrix, Vector3 destinationArray[], const int destinationIndex, const int length)
|
||||
{
|
||||
sassert(sourceArray != null, String::Format("sourceArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
@ -490,7 +504,7 @@ namespace XFX
|
||||
Transform(sourceArray[i], matrix, destinationArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Vector3::Transform(const Vector3 sourceArray[], const int sourceIndex, const Quaternion rotation, Vector3 destinationArray[], const int destinationIndex, const int length)
|
||||
{
|
||||
sassert(sourceArray != null, String::Format("sourceArray; %s", FrameworkResources::ArgumentNull_Generic));
|
||||
@ -502,19 +516,19 @@ namespace XFX
|
||||
Transform(sourceArray[i], rotation, destinationArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::TransformNormal(Vector3 normal, Matrix matrix)
|
||||
{
|
||||
Vector3 result;
|
||||
TransformNormal(normal, matrix, result);
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector3::TransformNormal(Vector3 normal, Matrix matrix, out Vector3& result)
|
||||
{
|
||||
result.X = ((normal.X * matrix.M11) + (normal.Y * matrix.M21)) + (normal.Z * matrix.M31);
|
||||
result.Y = ((normal.X * matrix.M12) + (normal.Y * matrix.M22)) + (normal.Z * matrix.M32);
|
||||
result.Z = ((normal.X * matrix.M13) + (normal.Y * matrix.M23)) + (normal.Z * matrix.M33);
|
||||
result.Y = ((normal.X * matrix.M12) + (normal.Y * matrix.M22)) + (normal.Z * matrix.M32);
|
||||
result.Z = ((normal.X * matrix.M13) + (normal.Y * matrix.M23)) + (normal.Z * matrix.M33);
|
||||
}
|
||||
|
||||
void Vector3::TransformNormal(const Vector3 sourceArray[], const int sourceIndex, const Matrix matrix, Vector3 destinationArray[], const int destinationIndex, const int length)
|
||||
@ -528,7 +542,7 @@ namespace XFX
|
||||
TransformNormal(sourceArray[i], matrix, destinationArray[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator+(const Vector3& other)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -537,7 +551,7 @@ namespace XFX
|
||||
result.Z = Z + other.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator/(const float divider)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -546,7 +560,7 @@ namespace XFX
|
||||
result.Z = Z / divider;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator/(const Vector3& other)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -555,17 +569,17 @@ namespace XFX
|
||||
result.Z = Z / other.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
bool Vector3::operator==(const Vector3& other) const
|
||||
{
|
||||
return Equals(other);
|
||||
}
|
||||
|
||||
|
||||
bool Vector3::operator!=(const Vector3& other) const
|
||||
{
|
||||
return !Equals(other);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator*(const float scaleFactor)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -574,7 +588,7 @@ namespace XFX
|
||||
result.Z = Z * scaleFactor;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator*(const Vector3& other)
|
||||
{
|
||||
Vector3 result;
|
||||
@ -583,12 +597,12 @@ namespace XFX
|
||||
result.Z = Z * other.Z;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator-(const Vector3& other)
|
||||
{
|
||||
return Vector3(X -= other.X, Y -= other.Y, Z -= other.Z);
|
||||
}
|
||||
|
||||
|
||||
Vector3 Vector3::operator-()
|
||||
{
|
||||
return Vector3(-X, -Y, -Z);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <Vector4.h>
|
||||
#include <System/Array.h>
|
||||
#include <System/Math.h>
|
||||
#include <System/Type.h>
|
||||
|
||||
#include <sassert.h>
|
||||
|
||||
@ -46,6 +47,7 @@ namespace XFX
|
||||
const Vector4 Vector4::UnitY = Vector4(0,1,0,0);
|
||||
const Vector4 Vector4::UnitZ = Vector4(0,0,1,0);
|
||||
const Vector4 Vector4::Zero = Vector4(0,0,0,0);
|
||||
const Type Vector4TypeInfo("Vector4", "XFX::Vector4", TypeCode::Object);
|
||||
|
||||
Vector4::Vector4(float value)
|
||||
: X(value), Y(value), Z(value), W(value)
|
||||
@ -66,12 +68,12 @@ namespace XFX
|
||||
: X(value.X), Y(value.Y), Z(value.Z), W(w)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Vector4::Vector4(const Vector4 &obj)
|
||||
: X(obj.X), Y(obj.Y), Z(obj.Z), W(obj.W)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Vector4::Vector4()
|
||||
: X(0), Y(0), Z(0), W(0)
|
||||
{
|
||||
@ -91,22 +93,22 @@ namespace XFX
|
||||
result.Y = vector1.Y + vector2.Y;
|
||||
result.Z = vector1.Z + vector2.Z;
|
||||
}
|
||||
|
||||
|
||||
Vector4 Vector4::Baricentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2)
|
||||
{
|
||||
Vector4 result;
|
||||
Baricentric(value1, value2, value3, amount1, amount2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector4::Baricentric(Vector4 value1, Vector4 value2, Vector4 value3, float amount1, float amount2, out Vector4& result)
|
||||
{
|
||||
result.X = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper::Baricentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
result.Z = MathHelper::Baricentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||
result.W = MathHelper::Baricentric(value1.W, value2.W, value3.W, amount1, amount2);
|
||||
result.X = MathHelper::Baricentric(value1.X, value2.X, value3.X, amount1, amount2);
|
||||
result.Y = MathHelper::Baricentric(value1.Y, value2.Y, value3.Y, amount1, amount2);
|
||||
result.Z = MathHelper::Baricentric(value1.Z, value2.Z, value3.Z, amount1, amount2);
|
||||
result.W = MathHelper::Baricentric(value1.W, value2.W, value3.W, amount1, amount2);
|
||||
}
|
||||
|
||||
|
||||
Vector4 Vector4::CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount)
|
||||
{
|
||||
Vector4 result;
|
||||
@ -116,7 +118,7 @@ namespace XFX
|
||||
result.W = MathHelper::CatmullRom(value1.W, value2.W, value3.W, value4.W, amount);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector4::CatmullRom(Vector4 value1, Vector4 value2, Vector4 value3, Vector4 value4, float amount, out Vector4& result)
|
||||
{
|
||||
result.X = MathHelper::CatmullRom(value1.X, value2.X, value3.X, value4.X, amount);
|
||||
@ -124,49 +126,49 @@ namespace XFX
|
||||
result.Z = MathHelper::CatmullRom(value1.Z, value2.Z, value3.Z, value4.Z, amount);
|
||||
result.W = MathHelper::CatmullRom(value1.W, value2.W, value3.W, value4.W, amount);
|
||||
}
|
||||
|
||||
|
||||
Vector4 Vector4::Clamp(Vector4 value1, Vector4 min, Vector4 max)
|
||||
{
|
||||
Vector4 result;
|
||||
Clamp(value1, min, max, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void Vector4::Clamp(Vector4 value1, Vector4 min, Vector4 max, out Vector4& result)
|
||||
{
|
||||
result = Vector4(
|
||||
MathHelper::Clamp(value1.X, min.X, max.X),
|
||||
MathHelper::Clamp(value1.Y, min.Y, max.Y),
|
||||
MathHelper::Clamp(value1.Z, min.Z, max.Z),
|
||||
MathHelper::Clamp(value1.W, min.W, max.W));
|
||||
}
|
||||
result = Vector4(
|
||||
MathHelper::Clamp(value1.X, min.X, max.X),
|
||||
MathHelper::Clamp(value1.Y, min.Y, max.Y),
|
||||
MathHelper::Clamp(value1.Z, min.Z, max.Z),
|
||||
MathHelper::Clamp(value1.W, min.W, max.W));
|
||||
}
|
||||
|
||||
float Vector4::Distance(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
return Math::Sqrt(DistanceSquared(value1, value2));
|
||||
}
|
||||
|
||||
void Vector4::Distance(Vector4 value1, Vector4 value2, out float& result)
|
||||
{
|
||||
result = Math::Sqrt(DistanceSquared(value1, value2));
|
||||
}
|
||||
|
||||
float Vector4::DistanceSquared(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
float result = (value1.W - value2.W) * (value1.W - value2.W) +
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
(value1.Y - value2.Y) * (value1.Y - value2.Y) +
|
||||
(value1.Z - value2.Z) * (value1.Z - value2.Z);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::DistanceSquared(Vector4 value1, Vector4 value2, out float& result)
|
||||
{
|
||||
result = (value1.W - value2.W) * (value1.W - value2.W) +
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
(value1.Y - value2.Y) * (value1.Y - value2.Y) +
|
||||
(value1.Z - value2.Z) * (value1.Z - value2.Z);
|
||||
}
|
||||
float Vector4::Distance(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
return Math::Sqrt(DistanceSquared(value1, value2));
|
||||
}
|
||||
|
||||
void Vector4::Distance(Vector4 value1, Vector4 value2, out float& result)
|
||||
{
|
||||
result = Math::Sqrt(DistanceSquared(value1, value2));
|
||||
}
|
||||
|
||||
float Vector4::DistanceSquared(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
float result = (value1.W - value2.W) * (value1.W - value2.W) +
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
(value1.Y - value2.Y) * (value1.Y - value2.Y) +
|
||||
(value1.Z - value2.Z) * (value1.Z - value2.Z);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::DistanceSquared(Vector4 value1, Vector4 value2, out float& result)
|
||||
{
|
||||
result = (value1.W - value2.W) * (value1.W - value2.W) +
|
||||
(value1.X - value2.X) * (value1.X - value2.X) +
|
||||
(value1.Y - value2.Y) * (value1.Y - value2.Y) +
|
||||
(value1.Z - value2.Z) * (value1.Z - value2.Z);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Divide(Vector4 value, float scale)
|
||||
{
|
||||
@ -209,153 +211,157 @@ namespace XFX
|
||||
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 result;
|
||||
Hermite(value1, tangent1, value2, tangent2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount, out Vector4& result)
|
||||
{
|
||||
result.W = MathHelper::Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount);
|
||||
result.X = MathHelper::Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper::Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
result.Z = MathHelper::Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount);
|
||||
}
|
||||
|
||||
float Vector4::Length()
|
||||
{
|
||||
return Math::Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W));
|
||||
}
|
||||
|
||||
float Vector4::LengthSquared()
|
||||
{
|
||||
return (X * X) + (Y * Y) + (Z * Z) + (W * W);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Lerp(Vector4 value1, Vector4 value2, float amount)
|
||||
{
|
||||
Vector4 result;
|
||||
Lerp(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Lerp(Vector4 value1, Vector4 value2, float amount, out Vector4& result)
|
||||
{
|
||||
|
||||
Vector4 Vector4::Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount)
|
||||
{
|
||||
Vector4 result;
|
||||
Hermite(value1, tangent1, value2, tangent2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Hermite(Vector4 value1, Vector4 tangent1, Vector4 value2, Vector4 tangent2, float amount, out Vector4& result)
|
||||
{
|
||||
result.W = MathHelper::Hermite(value1.W, tangent1.W, value2.W, tangent2.W, amount);
|
||||
result.X = MathHelper::Hermite(value1.X, tangent1.X, value2.X, tangent2.X, amount);
|
||||
result.Y = MathHelper::Hermite(value1.Y, tangent1.Y, value2.Y, tangent2.Y, amount);
|
||||
result.Z = MathHelper::Hermite(value1.Z, tangent1.Z, value2.Z, tangent2.Z, amount);
|
||||
}
|
||||
|
||||
float Vector4::Length()
|
||||
{
|
||||
return Math::Sqrt((X * X) + (Y * Y) + (Z * Z) + (W * W));
|
||||
}
|
||||
|
||||
float Vector4::LengthSquared()
|
||||
{
|
||||
return (X * X) + (Y * Y) + (Z * Z) + (W * W);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Lerp(Vector4 value1, Vector4 value2, float amount)
|
||||
{
|
||||
Vector4 result;
|
||||
Lerp(value1, value2, amount, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Lerp(Vector4 value1, Vector4 value2, float amount, out Vector4& result)
|
||||
{
|
||||
result.X = MathHelper::Lerp(value1.X, value2.X, amount);
|
||||
result.Y = MathHelper::Lerp(value1.Y, value2.Y, amount);
|
||||
result.Z = MathHelper::Lerp(value1.Z, value2.Z, amount);
|
||||
result.W = MathHelper::Lerp(value1.W, value2.W, amount);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Max(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Max(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Max(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result.W = MathHelper::Lerp(value1.W, value2.W, amount);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Max(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Max(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Max(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result.X = MathHelper::Max(value1.X, value2.X);
|
||||
result.Y = MathHelper::Max(value1.Y, value2.Y);
|
||||
result.Z = MathHelper::Max(value1.Z, value2.Z);
|
||||
result.W = MathHelper::Max(value1.W, value2.W);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Min(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Min(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Min(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result = Vector4(
|
||||
MathHelper::Min(value1.X, value2.X),
|
||||
MathHelper::Min(value1.Y, value2.Y),
|
||||
MathHelper::Min(value1.Z, value2.Z),
|
||||
MathHelper::Min(value1.W, value2.W));
|
||||
}
|
||||
|
||||
Vector4 Vector4::Multiply(Vector4 value1, float scaleFactor)
|
||||
{
|
||||
Vector4 result;
|
||||
Multiply(value1, scaleFactor, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Multiply(Vector4 value1, float scaleFactor, out Vector4& result)
|
||||
{
|
||||
result.W = MathHelper::Max(value1.W, value2.W);
|
||||
}
|
||||
|
||||
Vector4 Vector4::Min(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Min(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Min(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result = Vector4(
|
||||
MathHelper::Min(value1.X, value2.X),
|
||||
MathHelper::Min(value1.Y, value2.Y),
|
||||
MathHelper::Min(value1.Z, value2.Z),
|
||||
MathHelper::Min(value1.W, value2.W));
|
||||
}
|
||||
|
||||
Vector4 Vector4::Multiply(Vector4 value1, float scaleFactor)
|
||||
{
|
||||
Vector4 result;
|
||||
Multiply(value1, scaleFactor, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Multiply(Vector4 value1, float scaleFactor, out Vector4& result)
|
||||
{
|
||||
result.X = value1.X * scaleFactor;
|
||||
result.Y = value1.Y * scaleFactor;
|
||||
result.Z = value1.Z * scaleFactor;
|
||||
result.W = value1.W * scaleFactor;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Multiply(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Multiply(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Multiply(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result.W = value1.W * value2.W;
|
||||
result.X = value1.X * value2.X;
|
||||
result.Y = value1.Y * value2.Y;
|
||||
result.Z = value1.Z * value2.Z;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Negate(Vector4 value)
|
||||
{
|
||||
Vector4 result;
|
||||
result.Y = value1.Y * scaleFactor;
|
||||
result.Z = value1.Z * scaleFactor;
|
||||
result.W = value1.W * scaleFactor;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Multiply(Vector4 value1, Vector4 value2)
|
||||
{
|
||||
Vector4 result;
|
||||
Multiply(value1, value2, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Multiply(Vector4 value1, Vector4 value2, out Vector4& result)
|
||||
{
|
||||
result.W = value1.W * value2.W;
|
||||
result.X = value1.X * value2.X;
|
||||
result.Y = value1.Y * value2.Y;
|
||||
result.Z = value1.Z * value2.Z;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Negate(Vector4 value)
|
||||
{
|
||||
Vector4 result;
|
||||
Negate(value, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void Vector4::Negate(Vector4 value, out Vector4& result)
|
||||
{
|
||||
result = Vector4(-value.X, -value.Y, -value.Z, -value.W);
|
||||
}
|
||||
|
||||
void Vector4::Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
if( length == 0 )
|
||||
return;
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
Z *= num;
|
||||
W *= num;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Normalize(Vector4 value)
|
||||
{
|
||||
Normalize(value, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Vector4::Normalize(Vector4 value, out Vector4& result)
|
||||
{
|
||||
float factor;
|
||||
float length = value.Length();
|
||||
factor = 1.0f / length;
|
||||
|
||||
result.W = value.W * factor;
|
||||
result.X = value.X * factor;
|
||||
result.Y = value.Y * factor;
|
||||
result.Z = value.Z * factor;
|
||||
}
|
||||
}
|
||||
|
||||
void Vector4::Negate(Vector4 value, out Vector4& result)
|
||||
{
|
||||
result = Vector4(-value.X, -value.Y, -value.Z, -value.W);
|
||||
}
|
||||
|
||||
void Vector4::Normalize()
|
||||
{
|
||||
float length = Length();
|
||||
|
||||
if(length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 1 / length;
|
||||
X *= num;
|
||||
Y *= num;
|
||||
Z *= num;
|
||||
W *= num;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Normalize(Vector4 value)
|
||||
{
|
||||
Normalize(value, value);
|
||||
return value;
|
||||
}
|
||||
|
||||
void Vector4::Normalize(Vector4 value, out Vector4& result)
|
||||
{
|
||||
float factor;
|
||||
float length = value.Length();
|
||||
factor = 1.0f / length;
|
||||
|
||||
result.W = value.W * factor;
|
||||
result.X = value.X * factor;
|
||||
result.Y = value.Y * factor;
|
||||
result.Z = value.Z * factor;
|
||||
}
|
||||
|
||||
Vector4 Vector4::SmoothStep(Vector4 value1, Vector4 value2, float amount)
|
||||
{
|
||||
@ -363,7 +369,7 @@ namespace XFX
|
||||
MathHelper::SmoothStep(value1.X, value2.X, amount),
|
||||
MathHelper::SmoothStep(value1.Y, value2.Y, amount),
|
||||
MathHelper::SmoothStep(value1.Z, value2.Z, amount),
|
||||
MathHelper::SmoothStep(value1.W, value2.W, amount));
|
||||
MathHelper::SmoothStep(value1.W, value2.W, amount));
|
||||
}
|
||||
|
||||
void Vector4::SmoothStep(Vector4 value1, Vector4 value2, float amount, out Vector4& result)
|
||||
@ -372,7 +378,7 @@ namespace XFX
|
||||
MathHelper::SmoothStep(value1.X, value2.X, amount),
|
||||
MathHelper::SmoothStep(value1.Y, value2.Y, amount),
|
||||
MathHelper::SmoothStep(value1.Z, value2.Z, amount),
|
||||
MathHelper::SmoothStep(value1.W, value2.W, amount));
|
||||
MathHelper::SmoothStep(value1.W, value2.W, amount));
|
||||
}
|
||||
|
||||
Vector4 Vector4::Subtract(Vector4 vector1, Vector4 vector2)
|
||||
@ -464,7 +470,7 @@ namespace XFX
|
||||
result.X = ((vector.X * ((1.0f - yy) - zz)) + (vector.Y * (xy - wz))) + (vector.Z * (xz + wy));
|
||||
result.Y = ((vector.X * (xy + wz)) + (vector.Y * ((1.0f - xx) - zz))) + (vector.Z * (yz - wx));
|
||||
result.Z = ((vector.X * (xz - wy)) + (vector.Y * (yz + wx))) + (vector.Z * ((1.0f - xx) - yy));
|
||||
result.W = 1.0f;
|
||||
result.W = 1.0f;
|
||||
}
|
||||
|
||||
Vector4 Vector4::Transform(Vector2 vector, Quaternion rotation)
|
||||
@ -549,7 +555,7 @@ namespace XFX
|
||||
W -= other.W;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Vector4 Vector4::operator -()
|
||||
{
|
||||
return Vector4(-X, -Y, -Z, -W);
|
||||
|
Loading…
x
Reference in New Issue
Block a user