ソースを参照

Remove some unneeded crymath files. (#19072)

Signed-off-by: Ross Charles C. <[email protected]>
Ross Charles C. 3 週間 前
コミット
2601439943

+ 0 - 1
Code/Editor/EditorDefs.h

@@ -116,7 +116,6 @@
 #include "Util/EditorUtils.h"
 #include "Util/FileEnum.h"
 #include <Editor/Util/EditorUtils.h>
-#include <CryCommon/Cry_GeoIntersect.h>
 #include "Util/AffineParts.h"
 
 // Xml support.

+ 0 - 111
Code/Legacy/CryCommon/Cry_Geo.h

@@ -15,99 +15,10 @@
 // Forward declarations                                                      //
 ///////////////////////////////////////////////////////////////////////////////
 
-struct Ray;
-template <typename F>
-struct Lineseg_tpl;
-template <typename F>
-struct Triangle_tpl;
-
 struct AABB;
 template <typename F>
 struct OBB_tpl;
 
-//-----------------------------------------------------
-
-
-///////////////////////////////////////////////////////////////////////////////
-// Definitions                                                               //
-///////////////////////////////////////////////////////////////////////////////
-
-struct PosNorm
-{
-    Vec3    vPos;
-    Vec3    vNorm;
-};
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// struct Ray
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-struct Ray
-{
-    Vec3 origin;
-    Vec3 direction;
-
-    //default Ray constructor (without initialisation)
-    inline Ray(void) {}
-    inline Ray(const Vec3& o, const Vec3& d) {  origin = o; direction = d; }
-    inline void operator () (const Vec3& o, const Vec3& d) {  origin = o; direction = d; }
-
-    ~Ray(void) {};
-};
-
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// struct Lineseg
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-struct Lineseg
-{
-    Vec3_tpl<float> start;
-    Vec3_tpl<float> end;
-
-    //default Lineseg constructor (without initialisation)
-    inline Lineseg(void) {}
-    inline Lineseg(const Vec3_tpl<float>& s, const Vec3_tpl<float>& e) {  start = s; end = e; }
-
-    ~Lineseg(void) {};
-};
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// struct Triangle
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-template <typename F>
-struct Triangle_tpl
-{
-    Vec3_tpl<F> v0, v1, v2;
-
-    //default Lineseg constructor (without initialisation)
-    ILINE Triangle_tpl(void) {}
-    ILINE Triangle_tpl(const Vec3_tpl<F>& a, const Vec3_tpl<F>& b, const Vec3_tpl<F>& c) {  v0 = a; v1 = b; v2 = c; }
-    ILINE void operator () (const Vec3_tpl<F>& a, const Vec3_tpl<F>& b, const Vec3_tpl<F>& c) { v0 = a; v1 = b; v2 = c; }
-
-    ~Triangle_tpl(void) {};
-
-    Vec3_tpl<F> GetNormal() const
-    {
-        return ((v1 - v0) ^ (v2 - v0)).GetNormalized();
-    }
-
-    F GetArea() const
-    {
-        return 0.5f * (v1 - v0).Cross(v2 - v0).GetLength();
-    }
-};
-
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////////////
@@ -358,25 +269,3 @@ struct OBB_tpl
 
 typedef OBB_tpl<f32>    OBB;
 
-
-
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-// struct Sphere
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-struct Sphere
-{
-    Vec3 center;
-    float radius;
-
-    Sphere() {}
-    Sphere(const Vec3& c, float r)
-        : center(c)
-        , radius(r) {}
-    void operator()(const Vec3& c, float r) { center = c; radius = r; }
-};
-
-typedef Triangle_tpl<f32>   Triangle;

+ 0 - 128
Code/Legacy/CryCommon/Cry_GeoDistance.h

@@ -1,128 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-
-// Description : Common distance-computations
-#pragma once
-
-#include <Cry_Geo.h>
-#include <AzCore/Math/Vector3.h>
-
-#ifdef max
-#undef max
-#endif
-
-namespace Distance {
-    //----------------------------------------------------------------------------------
-    /// Returns squared distance from a point to a line segment and also the "t value" (from 0 to 1) of the
-    /// closest point on the line segment
-    //----------------------------------------------------------------------------------
-    template<typename F>
-    ILINE F Point_LinesegSq(const Vec3_tpl<F>& p, const Lineseg& lineseg, F& fT)
-    {
-        Vec3_tpl<F> diff = p - lineseg.start;
-        Vec3_tpl<F> dir = lineseg.end - lineseg.start;
-        fT = diff.Dot(dir);
-
-        if (fT <= 0.0f)
-        {
-            fT = 0.0f;
-        }
-        else
-        {
-            F fSqrLen = dir.GetLengthSquared();
-            if (fT >= fSqrLen)
-            {
-                fT = 1.0f;
-                diff -= dir;
-            }
-            else
-            {
-                fT /= fSqrLen;
-                diff -= fT * dir;
-            }
-        }
-
-        return diff.GetLengthSquared();
-    }
-
-    /// Returns distance from a point to a line segment and also the "t value" (from 0 to 1) of the
-    /// closest point on the line segment
-    template<typename F>
-    ILINE F Point_Lineseg(const Vec3_tpl<F>& p, const Lineseg& lineseg, F& fT)
-    {
-        return sqrt_tpl(Point_LinesegSq(p, lineseg, fT));
-    }
-
-    //! \brief Get the distance squared from a Point to a Cylinder.
-    //! \param point AZ::Vector3 The point to test distance against the cylinder
-    //! \param cylinderAxisEndA AZ::Vector3 One end of the cylinder axis (centered in the circle)
-    //! \param cylinderAxisEndB AZ::Vector3 Other end of the cylinder axis (centered in the circle)
-    //! \param radius float Radius of the cylinder
-    //! \return float Closest distance squared from the point to the cylinder.
-    AZ_INLINE float Point_CylinderSq(
-        const AZ::Vector3& point,
-        const AZ::Vector3& cylinderAxisEndA,
-        const AZ::Vector3& cylinderAxisEndB,
-        float radius
-    )
-    {
-        // Use the cylinder axis' center point to determine distance by
-        // splitting into Voronoi regions and using symmetry.
-        // The regions are:
-        // - Inside
-        // - Beyond cylinder radius but between two disc ends.
-        // - Within cylinder radius but beyond two disc ends.
-        // - Beyond cylinder radius and beyond two disc ends.
-
-        const AZ::Vector3 cylinderAxis = cylinderAxisEndB - cylinderAxisEndA;
-        float halfLength = cylinderAxis.GetLength() * 0.5f;
-        const AZ::Vector3 cylinderAxisUnit = cylinderAxis.GetNormalized();
-
-        // get the center of the axis and the vector from center to the test point
-        const AZ::Vector3 centerPoint = (cylinderAxis * 0.5) + cylinderAxisEndA;
-        const AZ::Vector3 pointToCenter = point - centerPoint;
-
-        // distance point is from center (projected onto axis)
-        // the abs here takes advantage of symmetry.
-        float x = fabsf(pointToCenter.Dot(cylinderAxisUnit));
-
-        // squared distance from point to center (hypotenuse)
-        float n2 = pointToCenter.GetLengthSq();
-
-        // squared distance from point to center perpendicular to axis (pythagorean)
-        float y2 = n2 - sqr(x);
-
-        float distanceSquared = 0.f;
-
-        if (x < halfLength) // point is between the two ends
-        {
-            if (y2 > sqr(radius))   // point is outside of radius
-            {
-                distanceSquared = sqr(sqrtf(y2) - radius);
-            }
-            // else point is inside cylinder, distance is zero.
-        }
-        else if (y2 < sqr(radius))
-        {
-            // point is within radius
-            // point projects into a disc at either end, grab the "parallel" distance only
-            distanceSquared = sqr(x - halfLength);
-        }
-        else
-        {
-            // point is outside of radius
-            // point projects onto the edge of the disc, grab distance in two directions,
-            // combine "parallel" and "perpendicular" distances.
-            distanceSquared = sqr(sqrtf(y2) - radius) + sqr(x - halfLength);
-        }
-
-        return distanceSquared;
-    }
-
-} //namespace Distance

+ 0 - 218
Code/Legacy/CryCommon/Cry_GeoIntersect.h

@@ -1,218 +0,0 @@
-/*
- * Copyright (c) Contributors to the Open 3D Engine Project.
- * For complete copyright and license terms please see the LICENSE at the root of this distribution.
- *
- * SPDX-License-Identifier: Apache-2.0 OR MIT
- *
- */
-
-
-// Description : Common intersection-tests
-#pragma once
-
-#include <Cry_Geo.h>
-
-namespace Intersect {
-    inline bool Ray_Plane(const Ray& ray, const Plane_tpl<f32>& plane, Vec3& output, bool bSingleSidePlane = true)
-    {
-        float cosine = plane.n | ray.direction;
-
-        //REJECTION 1: if "line-direction" is perpendicular to "plane-normal", an intersection is not possible! That means ray is parallel
-        //             to the plane
-        //REJECTION 2: if bSingleSidePlane == true we deal with single-sided planes. That means
-        //             if "line-direction" is pointing in the same direction as "the plane-normal",
-        //             an intersection is not possible!
-        if ((cosine == 0.0f) ||                                     // normal is orthogonal to vector, cant intersect
-            (bSingleSidePlane && (cosine > 0.0f)))  // we are trying to find an intersection in the same direction as the plane normal
-        {
-            return false;
-        }
-
-        float numer = plane.DistFromPlane(ray.origin);
-        float fLength = -numer / cosine;
-        output = ray.origin + (ray.direction * fLength);
-        //skip, if cutting-point is "behind" ray.origin
-        if (fLength < 0.0f)
-        {
-            return false;
-        }
-
-        return true;        //intersection occurred
-    }
-
-    /*
-    * calculates intersection between a ray and a triangle.
-    * IMPORTANT: this is a single-sided intersection test. That means its not sufficient
-    * that the triangle and rayt overlap, its also important that the triangle
-    * is "visible" when you from the origin along the ray-direction.
-    *
-    * If you need a double-sided test, you'll have to call this function twice with
-    * reversed order of triangle vertices.
-    *
-    * return values
-    * if there is an intertection the functions return "true" and stores the
-    * 3d-intersection point in "output". if the function returns "false" the value in
-    * "output" is undefined
-    */
-    inline bool Ray_Triangle(const Ray& ray, const Vec3& v0, const Vec3& v1, const Vec3& v2, Vec3& output)
-    {
-        const float Epsilon = 0.0000001f;
-
-        Vec3 edgeA = v1 - v0;
-        Vec3 edgeB = v2 - v0;
-
-        Vec3 dir = ray.direction;
-
-        Vec3 p = dir.Cross(edgeA);
-        Vec3 t = ray.origin - v0;
-        Vec3 q = t.Cross(edgeB);
-
-        float dot = edgeB.Dot(p);
-
-        float u = t.Dot(p);
-        float v = dir.Dot(q);
-
-        float DotGreaterThanEpsilon = dot - Epsilon;
-        float VGreaterEqualThanZero = v;
-        float UGreaterEqualThanZero = u;
-        float UVLessThanDot = dot - (u + v);
-        float ULessThanDot = dot - u;
-
-        float UVGreaterEqualThanZero = (float)fsel(VGreaterEqualThanZero, UGreaterEqualThanZero, VGreaterEqualThanZero);
-        float UUVLessThanDot = (float)fsel(UVLessThanDot, ULessThanDot, UVLessThanDot);
-        float BothGood = (float)fsel(UVGreaterEqualThanZero, UUVLessThanDot, UVGreaterEqualThanZero);
-        float AllGood = (float)fsel(DotGreaterThanEpsilon, BothGood, DotGreaterThanEpsilon);
-
-        if (AllGood < 0.0f)
-        {
-            return false;
-        }
-
-        float dt = edgeA.Dot(q) / dot;
-
-        Vec3 result = (dir * dt) + ray.origin;
-        output = result;
-
-        float AfterStart = (result - ray.origin).Dot(dir);
-
-        return AfterStart >= 0.0f;
-    }
-
-    //----------------------------------------------------------------------------------
-    //  Ray_AABB
-    //
-    //  just ONE intersection point is calculated, and thats the entry point           -
-    //   Lineseg and AABB are assumed to be in the same space
-    //
-    //--- 0x00 = no intersection (output undefined)        --------------------------
-    //--- 0x01 = intersection (intersection point in output)              --------------
-    //--- 0x02 = start of Lineseg is inside the AABB (ls.start is output)
-    //----------------------------------------------------------------------------------
-    inline uint8 Ray_AABB(const Ray& ray, const AABB& aabb, Vec3& output1)
-    {
-        uint8 cflags;
-        float cosine;
-        Vec3 cut;
-        //--------------------------------------------------------------------------------------
-        //----         check if "ray.origin" is inside of AABB    ---------------------------
-        //--------------------------------------------------------------------------------------
-        cflags = (ray.origin.x >= aabb.min.x) << 0;
-        cflags |= (ray.origin.x <= aabb.max.x) << 1;
-        cflags |= (ray.origin.y >= aabb.min.y) << 2;
-        cflags |= (ray.origin.y <= aabb.max.y) << 3;
-        cflags |= (ray.origin.z >= aabb.min.z) << 4;
-        cflags |= (ray.origin.z <= aabb.max.z) << 5;
-        if (cflags == 0x3f)
-        {
-            output1 = ray.origin;
-            return 0x02;
-        }
-
-        //--------------------------------------------------------------------------------------
-        //----         check intersection with planes           ------------------------------
-        //--------------------------------------------------------------------------------------
-        for (int i = 0; i < 3; i++)
-        {
-            if ((ray.direction[i] > 0) && (ray.origin[i] < aabb.min[i]))
-            {
-                cosine = (-ray.origin[i] + aabb.min[i]) / ray.direction[i];
-                cut[i] = aabb.min[i];
-                cut[incm3(i)] = ray.origin[incm3(i)] + (ray.direction[incm3(i)] * cosine);
-                cut[decm3(i)] = ray.origin[decm3(i)] + (ray.direction[decm3(i)] * cosine);
-                if ((cut[incm3(i)] > aabb.min[incm3(i)]) && (cut[incm3(i)] < aabb.max[incm3(i)]) && (cut[decm3(i)] > aabb.min[decm3(i)]) && (cut[decm3(i)] < aabb.max[decm3(i)]))
-                {
-                    output1 = cut;
-                    return 0x01;
-                }
-            }
-            if ((ray.direction[i] < 0) && (ray.origin[i] > aabb.max[i]))
-            {
-                cosine = (+ray.origin[i] - aabb.max[i]) / ray.direction[i];
-                cut[i] = aabb.max[i];
-                cut[incm3(i)] = ray.origin[incm3(i)] - (ray.direction[incm3(i)] * cosine);
-                cut[decm3(i)] = ray.origin[decm3(i)] - (ray.direction[decm3(i)] * cosine);
-                if ((cut[incm3(i)] > aabb.min[incm3(i)]) && (cut[incm3(i)] < aabb.max[incm3(i)]) && (cut[decm3(i)] > aabb.min[decm3(i)]) && (cut[decm3(i)] < aabb.max[decm3(i)]))
-                {
-                    output1 = cut;
-                    return 0x01;
-                }
-            }
-        }
-        return 0x00;//no intersection
-    }
-
-    //----------------------------------------------------------------------------------
-    //--- 0x00 = no intersection                               --------------------------
-    //--- 0x01 = not possible   --
-    //--- 0x02 = one intersection, lineseg has just an EXIT point but no ENTRY point (ls.start is inside the sphere)  --
-    //--- 0x03 = two intersection, lineseg has ENTRY and EXIT point  --
-    //----------------------------------------------------------------------------------
-
-    inline unsigned char Ray_Sphere(const Ray& ray, const ::Sphere& s, Vec3& i0, Vec3& i1)
-    {
-        Vec3 end = ray.origin + ray.direction;
-        float a = ray.direction | ray.direction;
-        float b = (ray.direction | (ray.origin - s.center)) * 2.0f;
-        float c = ((ray.origin - s.center) | (ray.origin - s.center)) - (s.radius * s.radius);
-
-        float desc = (b * b) - (4 * a * c);
-
-        unsigned char intersection = 0;
-        if (desc >= 0.0f)
-        {
-            float lamba0 = (-b - sqrt_tpl(desc)) / (2.0f * a);
-            //  _stprintf(d3dApp.token,"lamba0: %20.12f",lamba0);
-            //  d3dApp.m_pFont->DrawText( 2, d3dApp.PrintY, D3DCOLOR_ARGB(255,255,255,0), d3dApp.token );   d3dApp.PrintY+=20;
-            if (lamba0 > 0.0f)
-            {
-                i0 = ray.origin + ((end - ray.origin) * lamba0);
-                intersection = 1;
-            }
-
-            float lamba1 = (-b + sqrt_tpl(desc)) / (2.0f * a);
-            //  _stprintf(d3dApp.token,"lamba1: %20.12f",lamba1);
-            //  d3dApp.m_pFont->DrawText( 2, d3dApp.PrintY, D3DCOLOR_ARGB(255,255,255,0), d3dApp.token );   d3dApp.PrintY+=20;
-            if (lamba1 > 0.0f)
-            {
-                i1 = ray.origin + ((end - ray.origin) * lamba1);
-                intersection |= 2;
-            }
-        }
-        return intersection;
-    }
-
-    inline bool Ray_SphereFirst(const Ray& ray, const ::Sphere& s, Vec3& intPoint)
-    {
-        Vec3 p2;
-        unsigned char res = Ray_Sphere(ray, s, intPoint, p2);
-        if (res == 2)
-        {
-            intPoint = p2;
-        }
-        if (res > 1)
-        {
-            return true;
-        }
-        return false;
-    }
-} //Intersect

+ 0 - 2
Code/Legacy/CryCommon/crycommon_files.cmake

@@ -62,8 +62,6 @@ set(FILES
     Cry_Vector4.h
     Cry_Color.h
     Cry_Geo.h
-    Cry_GeoDistance.h
-    Cry_GeoIntersect.h
     Cry_Math.h
     Cry_Quat.h
     Cry_ValidNumber.h

+ 2 - 7
Gems/LmbrCentral/Code/Source/Shape/CapsuleShape.cpp

@@ -13,7 +13,6 @@
 #include <AzCore/Math/Transform.h>
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/SerializeContext.h>
-#include <CryCommon/Cry_GeoDistance.h>
 #include <MathConversion.h>
 
 namespace LmbrCentral
@@ -183,12 +182,8 @@ namespace LmbrCentral
         AZStd::shared_lock lock(m_mutex);
         m_intersectionDataCache.UpdateIntersectionParams(m_currentTransform, m_capsuleShapeConfig, &m_mutex);
 
-        const Lineseg lineSeg(
-            AZVec3ToLYVec3(m_intersectionDataCache.m_basePlaneCenterPoint),
-            AZVec3ToLYVec3(m_intersectionDataCache.m_topPlaneCenterPoint));
-
-        float t = 0.0f;
-        float distance = Distance::Point_Lineseg(AZVec3ToLYVec3(point), lineSeg, t);
+        float distanceSq = AZ::Intersect::PointSegmentDistanceSq(point, m_intersectionDataCache.m_basePlaneCenterPoint, m_intersectionDataCache.m_topPlaneCenterPoint);
+        float distance = AZ::Sqrt(distanceSq);
         distance -= m_intersectionDataCache.m_radius;
         const float clampedDistance = AZStd::max(distance, 0.0f);
         return clampedDistance * clampedDistance;

+ 52 - 5
Gems/LmbrCentral/Code/Source/Shape/CylinderShape.cpp

@@ -19,7 +19,6 @@
 #include <AzFramework/Entity/EntityDebugDisplayBus.h>
 #include <Shape/ShapeDisplay.h>
 
-#include "Cry_GeoDistance.h"
 #include <random>
 
 namespace LmbrCentral
@@ -260,10 +259,58 @@ namespace LmbrCentral
             AZ::Vector3 diff = m_intersectionDataCache.m_baseCenterPoint - point;
             return diff.GetLengthSq();
         }
-        return Distance::Point_CylinderSq(
-            point, m_intersectionDataCache.m_baseCenterPoint,
-            m_intersectionDataCache.m_baseCenterPoint + m_intersectionDataCache.m_axisVector,
-            m_intersectionDataCache.m_radius);
+        // Use the cylinder axis' center point to determine distance by
+        // splitting into Voronoi regions and using symmetry.
+        // The regions are:
+        // - Inside
+        // - Beyond cylinder radius but between two disc ends.
+        // - Within cylinder radius but beyond two disc ends.
+        // - Beyond cylinder radius and beyond two disc ends.
+        float radius = m_intersectionDataCache.m_radius;
+
+        const AZ::Vector3 cylinderAxis = m_intersectionDataCache.m_axisVector;
+        float halfLength = cylinderAxis.GetLength() * 0.5f;
+        const AZ::Vector3 cylinderAxisUnit = cylinderAxis.GetNormalized();
+
+        // get the center of the axis and the vector from center to the test point
+        const AZ::Vector3 centerPoint = (cylinderAxis * 0.5) + m_intersectionDataCache.m_baseCenterPoint;
+        const AZ::Vector3 pointToCenter = point - centerPoint;
+
+        // distance point is from center (projected onto axis)
+        // the abs here takes advantage of symmetry.
+        float x = AZ::Abs(pointToCenter.Dot(cylinderAxisUnit));
+
+        // squared distance from point to center (hypotenuse)
+        float n2 = pointToCenter.GetLengthSq();
+
+        // squared distance from point to center perpendicular to axis (pythagorean)
+        float y2 = n2 - x * x;
+
+        float distanceSquared = 0.f;
+
+        if (x < halfLength) // point is between the two ends
+        {
+            if (y2 > radius * radius)   // point is outside of radius
+            {
+                distanceSquared = (AZ::Sqrt(y2) - radius) * (AZ::Sqrt(y2) - radius);
+            }
+            // else point is inside cylinder, distance is zero.
+        }
+        else if (y2 < radius * radius)
+        {
+            // point is within radius
+            // point projects into a disc at either end, grab the "parallel" distance only
+            distanceSquared = (x - halfLength) * (x - halfLength);
+        }
+        else
+        {
+            // point is outside of radius
+            // point projects onto the edge of the disc, grab distance in two directions,
+            // combine "parallel" and "perpendicular" distances.
+            distanceSquared = (AZ::Sqrt(y2) - radius) * (AZ::Sqrt(y2) - radius) + (x - halfLength) * (x - halfLength);
+        }
+
+        return distanceSquared;
     }
 
     bool CylinderShape::IntersectRay(const AZ::Vector3& src, const AZ::Vector3& dir, float& distance) const