From cbaf10478a164005711bc417e7df46b06a8ae74c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Thu, 28 Jul 2022 14:24:29 +0200 Subject: [PATCH] More XZY->XYZ changes * dtIntersectSegSeg2D: Calculate over zy-plane instead. * dtOverlapPolyPoly2D: Calculate over zy-plane instead. * dtNavMeshQuery::findRandomPoint: z = h. * dtNavMeshQuery::raycast: Invert hit normals. * Update all comments to use xyz vector instead (previously xzy (xz-plane z-height)). --- r5dev/naveditor/ConvexVolumeTool.cpp | 2 +- .../recast/Detour/Include/DetourCommon.h | 12 +++---- .../Detour/Include/DetourNavMeshBuilder.h | 4 +-- .../recast/Detour/Source/DetourCommon.cpp | 19 +++++------ .../Detour/Source/DetourNavMeshQuery.cpp | 12 +++---- .../thirdparty/recast/Recast/Include/Recast.h | 34 +++++++++---------- .../recast/Recast/Source/RecastArea.cpp | 6 ++-- .../recast/Recast/Source/RecastContour.cpp | 2 +- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/r5dev/naveditor/ConvexVolumeTool.cpp b/r5dev/naveditor/ConvexVolumeTool.cpp index ecf54c8f..b803b95d 100644 --- a/r5dev/naveditor/ConvexVolumeTool.cpp +++ b/r5dev/naveditor/ConvexVolumeTool.cpp @@ -46,7 +46,7 @@ inline bool cmppt(const float* a, const float* b) if (a[1] > b[1]) return false; return false; } -// Calculates convex hull on xz-plane of points on 'pts', +// Calculates convex hull on xy-plane of points on 'pts', // stores the indices of the resulting hull in 'out' and // returns number of points on hull. static int convexhull(const float* pts, int npts, int* out) diff --git a/r5dev/thirdparty/recast/Detour/Include/DetourCommon.h b/r5dev/thirdparty/recast/Detour/Include/DetourCommon.h index 428831bf..5962b587 100644 --- a/r5dev/thirdparty/recast/Detour/Include/DetourCommon.h +++ b/r5dev/thirdparty/recast/Detour/Include/DetourCommon.h @@ -305,7 +305,7 @@ inline bool dtVisfinite2D(const float* v) return result; } -/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v) +/// Derives the dot product of two vectors on the xy-plane. (@p u . @p v) /// @param[in] u A vector [(x, y, z)] /// @param[in] v A vector [(x, y, z)] /// @return The dot product on the xy-plane. @@ -407,7 +407,7 @@ bool dtIntersectSegSeg2D(const float* ap, const float* aq, float distancePtLine2d(const float* pt, const float* p, const float* q); -/// Determines if the specified point is inside the convex polygon on the xz-plane. +/// Determines if the specified point is inside the convex polygon on the xy-plane. /// @param[in] pt The point to check. [(x, y, z)] /// @param[in] verts The polygon vertices. [(x, y, z) * @p nverts] /// @param[in] nverts The number of vertices. [Limit: >= 3] @@ -426,7 +426,7 @@ float dtDistancePtSegSqr2D(const float* pt, const float* p, const float* q, floa /// @param[in] verts The polygon vertices. [(x, y, z) * vertCount] void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts); -/// Determines if the two convex polygons overlap on the xz-plane. +/// Determines if the two convex polygons overlap on the xy-plane. /// @param[in] polya Polygon A vertices. [(x, y, z) * @p npolya] /// @param[in] npolya The number of vertices in polygon A. /// @param[in] polyb Polygon B vertices. [(x, y, z) * @p npolyb] @@ -538,13 +538,13 @@ TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(unsigned char*& buffer, const si @fn float dtTriArea2D(const float* a, const float* b, const float* c) @par -The vertices are projected onto the xz-plane, so the y-values are ignored. +The vertices are projected onto the xy-plane, so the z-values are ignored. This is a low cost function than can be used for various purposes. Its main purpose is for point/line relationship testing. In all cases: A value of zero indicates that all vertices are collinear or represent the same point. -(On the xz-plane.) +(On the xy-plane.) When used for point/line relationship tests, AB usually represents a line against which the C point is to be tested. In this case: @@ -555,7 +555,7 @@ A negative value indicates that point C is to the right of lineAB, looking from When used for evaluating a triangle: The absolute value of the return value is two times the area of the triangle when it is -projected onto the xz-plane. +projected onto the xy-plane. A positive return value indicates: diff --git a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h index e1de38d3..89e576d9 100644 --- a/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h +++ b/r5dev/thirdparty/recast/Detour/Include/DetourNavMeshBuilder.h @@ -94,8 +94,8 @@ struct dtNavMeshCreateParams float walkableHeight; ///< The agent height. [Unit: wu] float walkableRadius; ///< The agent radius. [Unit: wu] float walkableClimb; ///< The agent maximum traversable ledge. (Up/Down) [Unit: wu] - float cs; ///< The xz-plane cell size of the polygon mesh. [Limit: > 0] [Unit: wu] - float ch; ///< The y-axis cell height of the polygon mesh. [Limit: > 0] [Unit: wu] + float cs; ///< The xy-plane cell size of the polygon mesh. [Limit: > 0] [Unit: wu] + float ch; ///< The z-axis cell height of the polygon mesh. [Limit: > 0] [Unit: wu] /// True if a bounding volume tree should be built for the tile. /// @note The BVTree is not normally needed for layered navigation meshes. diff --git a/r5dev/thirdparty/recast/Detour/Source/DetourCommon.cpp b/r5dev/thirdparty/recast/Detour/Source/DetourCommon.cpp index c4441723..c12c3b68 100644 --- a/r5dev/thirdparty/recast/Detour/Source/DetourCommon.cpp +++ b/r5dev/thirdparty/recast/Detour/Source/DetourCommon.cpp @@ -290,7 +290,7 @@ inline bool overlapRange(const float amin, const float amax, /// @par /// -/// All vertices are projected onto the xz-plane, so the y-values are ignored. +/// All vertices are projected onto the xy-plane, so the z-values are ignored. bool dtOverlapPolyPoly2D(const float* polya, const int npolya, const float* polyb, const int npolyb) { @@ -300,7 +300,7 @@ bool dtOverlapPolyPoly2D(const float* polya, const int npolya, { const float* va = &polya[j*3]; const float* vb = &polya[i*3]; - const float n[3] = { vb[2]-va[2], 0, -(vb[0]-va[0]) }; + const float n[3] = { vb[1]-va[1], 0, -(vb[0]-va[0]) }; float amin,amax,bmin,bmax; projectPoly(n, polya, npolya, amin,amax); projectPoly(n, polyb, npolyb, bmin,bmax); @@ -314,7 +314,7 @@ bool dtOverlapPolyPoly2D(const float* polya, const int npolya, { const float* va = &polyb[j*3]; const float* vb = &polyb[i*3]; - const float n[3] = { vb[2]-va[2], 0, -(vb[0]-va[0]) }; + const float n[3] = { vb[1]-va[1], 0, -(vb[0]-va[0]) }; float amin,amax,bmin,bmax; projectPoly(n, polya, npolya, amin,amax); projectPoly(n, polyb, npolyb, bmin,bmax); @@ -388,14 +388,13 @@ bool dtIntersectSegSeg2D(const float* ap, const float* aq, float distancePtLine2d(const float* pt, const float* p, const float* q) { float pqx = q[0] - p[0]; - float pqz = q[2] - p[2]; + float pqy = q[1] - p[1]; float dx = pt[0] - p[0]; - float dz = pt[2] - p[2]; - float d = pqx * pqx + pqz * pqz; - float t = pqx * dx + pqz * dz; + float dy = pt[1] - p[1]; + float d = pqx * pqx + pqy * pqy; + float t = pqx * dx + pqy * dy; if (d != 0) t /= d; dx = p[0] + t * pqx - pt[0]; - dz = p[2] + t * pqz - pt[2]; - return dx * dx + dz * dz; + dy = p[1] + t * pqy - pt[1]; + return dx * dx + dy * dy; } - diff --git a/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp b/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp index 59c3253a..76e54549 100644 --- a/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp +++ b/r5dev/thirdparty/recast/Detour/Source/DetourNavMeshQuery.cpp @@ -305,7 +305,7 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr dtStatus status = getPolyHeight(polyRef, pt, &h); if (dtStatusFailed(status)) return status; - pt[1] = h; + pt[2] = h; dtVcopy(randomPt, pt); *randomRef = polyRef; @@ -2654,8 +2654,8 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons const float* vb = &verts[b*3]; const float dx = vb[0] - va[0]; const float dy = vb[1] - va[1]; - hit->hitNormal[0] = dy; - hit->hitNormal[1] = -dx; + hit->hitNormal[0] = -dy; + hit->hitNormal[1] = dx; hit->hitNormal[2] = 0; dtVnormalize(hit->hitNormal); @@ -2700,7 +2700,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons /// y-value will effect the costs. /// /// Intersection tests occur in 2D. All polygons and the search circle are -/// projected onto the xz-plane. So the y-value of the center point does not +/// projected onto the xy-plane. So the z-value of the center point does not /// effect intersection tests. /// /// If the result arrays are to small to hold the entire result set, they will be @@ -2875,7 +2875,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float* /// calculations. /// /// Intersection tests occur in 2D. All polygons are projected onto the -/// xz-plane. So the y-values of the vertices do not effect intersection tests. +/// xy-plane. So the z-values of the vertices do not effect intersection tests. /// /// If the result arrays are is too small to hold the entire result set, they will /// be filled to capacity. @@ -3072,7 +3072,7 @@ dtStatus dtNavMeshQuery::getPathFromDijkstraSearch(dtPolyRef endRef, dtPolyRef* /// the costs. /// /// Intersection tests occur in 2D. All polygons and the search circle are -/// projected onto the xz-plane. So the y-value of the center point does not +/// projected onto the xy-plane. So the z-value of the center point does not /// effect intersection tests. /// /// If the result arrays are is too small to hold the entire result set, they will diff --git a/r5dev/thirdparty/recast/Recast/Include/Recast.h b/r5dev/thirdparty/recast/Recast/Include/Recast.h index fa212b35..2c4101fd 100644 --- a/r5dev/thirdparty/recast/Recast/Include/Recast.h +++ b/r5dev/thirdparty/recast/Recast/Include/Recast.h @@ -203,16 +203,16 @@ struct rcConfig /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx] int height; - /// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx] + /// The width/height size of tile's on the xy-plane. [Limit: >= 0] [Units: vx] int tileSize; /// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx] int borderSize; - /// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] + /// The xy-plane cell size to use for fields. [Limit: > 0] [Units: wu] float cs; - /// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu] + /// The z-axis cell size to use for fields. [Limit: > 0] [Units: wu] float ch; /// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu] @@ -300,8 +300,8 @@ struct rcHeightfield int height; ///< The height of the heightfield. (Along the z-axis in cell units.) float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] - float cs; ///< The size of each cell. (On the xz-plane.) - float ch; ///< The height of each cell. (The minimum increment along the y-axis.) + float cs; ///< The size of each cell. (On the xy-plane.) + float ch; ///< The height of each cell. (The minimum increment along the z-axis.) rcSpan** spans; ///< Heightfield of spans (width*height). rcSpanPool* pools; ///< Linked list of span pools. rcSpan* freelist; ///< The next free span. @@ -344,8 +344,8 @@ struct rcCompactHeightfield unsigned short maxRegions; ///< The maximum region id of any span within the field. float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] - float cs; ///< The size of each cell. (On the xz-plane.) - float ch; ///< The height of each cell. (The minimum increment along the y-axis.) + float cs; ///< The size of each cell. (On the xy-plane.) + float ch; ///< The height of each cell. (The minimum increment along the z-axis.) rcCompactCell* cells; ///< Array of cells. [Size: #width*#height] rcCompactSpan* spans; ///< Array of spans. [Size: #spanCount] unsigned short* dist; ///< Array containing border distance data. [Size: #spanCount] @@ -358,8 +358,8 @@ struct rcHeightfieldLayer { float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] - float cs; ///< The size of each cell. (On the xz-plane.) - float ch; ///< The height of each cell. (The minimum increment along the y-axis.) + float cs; ///< The size of each cell. (On the xy-plane.) + float ch; ///< The height of each cell. (The minimum increment along the z-axis.) int width; ///< The width of the heightfield. (Along the x-axis in cell units.) int height; ///< The height of the heightfield. (Along the z-axis in cell units.) int minx; ///< The minimum x-bounds of usable data. @@ -405,8 +405,8 @@ struct rcContourSet int nconts; ///< The number of contours in the set. float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] - float cs; ///< The size of each cell. (On the xz-plane.) - float ch; ///< The height of each cell. (The minimum increment along the y-axis.) + float cs; ///< The size of each cell. (On the xy-plane.) + float ch; ///< The height of each cell. (The minimum increment along the z-axis.) int width; ///< The width of the set. (Along the x-axis in cell units.) int height; ///< The height of the set. (Along the z-axis in cell units.) int borderSize; ///< The AABB border size used to generate the source data from which the contours were derived. @@ -430,8 +430,8 @@ struct rcPolyMesh int nvp; ///< The maximum number of vertices per polygon. float bmin[3]; ///< The minimum bounds in world space. [(x, y, z)] float bmax[3]; ///< The maximum bounds in world space. [(x, y, z)] - float cs; ///< The size of each cell. (On the xz-plane.) - float ch; ///< The height of each cell. (The minimum increment along the y-axis.) + float cs; ///< The size of each cell. (On the xy-plane.) + float ch; ///< The height of each cell. (The minimum increment along the z-axis.) int borderSize; ///< The AABB border size used to generate the source data from which the mesh was derived. float maxEdgeError; ///< The max error of the polygon edges in the mesh. }; @@ -785,9 +785,9 @@ void rcCalcBounds(const float* verts, int nv, float* bmin, float* bmax); /// @ingroup recast /// @param[in] bmin The minimum bounds of the AABB. [(x, y, z)] [Units: wu] /// @param[in] bmax The maximum bounds of the AABB. [(x, y, z)] [Units: wu] -/// @param[in] cs The xz-plane cell size. [Limit: > 0] [Units: wu] +/// @param[in] cs The xy-plane cell size. [Limit: > 0] [Units: wu] /// @param[out] w The width along the x-axis. [Limit: >= 0] [Units: vx] -/// @param[out] h The height along the z-axis. [Limit: >= 0] [Units: vx] +/// @param[out] h The height along the y-axis. [Limit: >= 0] [Units: vx] void rcCalcGridSize(const float* bmin, const float* bmax, float cs, int* w, int* h); /// Initializes a new heightfield. @@ -798,8 +798,8 @@ void rcCalcGridSize(const float* bmin, const float* bmax, float cs, int* w, int* /// @param[in] height The height of the field along the z-axis. [Limit: >= 0] [Units: vx] /// @param[in] bmin The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu] /// @param[in] bmax The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu] -/// @param[in] cs The xz-plane cell size to use for the field. [Limit: > 0] [Units: wu] -/// @param[in] ch The y-axis cell size to use for field. [Limit: > 0] [Units: wu] +/// @param[in] cs The xy-plane cell size to use for the field. [Limit: > 0] [Units: wu] +/// @param[in] ch The z-axis cell size to use for field. [Limit: > 0] [Units: wu] /// @returns True if the operation completed successfully. bool rcCreateHeightfield(rcContext* ctx, rcHeightfield& hf, int width, int height, const float* bmin, const float* bmax, diff --git a/r5dev/thirdparty/recast/Recast/Source/RecastArea.cpp b/r5dev/thirdparty/recast/Recast/Source/RecastArea.cpp index 4162e771..1d5f1f18 100644 --- a/r5dev/thirdparty/recast/Recast/Source/RecastArea.cpp +++ b/r5dev/thirdparty/recast/Recast/Source/RecastArea.cpp @@ -375,7 +375,7 @@ static int pointInPoly(int nvert, const float* verts, const float* p) /// The value of spacial parameters are in world units. /// /// The y-values of the polygon vertices are ignored. So the polygon is effectively -/// projected onto the xz-plane at @p hmin, then extruded to @p hmax. +/// projected onto the xy-plane at @p hmin, then extruded to @p hmax. /// /// @see rcCompactHeightfield, rcMedianFilterWalkableArea void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts, @@ -429,8 +429,8 @@ void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts, if ((int)s.z >= minz && (int)s.z <= maxz) { float p[3]; - p[0] = chf.bmin[0] + (x+0.5f)*chf.cs; - p[1] = chf.bmin[1] + (y + 0.5f)*chf.cs; + p[0] = chf.bmin[0] + (x+0.5f)*chf.cs; + p[1] = chf.bmin[1] + (y+0.5f)*chf.cs; p[2] = 0; if (pointInPoly(nverts, verts, p)) diff --git a/r5dev/thirdparty/recast/Recast/Source/RecastContour.cpp b/r5dev/thirdparty/recast/Recast/Source/RecastContour.cpp index 0f5928e8..7621ac4c 100644 --- a/r5dev/thirdparty/recast/Recast/Source/RecastContour.cpp +++ b/r5dev/thirdparty/recast/Recast/Source/RecastContour.cpp @@ -579,7 +579,7 @@ static bool inCone(int i, int n, const int* verts, const int* pj) static void removeDegenerateSegments(rcIntArray& simplified) { - // Remove adjacent vertices which are equal on xz-plane, + // Remove adjacent vertices which are equal on xy-plane, // or else the triangulator will get confused. int npts = simplified.size()/4; for (int i = 0; i < npts; ++i)