Merge remote-tracking branch 'origin/master' into 1.1

# Conflicts:
#	Source/Editor/Surface/SurfaceNode.cs
This commit is contained in:
Wojtek Figat
2021-01-27 10:39:44 +01:00
43 changed files with 1115 additions and 268 deletions

View File

@@ -15,7 +15,7 @@ void CollisionsHelper::ClosestPointPointLine(const Vector2& point, const Vector2
Vector2 n = p1 - p0;
const float length = n.Length();
if (length < 1e-10)
if (length < 1e-10f)
{
// Both points are the same, just give any
result = p0;
@@ -24,7 +24,7 @@ void CollisionsHelper::ClosestPointPointLine(const Vector2& point, const Vector2
n /= length;
const float dot = Vector2::Dot(n, p);
if (dot <= 0.0)
if (dot <= 0.0f)
{
// Before first point
result = p0;
@@ -41,6 +41,45 @@ void CollisionsHelper::ClosestPointPointLine(const Vector2& point, const Vector2
}
}
Vector2 CollisionsHelper::ClosestPointPointLine(const Vector2& point, const Vector2& p0, const Vector2& p1)
{
Vector2 result;
ClosestPointPointLine(point, p0, p1, result);
return result;
}
void CollisionsHelper::ClosestPointPointLine(const Vector3& point, const Vector3& p0, const Vector3& p1, Vector3& result)
{
const Vector3 p = point - p0;
Vector3 n = p1 - p0;
const float length = n.Length();
if (length < 1e-10f)
{
result = p0;
return;
}
n /= length;
const float dot = Vector3::Dot(n, p);
if (dot <= 0.0f)
{
result = p0;
return;
}
if (dot >= length)
{
result = p1;
return;
}
result = p0 + n * dot;
}
Vector3 CollisionsHelper::ClosestPointPointLine(const Vector3& point, const Vector3& p0, const Vector3& p1)
{
Vector3 result;
ClosestPointPointLine(point, p0, p1, result);
return result;
}
void CollisionsHelper::ClosestPointPointTriangle(const Vector3& point, const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3, Vector3& result)
{
// Source: Real-Time Collision Detection by Christer Ericson
@@ -101,6 +140,13 @@ void CollisionsHelper::ClosestPointPointTriangle(const Vector3& point, const Vec
result = vertex1 + ab * v2 + ac * w2; //= u*vertex1 + v*vertex2 + w*vertex3, u = va * denom = 1.0f - v - w
}
Vector3 CollisionsHelper::ClosestPointPointTriangle(const Vector3& point, const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3)
{
Vector3 result;
ClosestPointPointTriangle(point, vertex1, vertex2, vertex3, result);
return result;
}
void CollisionsHelper::ClosestPointPlanePoint(const Plane& plane, const Vector3& point, Vector3& result)
{
// Source: Real-Time Collision Detection by Christer Ericson
@@ -112,6 +158,13 @@ void CollisionsHelper::ClosestPointPlanePoint(const Plane& plane, const Vector3&
result = point - t * plane.Normal;
}
Vector3 CollisionsHelper::ClosestPointPlanePoint(const Plane& plane, const Vector3& point)
{
Vector3 result;
ClosestPointPlanePoint(plane, point, result);
return result;
}
void CollisionsHelper::ClosestPointBoxPoint(const BoundingBox& box, const Vector3& point, Vector3& result)
{
// Source: Real-Time Collision Detection by Christer Ericson
@@ -122,6 +175,13 @@ void CollisionsHelper::ClosestPointBoxPoint(const BoundingBox& box, const Vector
Vector3::Min(temp, box.Maximum, result);
}
Vector3 CollisionsHelper::ClosestPointBoxPoint(const BoundingBox& box, const Vector3& point)
{
Vector3 result;
ClosestPointBoxPoint(box, point, result);
return result;
}
void CollisionsHelper::ClosestPointRectanglePoint(const Rectangle& rect, const Vector2& point, Vector2& result)
{
Vector2 temp, end;
@@ -130,6 +190,13 @@ void CollisionsHelper::ClosestPointRectanglePoint(const Rectangle& rect, const V
Vector2::Min(temp, end, result);
}
Vector2 CollisionsHelper::ClosestPointRectanglePoint(const Rectangle& rect, const Vector2& point)
{
Vector2 result;
ClosestPointRectanglePoint(rect, point, result);
return result;
}
void CollisionsHelper::ClosestPointSpherePoint(const BoundingSphere& sphere, const Vector3& point, Vector3& result)
{
// Source: Jorgy343
@@ -147,6 +214,13 @@ void CollisionsHelper::ClosestPointSpherePoint(const BoundingSphere& sphere, con
result += sphere.Center;
}
Vector3 CollisionsHelper::ClosestPointSpherePoint(const BoundingSphere& sphere, const Vector3& point)
{
Vector3 result;
ClosestPointSpherePoint(sphere, point, result);
return result;
}
void CollisionsHelper::ClosestPointSphereSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2, Vector3& result)
{
// Source: Jorgy343
@@ -164,6 +238,13 @@ void CollisionsHelper::ClosestPointSphereSphere(const BoundingSphere& sphere1, c
result += sphere1.Center;
}
Vector3 CollisionsHelper::ClosestPointSphereSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2)
{
Vector3 result;
ClosestPointSphereSphere(sphere1, sphere2, result);
return result;
}
float CollisionsHelper::DistancePlanePoint(const Plane& plane, const Vector3& point)
{
// Source: Real-Time Collision Detection by Christer Ericson
@@ -821,7 +902,6 @@ bool CollisionsHelper::RayIntersectsBox(const Ray& ray, const BoundingBox& box,
d = Math::Abs(size.Z - Math::Abs(localPoint.Z));
if (d < dMin)
{
dMin = d;
normal = Vector3(0, 0, Math::Sign(localPoint.Z));
}
@@ -990,15 +1070,11 @@ PlaneIntersectionType CollisionsHelper::PlaneIntersectsBox(const Plane& plane, c
min.Z = plane.Normal.Z >= 0.0f ? box.Maximum.Z : box.Minimum.Z;
float distance = Vector3::Dot(plane.Normal, max);
if (distance + plane.D > Plane::DistanceEpsilon)
return PlaneIntersectionType::Front;
distance = Vector3::Dot(plane.Normal, min);
if (distance + plane.D < Plane::DistanceEpsilon)
return PlaneIntersectionType::Back;
return PlaneIntersectionType::Intersecting;
}
@@ -1012,10 +1088,8 @@ PlaneIntersectionType CollisionsHelper::PlaneIntersectsSphere(const Plane& plane
if (distance > sphere.Radius)
return PlaneIntersectionType::Front;
if (distance < -sphere.Radius)
return PlaneIntersectionType::Back;
return PlaneIntersectionType::Intersecting;
}
@@ -1023,13 +1097,10 @@ bool CollisionsHelper::BoxIntersectsBox(const BoundingBox& box1, const BoundingB
{
if (box1.Minimum.X > box2.Maximum.X || box2.Minimum.X > box1.Maximum.X)
return false;
if (box1.Minimum.Y > box2.Maximum.Y || box2.Minimum.Y > box1.Maximum.Y)
return false;
if (box1.Minimum.Z > box2.Maximum.Z || box2.Minimum.Z > box1.Maximum.Z)
return false;
return true;
}

View File

@@ -72,6 +72,33 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointPointLine(const Vector2& point, const Vector2& p0, const Vector2& p1, Vector2& result);
/// <summary>
/// Determines the closest point between a point and a line.
/// </summary>
/// <param name="point">The point to test.</param>
/// <param name="p0">The line first point.</param>
/// <param name="p1">The line second point.</param>
/// <returns>The closest point between the two objects.</result>
static Vector2 ClosestPointPointLine(const Vector2& point, const Vector2& p0, const Vector2& p1);
/// <summary>
/// Determines the closest point between a point and a line.
/// </summary>
/// <param name="point">The point to test.</param>
/// <param name="p0">The line first point.</param>
/// <param name="p1">The line second point.</param>
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointPointLine(const Vector3& point, const Vector3& p0, const Vector3& p1, Vector3& result);
/// <summary>
/// Determines the closest point between a point and a line.
/// </summary>
/// <param name="point">The point to test.</param>
/// <param name="p0">The line first point.</param>
/// <param name="p1">The line second point.</param>
/// <returns>The closest point between the two objects.</result>
static Vector3 ClosestPointPointLine(const Vector3& point, const Vector3& p0, const Vector3& p1);
/// <summary>
/// Determines the closest point between a point and a triangle.
/// </summary>
@@ -82,6 +109,16 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointPointTriangle(const Vector3& point, const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3, Vector3& result);
/// <summary>
/// Determines the closest point between a point and a triangle.
/// </summary>
/// <param name="point">The point to test.</param>
/// <param name="vertex1">The first vertex to test.</param>
/// <param name="vertex2">The second vertex to test.</param>
/// <param name="vertex3">The third vertex to test.</param>
/// <returns>The closest point between the two objects.</returns>
static Vector3 ClosestPointPointTriangle(const Vector3& point, const Vector3& vertex1, const Vector3& vertex2, const Vector3& vertex3);
/// <summary>
/// Determines the closest point between a <see cref="Plane" /> and a point.
/// </summary>
@@ -90,6 +127,14 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointPlanePoint(const Plane& plane, const Vector3& point, Vector3& result);
/// <summary>
/// Determines the closest point between a <see cref="Plane" /> and a point.
/// </summary>
/// <param name="plane">The plane to test.</param>
/// <param name="point">The point to test.</param>
/// <returns>The closest point between the two objects.</returns>
static Vector3 ClosestPointPlanePoint(const Plane& plane, const Vector3& point);
/// <summary>
/// Determines the closest point between a <see cref="BoundingBox" /> and a point.
/// </summary>
@@ -98,6 +143,14 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointBoxPoint(const BoundingBox& box, const Vector3& point, Vector3& result);
/// <summary>
/// Determines the closest point between a <see cref="BoundingBox" /> and a point.
/// </summary>
/// <param name="box">The box to test.</param>
/// <param name="point">The point to test.</param>
/// <returns>The closest point between the two objects.</returns>
static Vector3 ClosestPointBoxPoint(const BoundingBox& box, const Vector3& point);
/// <summary>
/// Determines the closest point between a <see cref="Rectangle" /> and a point.
/// </summary>
@@ -106,6 +159,14 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects.</param>
static void ClosestPointRectanglePoint(const Rectangle& rect, const Vector2& point, Vector2& result);
/// <summary>
/// Determines the closest point between a <see cref="Rectangle" /> and a point.
/// </summary>
/// <param name="rect">The rectangle to test.</param>
/// <param name="point">The point to test.</param>
/// <returns>The closest point between the two objects.</returns>
static Vector2 ClosestPointRectanglePoint(const Rectangle& rect, const Vector2& point);
/// <summary>
/// Determines the closest point between a <see cref="BoundingSphere" /> and a point.
/// </summary>
@@ -114,6 +175,14 @@ public:
/// <param name="result">When the method completes, contains the closest point between the two objects; or, if the point is directly in the center of the sphere, contains <see cref="Vector3.Zero" />.</param>
static void ClosestPointSpherePoint(const BoundingSphere& sphere, const Vector3& point, Vector3& result);
/// <summary>
/// Determines the closest point between a <see cref="BoundingSphere" /> and a point.
/// </summary>
/// <param name="sphere">The sphere to test.</param>
/// <param name="point">The point to test.</param>
/// <returns>The closest point between the two objects; or, if the point is directly in the center of the sphere, contains <see cref="Vector3.Zero" />.</return>
static Vector3 ClosestPointSpherePoint(const BoundingSphere& sphere, const Vector3& point);
/// <summary>
/// Determines the closest point between a <see cref="BoundingSphere" /> and a <see cref="BoundingSphere" />.
/// </summary>
@@ -127,6 +196,19 @@ public:
/// </remarks>
static void ClosestPointSphereSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2, Vector3& result);
/// <summary>
/// Determines the closest point between a <see cref="BoundingSphere" /> and a <see cref="BoundingSphere" />.
/// </summary>
/// <param name="sphere1">The first sphere to test.</param>
/// <param name="sphere2">The second sphere to test.</param>
/// <returns>The closest point between the two objects; or, if the point is directly in the center of the sphere, contains <see cref="Vector3.Zero" />.</returns>
/// <remarks>
/// If the two spheres are overlapping, but not directly on top of each other, the closest point
/// is the 'closest' point of intersection. This can also be considered is the deepest point of
/// intersection.
/// </remarks>
static Vector3 ClosestPointSphereSphere(const BoundingSphere& sphere1, const BoundingSphere& sphere2);
/// <summary>
/// Determines the distance between a <see cref="Plane" /> and a point.
/// </summary>