mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Recast: make all math helpers shared
There was an issue where Recast's common math library was less complete than that of Detour. Some common math operations were also isolated in specific translation units causing copies everywhere. All common math operations have been moved to the Shared library ultimately fixing all the above issues.
This commit is contained in:
parent
13db18f700
commit
5f90ea08f2
@ -18,7 +18,7 @@
|
||||
#include "game/server/ai_networkmanager.h"
|
||||
#include "game/server/ai_network.h"
|
||||
#include "game/client/viewrender.h"
|
||||
#include "thirdparty/recast/Detour/Include/DetourCommon.h"
|
||||
#include "thirdparty/recast/Shared/Include/SharedCommon.h"
|
||||
#include "thirdparty/recast/Detour/Include/DetourNavMesh.h"
|
||||
|
||||
static ConVar ai_script_nodes_draw_range("ai_script_nodes_draw_range", "0", FCVAR_DEVELOPMENTONLY, "Debug draw AIN script nodes ranging from shift index to this cvar");
|
||||
@ -543,8 +543,8 @@ void CAI_Utility::DrawNavMeshPolyBoundaries(const dtNavMesh* pMesh,
|
||||
if ((dtGetDetailTriEdgeFlags(t[3], n) & DT_DETAIL_EDGE_BOUNDARY) == 0)
|
||||
continue;
|
||||
|
||||
if (distancePtLine2d(tv[n], v0, v1) < thr &&
|
||||
distancePtLine2d(tv[m], v0, v1) < thr)
|
||||
if (rdDistancePtLine2d(tv[n], v0, v1) < thr &&
|
||||
rdDistancePtLine2d(tv[m], v0, v1) < thr)
|
||||
{
|
||||
v_RenderLine(Vector3D(tv[n][0], tv[n][1], tv[n][2]), Vector3D(tv[m][0], tv[m][1], tv[m][2]), col, bDepthBuffer);
|
||||
}
|
||||
|
@ -193,18 +193,18 @@ void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shif
|
||||
// Create
|
||||
|
||||
// If clicked on that last pt, create the shape.
|
||||
if (m_npts && rcVdistSqr(p, &m_pts[(m_npts-1)*3]) < rcSqr(0.2f))
|
||||
if (m_npts && rdVdistSqr(p, &m_pts[(m_npts-1)*3]) < rdSqr(0.2f))
|
||||
{
|
||||
if (m_nhull > 2)
|
||||
{
|
||||
// Create shape.
|
||||
float verts[MAX_PTS*3];
|
||||
for (int i = 0; i < m_nhull; ++i)
|
||||
rcVcopy(&verts[i*3], &m_pts[m_hull[i]*3]);
|
||||
rdVcopy(&verts[i*3], &m_pts[m_hull[i]*3]);
|
||||
|
||||
float minh = FLT_MAX, maxh = 0;
|
||||
for (int i = 0; i < m_nhull; ++i)
|
||||
minh = rcMin(minh, verts[i*3+2]);
|
||||
minh = rdMin(minh, verts[i*3+2]);
|
||||
minh -= m_boxDescent;
|
||||
maxh = minh + m_boxHeight;
|
||||
|
||||
@ -229,7 +229,7 @@ void ConvexVolumeTool::handleClick(const float* /*s*/, const float* p, bool shif
|
||||
// Add new point
|
||||
if (m_npts < MAX_PTS)
|
||||
{
|
||||
rcVcopy(&m_pts[m_npts*3], p);
|
||||
rdVcopy(&m_pts[m_npts*3], p);
|
||||
const float* f = &m_pts[m_npts * 3];
|
||||
|
||||
printf("<%f, %f, %f>\n", f[0], f[1], f[2]);
|
||||
@ -266,7 +266,7 @@ void ConvexVolumeTool::handleRender()
|
||||
// Find height extent of the shape.
|
||||
float minh = FLT_MAX, maxh = 0;
|
||||
for (int i = 0; i < m_npts; ++i)
|
||||
minh = rcMin(minh, m_pts[i*3+2]);
|
||||
minh = rdMin(minh, m_pts[i*3+2]);
|
||||
minh -= m_boxDescent;
|
||||
maxh = minh + m_boxHeight;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
//
|
||||
|
||||
#include "Pch.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
#include "DetourCrowd/Include/DetourCrowd.h"
|
||||
#include "DetourCrowd/Include/DetourObstacleAvoidance.h"
|
||||
@ -35,7 +35,7 @@ static bool isectSegAABB(const float* sp, const float* sq,
|
||||
static const float EPS = 1e-6f;
|
||||
|
||||
float d[3];
|
||||
dtVsub(d, sq, sp);
|
||||
rdVsub(d, sq, sp);
|
||||
tmin = 0; // set to -FLT_MAX to get first hit on line
|
||||
tmax = FLT_MAX; // set to max distance ray can travel (for segment)
|
||||
|
||||
@ -55,7 +55,7 @@ static bool isectSegAABB(const float* sp, const float* sq,
|
||||
float t1 = (amin[i] - sp[i]) * ood;
|
||||
float t2 = (amax[i] - sp[i]) * ood;
|
||||
// Make t1 be intersection with near plane, t2 with far plane
|
||||
if (t1 > t2) dtSwap(t1, t2);
|
||||
if (t1 > t2) rdSwap(t1, t2);
|
||||
// Compute the intersection of slab intersections intervals
|
||||
if (t1 > tmin) tmin = t1;
|
||||
if (t2 < tmax) tmax = t2;
|
||||
@ -238,7 +238,7 @@ void CrowdToolState::handleRender()
|
||||
const dtCrowdAgent* ag = crowd->getAgent(i);
|
||||
if (!ag->active) continue;
|
||||
const float* pos = ag->corridor.getPos();
|
||||
gridz = dtMax(gridz, pos[2]);
|
||||
gridz = rdMax(gridz, pos[2]);
|
||||
}
|
||||
gridz += 1.0f;
|
||||
|
||||
@ -252,7 +252,7 @@ void CrowdToolState::handleRender()
|
||||
{
|
||||
const int count = grid->getItemCountAt(x,y);
|
||||
if (!count) continue;
|
||||
unsigned int col = duRGBA(128,0,0,dtMin(count*40,255));
|
||||
unsigned int col = duRGBA(128,0,0,rdMin(count*40,255));
|
||||
|
||||
dd.vertex(x*cs+cs,y*cs,gridz, col);
|
||||
dd.vertex(x*cs+cs,y*cs+cs,gridz,col);
|
||||
@ -274,7 +274,7 @@ void CrowdToolState::handleRender()
|
||||
|
||||
dd.begin(DU_DRAW_LINES,3.0f,drawOffset);
|
||||
float prev[3], preva = 1;
|
||||
dtVcopy(prev, pos);
|
||||
rdVcopy(prev, pos);
|
||||
for (int j = 0; j < AGENT_MAX_TRAIL-1; ++j)
|
||||
{
|
||||
const int idx = (trail->htrail + AGENT_MAX_TRAIL-j) % AGENT_MAX_TRAIL;
|
||||
@ -283,7 +283,7 @@ void CrowdToolState::handleRender()
|
||||
dd.vertex(prev[0],prev[1],prev[2]+0.1f, duRGBA(0,0,0,(int)(128*preva)));
|
||||
dd.vertex(v[0],v[1],v[2]+0.1f, duRGBA(0,0,0,(int)(128*a)));
|
||||
preva = a;
|
||||
dtVcopy(prev, v);
|
||||
rdVcopy(prev, v);
|
||||
}
|
||||
dd.end();
|
||||
|
||||
@ -359,7 +359,7 @@ void CrowdToolState::handleRender()
|
||||
{
|
||||
const float* s = ag->boundary.getSegment(j);
|
||||
unsigned int col = duRGBA(192,0,128,192);
|
||||
if (dtTriArea2D(agentPos, s, s+3) < 0.0f)
|
||||
if (rdTriArea2D(agentPos, s, s+3) < 0.0f)
|
||||
col = duDarkenCol(col);
|
||||
|
||||
duAppendArrow(&dd, s[0],s[1],s[2]+0.2f, s[3],s[4],s[5]+0.2f, 0.0f, 30.0f, col);
|
||||
@ -707,7 +707,7 @@ void CrowdToolState::addAgent(const float* p)
|
||||
// Init trail
|
||||
AgentTrail* trail = &m_trails[idx];
|
||||
for (int i = 0; i < AGENT_MAX_TRAIL; ++i)
|
||||
dtVcopy(&trail->trail[i*3], p);
|
||||
rdVcopy(&trail->trail[i*3], p);
|
||||
trail->htrail = 0;
|
||||
}
|
||||
}
|
||||
@ -730,10 +730,10 @@ void CrowdToolState::hilightAgent(const int idx)
|
||||
|
||||
static void calcVel(float* vel, const float* pos, const float* tgt, const float speed)
|
||||
{
|
||||
dtVsub(vel, tgt, pos);
|
||||
rdVsub(vel, tgt, pos);
|
||||
vel[2] = 0.0;
|
||||
dtVnormalize(vel);
|
||||
dtVscale(vel, vel, speed);
|
||||
rdVnormalize(vel);
|
||||
rdVscale(vel, vel, speed);
|
||||
}
|
||||
|
||||
void CrowdToolState::setMoveTarget(const float* p, bool adjust)
|
||||
@ -882,7 +882,7 @@ void CrowdToolState::updateTick(const float dt)
|
||||
continue;
|
||||
// Update agent movement trail.
|
||||
trail->htrail = (trail->htrail + 1) % AGENT_MAX_TRAIL;
|
||||
dtVcopy(&trail->trail[trail->htrail*3], ag->npos);
|
||||
rdVcopy(&trail->trail[trail->htrail*3], ag->npos);
|
||||
}
|
||||
|
||||
m_agentDebug.vod->normalizeSamples();
|
||||
@ -1114,7 +1114,7 @@ void CrowdTool::handleToggle()
|
||||
|
||||
void CrowdTool::handleUpdate(const float dt)
|
||||
{
|
||||
rcIgnoreUnused(dt);
|
||||
rdIgnoreUnused(dt);
|
||||
}
|
||||
|
||||
void CrowdTool::handleRender()
|
||||
@ -1123,9 +1123,9 @@ void CrowdTool::handleRender()
|
||||
|
||||
void CrowdTool::handleRenderOverlay(double* proj, double* model, int* view)
|
||||
{
|
||||
rcIgnoreUnused(model);
|
||||
rcIgnoreUnused(proj);
|
||||
rcIgnoreUnused(view);
|
||||
rdIgnoreUnused(model);
|
||||
rdIgnoreUnused(proj);
|
||||
rdIgnoreUnused(view);
|
||||
|
||||
// Tool help
|
||||
float ty = 40;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "Pch.h"
|
||||
#include "Recast/Include/Recast.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNavMeshQuery.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
@ -82,8 +82,8 @@ Editor::Editor() :
|
||||
for (int i = 0; i < MAX_TOOLS; i++)
|
||||
m_toolStates[i] = 0;
|
||||
|
||||
dtVset(m_recastDrawOffset, 0.0f,0.0f,4.0f);
|
||||
dtVset(m_detourDrawOffset, 0.0f,0.0f,8.0f);
|
||||
rdVset(m_recastDrawOffset, 0.0f,0.0f,4.0f);
|
||||
rdVset(m_detourDrawOffset, 0.0f,0.0f,8.0f);
|
||||
}
|
||||
|
||||
Editor::~Editor()
|
||||
@ -266,8 +266,8 @@ void Editor::handleCommonSettings()
|
||||
|
||||
if (ImGui::Button("Reset##BuildSettings", ImVec2(120, 0)))
|
||||
{
|
||||
dtVcopy(navMeshBMin, m_geom->getOriginalNavMeshBoundsMin());
|
||||
dtVcopy(navMeshBMax, m_geom->getOriginalNavMeshBoundsMax());
|
||||
rdVcopy(navMeshBMin, m_geom->getOriginalNavMeshBoundsMin());
|
||||
rdVcopy(navMeshBMax, m_geom->getOriginalNavMeshBoundsMax());
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "Pch.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Recast/Include/Recast.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "DebugUtils/Include/RecastDebugDraw.h"
|
||||
#include "DebugUtils/Include/DetourDebugDraw.h"
|
||||
#include "NavEditor/Include/EditorInterfaces.h"
|
||||
@ -38,7 +38,7 @@ void BuildContext::doLog(const rcLogCategory category, const char* msg, const in
|
||||
// Store category
|
||||
*cat = (char)category;
|
||||
// Store message
|
||||
const int count = rcMin(len+1, maxtext);
|
||||
const int count = rdMin(len+1, maxtext);
|
||||
memcpy(text, msg, count);
|
||||
text[count-1] = '\0';
|
||||
m_textPoolSize += 1 + count;
|
||||
@ -217,7 +217,7 @@ void DebugDrawGL::begin(const duDebugDrawPrimitives prim, const float size, cons
|
||||
};
|
||||
|
||||
if (offset)
|
||||
dtVcopy(m_drawOffset,offset);
|
||||
rdVcopy(m_drawOffset,offset);
|
||||
}
|
||||
|
||||
void DebugDrawGL::vertex(const float* pos, unsigned int color)
|
||||
@ -225,7 +225,7 @@ void DebugDrawGL::vertex(const float* pos, unsigned int color)
|
||||
glColor4ubv((GLubyte*)&color);
|
||||
|
||||
float opos[3];
|
||||
dtVadd(opos,pos,m_drawOffset);
|
||||
rdVadd(opos,pos,m_drawOffset);
|
||||
|
||||
glVertex3fv(opos);
|
||||
}
|
||||
@ -236,8 +236,8 @@ void DebugDrawGL::vertex(const float x, const float y, const float z, unsigned i
|
||||
|
||||
float opos[3];
|
||||
|
||||
dtVset(opos, x,y,z);
|
||||
dtVadd(opos,opos,m_drawOffset);
|
||||
rdVset(opos, x,y,z);
|
||||
rdVadd(opos,opos,m_drawOffset);
|
||||
|
||||
glVertex3fv(opos);
|
||||
}
|
||||
@ -248,7 +248,7 @@ void DebugDrawGL::vertex(const float* pos, unsigned int color, const float* uv)
|
||||
glTexCoord2fv(uv);
|
||||
|
||||
float opos[3];
|
||||
dtVadd(opos,pos,m_drawOffset);
|
||||
rdVadd(opos,pos,m_drawOffset);
|
||||
|
||||
glVertex3fv(opos);
|
||||
}
|
||||
@ -260,8 +260,8 @@ void DebugDrawGL::vertex(const float x, const float y, const float z, unsigned i
|
||||
|
||||
float opos[3];
|
||||
|
||||
dtVset(opos, x,y,z);
|
||||
dtVadd(opos,opos,m_drawOffset);
|
||||
rdVset(opos, x,y,z);
|
||||
rdVadd(opos,opos,m_drawOffset);
|
||||
|
||||
glVertex3fv(opos);
|
||||
}
|
||||
@ -272,7 +272,7 @@ void DebugDrawGL::end()
|
||||
glLineWidth(1.0f);
|
||||
glPointSize(1.0f);
|
||||
|
||||
dtVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
rdVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -24,32 +24,6 @@
|
||||
#include "Include/InputGeom.h"
|
||||
#include <DetourTileCache/Include/DetourTileCache.h>
|
||||
|
||||
// todo(amos): move these to common math.
|
||||
inline unsigned int nextPow2(unsigned int v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v++;
|
||||
return v;
|
||||
}
|
||||
|
||||
// todo(amos): move these to common math.
|
||||
inline unsigned int ilog2(unsigned int v)
|
||||
{
|
||||
unsigned int r;
|
||||
unsigned int shift;
|
||||
r = (v > 0xffff) << 4; v >>= r;
|
||||
shift = (v > 0xff) << 3; v >>= shift; r |= shift;
|
||||
shift = (v > 0xf) << 2; v >>= shift; r |= shift;
|
||||
shift = (v > 0x3) << 1; v >>= shift; r |= shift;
|
||||
r |= (v >> 1);
|
||||
return r;
|
||||
}
|
||||
|
||||
static void EditorCommon_DrawInputGeometry(duDebugDraw* const dd, const InputGeom* const geom,
|
||||
const float maxSlope, const float textureScale)
|
||||
{
|
||||
@ -68,7 +42,7 @@ static void EditorCommon_DrawBoundingBox(duDebugDraw* const dd, const InputGeom*
|
||||
const float* const navBmin = geom->getNavMeshBoundsMin();
|
||||
const float* const navBmax = geom->getNavMeshBoundsMax();
|
||||
|
||||
if (!rcVequal(origBmin, navBmin) || !rcVequal(origBmax, navBmax))
|
||||
if (!rdVequal(origBmin, navBmin) || !rdVequal(origBmax, navBmax))
|
||||
duDebugDrawBoxWire(dd, navBmin[0], navBmin[1], navBmin[2], navBmax[0], navBmax[1], navBmax[2], duRGBA(0, 255, 0, 215), 1.0f, nullptr);
|
||||
}
|
||||
|
||||
@ -107,7 +81,7 @@ int EditorCommon_SetAndRenderTileProperties(const InputGeom* const geom, const i
|
||||
|
||||
// Max tiles and max polys affect how the tile IDs are calculated.
|
||||
// There are 28 bits available for identifying a tile and a polygon.
|
||||
int tileBits = rcMin((int)ilog2(nextPow2(tw*th)), 16);
|
||||
int tileBits = rdMin((int)rdIlog2(rdNextPow2(tw*th)), 16);
|
||||
int polyBits = 28 - tileBits;
|
||||
|
||||
maxTiles = 1 << tileBits;
|
||||
|
@ -79,7 +79,7 @@ Editor_Debug::Editor_Debug() :
|
||||
int maxSpans = 0;
|
||||
for (int i = 0; i < m_chf->width*m_chf->height; ++i)
|
||||
{
|
||||
maxSpans = rcMax(maxSpans, (int)m_chf->cells[i].count);
|
||||
maxSpans = rdMax(maxSpans, (int)m_chf->cells[i].count);
|
||||
}
|
||||
printf("maxSpans = %d\n", maxSpans);
|
||||
}*/
|
||||
@ -195,8 +195,8 @@ void Editor_Debug::handleRender()
|
||||
duDebugDrawNavMeshPoly(&m_dd, *m_navMesh, m_ref, m_detourDrawOffset, m_navMeshDrawFlags, duRGBA(255,0,0,128));
|
||||
|
||||
/* float bmin[3], bmax[3];
|
||||
rcVsub(bmin, m_center, m_halfExtents);
|
||||
rcVadd(bmax, m_center, m_halfExtents);
|
||||
rdVsub(bmin, m_center, m_halfExtents);
|
||||
rdVadd(bmax, m_center, m_halfExtents);
|
||||
duDebugDrawBoxWire(&dd, bmin[0],bmin[1],bmin[2], bmax[0],bmax[1],bmax[2], duRGBA(255,255,255,128), 1.0f);
|
||||
duDebugDrawCross(&dd, m_center[0], m_center[1], m_center[2], 1.0f, duRGBA(255,255,255,128), 2.0f);*/
|
||||
|
||||
|
@ -185,8 +185,8 @@ bool Editor_SoloMesh::handleBuild()
|
||||
m_cfg.walkableRadius = (int)ceilf(m_agentRadius / m_cfg.cs);
|
||||
m_cfg.maxEdgeLen = (int)(m_edgeMaxLen / m_cellSize);
|
||||
m_cfg.maxSimplificationError = m_edgeMaxError;
|
||||
m_cfg.minRegionArea = rcSqr(m_regionMinSize); // Note: area = size*size
|
||||
m_cfg.mergeRegionArea = rcSqr(m_regionMergeSize); // Note: area = size*size
|
||||
m_cfg.minRegionArea = rdSqr(m_regionMinSize); // Note: area = size*size
|
||||
m_cfg.mergeRegionArea = rdSqr(m_regionMergeSize); // Note: area = size*size
|
||||
m_cfg.maxVertsPerPoly = (int)m_vertsPerPoly;
|
||||
m_cfg.detailSampleDist = m_detailSampleDist < 0.9f ? 0 : m_cellSize * m_detailSampleDist;
|
||||
m_cfg.detailSampleMaxError = m_cellHeight * m_detailSampleMaxError;
|
||||
@ -194,8 +194,8 @@ bool Editor_SoloMesh::handleBuild()
|
||||
// Set the area where the navigation will be build.
|
||||
// Here the bounds of the input mesh are used, but the
|
||||
// area could be specified by an user defined box, etc.
|
||||
rcVcopy(m_cfg.bmin, bmin);
|
||||
rcVcopy(m_cfg.bmax, bmax);
|
||||
rdVcopy(m_cfg.bmin, bmin);
|
||||
rdVcopy(m_cfg.bmax, bmax);
|
||||
rcCalcGridSize(m_cfg.bmin, m_cfg.bmax, m_cfg.cs, &m_cfg.width, &m_cfg.height);
|
||||
|
||||
// Reset build times gathering.
|
||||
@ -490,8 +490,8 @@ bool Editor_SoloMesh::handleBuild()
|
||||
params.walkableHeight = m_agentHeight;
|
||||
params.walkableRadius = m_agentRadius;
|
||||
params.walkableClimb = m_agentMaxClimb;
|
||||
rcVcopy(params.bmin, m_pmesh->bmin);
|
||||
rcVcopy(params.bmax, m_pmesh->bmax);
|
||||
rdVcopy(params.bmin, m_pmesh->bmin);
|
||||
rdVcopy(params.bmax, m_pmesh->bmax);
|
||||
params.cs = m_cfg.cs;
|
||||
params.ch = m_cfg.ch;
|
||||
params.buildBvTree = true;
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
#include "Pch.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Recast/Include/Recast.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
#include "DebugUtils/Include/RecastDebugDraw.h"
|
||||
@ -106,7 +106,7 @@ public:
|
||||
virtual void handleClick(const float* /*s*/, const float* p, bool shift)
|
||||
{
|
||||
m_hitPosSet = true;
|
||||
rcVcopy(m_hitPos,p);
|
||||
rdVcopy(m_hitPos,p);
|
||||
if (m_editor)
|
||||
{
|
||||
if (shift)
|
||||
@ -327,7 +327,7 @@ void Editor_TileMesh::handleRenderOverlay(double* proj, double* model, int* view
|
||||
const float* drawOffset = getDetourDrawOffset();
|
||||
|
||||
float projectPos[3];
|
||||
dtVset(projectPos,
|
||||
rdVset(projectPos,
|
||||
((m_lastBuiltTileBmin[0]+m_lastBuiltTileBmax[0])/2)+drawOffset[0],
|
||||
((m_lastBuiltTileBmin[1]+m_lastBuiltTileBmax[1])/2)+drawOffset[1],
|
||||
((m_lastBuiltTileBmin[2]+m_lastBuiltTileBmax[2])/2)+drawOffset[2]);
|
||||
@ -387,7 +387,7 @@ bool Editor_TileMesh::handleBuild()
|
||||
m_loadedNavMeshType = m_selectedNavMeshType;
|
||||
|
||||
dtNavMeshParams params;
|
||||
rcVcopy(params.orig, m_geom->getNavMeshBoundsMin());
|
||||
rdVcopy(params.orig, m_geom->getNavMeshBoundsMin());
|
||||
|
||||
params.orig[0] = m_geom->getNavMeshBoundsMax()[0];
|
||||
|
||||
@ -614,8 +614,8 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
|
||||
m_cfg.walkableRadius = (int)ceilf(m_agentRadius / m_cfg.cs);
|
||||
m_cfg.maxEdgeLen = (int)(m_edgeMaxLen / m_cellSize);
|
||||
m_cfg.maxSimplificationError = m_edgeMaxError;
|
||||
m_cfg.minRegionArea = rcSqr(m_regionMinSize); // Note: area = size*size
|
||||
m_cfg.mergeRegionArea = rcSqr(m_regionMergeSize); // Note: area = size*size
|
||||
m_cfg.minRegionArea = rdSqr(m_regionMinSize); // Note: area = size*size
|
||||
m_cfg.mergeRegionArea = rdSqr(m_regionMergeSize); // Note: area = size*size
|
||||
m_cfg.maxVertsPerPoly = (int)m_vertsPerPoly;
|
||||
m_cfg.tileSize = m_tileSize;
|
||||
m_cfg.borderSize = m_cfg.walkableRadius + 3; // Reserve enough padding.
|
||||
@ -645,8 +645,8 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
|
||||
// For example if you build a navmesh for terrain, and want the navmesh tiles to match the terrain tile size
|
||||
// you will need to pass in data from neighbour terrain tiles too! In a simple case, just pass in all the 8 neighbours,
|
||||
// or use the bounding box below to only pass in a sliver of each of the 8 neighbours.
|
||||
rcVcopy(m_cfg.bmin, bmin);
|
||||
rcVcopy(m_cfg.bmax, bmax);
|
||||
rdVcopy(m_cfg.bmin, bmin);
|
||||
rdVcopy(m_cfg.bmax, bmax);
|
||||
m_cfg.bmin[0] -= m_cfg.borderSize*m_cfg.cs;
|
||||
m_cfg.bmin[1] -= m_cfg.borderSize*m_cfg.cs;
|
||||
m_cfg.bmax[0] += m_cfg.borderSize*m_cfg.cs;
|
||||
@ -973,8 +973,8 @@ unsigned char* Editor_TileMesh::buildTileMesh(const int tx, const int ty, const
|
||||
params.tileX = tx;
|
||||
params.tileY = ty;
|
||||
params.tileLayer = 0;
|
||||
rcVcopy(params.bmin, m_pmesh->bmin);
|
||||
rcVcopy(params.bmax, m_pmesh->bmax);
|
||||
rdVcopy(params.bmin, m_pmesh->bmin);
|
||||
rdVcopy(params.bmax, m_pmesh->bmax);
|
||||
params.cs = m_cfg.cs;
|
||||
params.ch = m_cfg.ch;
|
||||
params.buildBvTree = true;
|
||||
|
@ -34,32 +34,32 @@ static bool intersectSegmentTriangle(const float* sp, const float* sq,
|
||||
{
|
||||
float v, w;
|
||||
float ab[3], ac[3], qp[3], ap[3], norm[3], e[3];
|
||||
rcVsub(ab, b, a);
|
||||
rcVsub(ac, c, a);
|
||||
rcVsub(qp, sp, sq);
|
||||
rdVsub(ab, b, a);
|
||||
rdVsub(ac, c, a);
|
||||
rdVsub(qp, sp, sq);
|
||||
|
||||
// Compute triangle normal. Can be precalculated or cached if
|
||||
// intersecting multiple segments against the same triangle
|
||||
rcVcross(norm, ab, ac);
|
||||
rdVcross(norm, ab, ac);
|
||||
|
||||
// Compute denominator d. If d <= 0, segment is parallel to or points
|
||||
// away from triangle, so exit early
|
||||
float d = rcVdot(qp, norm);
|
||||
float d = rdVdot(qp, norm);
|
||||
if (d <= 0.0f) return false;
|
||||
|
||||
// Compute intersection t value of pq with plane of triangle. A ray
|
||||
// intersects if 0 <= t. Segment intersects if 0 <= t <= 1. Delay
|
||||
// dividing by d until intersection has been found to pierce triangle
|
||||
rcVsub(ap, sp, a);
|
||||
t = rcVdot(ap, norm);
|
||||
rdVsub(ap, sp, a);
|
||||
t = rdVdot(ap, norm);
|
||||
if (t < 0.0f) return false;
|
||||
if (t > d) return false; // For segment; exclude this code line for a ray test
|
||||
|
||||
// Compute barycentric coordinate components and test if within bounds
|
||||
rcVcross(e, qp, ap);
|
||||
v = rcVdot(ac, e);
|
||||
rdVcross(e, qp, ap);
|
||||
v = rdVdot(ac, e);
|
||||
if (v < 0.0f || v > d) return false;
|
||||
w = -rcVdot(ab, e);
|
||||
w = -rdVdot(ab, e);
|
||||
if (w < 0.0f || v + w > d) return false;
|
||||
|
||||
// Segment/ray intersects triangle. Perform delayed division
|
||||
@ -111,10 +111,10 @@ InputGeom::InputGeom() :
|
||||
m_offMeshConCount(0),
|
||||
m_volumeCount(0)
|
||||
{
|
||||
rcVset(m_meshBMin, 0.0f, 0.0f, 0.0f);
|
||||
rcVset(m_meshBMax, 0.0f, 0.0f, 0.0f);
|
||||
rcVset(m_navMeshBMin, 0.0f, 0.0f, 0.0f);
|
||||
rcVset(m_navMeshBMax, 0.0f, 0.0f, 0.0f);
|
||||
rdVset(m_meshBMin, 0.0f, 0.0f, 0.0f);
|
||||
rdVset(m_meshBMax, 0.0f, 0.0f, 0.0f);
|
||||
rdVset(m_navMeshBMin, 0.0f, 0.0f, 0.0f);
|
||||
rdVset(m_navMeshBMax, 0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
|
||||
InputGeom::~InputGeom()
|
||||
@ -148,8 +148,8 @@ bool InputGeom::loadMesh(rcContext* ctx, const std::string& filepath)
|
||||
}
|
||||
|
||||
rcCalcBounds(m_mesh->getVerts(), m_mesh->getVertCount(), m_meshBMin, m_meshBMax);
|
||||
rcVcopy(m_navMeshBMin, m_meshBMin);
|
||||
rcVcopy(m_navMeshBMax, m_meshBMax);
|
||||
rdVcopy(m_navMeshBMin, m_meshBMin);
|
||||
rdVcopy(m_navMeshBMax, m_meshBMax);
|
||||
|
||||
m_chunkyMesh = new rcChunkyTriMesh;
|
||||
if (!m_chunkyMesh)
|
||||
@ -190,8 +190,8 @@ bool InputGeom::loadPlyMesh(rcContext* ctx, const std::string& filepath)
|
||||
}
|
||||
|
||||
rcCalcBounds(m_mesh->getVerts(), m_mesh->getVertCount(), m_meshBMin, m_meshBMax);
|
||||
rcVcopy(m_navMeshBMin, m_meshBMin);
|
||||
rcVcopy(m_navMeshBMax, m_meshBMax);
|
||||
rdVcopy(m_navMeshBMin, m_meshBMin);
|
||||
rdVcopy(m_navMeshBMax, m_meshBMax);
|
||||
|
||||
m_chunkyMesh = new rcChunkyTriMesh;
|
||||
if (!m_chunkyMesh)
|
||||
@ -345,8 +345,8 @@ bool InputGeom::loadGeomSet(rcContext* ctx, const std::string& filepath)
|
||||
|
||||
// Copy the original values over so we can reset to them in the
|
||||
// editor after changes have been made.
|
||||
rcVcopy(m_buildSettings.origNavMeshBMin, m_buildSettings.navMeshBMin);
|
||||
rcVcopy(m_buildSettings.origNavMeshBMax, m_buildSettings.navMeshBMax);
|
||||
rdVcopy(m_buildSettings.origNavMeshBMin, m_buildSettings.navMeshBMin);
|
||||
rdVcopy(m_buildSettings.origNavMeshBMax, m_buildSettings.navMeshBMax);
|
||||
}
|
||||
}
|
||||
|
||||
@ -551,8 +551,8 @@ void InputGeom::addOffMeshConnection(const float* spos, const float* epos, const
|
||||
m_offMeshConAreas[m_offMeshConCount] = area;
|
||||
m_offMeshConFlags[m_offMeshConCount] = flags;
|
||||
m_offMeshConId[m_offMeshConCount] = 1000 + m_offMeshConCount;
|
||||
rcVcopy(&verts[0], spos);
|
||||
rcVcopy(&verts[3], epos);
|
||||
rdVcopy(&verts[0], spos);
|
||||
rdVcopy(&verts[3], epos);
|
||||
m_offMeshConCount++;
|
||||
}
|
||||
|
||||
@ -563,9 +563,9 @@ void InputGeom::deleteOffMeshConnection(int i)
|
||||
float* vertsDst = &m_offMeshConVerts[i*3*2];
|
||||
float* refSrc = &m_offMeshConRefPos[m_offMeshConCount*3];
|
||||
float* refDst = &m_offMeshConRefPos[i*3];
|
||||
rcVcopy(&vertsDst[0], &vertsSrc[0]);
|
||||
rcVcopy(&vertsDst[3], &vertsSrc[3]);
|
||||
rcVcopy(&refDst[0], &refSrc[0]);
|
||||
rdVcopy(&vertsDst[0], &vertsSrc[0]);
|
||||
rdVcopy(&vertsDst[3], &vertsSrc[3]);
|
||||
rdVcopy(&refDst[0], &refSrc[0]);
|
||||
m_offMeshConRads[i] = m_offMeshConRads[m_offMeshConCount];
|
||||
m_offMeshConRefYaws[i] = m_offMeshConRefYaws[m_offMeshConCount];
|
||||
m_offMeshConDirs[i] = m_offMeshConDirs[m_offMeshConCount];
|
||||
|
@ -17,8 +17,8 @@
|
||||
//
|
||||
|
||||
#include "Pch.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "DebugUtils/Include/DetourDebugDraw.h"
|
||||
#include "NavEditor/Include/NavMeshPruneTool.h"
|
||||
#include "NavEditor/Include/InputGeom.h"
|
||||
@ -226,8 +226,8 @@ void NavMeshPruneTool::handleMenu()
|
||||
|
||||
void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift)
|
||||
{
|
||||
rcIgnoreUnused(s);
|
||||
rcIgnoreUnused(shift);
|
||||
rdIgnoreUnused(s);
|
||||
rdIgnoreUnused(shift);
|
||||
|
||||
if (!m_editor) return;
|
||||
InputGeom* geom = m_editor->getInputGeom();
|
||||
@ -237,7 +237,7 @@ void NavMeshPruneTool::handleClick(const float* s, const float* p, bool shift)
|
||||
dtNavMeshQuery* query = m_editor->getNavMeshQuery();
|
||||
if (!query) return;
|
||||
|
||||
dtVcopy(m_hitPos, p);
|
||||
rdVcopy(m_hitPos, p);
|
||||
m_hitPosSet = true;
|
||||
|
||||
if (!m_flags)
|
||||
@ -309,9 +309,9 @@ void NavMeshPruneTool::handleRender()
|
||||
|
||||
void NavMeshPruneTool::handleRenderOverlay(double* proj, double* model, int* view)
|
||||
{
|
||||
rcIgnoreUnused(model);
|
||||
rcIgnoreUnused(proj);
|
||||
rcIgnoreUnused(view);
|
||||
rdIgnoreUnused(model);
|
||||
rdIgnoreUnused(proj);
|
||||
rdIgnoreUnused(view);
|
||||
|
||||
// Tool help
|
||||
ImGui_RenderText(ImGuiTextAlign_e::kAlignLeft, ImVec2(280, 40), ImVec4(1.0f,1.0f,1.0f,0.75f), "LMB: Click fill area.");
|
||||
|
@ -17,10 +17,10 @@
|
||||
//
|
||||
|
||||
#include "Pch.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Recast/Include/Recast.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "DetourCrowd/Include/DetourPathCorridor.h"
|
||||
#include "DebugUtils/Include/DetourDebugDraw.h"
|
||||
#include "DebugUtils/Include/RecastDebugDraw.h"
|
||||
@ -85,7 +85,7 @@ static int fixupShortcuts(dtPolyRef* path, int npath, dtNavMeshQuery* navQuery)
|
||||
// in the path, short cut to that polygon directly.
|
||||
static const int maxLookAhead = 6;
|
||||
int cut = 0;
|
||||
for (int i = dtMin(maxLookAhead, npath) - 1; i > 1 && cut == 0; i--) {
|
||||
for (int i = rdMin(maxLookAhead, npath) - 1; i > 1 && cut == 0; i--) {
|
||||
for (int j = 0; j < nneis; j++)
|
||||
{
|
||||
if (path[i] == neis[j]) {
|
||||
@ -126,7 +126,7 @@ static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, cons
|
||||
{
|
||||
*outPointCount = nsteerPath;
|
||||
for (int i = 0; i < nsteerPath; ++i)
|
||||
dtVcopy(&outPoints[i*3], &steerPath[i*3]);
|
||||
rdVcopy(&outPoints[i*3], &steerPath[i*3]);
|
||||
}
|
||||
|
||||
|
||||
@ -144,7 +144,7 @@ static bool getSteerTarget(dtNavMeshQuery* navQuery, const float* startPos, cons
|
||||
if (ns >= nsteerPath)
|
||||
return false;
|
||||
|
||||
dtVcopy(steerPos, &steerPath[ns*3]);
|
||||
rdVcopy(steerPos, &steerPath[ns*3]);
|
||||
steerPos[2] = startPos[2];
|
||||
steerPosFlag = steerPathFlags[ns];
|
||||
steerPosRef = steerPathPolys[ns];
|
||||
@ -351,7 +351,7 @@ void NavMeshTesterTool::handleMenu()
|
||||
dtStatus status = m_navQuery->findRandomPoint(&m_filter, frand, &ref, pt);
|
||||
if (dtStatusSucceed(status))
|
||||
{
|
||||
dtVcopy(&m_randPoints[m_nrandPoints*3], pt);
|
||||
rdVcopy(&m_randPoints[m_nrandPoints*3], pt);
|
||||
m_nrandPoints++;
|
||||
}
|
||||
}
|
||||
@ -372,7 +372,7 @@ void NavMeshTesterTool::handleMenu()
|
||||
dtStatus status = m_navQuery->findRandomPointAroundCircle(m_startRef, m_spos, m_randomRadius, &m_filter, frand, &ref, pt);
|
||||
if (dtStatusSucceed(status))
|
||||
{
|
||||
dtVcopy(&m_randPoints[m_nrandPoints*3], pt);
|
||||
rdVcopy(&m_randPoints[m_nrandPoints*3], pt);
|
||||
m_nrandPoints++;
|
||||
}
|
||||
}
|
||||
@ -494,12 +494,12 @@ void NavMeshTesterTool::handleClick(const float* /*s*/, const float* p, bool shi
|
||||
if (!shift)
|
||||
{
|
||||
m_sposSet = true;
|
||||
dtVcopy(m_spos, p);
|
||||
rdVcopy(m_spos, p);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_eposSet = true;
|
||||
dtVcopy(m_epos, p);
|
||||
rdVcopy(m_epos, p);
|
||||
}
|
||||
recalc();
|
||||
}
|
||||
@ -551,12 +551,12 @@ void NavMeshTesterTool::handleToggle()
|
||||
|
||||
m_nsmoothPath = 0;
|
||||
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
}
|
||||
|
||||
dtVcopy(m_prevIterPos, m_iterPos);
|
||||
rdVcopy(m_prevIterPos, m_iterPos);
|
||||
|
||||
m_pathIterNum++;
|
||||
|
||||
@ -579,22 +579,22 @@ void NavMeshTesterTool::handleToggle()
|
||||
m_steerPoints, &m_steerPointCount))
|
||||
return;
|
||||
|
||||
dtVcopy(m_steerPos, steerPos);
|
||||
rdVcopy(m_steerPos, steerPos);
|
||||
|
||||
bool endOfPath = (steerPosFlag & DT_STRAIGHTPATH_END) ? true : false;
|
||||
bool offMeshConnection = (steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ? true : false;
|
||||
|
||||
// Find movement delta.
|
||||
float delta[3], len;
|
||||
dtVsub(delta, steerPos, m_iterPos);
|
||||
len = sqrtf(dtVdot(delta,delta));
|
||||
rdVsub(delta, steerPos, m_iterPos);
|
||||
len = sqrtf(rdVdot(delta,delta));
|
||||
// If the steer target is end of path or off-mesh link, do not move past the location.
|
||||
if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
|
||||
len = 1;
|
||||
else
|
||||
len = STEP_SIZE / len;
|
||||
float moveTgt[3];
|
||||
dtVmad(moveTgt, m_iterPos, delta, len);
|
||||
rdVmad(moveTgt, m_iterPos, delta, len);
|
||||
|
||||
// Move
|
||||
float result[3];
|
||||
@ -608,16 +608,16 @@ void NavMeshTesterTool::handleToggle()
|
||||
float h = 0;
|
||||
m_navQuery->getPolyHeight(m_pathIterPolys[0], result, &h);
|
||||
result[2] = h;
|
||||
dtVcopy(m_iterPos, result);
|
||||
rdVcopy(m_iterPos, result);
|
||||
|
||||
// Handle end of path and off-mesh links when close enough.
|
||||
if (endOfPath && inRange(m_iterPos, steerPos, SLOP, 1.0f))
|
||||
{
|
||||
// Reached end of path.
|
||||
dtVcopy(m_iterPos, m_targetPos);
|
||||
rdVcopy(m_iterPos, m_targetPos);
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
return;
|
||||
@ -646,17 +646,17 @@ void NavMeshTesterTool::handleToggle()
|
||||
{
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
m_nsmoothPath++;
|
||||
// Hack to make the dotted path not visible during off-mesh connection.
|
||||
if (m_nsmoothPath & 1)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
}
|
||||
// Move position at the other side of the off-mesh link.
|
||||
dtVcopy(m_iterPos, endPos);
|
||||
rdVcopy(m_iterPos, endPos);
|
||||
float eh = 0.0f;
|
||||
m_navQuery->getPolyHeight(m_pathIterPolys[0], m_iterPos, &eh);
|
||||
m_iterPos[2] = eh;
|
||||
@ -666,7 +666,7 @@ void NavMeshTesterTool::handleToggle()
|
||||
// Store results.
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], m_iterPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
|
||||
@ -688,7 +688,7 @@ void NavMeshTesterTool::handleUpdate(const float /*dt*/)
|
||||
{
|
||||
// In case of partial path, make sure the end point is clamped to the last polygon.
|
||||
float epos[3];
|
||||
dtVcopy(epos, m_epos);
|
||||
rdVcopy(epos, m_epos);
|
||||
if (m_polys[m_npolys-1] != m_endRef)
|
||||
m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos, 0);
|
||||
|
||||
@ -779,7 +779,7 @@ void NavMeshTesterTool::recalc()
|
||||
|
||||
m_nsmoothPath = 0;
|
||||
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
m_nsmoothPath++;
|
||||
|
||||
// Move towards target a small advancement at a time until target reached or
|
||||
@ -800,15 +800,15 @@ void NavMeshTesterTool::recalc()
|
||||
|
||||
// Find movement delta.
|
||||
float delta[3], len;
|
||||
dtVsub(delta, steerPos, iterPos);
|
||||
len = dtMathSqrtf(dtVdot(delta, delta));
|
||||
rdVsub(delta, steerPos, iterPos);
|
||||
len = rdMathSqrtf(rdVdot(delta, delta));
|
||||
// If the steer target is end of path or off-mesh link, do not move past the location.
|
||||
if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
|
||||
len = 1;
|
||||
else
|
||||
len = STEP_SIZE / len;
|
||||
float moveTgt[3];
|
||||
dtVmad(moveTgt, iterPos, delta, len);
|
||||
rdVmad(moveTgt, iterPos, delta, len);
|
||||
|
||||
// Move
|
||||
float result[3];
|
||||
@ -823,16 +823,16 @@ void NavMeshTesterTool::recalc()
|
||||
float h = 0;
|
||||
m_navQuery->getPolyHeight(polys[0], result, &h);
|
||||
result[2] = h;
|
||||
dtVcopy(iterPos, result);
|
||||
rdVcopy(iterPos, result);
|
||||
|
||||
// Handle end of path and off-mesh links when close enough.
|
||||
if (endOfPath && inRange(iterPos, steerPos, SLOP, 1.0f))
|
||||
{
|
||||
// Reached end of path.
|
||||
dtVcopy(iterPos, targetPos);
|
||||
rdVcopy(iterPos, targetPos);
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
break;
|
||||
@ -861,17 +861,17 @@ void NavMeshTesterTool::recalc()
|
||||
{
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
m_nsmoothPath++;
|
||||
// Hack to make the dotted path not visible during off-mesh connection.
|
||||
if (m_nsmoothPath & 1)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], startPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
}
|
||||
// Move position at the other side of the off-mesh link.
|
||||
dtVcopy(iterPos, endPos);
|
||||
rdVcopy(iterPos, endPos);
|
||||
float eh = 0.0f;
|
||||
m_navQuery->getPolyHeight(polys[0], iterPos, &eh);
|
||||
iterPos[2] = eh;
|
||||
@ -881,7 +881,7 @@ void NavMeshTesterTool::recalc()
|
||||
// Store results.
|
||||
if (m_nsmoothPath < MAX_SMOOTH)
|
||||
{
|
||||
dtVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
rdVcopy(&m_smoothPath[m_nsmoothPath*3], iterPos);
|
||||
m_nsmoothPath++;
|
||||
}
|
||||
}
|
||||
@ -909,7 +909,7 @@ void NavMeshTesterTool::recalc()
|
||||
{
|
||||
// In case of partial path, make sure the end point is clamped to the last polygon.
|
||||
float epos[3];
|
||||
dtVcopy(epos, m_epos);
|
||||
rdVcopy(epos, m_epos);
|
||||
if (m_polys[m_npolys-1] != m_endRef)
|
||||
m_navQuery->closestPointOnPoly(m_polys[m_npolys-1], m_epos, epos, 0);
|
||||
|
||||
@ -964,13 +964,13 @@ void NavMeshTesterTool::recalc()
|
||||
if (t > 1)
|
||||
{
|
||||
// No hit
|
||||
dtVcopy(m_hitPos, m_epos);
|
||||
rdVcopy(m_hitPos, m_epos);
|
||||
m_hitResult = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hit
|
||||
dtVlerp(m_hitPos, m_spos, m_epos, t);
|
||||
rdVlerp(m_hitPos, m_spos, m_epos, t);
|
||||
m_hitResult = true;
|
||||
}
|
||||
// Adjust height.
|
||||
@ -980,7 +980,7 @@ void NavMeshTesterTool::recalc()
|
||||
m_navQuery->getPolyHeight(m_polys[m_npolys-1], m_hitPos, &h);
|
||||
m_hitPos[2] = h;
|
||||
}
|
||||
dtVcopy(&m_straightPath[3], m_hitPos);
|
||||
rdVcopy(&m_straightPath[3], m_hitPos);
|
||||
}
|
||||
}
|
||||
else if (m_toolMode == TOOLMODE_DISTANCE_TO_WALL)
|
||||
@ -1076,7 +1076,7 @@ static void getPolyCenter(dtNavMesh* navMesh, dtPolyRef ref, float* center)
|
||||
if (dtStatusFailed(status))
|
||||
return;
|
||||
|
||||
dtVcopy(center, poly->center);
|
||||
rdVcopy(center, poly->center);
|
||||
}
|
||||
|
||||
|
||||
@ -1358,18 +1358,18 @@ void NavMeshTesterTool::handleRender()
|
||||
|
||||
// Skip too distant segments.
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(m_spos, s, s+3, tseg);
|
||||
if (distSqr > dtSqr(m_neighbourhoodRadius))
|
||||
float distSqr = rdDistancePtSegSqr2D(m_spos, s, s+3, tseg);
|
||||
if (distSqr > rdSqr(m_neighbourhoodRadius))
|
||||
continue;
|
||||
|
||||
float delta[3], norm[3], p0[3], p1[3];
|
||||
dtVsub(delta, s+3,s);
|
||||
dtVmad(p0, s, delta, 0.5f);
|
||||
rdVsub(delta, s+3,s);
|
||||
rdVmad(p0, s, delta, 0.5f);
|
||||
norm[0] = -delta[1];
|
||||
norm[1] = delta[0];
|
||||
norm[2] = 0;
|
||||
dtVnormalize(norm);
|
||||
dtVmad(p1, p0, norm, agentRadius*0.5f);
|
||||
rdVnormalize(norm);
|
||||
rdVmad(p1, p0, norm, agentRadius*0.5f);
|
||||
|
||||
// Skip backfacing segments.
|
||||
if (refs[j])
|
||||
@ -1381,7 +1381,7 @@ void NavMeshTesterTool::handleRender()
|
||||
else
|
||||
{
|
||||
unsigned int col = duRGBA(192,32,16,192);
|
||||
if (dtTriArea2D(m_spos, s, s+3) < 0.0f)
|
||||
if (rdTriArea2D(m_spos, s, s+3) < 0.0f)
|
||||
col = duRGBA(96,32,16,192);
|
||||
|
||||
dd.vertex(p0[0],p0[1],p0[2]+agentClimb,col);
|
||||
|
@ -88,7 +88,7 @@ void OffMeshConnectionTool::handleClick(const float* /*s*/, const float* p, bool
|
||||
for (int i = 0; i < geom->getOffMeshConnectionCount()*2; ++i)
|
||||
{
|
||||
const float* v = &verts[i*3];
|
||||
float d = rcVdistSqr(p, v);
|
||||
float d = rdVdistSqr(p, v);
|
||||
if (d < nearestDist)
|
||||
{
|
||||
nearestDist = d;
|
||||
@ -107,7 +107,7 @@ void OffMeshConnectionTool::handleClick(const float* /*s*/, const float* p, bool
|
||||
// Create
|
||||
if (!m_hitPosSet)
|
||||
{
|
||||
rcVcopy(m_hitPos, p);
|
||||
rdVcopy(m_hitPos, p);
|
||||
m_hitPosSet = true;
|
||||
}
|
||||
else
|
||||
|
@ -17,7 +17,7 @@
|
||||
//
|
||||
|
||||
#include "Pch.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNavMeshQuery.h"
|
||||
#include "NavEditor/Include/TestCase.h"
|
||||
@ -276,12 +276,12 @@ void TestCase::doTests(dtNavMesh* navmesh, dtNavMeshQuery* navquery)
|
||||
if (t > 1)
|
||||
{
|
||||
// No hit
|
||||
dtVcopy(hitPos, iter->epos);
|
||||
rdVcopy(hitPos, iter->epos);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hit
|
||||
dtVlerp(hitPos, iter->spos, iter->epos, t);
|
||||
rdVlerp(hitPos, iter->spos, iter->epos, t);
|
||||
}
|
||||
// Adjust height.
|
||||
if (iter->npolys > 0)
|
||||
@ -290,7 +290,7 @@ void TestCase::doTests(dtNavMesh* navmesh, dtNavMeshQuery* navquery)
|
||||
navquery->getPolyHeight(polys[iter->npolys-1], hitPos, &h);
|
||||
hitPos[2] = h;
|
||||
}
|
||||
dtVcopy(&iter->straight[3], hitPos);
|
||||
rdVcopy(&iter->straight[3], hitPos);
|
||||
|
||||
if (iter->npolys)
|
||||
{
|
||||
@ -321,8 +321,8 @@ void TestCase::handleRender()
|
||||
for (Test* iter = m_tests; iter; iter = iter->next)
|
||||
{
|
||||
float dir[3];
|
||||
dtVsub(dir, iter->epos, iter->spos);
|
||||
dtVnormalize(dir);
|
||||
rdVsub(dir, iter->epos, iter->spos);
|
||||
rdVnormalize(dir);
|
||||
glColor4ub(128,25,0,192);
|
||||
glVertex3f(iter->spos[0],iter->spos[1],iter->spos[2]-0.3f);
|
||||
glVertex3f(iter->spos[0],iter->spos[1],iter->spos[2]+0.3f);
|
||||
@ -387,20 +387,20 @@ bool TestCase::handleRenderOverlay(double* proj, double* model, int* view)
|
||||
float pt[3], dir[3];
|
||||
if (iter->nstraight)
|
||||
{
|
||||
dtVcopy(pt, &iter->straight[3]);
|
||||
if (dtVdist(pt, iter->spos) > LABEL_DIST)
|
||||
rdVcopy(pt, &iter->straight[3]);
|
||||
if (rdVdist(pt, iter->spos) > LABEL_DIST)
|
||||
{
|
||||
dtVsub(dir, pt, iter->spos);
|
||||
dtVnormalize(dir);
|
||||
dtVmad(pt, iter->spos, dir, LABEL_DIST);
|
||||
rdVsub(dir, pt, iter->spos);
|
||||
rdVnormalize(dir);
|
||||
rdVmad(pt, iter->spos, dir, LABEL_DIST);
|
||||
}
|
||||
pt[2]+=0.5f;
|
||||
}
|
||||
else
|
||||
{
|
||||
dtVsub(dir, iter->epos, iter->spos);
|
||||
dtVnormalize(dir);
|
||||
dtVmad(pt, iter->spos, dir, LABEL_DIST);
|
||||
rdVsub(dir, iter->epos, iter->spos);
|
||||
rdVnormalize(dir);
|
||||
rdVmad(pt, iter->spos, dir, LABEL_DIST);
|
||||
pt[2]+=0.5f;
|
||||
}
|
||||
|
||||
|
@ -161,9 +161,9 @@ void update_camera(const float* bmin, const float* bmax,float* cameraPos,float*
|
||||
// Reset camera and fog to match the mesh bounds.
|
||||
if (bmin && bmax)
|
||||
{
|
||||
camr = sqrtf(rcSqr(bmax[0] - bmin[0]) +
|
||||
rcSqr(bmax[1] - bmin[1]) +
|
||||
rcSqr(bmax[2] - bmin[2])) / 2;
|
||||
camr = sqrtf(rdSqr(bmax[0] - bmin[0]) +
|
||||
rdSqr(bmax[1] - bmin[1]) +
|
||||
rdSqr(bmax[2] - bmin[2])) / 2;
|
||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||
cameraPos[2] = (bmax[2] + bmin[2]) / 2 + camr;
|
||||
@ -288,7 +288,7 @@ bool sdl_init(SDL_Window*& window, SDL_Renderer*& renderer, int &width, int &hei
|
||||
else
|
||||
{
|
||||
float aspect = 16.0f / 9.0f;
|
||||
width = rcMin(displayMode.w, static_cast<int>((displayMode.h * aspect))) - 80;
|
||||
width = rdMin(displayMode.w, static_cast<int>((displayMode.h * aspect))) - 80;
|
||||
height = displayMode.h - 80;
|
||||
}
|
||||
|
||||
@ -635,8 +635,8 @@ int not_main(int argc, char** argv)
|
||||
BuildSettings settings;
|
||||
memset(&settings, 0, sizeof(settings));
|
||||
|
||||
rcVcopy(settings.navMeshBMin, geom->getNavMeshBoundsMin());
|
||||
rcVcopy(settings.navMeshBMax, geom->getNavMeshBoundsMax());
|
||||
rdVcopy(settings.navMeshBMin, geom->getNavMeshBoundsMin());
|
||||
rdVcopy(settings.navMeshBMax, geom->getNavMeshBoundsMax());
|
||||
|
||||
editor->collectSettings(settings);
|
||||
|
||||
@ -781,7 +781,7 @@ int not_main(int argc, char** argv)
|
||||
// Update editor simulation.
|
||||
const float SIM_RATE = 20;
|
||||
const float DELTA_TIME = 1.0f / SIM_RATE;
|
||||
timeAcc = rcClamp(timeAcc + dt, -1.0f, 1.0f);
|
||||
timeAcc = rdClamp(timeAcc + dt, -1.0f, 1.0f);
|
||||
int simIter = 0;
|
||||
while (timeAcc > DELTA_TIME)
|
||||
{
|
||||
@ -856,12 +856,12 @@ int not_main(int argc, char** argv)
|
||||
{
|
||||
// Handle keyboard movement.
|
||||
const Uint8* keystate = SDL_GetKeyboardState(NULL);
|
||||
moveFront = rcClamp(moveFront + dt * 4 * ((keystate[SDL_SCANCODE_W] || keystate[SDL_SCANCODE_UP ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveLeft = rcClamp(moveLeft + dt * 4 * ((keystate[SDL_SCANCODE_A] || keystate[SDL_SCANCODE_LEFT ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveBack = rcClamp(moveBack + dt * 4 * ((keystate[SDL_SCANCODE_S] || keystate[SDL_SCANCODE_DOWN ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveRight = rcClamp(moveRight + dt * 4 * ((keystate[SDL_SCANCODE_D] || keystate[SDL_SCANCODE_RIGHT ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveUp = rcClamp(moveUp + dt * 4 * ((keystate[SDL_SCANCODE_Q] || keystate[SDL_SCANCODE_PAGEUP ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveDown = rcClamp(moveDown + dt * 4 * ((keystate[SDL_SCANCODE_E] || keystate[SDL_SCANCODE_PAGEDOWN ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveFront = rdClamp(moveFront + dt * 4 * ((keystate[SDL_SCANCODE_W] || keystate[SDL_SCANCODE_UP ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveLeft = rdClamp(moveLeft + dt * 4 * ((keystate[SDL_SCANCODE_A] || keystate[SDL_SCANCODE_LEFT ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveBack = rdClamp(moveBack + dt * 4 * ((keystate[SDL_SCANCODE_S] || keystate[SDL_SCANCODE_DOWN ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveRight = rdClamp(moveRight + dt * 4 * ((keystate[SDL_SCANCODE_D] || keystate[SDL_SCANCODE_RIGHT ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveUp = rdClamp(moveUp + dt * 4 * ((keystate[SDL_SCANCODE_Q] || keystate[SDL_SCANCODE_PAGEUP ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
moveDown = rdClamp(moveDown + dt * 4 * ((keystate[SDL_SCANCODE_E] || keystate[SDL_SCANCODE_PAGEDOWN ]) ? 1 : -1), 0.0f, 1.0f);
|
||||
|
||||
float keybSpeed = 8800.0f;
|
||||
if (SDL_GetModState() & KMOD_SHIFT)
|
||||
@ -1261,7 +1261,7 @@ int not_main(int argc, char** argv)
|
||||
const float r = 25.0f;
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
const float a = (float)i / 20.0f * RC_PI*2;
|
||||
const float a = (float)i / 20.0f * RD_PI*2;
|
||||
const float fx = (float)x + cosf(a)*r;
|
||||
const float fy = (float)y + sinf(a)*r;
|
||||
glVertex2f(fx,fy);
|
||||
|
6
src/thirdparty/recast/CMakeLists.txt
vendored
6
src/thirdparty/recast/CMakeLists.txt
vendored
@ -10,11 +10,14 @@ start_sources()
|
||||
add_sources( SOURCE_GROUP "Source"
|
||||
"Shared/Source/SharedAlloc.cpp"
|
||||
"Shared/Source/SharedAssert.cpp"
|
||||
"Shared/Source/SharedCommon.cpp"
|
||||
)
|
||||
|
||||
add_sources( SOURCE_GROUP "Include"
|
||||
"Shared/Include/SharedAlloc.h"
|
||||
"Shared/Include/SharedAssert.h"
|
||||
"Shared/Include/SharedCommon.h"
|
||||
"Shared/Include/SharedMath.h"
|
||||
)
|
||||
|
||||
end_sources()
|
||||
@ -56,7 +59,6 @@ add_module( "lib" "libdetour" "navsharedcommon" ${FOLDER_CONTEXT} TRUE TRUE )
|
||||
start_sources()
|
||||
|
||||
add_sources( SOURCE_GROUP "Source"
|
||||
"Detour/Source/DetourCommon.cpp"
|
||||
"Detour/Source/DetourNavMesh.cpp"
|
||||
"Detour/Source/DetourNavMeshBuilder.cpp"
|
||||
"Detour/Source/DetourNavMeshQuery.cpp"
|
||||
@ -64,8 +66,6 @@ add_sources( SOURCE_GROUP "Source"
|
||||
)
|
||||
|
||||
add_sources( SOURCE_GROUP "Include"
|
||||
"Detour/Include/DetourCommon.h"
|
||||
"Detour/Include/DetourMath.h"
|
||||
"Detour/Include/DetourNavMesh.h"
|
||||
"Detour/Include/DetourNavMeshBuilder.h"
|
||||
"Detour/Include/DetourNavMeshQuery.h"
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <string.h>
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "DebugUtils/Include/DebugDraw.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
|
||||
|
||||
@ -217,8 +217,8 @@ void duAppendCylinderWire(struct duDebugDraw* dd, float minx, float miny, float
|
||||
for (int i = 0; i < NUM_SEG; ++i)
|
||||
{
|
||||
const float a = (float)i/(float)NUM_SEG*DU_PI*2;
|
||||
dir[i*2] = dtMathCosf(a);
|
||||
dir[i*2+1] = dtMathSinf(a);
|
||||
dir[i*2] = rdMathCosf(a);
|
||||
dir[i*2+1] = rdMathSinf(a);
|
||||
}
|
||||
}
|
||||
|
||||
@ -557,7 +557,7 @@ duDisplayList::duDisplayList(int cap) :
|
||||
if (cap < 8)
|
||||
cap = 8;
|
||||
resize(cap);
|
||||
dtVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
rdVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
}
|
||||
|
||||
duDisplayList::~duDisplayList()
|
||||
@ -599,7 +599,7 @@ void duDisplayList::begin(const duDebugDrawPrimitives prim, const float size, co
|
||||
m_prim = prim;
|
||||
m_primSize = size;
|
||||
if (offset)
|
||||
dtVcopy(m_drawOffset, offset);
|
||||
rdVcopy(m_drawOffset, offset);
|
||||
}
|
||||
|
||||
void duDisplayList::vertex(const float x, const float y, const float z, unsigned int color)
|
||||
@ -607,8 +607,8 @@ void duDisplayList::vertex(const float x, const float y, const float z, unsigned
|
||||
if (m_size+1 >= m_cap)
|
||||
resize(m_cap*2);
|
||||
float* p = &m_pos[m_size*3];
|
||||
dtVset(p,x,y,z);
|
||||
dtVadd(p,p,m_drawOffset);
|
||||
rdVset(p,x,y,z);
|
||||
rdVadd(p,p,m_drawOffset);
|
||||
m_color[m_size] = color;
|
||||
m_size++;
|
||||
}
|
||||
@ -620,7 +620,7 @@ void duDisplayList::vertex(const float* pos, unsigned int color)
|
||||
|
||||
void duDisplayList::end()
|
||||
{
|
||||
dtVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
rdVset(m_drawOffset, 0.0f,0.0f,0.0f);
|
||||
}
|
||||
|
||||
void duDisplayList::draw(struct duDebugDraw* dd)
|
||||
|
@ -19,8 +19,8 @@
|
||||
#include "DebugUtils/Include/DebugDraw.h"
|
||||
#include "DebugUtils/Include/DetourDebugDraw.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
|
||||
static unsigned int getPolySurfaceColor(const dtPoly* poly, duDebugDraw* dd, const unsigned int alpha)
|
||||
{
|
||||
@ -111,8 +111,8 @@ static void drawPolyBoundaries(duDebugDraw* dd, const dtMeshTile* tile,
|
||||
if ((dtGetDetailTriEdgeFlags(t[3], n) & DT_DETAIL_EDGE_BOUNDARY) == 0)
|
||||
continue;
|
||||
|
||||
if (distancePtLine2d(tv[n],v0,v1) < thr &&
|
||||
distancePtLine2d(tv[m],v0,v1) < thr)
|
||||
if (rdDistancePtLine2d(tv[n],v0,v1) < thr &&
|
||||
rdDistancePtLine2d(tv[m],v0,v1) < thr)
|
||||
{
|
||||
dd->vertex(tv[n], c);
|
||||
dd->vertex(tv[m], c);
|
||||
|
@ -55,9 +55,9 @@ void duDebugDrawTriMesh(duDebugDraw* dd, const float* verts, int /*nverts*/,
|
||||
const float* vc = &verts[tris[i+2]*3];
|
||||
|
||||
int ax = 0, ay = 0;
|
||||
if (rcAbs(norm[1]) > rcAbs(norm[ax]))
|
||||
if (rdAbs(norm[1]) > rdAbs(norm[ax]))
|
||||
ax = 1;
|
||||
if (rcAbs(norm[2]) > rcAbs(norm[ax]))
|
||||
if (rdAbs(norm[2]) > rdAbs(norm[ax]))
|
||||
ax = 2;
|
||||
ax = (1<<ax)&3; // +1 mod 3
|
||||
ay = (1<<ax)&3; // +1 mod 3
|
||||
@ -112,9 +112,9 @@ void duDebugDrawTriMeshSlope(duDebugDraw* dd, const float* verts, int /*nverts*/
|
||||
const float* vc = &verts[tris[i+2]*3];
|
||||
|
||||
int ax = 0, ay = 0;
|
||||
if (rcAbs(norm[1]) > rcAbs(norm[ax]))
|
||||
if (rdAbs(norm[1]) > rdAbs(norm[ax]))
|
||||
ax = 1;
|
||||
if (rcAbs(norm[2]) > rcAbs(norm[ax]))
|
||||
if (rdAbs(norm[2]) > rdAbs(norm[ax]))
|
||||
ax = 2;
|
||||
ax = (1<<ax)&3; // +1 mod 3
|
||||
ay = (1<<ax)&3; // +1 mod 3
|
||||
|
@ -1,30 +0,0 @@
|
||||
/**
|
||||
@defgroup detour Detour
|
||||
|
||||
Members in this module are wrappers around the standard math library
|
||||
*/
|
||||
|
||||
#ifndef DETOURMATH_H
|
||||
#define DETOURMATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/// The value of PI used by Recast.
|
||||
static const float DT_PI = 3.14159265f;
|
||||
|
||||
/// The total number of bits in an bit cell integer.
|
||||
static const int DT_BITS_PER_BIT_CELL = 32;
|
||||
|
||||
inline int dtBitCellBit(const int bitNum) { return (1 << ((bitNum) & (DT_BITS_PER_BIT_CELL-1))); }
|
||||
|
||||
inline float dtMathFabsf(float x) { return fabsf(x); }
|
||||
inline float dtMathSqrtf(float x) { return sqrtf(x); }
|
||||
inline float dtMathFloorf(float x) { return floorf(x); }
|
||||
inline float dtMathCeilf(float x) { return ceilf(x); }
|
||||
inline float dtMathRoundf(float x) { return roundf(x); }
|
||||
inline float dtMathCosf(float x) { return cosf(x); }
|
||||
inline float dtMathSinf(float x) { return sinf(x); }
|
||||
inline float dtMathAtan2f(float y, float x) { return atan2f(y, x); }
|
||||
inline bool dtMathIsfinite(float x) { return isfinite(x); }
|
||||
|
||||
#endif
|
@ -19,13 +19,13 @@
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include <new>
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Shared/Include/SharedAlloc.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include <new>
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
|
||||
|
||||
inline bool overlapSlabs(const float* amin, const float* amax,
|
||||
@ -35,8 +35,8 @@ inline bool overlapSlabs(const float* amin, const float* amax,
|
||||
// Check for horizontal overlap.
|
||||
// The segment is shrunken a little so that slabs which touch
|
||||
// at end points are not connected.
|
||||
const float minx = dtMax(amin[0]+px,bmin[0]+px);
|
||||
const float maxx = dtMin(amax[0]-px,bmax[0]-px);
|
||||
const float minx = rdMax(amin[0]+px,bmin[0]+px);
|
||||
const float maxx = rdMin(amax[0]-px,bmax[0]-px);
|
||||
if (minx > maxx)
|
||||
return false;
|
||||
|
||||
@ -57,7 +57,7 @@ inline bool overlapSlabs(const float* amin, const float* amax,
|
||||
return true;
|
||||
|
||||
// Check for overlap at endpoints.
|
||||
const float thr = dtSqr(pz*2);
|
||||
const float thr = rdSqr(pz*2);
|
||||
if (dmin*dmin <= thr || dmax*dmax <= thr)
|
||||
return true;
|
||||
|
||||
@ -137,12 +137,12 @@ inline void freeLink(dtMeshTile* tile, unsigned int link)
|
||||
int calcTraversalTableCellIndex(const int numPolyGroups,
|
||||
const unsigned short polyGroup1, const unsigned short polyGroup2)
|
||||
{
|
||||
return polyGroup1*((numPolyGroups+(DT_BITS_PER_BIT_CELL-1))/DT_BITS_PER_BIT_CELL)+(polyGroup2/DT_BITS_PER_BIT_CELL);
|
||||
return polyGroup1*((numPolyGroups+(RD_BITS_PER_BIT_CELL-1))/RD_BITS_PER_BIT_CELL)+(polyGroup2/RD_BITS_PER_BIT_CELL);
|
||||
}
|
||||
|
||||
int calcTraversalTableSize(const int numPolyGroups)
|
||||
{
|
||||
return sizeof(int)*(numPolyGroups*((numPolyGroups+(DT_BITS_PER_BIT_CELL-1))/DT_BITS_PER_BIT_CELL));
|
||||
return sizeof(int)*(numPolyGroups*((numPolyGroups+(RD_BITS_PER_BIT_CELL-1))/RD_BITS_PER_BIT_CELL));
|
||||
}
|
||||
|
||||
dtNavMesh* dtAllocNavMesh()
|
||||
@ -250,14 +250,14 @@ dtNavMesh::~dtNavMesh() // TODO: see [r5apex_ds + F43720] to re-implement this c
|
||||
dtStatus dtNavMesh::init(const dtNavMeshParams* params)
|
||||
{
|
||||
memcpy(&m_params, params, sizeof(dtNavMeshParams));
|
||||
dtVcopy(m_orig, params->orig);
|
||||
rdVcopy(m_orig, params->orig);
|
||||
|
||||
m_tileWidth = params->tileWidth;
|
||||
m_tileHeight = params->tileHeight;
|
||||
|
||||
// Init tiles
|
||||
m_maxTiles = params->maxTiles;
|
||||
m_tileLutSize = dtNextPow2(params->maxTiles/4);
|
||||
m_tileLutSize = rdNextPow2(params->maxTiles/4);
|
||||
if (!m_tileLutSize) m_tileLutSize = 1;
|
||||
m_tileLutMask = m_tileLutSize-1;
|
||||
|
||||
@ -293,8 +293,8 @@ dtStatus dtNavMesh::init(const dtNavMeshParams* params)
|
||||
|
||||
// Init ID generator values.
|
||||
#ifndef DT_POLYREF64
|
||||
m_tileBits = dtIlog2(dtNextPow2((unsigned int)params->maxTiles));
|
||||
m_polyBits = dtIlog2(dtNextPow2((unsigned int)params->maxPolys));
|
||||
m_tileBits = rdIlog2(rdNextPow2((unsigned int)params->maxTiles));
|
||||
m_polyBits = rdIlog2(rdNextPow2((unsigned int)params->maxPolys));
|
||||
m_saltBits = 32 - m_tileBits - m_polyBits;
|
||||
#endif
|
||||
|
||||
@ -311,7 +311,7 @@ dtStatus dtNavMesh::init(unsigned char* data, const int dataSize, const int tabl
|
||||
return DT_FAILURE | DT_WRONG_VERSION;
|
||||
|
||||
dtNavMeshParams params;
|
||||
dtVcopy(params.orig, header->bmin);
|
||||
rdVcopy(params.orig, header->bmin);
|
||||
params.orig[0] = header->bmax[0];
|
||||
params.tileWidth = header->bmax[0] - header->bmin[0];
|
||||
params.tileHeight = header->bmax[1] - header->bmin[1];
|
||||
@ -372,7 +372,7 @@ int dtNavMesh::findConnectingPolys(const float* va, const float* vb,
|
||||
const float bpos = getSlabCoord(vc, side);
|
||||
|
||||
// Segments are not close enough.
|
||||
if (dtAbs(apos-bpos) > near_thresh)
|
||||
if (rdAbs(apos-bpos) > near_thresh)
|
||||
continue;
|
||||
|
||||
// Check if the segments touch.
|
||||
@ -383,8 +383,8 @@ int dtNavMesh::findConnectingPolys(const float* va, const float* vb,
|
||||
// Add return value.
|
||||
if (n < maxcon)
|
||||
{
|
||||
conarea[n*2+0] = dtMax(amin[0], bmin[0]);
|
||||
conarea[n*2+1] = dtMin(amax[0], bmax[0]);
|
||||
conarea[n*2+0] = rdMax(amin[0], bmin[0]);
|
||||
conarea[n*2+1] = rdMin(amax[0], bmax[0]);
|
||||
con[n] = base | (dtPolyRef)i;
|
||||
n++;
|
||||
}
|
||||
@ -456,7 +456,7 @@ void dtNavMesh::connectExtLinks(dtMeshTile* tile, dtMeshTile* target, int side)
|
||||
const float* vb = &tile->verts[poly->verts[(j+1) % nv]*3];
|
||||
dtPolyRef nei[4];
|
||||
float neia[4*2];
|
||||
int nnei = findConnectingPolys(va,vb, target, dtOppositeTile(dir), nei,neia,4);
|
||||
int nnei = findConnectingPolys(va,vb, target, rdOppositeTile(dir), nei,neia,4);
|
||||
for (int k = 0; k < nnei; ++k)
|
||||
{
|
||||
unsigned int idx = allocLink(tile);
|
||||
@ -480,18 +480,18 @@ void dtNavMesh::connectExtLinks(dtMeshTile* tile, dtMeshTile* target, int side)
|
||||
float tmin = (neia[k*2+0]-va[1]) / (vb[1]-va[1]);
|
||||
float tmax = (neia[k*2+1]-va[1]) / (vb[1]-va[1]);
|
||||
if (tmin > tmax)
|
||||
dtSwap(tmin,tmax);
|
||||
link->bmin = (unsigned char)(dtClamp(tmin, 0.0f, 1.0f)*255.0f);
|
||||
link->bmax = (unsigned char)(dtClamp(tmax, 0.0f, 1.0f)*255.0f);
|
||||
rdSwap(tmin,tmax);
|
||||
link->bmin = (unsigned char)(rdClamp(tmin, 0.0f, 1.0f)*255.0f);
|
||||
link->bmax = (unsigned char)(rdClamp(tmax, 0.0f, 1.0f)*255.0f);
|
||||
}
|
||||
else if (dir == 2 || dir == 6)
|
||||
{
|
||||
float tmin = (neia[k*2+0]-va[0]) / (vb[0]-va[0]);
|
||||
float tmax = (neia[k*2+1]-va[0]) / (vb[0]-va[0]);
|
||||
if (tmin > tmax)
|
||||
dtSwap(tmin,tmax);
|
||||
link->bmin = (unsigned char)(dtClamp(tmin, 0.0f, 1.0f)*255.0f);
|
||||
link->bmax = (unsigned char)(dtClamp(tmax, 0.0f, 1.0f)*255.0f);
|
||||
rdSwap(tmin,tmax);
|
||||
link->bmin = (unsigned char)(rdClamp(tmin, 0.0f, 1.0f)*255.0f);
|
||||
link->bmax = (unsigned char)(rdClamp(tmax, 0.0f, 1.0f)*255.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -505,7 +505,7 @@ void dtNavMesh::connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int
|
||||
|
||||
// Connect off-mesh links.
|
||||
// We are interested on links which land from target tile to this tile.
|
||||
const unsigned char oppositeSide = (side == -1) ? 0xff : (unsigned char)dtOppositeTile(side);
|
||||
const unsigned char oppositeSide = (side == -1) ? 0xff : (unsigned char)rdOppositeTile(side);
|
||||
|
||||
for (int i = 0; i < target->header->offMeshConCount; ++i)
|
||||
{
|
||||
@ -527,11 +527,11 @@ void dtNavMesh::connectExtOffMeshLinks(dtMeshTile* tile, dtMeshTile* target, int
|
||||
if (!ref)
|
||||
continue;
|
||||
// findNearestPoly may return too optimistic results, further check to make sure.
|
||||
if (dtSqr(nearestPt[0]-p[0])+dtSqr(nearestPt[1]-p[1]) > dtSqr(targetCon->rad))
|
||||
if (rdSqr(nearestPt[0]-p[0])+rdSqr(nearestPt[1]-p[1]) > rdSqr(targetCon->rad))
|
||||
continue;
|
||||
// Make sure the location is on current mesh.
|
||||
float* v = &target->verts[targetPoly->verts[1]*3];
|
||||
dtVcopy(v, nearestPt);
|
||||
rdVcopy(v, nearestPt);
|
||||
|
||||
// Link off-mesh connection to target poly.
|
||||
unsigned int idx = allocLink(target);
|
||||
@ -634,11 +634,11 @@ void dtNavMesh::baseOffMeshLinks(dtMeshTile* tile)
|
||||
dtPolyRef ref = findNearestPolyInTile(tile, p, halfExtents, nearestPt);
|
||||
if (!ref) continue;
|
||||
// findNearestPoly may return too optimistic results, further check to make sure.
|
||||
if (dtSqr(nearestPt[0]-p[0])+dtSqr(nearestPt[1]-p[1]) > dtSqr(con->rad))
|
||||
if (rdSqr(nearestPt[0]-p[0])+rdSqr(nearestPt[1]-p[1]) > rdSqr(con->rad))
|
||||
continue;
|
||||
// Make sure the location is on current mesh.
|
||||
float* v = &tile->verts[poly->verts[0]*3];
|
||||
dtVcopy(v, nearestPt);
|
||||
rdVcopy(v, nearestPt);
|
||||
|
||||
// Link off-mesh connection to target poly.
|
||||
unsigned int idx = allocLink(tile);
|
||||
@ -721,7 +721,7 @@ namespace
|
||||
}
|
||||
|
||||
float t;
|
||||
float d = dtDistancePtSegSqr2D(pos, v[j], v[k], t);
|
||||
float d = rdDistancePtSegSqr2D(pos, v[j], v[k], t);
|
||||
if (d < dmin)
|
||||
{
|
||||
dmin = d;
|
||||
@ -732,7 +732,7 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
dtVlerp(closest, pmin, pmax, tmin);
|
||||
rdVlerp(closest, pmin, pmax, tmin);
|
||||
}
|
||||
}
|
||||
|
||||
@ -749,9 +749,9 @@ bool dtNavMesh::getPolyHeight(const dtMeshTile* tile, const dtPoly* poly, const
|
||||
float verts[DT_VERTS_PER_POLYGON*3];
|
||||
const int nv = poly->vertCount;
|
||||
for (int i = 0; i < nv; ++i)
|
||||
dtVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]);
|
||||
rdVcopy(&verts[i*3], &tile->verts[poly->verts[i]*3]);
|
||||
|
||||
if (!dtPointInPolygon(pos, verts, nv))
|
||||
if (!rdPointInPolygon(pos, verts, nv))
|
||||
return false;
|
||||
|
||||
if (!height)
|
||||
@ -770,7 +770,7 @@ bool dtNavMesh::getPolyHeight(const dtMeshTile* tile, const dtPoly* poly, const
|
||||
v[k] = &tile->detailVerts[(pd->vertBase+(t[k]-poly->vertCount))*3];
|
||||
}
|
||||
float h;
|
||||
if (dtClosestHeightPointTriangle(pos, v[0], v[1], v[2], h))
|
||||
if (rdClosestHeightPointTriangle(pos, v[0], v[1], v[2], h))
|
||||
{
|
||||
*height = h;
|
||||
return true;
|
||||
@ -793,7 +793,7 @@ void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* close
|
||||
const dtPoly* poly = 0;
|
||||
getTileAndPolyByRefUnsafe(ref, &tile, &poly);
|
||||
|
||||
dtVcopy(closest, pos);
|
||||
rdVcopy(closest, pos);
|
||||
if (getPolyHeight(tile, poly, pos, &closest[2]))
|
||||
{
|
||||
if (posOverPoly)
|
||||
@ -810,8 +810,8 @@ void dtNavMesh::closestPointOnPoly(dtPolyRef ref, const float* pos, float* close
|
||||
const float* v0 = &tile->verts[poly->verts[0]*3];
|
||||
const float* v1 = &tile->verts[poly->verts[1]*3];
|
||||
float t;
|
||||
dtDistancePtSegSqr2D(pos, v0, v1, t);
|
||||
dtVlerp(closest, v0, v1, t);
|
||||
rdDistancePtSegSqr2D(pos, v0, v1, t);
|
||||
rdVlerp(closest, v0, v1, t);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -824,8 +824,8 @@ dtPolyRef dtNavMesh::findNearestPolyInTile(const dtMeshTile* tile,
|
||||
float* nearestPt) const
|
||||
{
|
||||
float bmin[3], bmax[3];
|
||||
dtVsub(bmin, center, halfExtents);
|
||||
dtVadd(bmax, center, halfExtents);
|
||||
rdVsub(bmin, center, halfExtents);
|
||||
rdVadd(bmax, center, halfExtents);
|
||||
|
||||
// Get nearby polygons from proximity grid.
|
||||
dtPolyRef polys[128];
|
||||
@ -845,20 +845,20 @@ dtPolyRef dtNavMesh::findNearestPolyInTile(const dtMeshTile* tile,
|
||||
|
||||
// If a point is directly over a polygon and closer than
|
||||
// climb height, favor that instead of straight line nearest point.
|
||||
dtVsub(diff, center, closestPtPoly);
|
||||
rdVsub(diff, center, closestPtPoly);
|
||||
if (posOverPoly)
|
||||
{
|
||||
d = dtAbs(diff[1]) - tile->header->walkableClimb;
|
||||
d = rdAbs(diff[1]) - tile->header->walkableClimb;
|
||||
d = d > 0 ? d*d : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d = dtVlenSqr(diff);
|
||||
d = rdVlenSqr(diff);
|
||||
}
|
||||
|
||||
if (d < nearestDistanceSqr)
|
||||
{
|
||||
dtVcopy(nearestPt, closestPtPoly);
|
||||
rdVcopy(nearestPt, closestPtPoly);
|
||||
nearestDistanceSqr = d;
|
||||
nearest = ref;
|
||||
}
|
||||
@ -881,12 +881,12 @@ int dtNavMesh::queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, co
|
||||
// Calculate quantized box
|
||||
unsigned short bmin[3], bmax[3];
|
||||
// dtClamp query box to world box.
|
||||
float minx = dtClamp(qmin[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float miny = dtClamp(qmin[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float minz = dtClamp(qmin[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float maxx = dtClamp(qmax[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float maxy = dtClamp(qmax[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float maxz = dtClamp(qmax[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float minx = rdClamp(qmin[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float miny = rdClamp(qmin[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float minz = rdClamp(qmin[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float maxx = rdClamp(qmax[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float maxy = rdClamp(qmax[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float maxz = rdClamp(qmax[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
// Quantize
|
||||
bmin[0] = (unsigned short)(qfac * minx) & 0xfffe;
|
||||
bmin[1] = (unsigned short)(qfac * miny) & 0xfffe;
|
||||
@ -900,7 +900,7 @@ int dtNavMesh::queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, co
|
||||
int n = 0;
|
||||
while (node < end)
|
||||
{
|
||||
const bool overlap = dtOverlapQuantBounds(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool overlap = rdOverlapQuantBounds(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool isLeafNode = node->i >= 0;
|
||||
|
||||
if (isLeafNode && overlap)
|
||||
@ -933,15 +933,15 @@ int dtNavMesh::queryPolygonsInTile(const dtMeshTile* tile, const float* qmin, co
|
||||
continue;
|
||||
// Calc polygon bounds.
|
||||
const float* v = &tile->verts[p->verts[0]*3];
|
||||
dtVcopy(bmin, v);
|
||||
dtVcopy(bmax, v);
|
||||
rdVcopy(bmin, v);
|
||||
rdVcopy(bmax, v);
|
||||
for (int j = 1; j < p->vertCount; ++j)
|
||||
{
|
||||
v = &tile->verts[p->verts[j]*3];
|
||||
dtVmin(bmin, v);
|
||||
dtVmax(bmax, v);
|
||||
rdVmin(bmin, v);
|
||||
rdVmax(bmax, v);
|
||||
}
|
||||
if (dtOverlapBounds(qmin,qmax, bmin,bmax))
|
||||
if (rdOverlapBounds(qmin,qmax, bmin,bmax))
|
||||
{
|
||||
if (n < maxPolys)
|
||||
polys[n++] = base | (dtPolyRef)i;
|
||||
@ -980,7 +980,7 @@ dtStatus dtNavMesh::addTile(unsigned char* data, int dataSize, int flags,
|
||||
#ifndef DT_POLYREF64
|
||||
// Do not allow adding more polygons than specified in the NavMesh's maxPolys constraint.
|
||||
// Otherwise, the poly ID cannot be represented with the given number of bits.
|
||||
if (m_polyBits < dtIlog2(dtNextPow2((unsigned int)header->polyCount)))
|
||||
if (m_polyBits < rdIlog2(rdNextPow2((unsigned int)header->polyCount)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
#endif
|
||||
|
||||
@ -1037,25 +1037,25 @@ dtStatus dtNavMesh::addTile(unsigned char* data, int dataSize, int flags,
|
||||
m_posLookup[h] = tile;
|
||||
|
||||
// Patch header pointers.
|
||||
const int headerSize = dtAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = dtAlign4(sizeof(float)*3*header->vertCount);
|
||||
const int polysSize = dtAlign4(sizeof(dtPoly)*header->polyCount);
|
||||
const int linksSize = dtAlign4(sizeof(dtLink)*(header->maxLinkCount));
|
||||
const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*header->detailMeshCount);
|
||||
const int detailVertsSize = dtAlign4(sizeof(float)*3*header->detailVertCount);
|
||||
const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*header->detailTriCount);
|
||||
const int bvtreeSize = dtAlign4(sizeof(dtBVNode)*header->bvNodeCount);
|
||||
const int offMeshLinksSize = dtAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount);
|
||||
const int headerSize = rdAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = rdAlign4(sizeof(float)*3*header->vertCount);
|
||||
const int polysSize = rdAlign4(sizeof(dtPoly)*header->polyCount);
|
||||
const int linksSize = rdAlign4(sizeof(dtLink)*(header->maxLinkCount));
|
||||
const int detailMeshesSize = rdAlign4(sizeof(dtPolyDetail)*header->detailMeshCount);
|
||||
const int detailVertsSize = rdAlign4(sizeof(float)*3*header->detailVertCount);
|
||||
const int detailTrisSize = rdAlign4(sizeof(unsigned char)*4*header->detailTriCount);
|
||||
const int bvtreeSize = rdAlign4(sizeof(dtBVNode)*header->bvNodeCount);
|
||||
const int offMeshLinksSize = rdAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount);
|
||||
|
||||
unsigned char* d = data + headerSize;
|
||||
tile->verts = dtGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
tile->polys = dtGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
tile->links = dtGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
tile->detailMeshes = dtGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
tile->detailVerts = dtGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
tile->detailTris = dtGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
tile->bvTree = dtGetThenAdvanceBufferPointer<dtBVNode>(d, bvtreeSize);
|
||||
tile->offMeshCons = dtGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshLinksSize);
|
||||
tile->verts = rdGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
tile->polys = rdGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
tile->links = rdGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
tile->detailMeshes = rdGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
tile->detailVerts = rdGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
tile->detailTris = rdGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
tile->bvTree = rdGetThenAdvanceBufferPointer<dtBVNode>(d, bvtreeSize);
|
||||
tile->offMeshCons = rdGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshLinksSize);
|
||||
|
||||
// If there are no items in the bvtree, reset the tree pointer.
|
||||
if (!bvtreeSize)
|
||||
@ -1107,9 +1107,9 @@ dtStatus dtNavMesh::addTile(unsigned char* data, int dataSize, int flags,
|
||||
for (int j = 0; j < nneis; ++j)
|
||||
{
|
||||
connectExtLinks(tile, neis[j], i);
|
||||
connectExtLinks(neis[j], tile, dtOppositeTile(i));
|
||||
connectExtLinks(neis[j], tile, rdOppositeTile(i));
|
||||
connectExtOffMeshLinks(tile, neis[j], i);
|
||||
connectExtOffMeshLinks(neis[j], tile, dtOppositeTile(i));
|
||||
connectExtOffMeshLinks(neis[j], tile, rdOppositeTile(i));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1323,7 +1323,7 @@ bool dtNavMesh::isGoalPolyReachable(const dtPolyRef fromRef, const dtPolyRef goa
|
||||
|
||||
// Check if the bit corresponding to our goal poly is set, if it isn't then
|
||||
// there are no available traversal links from the current poly to the goal.
|
||||
return fromPolyBitCell & dtBitCellBit(goalPolyGroupId);
|
||||
return fromPolyBitCell & rdBitCellBit(goalPolyGroupId);
|
||||
}
|
||||
|
||||
bool dtNavMesh::isValidPolyRef(dtPolyRef ref) const
|
||||
@ -1483,8 +1483,8 @@ struct dtPolyState
|
||||
int dtNavMesh::getTileStateSize(const dtMeshTile* tile) const
|
||||
{
|
||||
if (!tile) return 0;
|
||||
const int headerSize = dtAlign4(sizeof(dtTileState));
|
||||
const int polyStateSize = dtAlign4(sizeof(dtPolyState) * tile->header->polyCount);
|
||||
const int headerSize = rdAlign4(sizeof(dtTileState));
|
||||
const int polyStateSize = rdAlign4(sizeof(dtPolyState) * tile->header->polyCount);
|
||||
return headerSize + polyStateSize;
|
||||
}
|
||||
|
||||
@ -1500,8 +1500,8 @@ dtStatus dtNavMesh::storeTileState(const dtMeshTile* tile, unsigned char* data,
|
||||
if (maxDataSize < sizeReq)
|
||||
return DT_FAILURE | DT_BUFFER_TOO_SMALL;
|
||||
|
||||
dtTileState* tileState = dtGetThenAdvanceBufferPointer<dtTileState>(data, dtAlign4(sizeof(dtTileState)));
|
||||
dtPolyState* polyStates = dtGetThenAdvanceBufferPointer<dtPolyState>(data, dtAlign4(sizeof(dtPolyState) * tile->header->polyCount));
|
||||
dtTileState* tileState = rdGetThenAdvanceBufferPointer<dtTileState>(data, rdAlign4(sizeof(dtTileState)));
|
||||
dtPolyState* polyStates = rdGetThenAdvanceBufferPointer<dtPolyState>(data, rdAlign4(sizeof(dtPolyState) * tile->header->polyCount));
|
||||
|
||||
// Store tile state.
|
||||
tileState->magic = DT_NAVMESH_STATE_MAGIC;
|
||||
@ -1532,8 +1532,8 @@ dtStatus dtNavMesh::restoreTileState(dtMeshTile* tile, const unsigned char* data
|
||||
if (maxDataSize < sizeReq)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
const dtTileState* tileState = dtGetThenAdvanceBufferPointer<const dtTileState>(data, dtAlign4(sizeof(dtTileState)));
|
||||
const dtPolyState* polyStates = dtGetThenAdvanceBufferPointer<const dtPolyState>(data, dtAlign4(sizeof(dtPolyState) * tile->header->polyCount));
|
||||
const dtTileState* tileState = rdGetThenAdvanceBufferPointer<const dtTileState>(data, rdAlign4(sizeof(dtTileState)));
|
||||
const dtPolyState* polyStates = rdGetThenAdvanceBufferPointer<const dtPolyState>(data, rdAlign4(sizeof(dtPolyState) * tile->header->polyCount));
|
||||
|
||||
// Check that the restore is possible.
|
||||
if (tileState->magic != DT_NAVMESH_STATE_MAGIC)
|
||||
@ -1598,8 +1598,8 @@ dtStatus dtNavMesh::getOffMeshConnectionPolyEndPoints(dtPolyRef prevRef, dtPolyR
|
||||
}
|
||||
}
|
||||
|
||||
dtVcopy(startPos, &tile->verts[poly->verts[idx0]*3]);
|
||||
dtVcopy(endPos, &tile->verts[poly->verts[idx1]*3]);
|
||||
rdVcopy(startPos, &tile->verts[poly->verts[idx0]*3]);
|
||||
rdVcopy(endPos, &tile->verts[poly->verts[idx1]*3]);
|
||||
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
@ -1706,7 +1706,7 @@ float dtCalcPolySurfaceArea(const dtPoly* poly, const float* verts)
|
||||
const float* va = &verts[poly->verts[0]*3];
|
||||
const float* vb = &verts[poly->verts[i]*3];
|
||||
const float* vc = &verts[poly->verts[i-1]*3];
|
||||
polyArea += dtTriArea2D(va,vb,vc);
|
||||
polyArea += rdTriArea2D(va,vb,vc);
|
||||
}
|
||||
|
||||
return polyArea;
|
||||
@ -1717,15 +1717,15 @@ float dtCalcOffMeshRefYaw(const float* spos, const float* epos)
|
||||
float dx = epos[0]-spos[0];
|
||||
float dy = epos[1]-spos[1];
|
||||
|
||||
// Amos: yaw on original r2 sp navs' seem to be of range [180, -180], might need to multiply this with (180.0f/DT_PI).
|
||||
float yaw = dtMathAtan2f(dy, dx);
|
||||
// Amos: yaw on original r2 sp navs' seem to be of range [180, -180], might need to multiply this with (180.0f/RD_PI).
|
||||
float yaw = rdMathAtan2f(dy, dx);
|
||||
return yaw;
|
||||
}
|
||||
|
||||
void dtCalcOffMeshRefPos(const float* spos, float yaw, float offset, float* res)
|
||||
{
|
||||
float dx = offset*dtMathCosf(yaw);
|
||||
float dy = offset*dtMathSinf(yaw);
|
||||
float dx = offset*rdMathCosf(yaw);
|
||||
float dy = offset*rdMathSinf(yaw);
|
||||
|
||||
res[0] = spos[0]+dx;
|
||||
res[1] = spos[1]+dy;
|
||||
|
@ -21,12 +21,12 @@
|
||||
#include <string.h>
|
||||
#include <float.h>
|
||||
#include <map>
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Shared/Include/SharedAlloc.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
|
||||
static unsigned short MESH_NULL_IDX = 0xffff;
|
||||
|
||||
@ -187,23 +187,23 @@ static int createBVTree(dtNavMeshCreateParams* params, dtBVNode* nodes, int /*nn
|
||||
float bmax[3];
|
||||
|
||||
const float* dv = ¶ms->detailVerts[vb*3];
|
||||
dtVcopy(bmin, dv);
|
||||
dtVcopy(bmax, dv);
|
||||
rdVcopy(bmin, dv);
|
||||
rdVcopy(bmax, dv);
|
||||
|
||||
for (int j = 1; j < ndv; j++)
|
||||
{
|
||||
dtVmin(bmin, &dv[j * 3]);
|
||||
dtVmax(bmax, &dv[j * 3]);
|
||||
rdVmin(bmin, &dv[j * 3]);
|
||||
rdVmax(bmax, &dv[j * 3]);
|
||||
}
|
||||
|
||||
// BV-tree uses cs for all dimensions
|
||||
it.bmin[0] = (unsigned short)dtClamp((int)((bmin[0] - params->bmin[0])*quantFactor), 0, 0xffff);
|
||||
it.bmin[1] = (unsigned short)dtClamp((int)((bmin[1] - params->bmin[1])*quantFactor), 0, 0xffff);
|
||||
it.bmin[2] = (unsigned short)dtClamp((int)((bmin[2] - params->bmin[2])*quantFactor), 0, 0xffff);
|
||||
it.bmin[0] = (unsigned short)rdClamp((int)((bmin[0] - params->bmin[0])*quantFactor), 0, 0xffff);
|
||||
it.bmin[1] = (unsigned short)rdClamp((int)((bmin[1] - params->bmin[1])*quantFactor), 0, 0xffff);
|
||||
it.bmin[2] = (unsigned short)rdClamp((int)((bmin[2] - params->bmin[2])*quantFactor), 0, 0xffff);
|
||||
|
||||
it.bmax[0] = (unsigned short)dtClamp((int)((bmax[0] - params->bmin[0])*quantFactor), 0, 0xffff);
|
||||
it.bmax[1] = (unsigned short)dtClamp((int)((bmax[1] - params->bmin[1])*quantFactor), 0, 0xffff);
|
||||
it.bmax[2] = (unsigned short)dtClamp((int)((bmax[2] - params->bmin[2])*quantFactor), 0, 0xffff);
|
||||
it.bmax[0] = (unsigned short)rdClamp((int)((bmax[0] - params->bmin[0])*quantFactor), 0, 0xffff);
|
||||
it.bmax[1] = (unsigned short)rdClamp((int)((bmax[1] - params->bmin[1])*quantFactor), 0, 0xffff);
|
||||
it.bmax[2] = (unsigned short)rdClamp((int)((bmax[2] - params->bmin[2])*quantFactor), 0, 0xffff);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -228,8 +228,8 @@ static int createBVTree(dtNavMeshCreateParams* params, dtBVNode* nodes, int /*nn
|
||||
if (z > it.bmax[2]) it.bmax[2] = z;
|
||||
}
|
||||
// Remap z
|
||||
it.bmin[2] = (unsigned short)dtMathFloorf((float)it.bmin[2] * params->ch / params->cs);
|
||||
it.bmax[2] = (unsigned short)dtMathCeilf((float)it.bmax[2] * params->ch / params->cs);
|
||||
it.bmin[2] = (unsigned short)rdMathFloorf((float)it.bmin[2] * params->ch / params->cs);
|
||||
it.bmax[2] = (unsigned short)rdMathCeilf((float)it.bmax[2] * params->ch / params->cs);
|
||||
}
|
||||
}
|
||||
|
||||
@ -559,8 +559,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
for (int i = 0; i < params->detailVertsCount; ++i)
|
||||
{
|
||||
const float h = params->detailVerts[i*3+2];
|
||||
hmin = dtMin(hmin,h);
|
||||
hmax = dtMax(hmax,h);
|
||||
hmin = rdMin(hmin,h);
|
||||
hmax = rdMax(hmax,h);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -569,15 +569,15 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
{
|
||||
const unsigned short* iv = ¶ms->verts[i*3];
|
||||
const float h = params->bmin[2] + iv[2] * params->ch;
|
||||
hmin = dtMin(hmin,h);
|
||||
hmax = dtMax(hmax,h);
|
||||
hmin = rdMin(hmin,h);
|
||||
hmax = rdMax(hmax,h);
|
||||
}
|
||||
}
|
||||
hmin -= params->walkableClimb;
|
||||
hmax += params->walkableClimb;
|
||||
float bmin[3], bmax[3];
|
||||
dtVcopy(bmin, params->bmin);
|
||||
dtVcopy(bmax, params->bmax);
|
||||
rdVcopy(bmin, params->bmin);
|
||||
rdVcopy(bmax, params->bmax);
|
||||
bmin[2] = hmin;
|
||||
bmax[2] = hmax;
|
||||
|
||||
@ -672,15 +672,15 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
}
|
||||
int sth_per_poly_thingy = 0;
|
||||
// Calculate data size
|
||||
const int headerSize = dtAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = dtAlign4(sizeof(float)*3*totVertCount);
|
||||
const int polysSize = dtAlign4(sizeof(dtPoly)*totPolyCount);
|
||||
const int linksSize = dtAlign4(sizeof(dtLink)*maxLinkCount);
|
||||
const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*params->polyCount);
|
||||
const int detailVertsSize = dtAlign4(sizeof(float)*3*uniqueDetailVertCount);
|
||||
const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*detailTriCount);
|
||||
const int bvTreeSize = params->buildBvTree ? dtAlign4(sizeof(dtBVNode)*params->polyCount*2) : 0;
|
||||
const int offMeshConsSize = dtAlign4(sizeof(dtOffMeshConnection)*storedOffMeshConCount);
|
||||
const int headerSize = rdAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = rdAlign4(sizeof(float)*3*totVertCount);
|
||||
const int polysSize = rdAlign4(sizeof(dtPoly)*totPolyCount);
|
||||
const int linksSize = rdAlign4(sizeof(dtLink)*maxLinkCount);
|
||||
const int detailMeshesSize = rdAlign4(sizeof(dtPolyDetail)*params->polyCount);
|
||||
const int detailVertsSize = rdAlign4(sizeof(float)*3*uniqueDetailVertCount);
|
||||
const int detailTrisSize = rdAlign4(sizeof(unsigned char)*4*detailTriCount);
|
||||
const int bvTreeSize = params->buildBvTree ? rdAlign4(sizeof(dtBVNode)*params->polyCount*2) : 0;
|
||||
const int offMeshConsSize = rdAlign4(sizeof(dtOffMeshConnection)*storedOffMeshConCount);
|
||||
|
||||
const int sthSize = sth_per_poly_thingy * totPolyCount * 4;
|
||||
|
||||
@ -706,18 +706,18 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
// linksSize == sizeof(dtLink) * maxLinkCount
|
||||
// detailMeshesSize = sizeof(dtPolyDetail)*params->polyCount
|
||||
|
||||
dtMeshHeader* header = dtGetThenAdvanceBufferPointer<dtMeshHeader>(d, headerSize);
|
||||
float* navVerts = dtGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
dtPoly* navPolys = dtGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
dtMeshHeader* header = rdGetThenAdvanceBufferPointer<dtMeshHeader>(d, headerSize);
|
||||
float* navVerts = rdGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
dtPoly* navPolys = rdGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
//d += sthSize; //dunno hope it crashes
|
||||
unsigned int* some_arr = dtGetThenAdvanceBufferPointer<unsigned int>(d, sthSize);
|
||||
unsigned int* some_arr = rdGetThenAdvanceBufferPointer<unsigned int>(d, sthSize);
|
||||
d += linksSize; // Ignore links; just leave enough space for them. They'll be created on load.
|
||||
//dtLink* links = dtGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
dtPolyDetail* navDMeshes = dtGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
float* navDVerts = dtGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
unsigned char* navDTris = dtGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
dtBVNode* navBvtree = dtGetThenAdvanceBufferPointer<dtBVNode>(d, bvTreeSize);
|
||||
dtOffMeshConnection* offMeshCons = dtGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshConsSize);
|
||||
//dtLink* links = rdGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
dtPolyDetail* navDMeshes = rdGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
float* navDVerts = rdGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
unsigned char* navDTris = rdGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
dtBVNode* navBvtree = rdGetThenAdvanceBufferPointer<dtBVNode>(d, bvTreeSize);
|
||||
dtOffMeshConnection* offMeshCons = rdGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshConsSize);
|
||||
|
||||
for(int i=0;i<sth_per_poly_thingy*totPolyCount;i++)
|
||||
some_arr[i] = rand();
|
||||
@ -732,8 +732,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
header->polyCount = totPolyCount;
|
||||
header->vertCount = totVertCount;
|
||||
header->maxLinkCount = maxLinkCount;
|
||||
dtVcopy(header->bmin, params->bmin);
|
||||
dtVcopy(header->bmax, params->bmax);
|
||||
rdVcopy(header->bmin, params->bmin);
|
||||
rdVcopy(header->bmax, params->bmax);
|
||||
header->detailMeshCount = params->polyCount;
|
||||
header->detailVertCount = uniqueDetailVertCount;
|
||||
header->detailTriCount = detailTriCount;
|
||||
@ -769,8 +769,8 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
{
|
||||
const float* linkv = ¶ms->offMeshConVerts[i*2*3];
|
||||
float* v = &navVerts[(offMeshVertsBase + n*2)*3];
|
||||
dtVcopy(&v[0], &linkv[0]);
|
||||
dtVcopy(&v[3], &linkv[3]);
|
||||
rdVcopy(&v[0], &linkv[0]);
|
||||
rdVcopy(&v[3], &linkv[3]);
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@ -810,11 +810,11 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
// Normal connection
|
||||
p->neis[j] = src[nvp+j]+1;
|
||||
}
|
||||
dtVadd(p->center, p->center, &navVerts[p->verts[j] * 3]);
|
||||
rdVadd(p->center, p->center, &navVerts[p->verts[j] * 3]);
|
||||
p->vertCount++;
|
||||
}
|
||||
dtVscale(p->center, p->center, 1 / (float)(p->vertCount));
|
||||
p->surfaceArea = (unsigned short)dtMathFloorf(dtCalcPolySurfaceArea(p,navVerts) / DT_POLY_AREA_QUANT_FACTOR);
|
||||
rdVscale(p->center, p->center, 1 / (float)(p->vertCount));
|
||||
p->surfaceArea = (unsigned short)rdMathFloorf(dtCalcPolySurfaceArea(p,navVerts) / DT_POLY_AREA_QUANT_FACTOR);
|
||||
|
||||
src += nvp*2;
|
||||
}
|
||||
@ -908,9 +908,9 @@ bool dtCreateNavMeshData(dtNavMeshCreateParams* params, unsigned char** outData,
|
||||
// Copy connection end-points.
|
||||
const float* endPts = ¶ms->offMeshConVerts[i*2*3];
|
||||
const float* refPos = ¶ms->offMeshConRefPos[i*3];
|
||||
dtVcopy(&con->pos[0], &endPts[0]);
|
||||
dtVcopy(&con->pos[3], &endPts[3]);
|
||||
dtVcopy(&con->refPos[0], &refPos[0]);
|
||||
rdVcopy(&con->pos[0], &endPts[0]);
|
||||
rdVcopy(&con->pos[3], &endPts[3]);
|
||||
rdVcopy(&con->refPos[0], &refPos[0]);
|
||||
con->rad = params->offMeshConRad[i];
|
||||
con->refYaw = params->offMeshConRefYaw[i];
|
||||
con->flags = params->offMeshConDir[i] ? DT_OFFMESH_CON_BIDIR : 0;
|
||||
@ -935,8 +935,8 @@ bool dtNavMeshHeaderSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
|
||||
int swappedMagic = DT_NAVMESH_MAGIC;
|
||||
int swappedVersion = DT_NAVMESH_VERSION;
|
||||
dtSwapEndian(&swappedMagic);
|
||||
dtSwapEndian(&swappedVersion);
|
||||
rdSwapEndian(&swappedMagic);
|
||||
rdSwapEndian(&swappedVersion);
|
||||
|
||||
if ((header->magic != DT_NAVMESH_MAGIC || header->version != DT_NAVMESH_VERSION) &&
|
||||
(header->magic != swappedMagic || header->version != swappedVersion))
|
||||
@ -944,31 +944,31 @@ bool dtNavMeshHeaderSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
return false;
|
||||
}
|
||||
|
||||
dtSwapEndian(&header->magic);
|
||||
dtSwapEndian(&header->version);
|
||||
dtSwapEndian(&header->x);
|
||||
dtSwapEndian(&header->y);
|
||||
dtSwapEndian(&header->layer);
|
||||
dtSwapEndian(&header->userId);
|
||||
dtSwapEndian(&header->polyCount);
|
||||
dtSwapEndian(&header->vertCount);
|
||||
dtSwapEndian(&header->maxLinkCount);
|
||||
dtSwapEndian(&header->detailMeshCount);
|
||||
dtSwapEndian(&header->detailVertCount);
|
||||
dtSwapEndian(&header->detailTriCount);
|
||||
dtSwapEndian(&header->bvNodeCount);
|
||||
dtSwapEndian(&header->offMeshConCount);
|
||||
dtSwapEndian(&header->offMeshBase);
|
||||
dtSwapEndian(&header->walkableHeight);
|
||||
dtSwapEndian(&header->walkableRadius);
|
||||
dtSwapEndian(&header->walkableClimb);
|
||||
dtSwapEndian(&header->bmin[0]);
|
||||
dtSwapEndian(&header->bmin[1]);
|
||||
dtSwapEndian(&header->bmin[2]);
|
||||
dtSwapEndian(&header->bmax[0]);
|
||||
dtSwapEndian(&header->bmax[1]);
|
||||
dtSwapEndian(&header->bmax[2]);
|
||||
dtSwapEndian(&header->bvQuantFactor);
|
||||
rdSwapEndian(&header->magic);
|
||||
rdSwapEndian(&header->version);
|
||||
rdSwapEndian(&header->x);
|
||||
rdSwapEndian(&header->y);
|
||||
rdSwapEndian(&header->layer);
|
||||
rdSwapEndian(&header->userId);
|
||||
rdSwapEndian(&header->polyCount);
|
||||
rdSwapEndian(&header->vertCount);
|
||||
rdSwapEndian(&header->maxLinkCount);
|
||||
rdSwapEndian(&header->detailMeshCount);
|
||||
rdSwapEndian(&header->detailVertCount);
|
||||
rdSwapEndian(&header->detailTriCount);
|
||||
rdSwapEndian(&header->bvNodeCount);
|
||||
rdSwapEndian(&header->offMeshConCount);
|
||||
rdSwapEndian(&header->offMeshBase);
|
||||
rdSwapEndian(&header->walkableHeight);
|
||||
rdSwapEndian(&header->walkableRadius);
|
||||
rdSwapEndian(&header->walkableClimb);
|
||||
rdSwapEndian(&header->bmin[0]);
|
||||
rdSwapEndian(&header->bmin[1]);
|
||||
rdSwapEndian(&header->bmin[2]);
|
||||
rdSwapEndian(&header->bmax[0]);
|
||||
rdSwapEndian(&header->bmax[1]);
|
||||
rdSwapEndian(&header->bmax[2]);
|
||||
rdSwapEndian(&header->bvQuantFactor);
|
||||
|
||||
// Freelist index and pointers are updated when tile is added, no need to swap.
|
||||
|
||||
@ -991,32 +991,32 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
return false;
|
||||
|
||||
// Patch header pointers.
|
||||
const int headerSize = dtAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = dtAlign4(sizeof(float)*3*header->vertCount);
|
||||
const int polysSize = dtAlign4(sizeof(dtPoly)*header->polyCount);
|
||||
const int linksSize = dtAlign4(sizeof(dtLink)*(header->maxLinkCount));
|
||||
const int detailMeshesSize = dtAlign4(sizeof(dtPolyDetail)*header->detailMeshCount);
|
||||
const int detailVertsSize = dtAlign4(sizeof(float)*3*header->detailVertCount);
|
||||
const int detailTrisSize = dtAlign4(sizeof(unsigned char)*4*header->detailTriCount);
|
||||
const int bvtreeSize = dtAlign4(sizeof(dtBVNode)*header->bvNodeCount);
|
||||
const int offMeshLinksSize = dtAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount);
|
||||
const int headerSize = rdAlign4(sizeof(dtMeshHeader));
|
||||
const int vertsSize = rdAlign4(sizeof(float)*3*header->vertCount);
|
||||
const int polysSize = rdAlign4(sizeof(dtPoly)*header->polyCount);
|
||||
const int linksSize = rdAlign4(sizeof(dtLink)*(header->maxLinkCount));
|
||||
const int detailMeshesSize = rdAlign4(sizeof(dtPolyDetail)*header->detailMeshCount);
|
||||
const int detailVertsSize = rdAlign4(sizeof(float)*3*header->detailVertCount);
|
||||
const int detailTrisSize = rdAlign4(sizeof(unsigned char)*4*header->detailTriCount);
|
||||
const int bvtreeSize = rdAlign4(sizeof(dtBVNode)*header->bvNodeCount);
|
||||
const int offMeshLinksSize = rdAlign4(sizeof(dtOffMeshConnection)*header->offMeshConCount);
|
||||
|
||||
unsigned char* d = data + headerSize;
|
||||
float* verts = dtGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
dtPoly* polys = dtGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
float* verts = rdGetThenAdvanceBufferPointer<float>(d, vertsSize);
|
||||
dtPoly* polys = rdGetThenAdvanceBufferPointer<dtPoly>(d, polysSize);
|
||||
d += linksSize; // Ignore links; they technically should be endian-swapped but all their data is overwritten on load anyway.
|
||||
//dtLink* links = dtGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
dtPolyDetail* detailMeshes = dtGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
float* detailVerts = dtGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
//dtLink* links = rdGetThenAdvanceBufferPointer<dtLink>(d, linksSize);
|
||||
dtPolyDetail* detailMeshes = rdGetThenAdvanceBufferPointer<dtPolyDetail>(d, detailMeshesSize);
|
||||
float* detailVerts = rdGetThenAdvanceBufferPointer<float>(d, detailVertsSize);
|
||||
d += detailTrisSize; // Ignore detail tris; single bytes can't be endian-swapped.
|
||||
//unsigned char* detailTris = dtGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
dtBVNode* bvTree = dtGetThenAdvanceBufferPointer<dtBVNode>(d, bvtreeSize);
|
||||
dtOffMeshConnection* offMeshCons = dtGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshLinksSize);
|
||||
//unsigned char* detailTris = rdGetThenAdvanceBufferPointer<unsigned char>(d, detailTrisSize);
|
||||
dtBVNode* bvTree = rdGetThenAdvanceBufferPointer<dtBVNode>(d, bvtreeSize);
|
||||
dtOffMeshConnection* offMeshCons = rdGetThenAdvanceBufferPointer<dtOffMeshConnection>(d, offMeshLinksSize);
|
||||
|
||||
// Vertices
|
||||
for (int i = 0; i < header->vertCount*3; ++i)
|
||||
{
|
||||
dtSwapEndian(&verts[i]);
|
||||
rdSwapEndian(&verts[i]);
|
||||
}
|
||||
|
||||
// Polys
|
||||
@ -1026,10 +1026,10 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
// poly->firstLink is update when tile is added, no need to swap.
|
||||
for (int j = 0; j < DT_VERTS_PER_POLYGON; ++j)
|
||||
{
|
||||
dtSwapEndian(&p->verts[j]);
|
||||
dtSwapEndian(&p->neis[j]);
|
||||
rdSwapEndian(&p->verts[j]);
|
||||
rdSwapEndian(&p->neis[j]);
|
||||
}
|
||||
dtSwapEndian(&p->flags);
|
||||
rdSwapEndian(&p->flags);
|
||||
}
|
||||
|
||||
// Links are rebuild when tile is added, no need to swap.
|
||||
@ -1038,14 +1038,14 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
for (int i = 0; i < header->detailMeshCount; ++i)
|
||||
{
|
||||
dtPolyDetail* pd = &detailMeshes[i];
|
||||
dtSwapEndian(&pd->vertBase);
|
||||
dtSwapEndian(&pd->triBase);
|
||||
rdSwapEndian(&pd->vertBase);
|
||||
rdSwapEndian(&pd->triBase);
|
||||
}
|
||||
|
||||
// Detail verts
|
||||
for (int i = 0; i < header->detailVertCount*3; ++i)
|
||||
{
|
||||
dtSwapEndian(&detailVerts[i]);
|
||||
rdSwapEndian(&detailVerts[i]);
|
||||
}
|
||||
|
||||
// BV-tree
|
||||
@ -1054,10 +1054,10 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
dtBVNode* node = &bvTree[i];
|
||||
for (int j = 0; j < 3; ++j)
|
||||
{
|
||||
dtSwapEndian(&node->bmin[j]);
|
||||
dtSwapEndian(&node->bmax[j]);
|
||||
rdSwapEndian(&node->bmin[j]);
|
||||
rdSwapEndian(&node->bmax[j]);
|
||||
}
|
||||
dtSwapEndian(&node->i);
|
||||
rdSwapEndian(&node->i);
|
||||
}
|
||||
|
||||
// Off-mesh Connections.
|
||||
@ -1065,9 +1065,9 @@ bool dtNavMeshDataSwapEndian(unsigned char* data, const int /*dataSize*/)
|
||||
{
|
||||
dtOffMeshConnection* con = &offMeshCons[i];
|
||||
for (int j = 0; j < 6; ++j)
|
||||
dtSwapEndian(&con->pos[j]);
|
||||
dtSwapEndian(&con->rad);
|
||||
dtSwapEndian(&con->poly);
|
||||
rdSwapEndian(&con->pos[j]);
|
||||
rdSwapEndian(&con->rad);
|
||||
rdSwapEndian(&con->poly);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -18,11 +18,11 @@
|
||||
|
||||
#include <float.h>
|
||||
#include <string.h>
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Detour/Include/DetourNavMeshQuery.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Shared/Include/SharedAlloc.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include <new>
|
||||
@ -81,7 +81,7 @@ float dtQueryFilter::getCost(const float* pa, const float* pb,
|
||||
const dtPolyRef /*curRef*/, const dtMeshTile* /*curTile*/, const dtPoly* curPoly,
|
||||
const dtPolyRef /*nextRef*/, const dtMeshTile* /*nextTile*/, const dtPoly* /*nextPoly*/) const
|
||||
{
|
||||
return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()];
|
||||
return rdVdist(pa, pb) * m_areaCost[curPoly->getArea()];
|
||||
}
|
||||
#else
|
||||
inline bool dtQueryFilter::passFilter(const dtPolyRef /*ref*/,
|
||||
@ -96,7 +96,7 @@ inline float dtQueryFilter::getCost(const float* pa, const float* pb,
|
||||
const dtPolyRef /*curRef*/, const dtMeshTile* /*curTile*/, const dtPoly* curPoly,
|
||||
const dtPolyRef /*nextRef*/, const dtMeshTile* /*nextTile*/, const dtPoly* /*nextPoly*/) const
|
||||
{
|
||||
return dtVdist(pa, pb) * m_areaCost[curPoly->getArea()];
|
||||
return rdVdist(pa, pb) * m_areaCost[curPoly->getArea()];
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -179,7 +179,7 @@ dtStatus dtNavMeshQuery::init(const dtNavMesh* nav, const int maxNodes)
|
||||
rdFree(m_nodePool);
|
||||
m_nodePool = 0;
|
||||
}
|
||||
m_nodePool = new (rdAlloc(sizeof(dtNodePool), RD_ALLOC_PERM)) dtNodePool(maxNodes, dtNextPow2(maxNodes/4));
|
||||
m_nodePool = new (rdAlloc(sizeof(dtNodePool), RD_ALLOC_PERM)) dtNodePool(maxNodes, rdNextPow2(maxNodes/4));
|
||||
if (!m_nodePool)
|
||||
return DT_FAILURE | DT_OUT_OF_MEMORY;
|
||||
}
|
||||
@ -282,22 +282,22 @@ dtStatus dtNavMeshQuery::findRandomPoint(const dtQueryFilter* filter, float (*fr
|
||||
const float* v = &tile->verts[poly->verts[0]*3];
|
||||
float verts[3*DT_VERTS_PER_POLYGON];
|
||||
float areas[DT_VERTS_PER_POLYGON];
|
||||
dtVcopy(&verts[0*3],v);
|
||||
rdVcopy(&verts[0*3],v);
|
||||
for (int j = 1; j < poly->vertCount; ++j)
|
||||
{
|
||||
v = &tile->verts[poly->verts[j]*3];
|
||||
dtVcopy(&verts[j*3],v);
|
||||
rdVcopy(&verts[j*3],v);
|
||||
}
|
||||
|
||||
const float s = frand();
|
||||
const float t = frand();
|
||||
|
||||
float pt[3];
|
||||
dtRandomPointInConvexPoly(verts, poly->vertCount, areas, s, t, pt);
|
||||
rdRandomPointInConvexPoly(verts, poly->vertCount, areas, s, t, pt);
|
||||
|
||||
closestPointOnPoly(polyRef, pt, pt, NULL);
|
||||
|
||||
dtVcopy(randomPt, pt);
|
||||
rdVcopy(randomPt, pt);
|
||||
*randomRef = polyRef;
|
||||
|
||||
return DT_SUCCESS;
|
||||
@ -313,8 +313,8 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
|
||||
!centerPos || !rdVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !rdMathIsfinite(maxRadius) ||
|
||||
!filter || !frand || !randomRef || !randomPt)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -330,7 +330,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
m_openList->clear();
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, centerPos);
|
||||
rdVcopy(startNode->pos, centerPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = 0;
|
||||
@ -340,7 +340,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
|
||||
dtStatus status = DT_SUCCESS;
|
||||
|
||||
const float radiusSqr = dtSqr(maxRadius);
|
||||
const float radiusSqr = rdSqr(maxRadius);
|
||||
float areaSum = 0.0f;
|
||||
|
||||
const dtMeshTile* randomTile = 0;
|
||||
@ -411,7 +411,7 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
|
||||
// If the circle is not touching the next polygon, skip it.
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
if (distSqr > radiusSqr)
|
||||
continue;
|
||||
|
||||
@ -427,9 +427,9 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
|
||||
// Cost
|
||||
if (neighbourNode->flags == 0)
|
||||
dtVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
rdVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
|
||||
const float total = bestNode->total + dtVdist(bestNode->pos, neighbourNode->pos);
|
||||
const float total = bestNode->total + rdVdist(bestNode->pos, neighbourNode->pos);
|
||||
|
||||
// The node is already in open list and the new result is worse, skip.
|
||||
if ((neighbourNode->flags & DT_NODE_OPEN) && total >= neighbourNode->total)
|
||||
@ -459,22 +459,22 @@ dtStatus dtNavMeshQuery::findRandomPointAroundCircle(dtPolyRef startRef, const f
|
||||
const float* v = &randomTile->verts[randomPoly->verts[0]*3];
|
||||
float verts[3*DT_VERTS_PER_POLYGON];
|
||||
float areas[DT_VERTS_PER_POLYGON];
|
||||
dtVcopy(&verts[0*3],v);
|
||||
rdVcopy(&verts[0*3],v);
|
||||
for (int j = 1; j < randomPoly->vertCount; ++j)
|
||||
{
|
||||
v = &randomTile->verts[randomPoly->verts[j]*3];
|
||||
dtVcopy(&verts[j*3],v);
|
||||
rdVcopy(&verts[j*3],v);
|
||||
}
|
||||
|
||||
const float s = frand();
|
||||
const float t = frand();
|
||||
|
||||
float pt[3];
|
||||
dtRandomPointInConvexPoly(verts, randomPoly->vertCount, areas, s, t, pt);
|
||||
rdRandomPointInConvexPoly(verts, randomPoly->vertCount, areas, s, t, pt);
|
||||
|
||||
closestPointOnPoly(randomPolyRef, pt, pt, NULL);
|
||||
|
||||
dtVcopy(randomPt, pt);
|
||||
rdVcopy(randomPt, pt);
|
||||
*randomRef = randomPolyRef;
|
||||
|
||||
return status;
|
||||
@ -495,7 +495,7 @@ dtStatus dtNavMeshQuery::closestPointOnPoly(dtPolyRef ref, const float* pos, flo
|
||||
{
|
||||
rdAssert(m_nav);
|
||||
if (!m_nav->isValidPolyRef(ref) ||
|
||||
!pos || !dtVisfinite(pos) ||
|
||||
!pos || !rdVisfinite(pos) ||
|
||||
!closest)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -525,7 +525,7 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (!pos || !dtVisfinite(pos) || !closest)
|
||||
if (!pos || !rdVisfinite(pos) || !closest)
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// Collect vertices.
|
||||
@ -535,15 +535,15 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
|
||||
int nv = 0;
|
||||
for (int i = 0; i < (int)poly->vertCount; ++i)
|
||||
{
|
||||
dtVcopy(&verts[nv*3], &tile->verts[poly->verts[i]*3]);
|
||||
rdVcopy(&verts[nv*3], &tile->verts[poly->verts[i]*3]);
|
||||
nv++;
|
||||
}
|
||||
|
||||
bool inside = dtDistancePtPolyEdgesSqr(pos, verts, nv, edged, edget);
|
||||
bool inside = rdDistancePtPolyEdgesSqr(pos, verts, nv, edged, edget);
|
||||
if (inside)
|
||||
{
|
||||
// Point is inside the polygon, return the point.
|
||||
dtVcopy(closest, pos);
|
||||
rdVcopy(closest, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -560,7 +560,7 @@ dtStatus dtNavMeshQuery::closestPointOnPolyBoundary(dtPolyRef ref, const float*
|
||||
}
|
||||
const float* va = &verts[imin*3];
|
||||
const float* vb = &verts[((imin+1)%nv)*3];
|
||||
dtVlerp(closest, va, vb, edget[imin]);
|
||||
rdVlerp(closest, va, vb, edget[imin]);
|
||||
}
|
||||
|
||||
return DT_SUCCESS;
|
||||
@ -580,7 +580,7 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
|
||||
if (dtStatusFailed(m_nav->getTileAndPolyByRef(ref, &tile, &poly)))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
if (!pos || !dtVisfinite2D(pos))
|
||||
if (!pos || !rdVisfinite2D(pos))
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
|
||||
// We used to return success for offmesh connections, but the
|
||||
@ -591,7 +591,7 @@ dtStatus dtNavMeshQuery::getPolyHeight(dtPolyRef ref, const float* pos, float* h
|
||||
const float* v0 = &tile->verts[poly->verts[0]*3];
|
||||
const float* v1 = &tile->verts[poly->verts[1]*3];
|
||||
float t;
|
||||
dtDistancePtSegSqr2D(pos, v0, v1, t);
|
||||
rdDistancePtSegSqr2D(pos, v0, v1, t);
|
||||
if (height)
|
||||
*height = v0[2] + (v1[2] - v0[2])*t;
|
||||
|
||||
@ -624,7 +624,7 @@ public:
|
||||
|
||||
void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count)
|
||||
{
|
||||
dtIgnoreUnused(polys);
|
||||
rdIgnoreUnused(polys);
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
@ -637,20 +637,20 @@ public:
|
||||
|
||||
// If a point is directly over a polygon and closer than
|
||||
// climb height, favor that instead of straight line nearest point.
|
||||
dtVsub(diff, m_center, closestPtPoly);
|
||||
rdVsub(diff, m_center, closestPtPoly);
|
||||
if (posOverPoly)
|
||||
{
|
||||
d = dtAbs(diff[2]) - tile->header->walkableClimb;
|
||||
d = rdAbs(diff[2]) - tile->header->walkableClimb;
|
||||
d = d > 0 ? d*d : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
d = dtVlenSqr(diff);
|
||||
d = rdVlenSqr(diff);
|
||||
}
|
||||
|
||||
if (d < m_nearestDistanceSqr)
|
||||
{
|
||||
dtVcopy(m_nearestPoint, closestPtPoly);
|
||||
rdVcopy(m_nearestPoint, closestPtPoly);
|
||||
|
||||
m_nearestDistanceSqr = d;
|
||||
m_nearestRef = ref;
|
||||
@ -697,7 +697,7 @@ dtStatus dtNavMeshQuery::findNearestPoly(const float* center, const float* halfE
|
||||
// is valid.
|
||||
if (nearestPt && *nearestRef)
|
||||
{
|
||||
dtVcopy(nearestPt, query.nearestPoint());
|
||||
rdVcopy(nearestPt, query.nearestPoint());
|
||||
if (isOverPoly)
|
||||
*isOverPoly = query.isOverPoly();
|
||||
}
|
||||
@ -725,12 +725,12 @@ void dtNavMeshQuery::queryPolygonsInTile(const dtMeshTile* tile, const float* qm
|
||||
// Calculate quantized box
|
||||
unsigned short bmin[3], bmax[3];
|
||||
// dtClamp query box to world box.
|
||||
float minx = dtClamp(qmin[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float miny = dtClamp(qmin[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float minz = dtClamp(qmin[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float maxx = dtClamp(qmax[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float maxy = dtClamp(qmax[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float maxz = dtClamp(qmax[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float minx = rdClamp(qmin[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float miny = rdClamp(qmin[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float minz = rdClamp(qmin[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
float maxx = rdClamp(qmax[0], tbmin[0], tbmax[0]) - tbmin[0];
|
||||
float maxy = rdClamp(qmax[1], tbmin[1], tbmax[1]) - tbmin[1];
|
||||
float maxz = rdClamp(qmax[2], tbmin[2], tbmax[2]) - tbmin[2];
|
||||
// Quantize
|
||||
bmin[0] = (unsigned short)(qfac * minx) & 0xfffe;
|
||||
bmin[1] = (unsigned short)(qfac * miny) & 0xfffe;
|
||||
@ -743,7 +743,7 @@ void dtNavMeshQuery::queryPolygonsInTile(const dtMeshTile* tile, const float* qm
|
||||
const dtPolyRef base = m_nav->getPolyRefBase(tile);
|
||||
while (node < end)
|
||||
{
|
||||
const bool overlap = dtOverlapQuantBounds(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool overlap = rdOverlapQuantBounds(bmin, bmax, node->bmin, node->bmax);
|
||||
const bool isLeafNode = node->i >= 0;
|
||||
|
||||
if (isLeafNode && overlap)
|
||||
@ -791,15 +791,15 @@ void dtNavMeshQuery::queryPolygonsInTile(const dtMeshTile* tile, const float* qm
|
||||
continue;
|
||||
// Calc polygon bounds.
|
||||
const float* v = &tile->verts[p->verts[0]*3];
|
||||
dtVcopy(bmin, v);
|
||||
dtVcopy(bmax, v);
|
||||
rdVcopy(bmin, v);
|
||||
rdVcopy(bmax, v);
|
||||
for (int j = 1; j < p->vertCount; ++j)
|
||||
{
|
||||
v = &tile->verts[p->verts[j]*3];
|
||||
dtVmin(bmin, v);
|
||||
dtVmax(bmax, v);
|
||||
rdVmin(bmin, v);
|
||||
rdVmax(bmax, v);
|
||||
}
|
||||
if (dtOverlapBounds(qmin, qmax, bmin, bmax))
|
||||
if (rdOverlapBounds(qmin, qmax, bmin, bmax))
|
||||
{
|
||||
polyRefs[n] = ref;
|
||||
polys[n] = p;
|
||||
@ -840,8 +840,8 @@ public:
|
||||
|
||||
void process(const dtMeshTile* tile, dtPoly** polys, dtPolyRef* refs, int count)
|
||||
{
|
||||
dtIgnoreUnused(tile);
|
||||
dtIgnoreUnused(polys);
|
||||
rdIgnoreUnused(tile);
|
||||
rdIgnoreUnused(polys);
|
||||
|
||||
int numLeft = m_maxPolys - m_numCollected;
|
||||
int toCopy = count;
|
||||
@ -894,16 +894,16 @@ dtStatus dtNavMeshQuery::queryPolygons(const float* center, const float* halfExt
|
||||
{
|
||||
rdAssert(m_nav);
|
||||
|
||||
if (!center || !dtVisfinite(center) ||
|
||||
!halfExtents || !dtVisfinite(halfExtents) ||
|
||||
if (!center || !rdVisfinite(center) ||
|
||||
!halfExtents || !rdVisfinite(halfExtents) ||
|
||||
!filter || !query)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
|
||||
float bmin[3], bmax[3];
|
||||
dtVsub(bmin, center, halfExtents);
|
||||
dtVadd(bmax, center, halfExtents);
|
||||
rdVsub(bmin, center, halfExtents);
|
||||
rdVadd(bmax, center, halfExtents);
|
||||
|
||||
// Find tiles the query touches.
|
||||
int minx, miny, maxx, maxy;
|
||||
@ -955,8 +955,8 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!startPos || !rdVisfinite(startPos) ||
|
||||
!endPos || !rdVisfinite(endPos) ||
|
||||
!filter || !path || maxPath <= 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -973,10 +973,10 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
|
||||
m_openList->clear();
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, startPos);
|
||||
rdVcopy(startNode->pos, startPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = dtVdist(startPos, endPos) * H_SCALE;
|
||||
startNode->total = rdVdist(startPos, endPos) * H_SCALE;
|
||||
startNode->id = startRef;
|
||||
startNode->flags = DT_NODE_OPEN;
|
||||
m_openList->push(startNode);
|
||||
@ -1082,7 +1082,7 @@ dtStatus dtNavMeshQuery::findPath(dtPolyRef startRef, dtPolyRef endRef,
|
||||
bestRef, bestTile, bestPoly,
|
||||
neighbourRef, neighbourTile, neighbourPoly);
|
||||
cost = bestNode->cost + curCost;
|
||||
heuristic = dtVdist(neighbourNode->pos, endPos)*H_SCALE;
|
||||
heuristic = rdVdist(neighbourNode->pos, endPos)*H_SCALE;
|
||||
}
|
||||
|
||||
const float total = cost + heuristic;
|
||||
@ -1165,7 +1165,7 @@ dtStatus dtNavMeshQuery::getPathToNode(dtNode* endNode, dtPolyRef* path, int* pa
|
||||
|
||||
rdAssert(!curNode);
|
||||
|
||||
*pathCount = dtMin(length, maxPath);
|
||||
*pathCount = rdMin(length, maxPath);
|
||||
|
||||
if (length > maxPath)
|
||||
return DT_SUCCESS | DT_BUFFER_TOO_SMALL;
|
||||
@ -1196,16 +1196,16 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
|
||||
m_query.startRef = startRef;
|
||||
m_query.endRef = endRef;
|
||||
if (startPos)
|
||||
dtVcopy(m_query.startPos, startPos);
|
||||
rdVcopy(m_query.startPos, startPos);
|
||||
if (endPos)
|
||||
dtVcopy(m_query.endPos, endPos);
|
||||
rdVcopy(m_query.endPos, endPos);
|
||||
m_query.options = options;
|
||||
m_query.raycastLimitSqr = FLT_MAX;
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) || !m_nav->isValidPolyRef(endRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos))
|
||||
!startPos || !rdVisfinite(startPos) ||
|
||||
!endPos || !rdVisfinite(endPos))
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
}
|
||||
@ -1217,7 +1217,7 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
|
||||
// so it is enough to compute it from the first tile.
|
||||
const dtMeshTile* tile = m_nav->getTileByRef(startRef);
|
||||
float agentRadius = tile->header->walkableRadius;
|
||||
m_query.raycastLimitSqr = dtSqr(agentRadius * DT_RAY_CAST_LIMIT_PROPORTIONS);
|
||||
m_query.raycastLimitSqr = rdSqr(agentRadius * DT_RAY_CAST_LIMIT_PROPORTIONS);
|
||||
}
|
||||
|
||||
if (startRef == endRef)
|
||||
@ -1230,10 +1230,10 @@ dtStatus dtNavMeshQuery::initSlicedFindPath(dtPolyRef startRef, dtPolyRef endRef
|
||||
m_openList->clear();
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, startPos);
|
||||
rdVcopy(startNode->pos, startPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = dtVdist(startPos, endPos) * H_SCALE;
|
||||
startNode->total = rdVdist(startPos, endPos) * H_SCALE;
|
||||
startNode->id = startRef;
|
||||
startNode->flags = DT_NODE_OPEN;
|
||||
m_openList->push(startNode);
|
||||
@ -1329,7 +1329,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters,
|
||||
bool tryLOS = false;
|
||||
if (m_query.options & DT_FINDPATH_ANY_ANGLE)
|
||||
{
|
||||
if ((parentRef != 0) && (dtVdistSqr(parentNode->pos, bestNode->pos) < m_query.raycastLimitSqr))
|
||||
if ((parentRef != 0) && (rdVdistSqr(parentNode->pos, bestNode->pos) < m_query.raycastLimitSqr))
|
||||
tryLOS = true;
|
||||
}
|
||||
|
||||
@ -1417,7 +1417,7 @@ dtStatus dtNavMeshQuery::updateSlicedFindPath(const int maxIter, int* doneIters,
|
||||
}
|
||||
else
|
||||
{
|
||||
heuristic = dtVdist(neighbourNode->pos, m_query.endPos)*H_SCALE;
|
||||
heuristic = rdVdist(neighbourNode->pos, m_query.endPos)*H_SCALE;
|
||||
}
|
||||
|
||||
const float total = cost + heuristic;
|
||||
@ -1672,7 +1672,7 @@ dtStatus dtNavMeshQuery::appendVertex(const float* pos, const unsigned char flag
|
||||
float* straightPath, unsigned char* straightPathFlags, dtPolyRef* straightPathRefs,
|
||||
int* straightPathCount, const int maxStraightPath) const
|
||||
{
|
||||
if ((*straightPathCount) > 0 && dtVequal(&straightPath[((*straightPathCount)-1)*3], pos))
|
||||
if ((*straightPathCount) > 0 && rdVequal(&straightPath[((*straightPathCount)-1)*3], pos))
|
||||
{
|
||||
// The vertices are equal, update flags and poly.
|
||||
if (straightPathFlags)
|
||||
@ -1683,7 +1683,7 @@ dtStatus dtNavMeshQuery::appendVertex(const float* pos, const unsigned char flag
|
||||
else
|
||||
{
|
||||
// Append new vertex.
|
||||
dtVcopy(&straightPath[(*straightPathCount)*3], pos);
|
||||
rdVcopy(&straightPath[(*straightPathCount)*3], pos);
|
||||
if (straightPathFlags)
|
||||
straightPathFlags[(*straightPathCount)] = flags;
|
||||
if (straightPathRefs)
|
||||
@ -1740,10 +1740,10 @@ dtStatus dtNavMeshQuery::appendPortals(const int startIdx, const int endIdx, con
|
||||
|
||||
// Append intersection
|
||||
float s,t;
|
||||
if (dtIntersectSegSeg2D(startPos, endPos, left, right, s, t))
|
||||
if (rdIntersectSegSeg2D(startPos, endPos, left, right, s, t))
|
||||
{
|
||||
float pt[3];
|
||||
dtVlerp(pt, left,right, t);
|
||||
rdVlerp(pt, left,right, t);
|
||||
|
||||
stat = appendVertex(pt, 0, path[i+1],
|
||||
straightPath, straightPathFlags, straightPathRefs,
|
||||
@ -1784,8 +1784,8 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
|
||||
*straightPathCount = 0;
|
||||
|
||||
if (!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
if (!startPos || !rdVisfinite(startPos) ||
|
||||
!endPos || !rdVisfinite(endPos) ||
|
||||
!path || pathSize <= 0 || !path[0] ||
|
||||
maxStraightPath <= 0)
|
||||
{
|
||||
@ -1813,9 +1813,9 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
if (pathSize > 1)
|
||||
{
|
||||
float portalApex[3], portalLeft[3], portalRight[3];
|
||||
dtVcopy(portalApex, closestStartPos);
|
||||
dtVcopy(portalLeft, portalApex);
|
||||
dtVcopy(portalRight, portalApex);
|
||||
rdVcopy(portalApex, closestStartPos);
|
||||
rdVcopy(portalLeft, portalApex);
|
||||
rdVcopy(portalRight, portalApex);
|
||||
int apexIndex = 0;
|
||||
int leftIndex = 0;
|
||||
int rightIndex = 0;
|
||||
@ -1868,25 +1868,25 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
if (i == 0)
|
||||
{
|
||||
float t;
|
||||
if (dtDistancePtSegSqr2D(portalApex, left, right, t) < dtSqr(0.001f))
|
||||
if (rdDistancePtSegSqr2D(portalApex, left, right, t) < rdSqr(0.001f))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// End of the path.
|
||||
dtVcopy(left, closestEndPos);
|
||||
dtVcopy(right, closestEndPos);
|
||||
rdVcopy(left, closestEndPos);
|
||||
rdVcopy(right, closestEndPos);
|
||||
|
||||
toType = DT_POLYTYPE_GROUND;
|
||||
}
|
||||
|
||||
// Left vertex.
|
||||
if (dtTriArea2D(portalApex, portalLeft, left) <= 0.0f)
|
||||
if (rdTriArea2D(portalApex, portalLeft, left) <= 0.0f)
|
||||
{
|
||||
if (dtVequal(portalApex, portalLeft) || dtTriArea2D(portalApex, portalRight, left) > 0.0f)
|
||||
if (rdVequal(portalApex, portalLeft) || rdTriArea2D(portalApex, portalRight, left) > 0.0f)
|
||||
{
|
||||
dtVcopy(portalLeft, left);
|
||||
rdVcopy(portalLeft, left);
|
||||
leftPolyRef = (i+1 < pathSize) ? path[i+1] : 0;
|
||||
leftPolyType = toType;
|
||||
leftIndex = i;
|
||||
@ -1903,7 +1903,7 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
return stat;
|
||||
}
|
||||
|
||||
dtVcopy(portalApex, portalRight);
|
||||
rdVcopy(portalApex, portalRight);
|
||||
apexIndex = rightIndex;
|
||||
|
||||
unsigned char flags = 0;
|
||||
@ -1920,8 +1920,8 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
if (stat != DT_IN_PROGRESS)
|
||||
return stat;
|
||||
|
||||
dtVcopy(portalLeft, portalApex);
|
||||
dtVcopy(portalRight, portalApex);
|
||||
rdVcopy(portalLeft, portalApex);
|
||||
rdVcopy(portalRight, portalApex);
|
||||
leftIndex = apexIndex;
|
||||
rightIndex = apexIndex;
|
||||
|
||||
@ -1933,11 +1933,11 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
}
|
||||
|
||||
// Right vertex.
|
||||
if (dtTriArea2D(portalApex, portalRight, right) >= 0.0f)
|
||||
if (rdTriArea2D(portalApex, portalRight, right) >= 0.0f)
|
||||
{
|
||||
if (dtVequal(portalApex, portalRight) || dtTriArea2D(portalApex, portalLeft, right) < 0.0f)
|
||||
if (rdVequal(portalApex, portalRight) || rdTriArea2D(portalApex, portalLeft, right) < 0.0f)
|
||||
{
|
||||
dtVcopy(portalRight, right);
|
||||
rdVcopy(portalRight, right);
|
||||
rightPolyRef = (i+1 < pathSize) ? path[i+1] : 0;
|
||||
rightPolyType = toType;
|
||||
rightIndex = i;
|
||||
@ -1954,7 +1954,7 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
return stat;
|
||||
}
|
||||
|
||||
dtVcopy(portalApex, portalLeft);
|
||||
rdVcopy(portalApex, portalLeft);
|
||||
apexIndex = leftIndex;
|
||||
|
||||
unsigned char flags = 0;
|
||||
@ -1971,8 +1971,8 @@ dtStatus dtNavMeshQuery::findStraightPath(const float* startPos, const float* en
|
||||
if (stat != DT_IN_PROGRESS)
|
||||
return stat;
|
||||
|
||||
dtVcopy(portalLeft, portalApex);
|
||||
dtVcopy(portalRight, portalApex);
|
||||
rdVcopy(portalLeft, portalApex);
|
||||
rdVcopy(portalRight, portalApex);
|
||||
leftIndex = apexIndex;
|
||||
rightIndex = apexIndex;
|
||||
|
||||
@ -2036,8 +2036,8 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
*visitedCount = 0;
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!startPos || !rdVisfinite(startPos) ||
|
||||
!endPos || !rdVisfinite(endPos) ||
|
||||
!filter || !resultPos || !visited ||
|
||||
maxVisitedSize <= 0)
|
||||
{
|
||||
@ -2063,12 +2063,12 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
float bestPos[3];
|
||||
float bestDist = FLT_MAX;
|
||||
dtNode* bestNode = 0;
|
||||
dtVcopy(bestPos, startPos);
|
||||
rdVcopy(bestPos, startPos);
|
||||
|
||||
// Search constraints
|
||||
float searchPos[3], searchRadSqr;
|
||||
dtVlerp(searchPos, startPos, endPos, 0.5f);
|
||||
searchRadSqr = dtSqr(dtVdist(startPos, endPos)/2.0f + 0.001f);
|
||||
rdVlerp(searchPos, startPos, endPos, 0.5f);
|
||||
searchRadSqr = rdSqr(rdVdist(startPos, endPos)/2.0f + 0.001f);
|
||||
|
||||
float verts[DT_VERTS_PER_POLYGON*3];
|
||||
|
||||
@ -2090,13 +2090,13 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
// Collect vertices.
|
||||
const int nverts = curPoly->vertCount;
|
||||
for (int i = 0; i < nverts; ++i)
|
||||
dtVcopy(&verts[i*3], &curTile->verts[curPoly->verts[i]*3]);
|
||||
rdVcopy(&verts[i*3], &curTile->verts[curPoly->verts[i]*3]);
|
||||
|
||||
// If target is inside the poly, stop search.
|
||||
if (dtPointInPolygon(endPos, verts, nverts))
|
||||
if (rdPointInPolygon(endPos, verts, nverts))
|
||||
{
|
||||
bestNode = curNode;
|
||||
dtVcopy(bestPos, endPos);
|
||||
rdVcopy(bestPos, endPos);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -2147,11 +2147,11 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
const float* vj = &verts[j*3];
|
||||
const float* vi = &verts[i*3];
|
||||
float tseg;
|
||||
const float distSqr = dtDistancePtSegSqr2D(endPos, vj, vi, tseg);
|
||||
const float distSqr = rdDistancePtSegSqr2D(endPos, vj, vi, tseg);
|
||||
if (distSqr < bestDist)
|
||||
{
|
||||
// Update nearest distance.
|
||||
dtVlerp(bestPos, vj,vi, tseg);
|
||||
rdVlerp(bestPos, vj,vi, tseg);
|
||||
bestDist = distSqr;
|
||||
bestNode = curNode;
|
||||
}
|
||||
@ -2173,7 +2173,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
const float* vj = &verts[j*3];
|
||||
const float* vi = &verts[i*3];
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(searchPos, vj, vi, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(searchPos, vj, vi, tseg);
|
||||
if (distSqr > searchRadSqr)
|
||||
continue;
|
||||
|
||||
@ -2219,7 +2219,7 @@ dtStatus dtNavMeshQuery::moveAlongSurface(dtPolyRef startRef, const float* start
|
||||
while (node);
|
||||
}
|
||||
|
||||
dtVcopy(resultPos, bestPos);
|
||||
rdVcopy(resultPos, bestPos);
|
||||
|
||||
*visitedCount = n;
|
||||
|
||||
@ -2274,8 +2274,8 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
|
||||
if (fromTile->links[i].ref == to)
|
||||
{
|
||||
const int v = fromTile->links[i].edge;
|
||||
dtVcopy(left, &fromTile->verts[fromPoly->verts[v]*3]);
|
||||
dtVcopy(right, &fromTile->verts[fromPoly->verts[v]*3]);
|
||||
rdVcopy(left, &fromTile->verts[fromPoly->verts[v]*3]);
|
||||
rdVcopy(right, &fromTile->verts[fromPoly->verts[v]*3]);
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -2289,8 +2289,8 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
|
||||
if (toTile->links[i].ref == from)
|
||||
{
|
||||
const int v = toTile->links[i].edge;
|
||||
dtVcopy(left, &toTile->verts[toPoly->verts[v]*3]);
|
||||
dtVcopy(right, &toTile->verts[toPoly->verts[v]*3]);
|
||||
rdVcopy(left, &toTile->verts[toPoly->verts[v]*3]);
|
||||
rdVcopy(right, &toTile->verts[toPoly->verts[v]*3]);
|
||||
return DT_SUCCESS;
|
||||
}
|
||||
}
|
||||
@ -2300,8 +2300,8 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
|
||||
// Find portal vertices.
|
||||
const int v0 = fromPoly->verts[link->edge];
|
||||
const int v1 = fromPoly->verts[(link->edge+1) % (int)fromPoly->vertCount];
|
||||
dtVcopy(left, &fromTile->verts[v0*3]);
|
||||
dtVcopy(right, &fromTile->verts[v1*3]);
|
||||
rdVcopy(left, &fromTile->verts[v0*3]);
|
||||
rdVcopy(right, &fromTile->verts[v1*3]);
|
||||
|
||||
// If the link is at tile boundary, dtClamp the vertices to
|
||||
// the link width.
|
||||
@ -2313,8 +2313,8 @@ dtStatus dtNavMeshQuery::getPortalPoints(dtPolyRef from, const dtPoly* fromPoly,
|
||||
const float s = 1.0f/255.0f;
|
||||
const float tmin = link->bmin*s;
|
||||
const float tmax = link->bmax*s;
|
||||
dtVlerp(left, &fromTile->verts[v0*3], &fromTile->verts[v1*3], tmin);
|
||||
dtVlerp(right, &fromTile->verts[v0*3], &fromTile->verts[v1*3], tmax);
|
||||
rdVlerp(left, &fromTile->verts[v0*3], &fromTile->verts[v1*3], tmin);
|
||||
rdVlerp(right, &fromTile->verts[v0*3], &fromTile->verts[v1*3], tmax);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2399,7 +2399,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
|
||||
*t = hit.t;
|
||||
if (hitNormal)
|
||||
dtVcopy(hitNormal, hit.hitNormal);
|
||||
rdVcopy(hitNormal, hit.hitNormal);
|
||||
if (pathCount)
|
||||
*pathCount = hit.pathCount;
|
||||
|
||||
@ -2460,8 +2460,8 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!startPos || !dtVisfinite(startPos) ||
|
||||
!endPos || !dtVisfinite(endPos) ||
|
||||
!startPos || !rdVisfinite(startPos) ||
|
||||
!endPos || !rdVisfinite(endPos) ||
|
||||
!filter ||
|
||||
(prevRef && !m_nav->isValidPolyRef(prevRef)))
|
||||
{
|
||||
@ -2472,9 +2472,9 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
float verts[DT_VERTS_PER_POLYGON*3+3];
|
||||
int n = 0;
|
||||
|
||||
dtVcopy(curPos, startPos);
|
||||
dtVsub(dir, endPos, startPos);
|
||||
dtVset(hit->hitNormal, 0, 0, 0);
|
||||
rdVcopy(curPos, startPos);
|
||||
rdVsub(dir, endPos, startPos);
|
||||
rdVset(hit->hitNormal, 0, 0, 0);
|
||||
|
||||
dtStatus status = DT_SUCCESS;
|
||||
|
||||
@ -2500,13 +2500,13 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
int nv = 0;
|
||||
for (int i = 0; i < (int)poly->vertCount; ++i)
|
||||
{
|
||||
dtVcopy(&verts[nv*3], &tile->verts[poly->verts[i]*3]);
|
||||
rdVcopy(&verts[nv*3], &tile->verts[poly->verts[i]*3]);
|
||||
nv++;
|
||||
}
|
||||
|
||||
float tmin, tmax;
|
||||
int segMin, segMax;
|
||||
if (!dtIntersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax))
|
||||
if (!rdIntersectSegmentPoly2D(startPos, endPos, verts, nv, tmin, tmax, segMin, segMax))
|
||||
{
|
||||
// Could not hit the polygon, keep the old t and report hit.
|
||||
hit->pathCount = n;
|
||||
@ -2590,7 +2590,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
const float s = 1.0f/255.0f;
|
||||
float lmin = left[1] + (right[1] - left[1])*(link->bmin*s);
|
||||
float lmax = left[1] + (right[1] - left[1])*(link->bmax*s);
|
||||
if (lmin > lmax) dtSwap(lmin, lmax);
|
||||
if (lmin > lmax) rdSwap(lmin, lmax);
|
||||
|
||||
// Find Y intersection.
|
||||
float y = startPos[1] + (endPos[1]-startPos[1])*tmax;
|
||||
@ -2606,7 +2606,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
const float s = 1.0f/255.0f;
|
||||
float lmin = left[0] + (right[0] - left[0])*(link->bmin*s);
|
||||
float lmax = left[0] + (right[0] - left[0])*(link->bmax*s);
|
||||
if (lmin > lmax) dtSwap(lmin, lmax);
|
||||
if (lmin > lmax) rdSwap(lmin, lmax);
|
||||
|
||||
// Find X intersection.
|
||||
float x = startPos[0] + (endPos[0]-startPos[0])*tmax;
|
||||
@ -2623,14 +2623,14 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
{
|
||||
// compute the intersection point at the furthest end of the polygon
|
||||
// and correct the height (since the raycast moves in 2d)
|
||||
dtVcopy(lastPos, curPos);
|
||||
dtVmad(curPos, startPos, dir, hit->t);
|
||||
rdVcopy(lastPos, curPos);
|
||||
rdVmad(curPos, startPos, dir, hit->t);
|
||||
float* e1 = &verts[segMax*3];
|
||||
float* e2 = &verts[((segMax+1)%nv)*3];
|
||||
float eDir[3], diff[3];
|
||||
dtVsub(eDir, e2, e1);
|
||||
dtVsub(diff, curPos, e1);
|
||||
float s = dtSqr(eDir[0]) > dtSqr(eDir[1]) ? diff[0] / eDir[0] : diff[1] / eDir[1];
|
||||
rdVsub(eDir, e2, e1);
|
||||
rdVsub(diff, curPos, e1);
|
||||
float s = rdSqr(eDir[0]) > rdSqr(eDir[1]) ? diff[0] / eDir[0] : diff[1] / eDir[1];
|
||||
curPos[2] = e1[2] + eDir[2] * s;
|
||||
|
||||
hit->pathCost += filter->getCost(lastPos, curPos, prevRef, prevTile, prevPoly, curRef, tile, poly, nextRef, nextTile, nextPoly);
|
||||
@ -2650,7 +2650,7 @@ dtStatus dtNavMeshQuery::raycast(dtPolyRef startRef, const float* startPos, cons
|
||||
hit->hitNormal[0] = -dy;
|
||||
hit->hitNormal[1] = dx;
|
||||
hit->hitNormal[2] = 0;
|
||||
dtVnormalize(hit->hitNormal);
|
||||
rdVnormalize(hit->hitNormal);
|
||||
|
||||
hit->pathCount = n;
|
||||
return status;
|
||||
@ -2714,8 +2714,8 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
*resultCount = 0;
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
radius < 0 || !dtMathIsfinite(radius) ||
|
||||
!centerPos || !rdVisfinite(centerPos) ||
|
||||
radius < 0 || !rdMathIsfinite(radius) ||
|
||||
!filter || maxResult < 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -2725,7 +2725,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
m_openList->clear();
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, centerPos);
|
||||
rdVcopy(startNode->pos, centerPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = 0;
|
||||
@ -2737,7 +2737,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
|
||||
int n = 0;
|
||||
|
||||
const float radiusSqr = dtSqr(radius);
|
||||
const float radiusSqr = rdSqr(radius);
|
||||
|
||||
while (!m_openList->empty())
|
||||
{
|
||||
@ -2800,7 +2800,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
|
||||
// If the circle is not touching the next polygon, skip it.
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
if (distSqr > radiusSqr)
|
||||
continue;
|
||||
|
||||
@ -2816,7 +2816,7 @@ dtStatus dtNavMeshQuery::findPolysAroundCircle(dtPolyRef startRef, const float*
|
||||
|
||||
// Cost
|
||||
if (neighbourNode->flags == 0)
|
||||
dtVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
rdVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
|
||||
float cost = filter->getCost(
|
||||
bestNode->pos, neighbourNode->pos,
|
||||
@ -2903,11 +2903,11 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
|
||||
|
||||
float centerPos[3] = {0,0,0};
|
||||
for (int i = 0; i < nverts; ++i)
|
||||
dtVadd(centerPos,centerPos,&verts[i*3]);
|
||||
dtVscale(centerPos,centerPos,1.0f/nverts);
|
||||
rdVadd(centerPos,centerPos,&verts[i*3]);
|
||||
rdVscale(centerPos,centerPos,1.0f/nverts);
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, centerPos);
|
||||
rdVcopy(startNode->pos, centerPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = 0;
|
||||
@ -2982,7 +2982,7 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
|
||||
// If the poly is not touching the edge to the next polygon, skip the connection it.
|
||||
float tmin, tmax;
|
||||
int segMin, segMax;
|
||||
if (!dtIntersectSegmentPoly2D(va, vb, verts, nverts, tmin, tmax, segMin, segMax))
|
||||
if (!rdIntersectSegmentPoly2D(va, vb, verts, nverts, tmin, tmax, segMin, segMax))
|
||||
continue;
|
||||
if (tmin > 1.0f || tmax < 0.0f)
|
||||
continue;
|
||||
@ -2999,7 +2999,7 @@ dtStatus dtNavMeshQuery::findPolysAroundShape(dtPolyRef startRef, const float* v
|
||||
|
||||
// Cost
|
||||
if (neighbourNode->flags == 0)
|
||||
dtVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
rdVlerp(neighbourNode->pos, va, vb, 0.5f);
|
||||
|
||||
float cost = filter->getCost(
|
||||
bestNode->pos, neighbourNode->pos,
|
||||
@ -3085,8 +3085,8 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
*resultCount = 0;
|
||||
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
radius < 0 || !dtMathIsfinite(radius) ||
|
||||
!centerPos || !rdVisfinite(centerPos) ||
|
||||
radius < 0 || !rdMathIsfinite(radius) ||
|
||||
!filter || maxResult < 0)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -3104,7 +3104,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
startNode->flags = DT_NODE_CLOSED;
|
||||
stack[nstack++] = startNode;
|
||||
|
||||
const float radiusSqr = dtSqr(radius);
|
||||
const float radiusSqr = rdSqr(radius);
|
||||
|
||||
float pa[DT_VERTS_PER_POLYGON*3];
|
||||
float pb[DT_VERTS_PER_POLYGON*3];
|
||||
@ -3175,7 +3175,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
|
||||
// If the circle is not touching the next polygon, skip it.
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
if (distSqr > radiusSqr)
|
||||
continue;
|
||||
|
||||
@ -3189,7 +3189,7 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
// Collect vertices of the neighbour poly.
|
||||
const int npa = neighbourPoly->vertCount;
|
||||
for (int k = 0; k < npa; ++k)
|
||||
dtVcopy(&pa[k*3], &neighbourTile->verts[neighbourPoly->verts[k]*3]);
|
||||
rdVcopy(&pa[k*3], &neighbourTile->verts[neighbourPoly->verts[k]*3]);
|
||||
|
||||
bool overlap = false;
|
||||
for (int j = 0; j < n; ++j)
|
||||
@ -3217,9 +3217,9 @@ dtStatus dtNavMeshQuery::findLocalNeighbourhood(dtPolyRef startRef, const float*
|
||||
// Get vertices and test overlap
|
||||
const int npb = pastPoly->vertCount;
|
||||
for (int k = 0; k < npb; ++k)
|
||||
dtVcopy(&pb[k*3], &pastTile->verts[pastPoly->verts[k]*3]);
|
||||
rdVcopy(&pb[k*3], &pastTile->verts[pastPoly->verts[k]*3]);
|
||||
|
||||
if (dtOverlapPolyPoly2D(pa,npa, pb,npb))
|
||||
if (rdOverlapPolyPoly2D(pa,npa, pb,npb))
|
||||
{
|
||||
overlap = true;
|
||||
break;
|
||||
@ -3367,8 +3367,8 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
|
||||
const float* vj = &tile->verts[poly->verts[j]*3];
|
||||
const float* vi = &tile->verts[poly->verts[i]*3];
|
||||
float* seg = &segmentVerts[n*6];
|
||||
dtVcopy(seg+0, vj);
|
||||
dtVcopy(seg+3, vi);
|
||||
rdVcopy(seg+0, vj);
|
||||
rdVcopy(seg+3, vi);
|
||||
if (segmentRefs)
|
||||
segmentRefs[n] = neiRef;
|
||||
n++;
|
||||
@ -3398,8 +3398,8 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
|
||||
if (n < maxSegments)
|
||||
{
|
||||
float* seg = &segmentVerts[n*6];
|
||||
dtVlerp(seg+0, vj,vi, tmin);
|
||||
dtVlerp(seg+3, vj,vi, tmax);
|
||||
rdVlerp(seg+0, vj,vi, tmin);
|
||||
rdVlerp(seg+3, vj,vi, tmax);
|
||||
if (segmentRefs)
|
||||
segmentRefs[n] = ints[k].ref;
|
||||
n++;
|
||||
@ -3420,8 +3420,8 @@ dtStatus dtNavMeshQuery::getPolyWallSegments(dtPolyRef ref, const dtQueryFilter*
|
||||
if (n < maxSegments)
|
||||
{
|
||||
float* seg = &segmentVerts[n*6];
|
||||
dtVlerp(seg+0, vj,vi, tmin);
|
||||
dtVlerp(seg+3, vj,vi, tmax);
|
||||
rdVlerp(seg+0, vj,vi, tmin);
|
||||
rdVlerp(seg+3, vj,vi, tmax);
|
||||
if (segmentRefs)
|
||||
segmentRefs[n] = 0;
|
||||
n++;
|
||||
@ -3459,8 +3459,8 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
|
||||
// Validate input
|
||||
if (!m_nav->isValidPolyRef(startRef) ||
|
||||
!centerPos || !dtVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !dtMathIsfinite(maxRadius) ||
|
||||
!centerPos || !rdVisfinite(centerPos) ||
|
||||
maxRadius < 0 || !rdMathIsfinite(maxRadius) ||
|
||||
!filter || !hitDist || !hitPos || !hitNormal)
|
||||
{
|
||||
return DT_FAILURE | DT_INVALID_PARAM;
|
||||
@ -3470,7 +3470,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
m_openList->clear();
|
||||
|
||||
dtNode* startNode = m_nodePool->getNode(startRef);
|
||||
dtVcopy(startNode->pos, centerPos);
|
||||
rdVcopy(startNode->pos, centerPos);
|
||||
startNode->pidx = 0;
|
||||
startNode->cost = 0;
|
||||
startNode->total = 0;
|
||||
@ -3478,7 +3478,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
startNode->flags = DT_NODE_OPEN;
|
||||
m_openList->push(startNode);
|
||||
|
||||
float radiusSqr = dtSqr(maxRadius);
|
||||
float radiusSqr = rdSqr(maxRadius);
|
||||
|
||||
dtStatus status = DT_SUCCESS;
|
||||
|
||||
@ -3543,7 +3543,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
const float* vj = &bestTile->verts[bestPoly->verts[j]*3];
|
||||
const float* vi = &bestTile->verts[bestPoly->verts[i]*3];
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(centerPos, vj, vi, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(centerPos, vj, vi, tseg);
|
||||
|
||||
// Edge is too far, skip.
|
||||
if (distSqr > radiusSqr)
|
||||
@ -3578,7 +3578,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
const float* va = &bestTile->verts[bestPoly->verts[link->edge]*3];
|
||||
const float* vb = &bestTile->verts[bestPoly->verts[(link->edge+1) % bestPoly->vertCount]*3];
|
||||
float tseg;
|
||||
float distSqr = dtDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
float distSqr = rdDistancePtSegSqr2D(centerPos, va, vb, tseg);
|
||||
|
||||
// If the circle is not touching the next polygon, skip it.
|
||||
if (distSqr > radiusSqr)
|
||||
@ -3604,7 +3604,7 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
neighbourRef, neighbourPoly, neighbourTile, neighbourNode->pos);
|
||||
}
|
||||
|
||||
const float total = bestNode->total + dtVdist(bestNode->pos, neighbourNode->pos);
|
||||
const float total = bestNode->total + rdVdist(bestNode->pos, neighbourNode->pos);
|
||||
|
||||
// The node is already in open list and the new result is worse, skip.
|
||||
if ((neighbourNode->flags & DT_NODE_OPEN) && total >= neighbourNode->total)
|
||||
@ -3628,10 +3628,10 @@ dtStatus dtNavMeshQuery::findDistanceToWall(dtPolyRef startRef, const float* cen
|
||||
}
|
||||
|
||||
// Calc hit normal.
|
||||
dtVsub(hitNormal, centerPos, hitPos);
|
||||
dtVnormalize(hitNormal);
|
||||
rdVsub(hitNormal, centerPos, hitPos);
|
||||
rdVnormalize(hitNormal);
|
||||
|
||||
*hitDist = dtMathSqrtf(radiusSqr);
|
||||
*hitDist = rdMathSqrtf(radiusSqr);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include "Detour/Include/DetourNode.h"
|
||||
#include "Shared/Include/SharedAlloc.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DT_POLYREF64
|
||||
@ -56,7 +56,7 @@ dtNodePool::dtNodePool(int maxNodes, int hashSize) :
|
||||
m_hashSize(hashSize),
|
||||
m_nodeCount(0)
|
||||
{
|
||||
rdAssert(dtNextPow2(m_hashSize) == (unsigned int)m_hashSize);
|
||||
rdAssert(rdNextPow2(m_hashSize) == (unsigned int)m_hashSize);
|
||||
// pidx is special as 0 means "none" and 1 is the first node. For that reason
|
||||
// we have 1 fewer nodes available than the number of values it can contain.
|
||||
rdAssert(m_maxNodes > 0 && m_maxNodes <= DT_NULL_IDX && m_maxNodes <= (1 << DT_NODE_PARENT_BITS) - 1);
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include "DetourCrowd\Include\DetourObstacleAvoidance.h"
|
||||
#include "Detour\Include\DetourNavMesh.h"
|
||||
#include "Detour\Include\DetourNavMeshQuery.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Detour\Include\DetourMath.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "Shared\Include\SharedMath.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
|
||||
@ -54,7 +54,7 @@ static const int MAX_COMMON_NODES = 512;
|
||||
|
||||
inline float tween(const float t, const float t0, const float t1)
|
||||
{
|
||||
return dtClamp((t-t0) / (t1-t0), 0.0f, 1.0f);
|
||||
return rdClamp((t-t0) / (t1-t0), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -154,7 +154,7 @@ bool dtCrowd::init(const int maxAgents, const float maxAgentRadius, dtNavMesh* n
|
||||
m_maxAgentRadius = maxAgentRadius;
|
||||
|
||||
// Larger than agent radius because it is also used for agent recovery.
|
||||
dtVset(m_agentPlacementHalfExtents, m_maxAgentRadius*2.0f, m_maxAgentRadius*1.5f, m_maxAgentRadius*2.0f);
|
||||
rdVset(m_agentPlacementHalfExtents, m_maxAgentRadius*2.0f, m_maxAgentRadius*1.5f, m_maxAgentRadius*2.0f);
|
||||
|
||||
m_grid = dtAllocProximityGrid();
|
||||
if (!m_grid)
|
||||
@ -298,11 +298,11 @@ int dtCrowd::addAgent(const float* pos, const dtCrowdAgentParams* params)
|
||||
// Find nearest position on navmesh and place the agent there.
|
||||
float nearest[3];
|
||||
dtPolyRef ref = 0;
|
||||
dtVcopy(nearest, pos);
|
||||
rdVcopy(nearest, pos);
|
||||
dtStatus status = m_navquery->findNearestPoly(pos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &ref, nearest);
|
||||
if (dtStatusFailed(status))
|
||||
{
|
||||
dtVcopy(nearest, pos);
|
||||
rdVcopy(nearest, pos);
|
||||
ref = 0;
|
||||
}
|
||||
|
||||
@ -314,10 +314,10 @@ int dtCrowd::addAgent(const float* pos, const dtCrowdAgentParams* params)
|
||||
ag->targetReplanTime = 0;
|
||||
ag->nneis = 0;
|
||||
|
||||
dtVset(ag->dvel, 0,0,0);
|
||||
dtVset(ag->nvel, 0,0,0);
|
||||
dtVset(ag->vel, 0,0,0);
|
||||
dtVcopy(ag->npos, nearest);
|
||||
rdVset(ag->dvel, 0,0,0);
|
||||
rdVset(ag->nvel, 0,0,0);
|
||||
rdVset(ag->vel, 0,0,0);
|
||||
rdVcopy(ag->npos, nearest);
|
||||
|
||||
ag->desiredSpeed = 0;
|
||||
|
||||
@ -354,7 +354,7 @@ bool dtCrowd::requestMoveTargetReplan(const int idx, dtPolyRef ref, const float*
|
||||
|
||||
// Initialize request.
|
||||
ag->targetRef = ref;
|
||||
dtVcopy(ag->targetPos, pos);
|
||||
rdVcopy(ag->targetPos, pos);
|
||||
ag->targetPathqRef = DT_PATHQ_INVALID;
|
||||
ag->targetReplan = true;
|
||||
if (ag->targetRef)
|
||||
@ -383,7 +383,7 @@ bool dtCrowd::requestMoveTarget(const int idx, dtPolyRef ref, const float* pos)
|
||||
|
||||
// Initialize request.
|
||||
ag->targetRef = ref;
|
||||
dtVcopy(ag->targetPos, pos);
|
||||
rdVcopy(ag->targetPos, pos);
|
||||
ag->targetPathqRef = DT_PATHQ_INVALID;
|
||||
ag->targetReplan = false;
|
||||
if (ag->targetRef)
|
||||
@ -403,7 +403,7 @@ bool dtCrowd::requestMoveVelocity(const int idx, const float* vel)
|
||||
|
||||
// Initialize request.
|
||||
ag->targetRef = 0;
|
||||
dtVcopy(ag->targetPos, vel);
|
||||
rdVcopy(ag->targetPos, vel);
|
||||
ag->targetPathqRef = DT_PATHQ_INVALID;
|
||||
ag->targetReplan = false;
|
||||
ag->targetState = DT_CROWDAGENT_TARGET_VELOCITY;
|
||||
@ -420,8 +420,8 @@ bool dtCrowd::resetMoveTarget(const int idx)
|
||||
|
||||
// Initialize request.
|
||||
ag->targetRef = 0;
|
||||
dtVset(ag->targetPos, 0,0,0);
|
||||
dtVset(ag->dvel, 0,0,0);
|
||||
rdVset(ag->targetPos, 0,0,0);
|
||||
rdVset(ag->dvel, 0,0,0);
|
||||
ag->targetPathqRef = DT_PATHQ_INVALID;
|
||||
ag->targetReplan = false;
|
||||
ag->targetState = DT_CROWDAGENT_TARGET_NONE;
|
||||
@ -510,7 +510,7 @@ void dtCrowd::updateMoveRequest(const float /*dt*/)
|
||||
}
|
||||
else
|
||||
{
|
||||
dtVcopy(reqPos, ag->targetPos);
|
||||
rdVcopy(reqPos, ag->targetPos);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -521,7 +521,7 @@ void dtCrowd::updateMoveRequest(const float /*dt*/)
|
||||
if (!reqPathCount)
|
||||
{
|
||||
// Could not find path, start the request from current location.
|
||||
dtVcopy(reqPos, ag->npos);
|
||||
rdVcopy(reqPos, ag->npos);
|
||||
reqPath[0] = path[0];
|
||||
reqPathCount = 1;
|
||||
}
|
||||
@ -594,7 +594,7 @@ void dtCrowd::updateMoveRequest(const float /*dt*/)
|
||||
|
||||
// Apply results.
|
||||
float targetPos[3];
|
||||
dtVcopy(targetPos, ag->targetPos);
|
||||
rdVcopy(targetPos, ag->targetPos);
|
||||
|
||||
dtPolyRef* res = m_pathResult;
|
||||
bool valid = true;
|
||||
@ -656,7 +656,7 @@ void dtCrowd::updateMoveRequest(const float /*dt*/)
|
||||
float nearest[3];
|
||||
status = m_navquery->closestPointOnPoly(res[nres-1], targetPos, nearest, 0);
|
||||
if (dtStatusSucceed(status))
|
||||
dtVcopy(targetPos, nearest);
|
||||
rdVcopy(targetPos, nearest);
|
||||
else
|
||||
valid = false;
|
||||
}
|
||||
@ -735,16 +735,16 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const
|
||||
const int idx = getAgentIndex(ag);
|
||||
float agentPos[3];
|
||||
dtPolyRef agentRef = ag->corridor.getFirstPoly();
|
||||
dtVcopy(agentPos, ag->npos);
|
||||
rdVcopy(agentPos, ag->npos);
|
||||
if (!m_navquery->isValidPolyRef(agentRef, &m_filters[ag->params.queryFilterType]))
|
||||
{
|
||||
// Current location is not valid, try to reposition.
|
||||
// TODO: this can snap agents, how to handle that?
|
||||
float nearest[3];
|
||||
dtVcopy(nearest, agentPos);
|
||||
rdVcopy(nearest, agentPos);
|
||||
agentRef = 0;
|
||||
m_navquery->findNearestPoly(ag->npos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &agentRef, nearest);
|
||||
dtVcopy(agentPos, nearest);
|
||||
rdVcopy(agentPos, nearest);
|
||||
|
||||
if (!agentRef)
|
||||
{
|
||||
@ -761,7 +761,7 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const
|
||||
ag->corridor.fixPathStart(agentRef, agentPos);
|
||||
// ag->corridor.trimInvalidPath(agentRef, agentPos, m_navquery, &m_filter);
|
||||
ag->boundary.reset();
|
||||
dtVcopy(ag->npos, agentPos);
|
||||
rdVcopy(ag->npos, agentPos);
|
||||
|
||||
replan = true;
|
||||
}
|
||||
@ -777,10 +777,10 @@ void dtCrowd::checkPathValidity(dtCrowdAgent** agents, const int nagents, const
|
||||
{
|
||||
// Current target is not valid, try to reposition.
|
||||
float nearest[3];
|
||||
dtVcopy(nearest, ag->targetPos);
|
||||
rdVcopy(nearest, ag->targetPos);
|
||||
ag->targetRef = 0;
|
||||
m_navquery->findNearestPoly(ag->targetPos, m_agentPlacementHalfExtents, &m_filters[ag->params.queryFilterType], &ag->targetRef, nearest);
|
||||
dtVcopy(ag->targetPos, nearest);
|
||||
rdVcopy(ag->targetPos, nearest);
|
||||
replan = true;
|
||||
}
|
||||
if (!ag->targetRef)
|
||||
@ -859,7 +859,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
// Update the collision boundary after certain distance has been passed or
|
||||
// if it has become invalid.
|
||||
const float updateThr = ag->params.collisionQueryRange*0.25f;
|
||||
if (dtVdist2DSqr(ag->npos, ag->boundary.getCenter()) > dtSqr(updateThr) ||
|
||||
if (rdVdist2DSqr(ag->npos, ag->boundary.getCenter()) > rdSqr(updateThr) ||
|
||||
!ag->boundary.isValid(m_navquery, &m_filters[ag->params.queryFilterType]))
|
||||
{
|
||||
ag->boundary.update(ag->corridor.getFirstPoly(), ag->npos, ag->params.collisionQueryRange,
|
||||
@ -891,14 +891,14 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
// and short cut to there.
|
||||
if ((ag->params.updateFlags & DT_CROWD_OPTIMIZE_VIS) && ag->ncorners > 0)
|
||||
{
|
||||
const float* target = &ag->cornerVerts[dtMin(1,ag->ncorners-1)*3];
|
||||
const float* target = &ag->cornerVerts[rdMin(1,ag->ncorners-1)*3];
|
||||
ag->corridor.optimizePathVisibility(target, ag->params.pathOptimizationRange, m_navquery, &m_filters[ag->params.queryFilterType]);
|
||||
|
||||
// Copy data for debug purposes.
|
||||
if (debugIdx == i)
|
||||
{
|
||||
dtVcopy(debug->optStart, ag->corridor.getPos());
|
||||
dtVcopy(debug->optEnd, target);
|
||||
rdVcopy(debug->optStart, ag->corridor.getPos());
|
||||
rdVcopy(debug->optEnd, target);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -906,8 +906,8 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
// Copy data for debug purposes.
|
||||
if (debugIdx == i)
|
||||
{
|
||||
dtVset(debug->optStart, 0,0,0);
|
||||
dtVset(debug->optEnd, 0,0,0);
|
||||
rdVset(debug->optStart, 0,0,0);
|
||||
rdVset(debug->optEnd, 0,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -935,11 +935,11 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
if (ag->corridor.moveOverOffmeshConnection(ag->cornerPolys[ag->ncorners-1], refs,
|
||||
anim->startPos, anim->endPos, m_navquery))
|
||||
{
|
||||
dtVcopy(anim->initPos, ag->npos);
|
||||
rdVcopy(anim->initPos, ag->npos);
|
||||
anim->polyRef = refs[1];
|
||||
anim->active = true;
|
||||
anim->t = 0.0f;
|
||||
anim->tmax = (dtVdist2D(anim->startPos, anim->endPos) / ag->params.maxSpeed) * 0.5f;
|
||||
anim->tmax = (rdVdist2D(anim->startPos, anim->endPos) / ag->params.maxSpeed) * 0.5f;
|
||||
|
||||
ag->state = DT_CROWDAGENT_STATE_OFFMESH;
|
||||
ag->ncorners = 0;
|
||||
@ -967,8 +967,8 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
|
||||
if (ag->targetState == DT_CROWDAGENT_TARGET_VELOCITY)
|
||||
{
|
||||
dtVcopy(dvel, ag->targetPos);
|
||||
ag->desiredSpeed = dtVlen(ag->targetPos);
|
||||
rdVcopy(dvel, ag->targetPos);
|
||||
ag->desiredSpeed = rdVlen(ag->targetPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -983,7 +983,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
const float speedScale = getDistanceToGoal(ag, slowDownRadius) / slowDownRadius;
|
||||
|
||||
ag->desiredSpeed = ag->params.maxSpeed;
|
||||
dtVscale(dvel, dvel, ag->desiredSpeed * speedScale);
|
||||
rdVscale(dvel, dvel, ag->desiredSpeed * speedScale);
|
||||
}
|
||||
|
||||
// Separation
|
||||
@ -1001,35 +1001,35 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
const dtCrowdAgent* nei = &m_agents[ag->neis[j].idx];
|
||||
|
||||
float diff[3];
|
||||
dtVsub(diff, ag->npos, nei->npos);
|
||||
rdVsub(diff, ag->npos, nei->npos);
|
||||
diff[2] = 0;
|
||||
|
||||
const float distSqr = dtVlenSqr(diff);
|
||||
const float distSqr = rdVlenSqr(diff);
|
||||
if (distSqr < 0.00001f)
|
||||
continue;
|
||||
if (distSqr > dtSqr(separationDist))
|
||||
if (distSqr > rdSqr(separationDist))
|
||||
continue;
|
||||
const float dist = dtMathSqrtf(distSqr);
|
||||
const float weight = separationWeight * (1.0f - dtSqr(dist*invSeparationDist));
|
||||
const float dist = rdMathSqrtf(distSqr);
|
||||
const float weight = separationWeight * (1.0f - rdSqr(dist*invSeparationDist));
|
||||
|
||||
dtVmad(disp, disp, diff, weight/dist);
|
||||
rdVmad(disp, disp, diff, weight/dist);
|
||||
w += 1.0f;
|
||||
}
|
||||
|
||||
if (w > 0.0001f)
|
||||
{
|
||||
// Adjust desired velocity.
|
||||
dtVmad(dvel, dvel, disp, 1.0f/w);
|
||||
rdVmad(dvel, dvel, disp, 1.0f/w);
|
||||
// Clamp desired velocity to desired speed.
|
||||
const float speedSqr = dtVlenSqr(dvel);
|
||||
const float desiredSqr = dtSqr(ag->desiredSpeed);
|
||||
const float speedSqr = rdVlenSqr(dvel);
|
||||
const float desiredSqr = rdSqr(ag->desiredSpeed);
|
||||
if (speedSqr > desiredSqr)
|
||||
dtVscale(dvel, dvel, desiredSqr/speedSqr);
|
||||
rdVscale(dvel, dvel, desiredSqr/speedSqr);
|
||||
}
|
||||
}
|
||||
|
||||
// Set the desired velocity.
|
||||
dtVcopy(ag->dvel, dvel);
|
||||
rdVcopy(ag->dvel, dvel);
|
||||
}
|
||||
|
||||
// Velocity planning.
|
||||
@ -1055,7 +1055,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
for (int j = 0; j < ag->boundary.getSegmentCount(); ++j)
|
||||
{
|
||||
const float* s = ag->boundary.getSegment(j);
|
||||
if (dtTriArea2D(ag->npos, s, s+3) < 0.0f)
|
||||
if (rdTriArea2D(ag->npos, s, s+3) < 0.0f)
|
||||
continue;
|
||||
m_obstacleQuery->addSegment(s, s+3);
|
||||
}
|
||||
@ -1085,7 +1085,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
else
|
||||
{
|
||||
// If not using velocity planning, new velocity is directly the desired velocity.
|
||||
dtVcopy(ag->nvel, ag->dvel);
|
||||
rdVcopy(ag->nvel, ag->dvel);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1111,7 +1111,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
|
||||
continue;
|
||||
|
||||
dtVset(ag->disp, 0,0,0);
|
||||
rdVset(ag->disp, 0,0,0);
|
||||
|
||||
float w = 0;
|
||||
|
||||
@ -1121,21 +1121,21 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
const int idx1 = getAgentIndex(nei);
|
||||
|
||||
float diff[3];
|
||||
dtVsub(diff, ag->npos, nei->npos);
|
||||
rdVsub(diff, ag->npos, nei->npos);
|
||||
diff[2] = 0;
|
||||
|
||||
float dist = dtVlenSqr(diff);
|
||||
if (dist > dtSqr(ag->params.radius + nei->params.radius))
|
||||
float dist = rdVlenSqr(diff);
|
||||
if (dist > rdSqr(ag->params.radius + nei->params.radius))
|
||||
continue;
|
||||
dist = dtMathSqrtf(dist);
|
||||
dist = rdMathSqrtf(dist);
|
||||
float pen = (ag->params.radius + nei->params.radius) - dist;
|
||||
if (dist < 0.0001f)
|
||||
{
|
||||
// Agents on top of each other, try to choose diverging separation directions.
|
||||
if (idx0 > idx1)
|
||||
dtVset(diff, -ag->dvel[1],0,ag->dvel[0]);
|
||||
rdVset(diff, -ag->dvel[1],0,ag->dvel[0]);
|
||||
else
|
||||
dtVset(diff, ag->dvel[1],0,-ag->dvel[0]);
|
||||
rdVset(diff, ag->dvel[1],0,-ag->dvel[0]);
|
||||
pen = 0.01f;
|
||||
}
|
||||
else
|
||||
@ -1143,7 +1143,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
pen = (1.0f/dist) * (pen*0.5f) * COLLISION_RESOLVE_FACTOR;
|
||||
}
|
||||
|
||||
dtVmad(ag->disp, ag->disp, diff, pen);
|
||||
rdVmad(ag->disp, ag->disp, diff, pen);
|
||||
|
||||
w += 1.0f;
|
||||
}
|
||||
@ -1151,7 +1151,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
if (w > 0.0001f)
|
||||
{
|
||||
const float iw = 1.0f / w;
|
||||
dtVscale(ag->disp, ag->disp, iw);
|
||||
rdVscale(ag->disp, ag->disp, iw);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1161,7 +1161,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
if (ag->state != DT_CROWDAGENT_STATE_WALKING)
|
||||
continue;
|
||||
|
||||
dtVadd(ag->npos, ag->npos, ag->disp);
|
||||
rdVadd(ag->npos, ag->npos, ag->disp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1174,7 +1174,7 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
// Move along navmesh.
|
||||
ag->corridor.movePosition(ag->npos, m_navquery, &m_filters[ag->params.queryFilterType]);
|
||||
// Get valid constrained position back.
|
||||
dtVcopy(ag->npos, ag->corridor.getPos());
|
||||
rdVcopy(ag->npos, ag->corridor.getPos());
|
||||
|
||||
// If not using path, truncate the corridor to just one poly.
|
||||
if (ag->targetState == DT_CROWDAGENT_TARGET_NONE || ag->targetState == DT_CROWDAGENT_TARGET_VELOCITY)
|
||||
@ -1210,16 +1210,16 @@ void dtCrowd::update(const float dt, dtCrowdAgentDebugInfo* debug)
|
||||
if (anim->t < ta)
|
||||
{
|
||||
const float u = tween(anim->t, 0.0, ta);
|
||||
dtVlerp(ag->npos, anim->initPos, anim->startPos, u);
|
||||
rdVlerp(ag->npos, anim->initPos, anim->startPos, u);
|
||||
}
|
||||
else
|
||||
{
|
||||
const float u = tween(anim->t, ta, tb);
|
||||
dtVlerp(ag->npos, anim->startPos, anim->endPos, u);
|
||||
rdVlerp(ag->npos, anim->startPos, anim->endPos, u);
|
||||
}
|
||||
|
||||
// Update velocity.
|
||||
dtVset(ag->vel, 0,0,0);
|
||||
dtVset(ag->dvel, 0,0,0);
|
||||
rdVset(ag->vel, 0,0,0);
|
||||
rdVset(ag->dvel, 0,0,0);
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,8 @@
|
||||
#include "DetourCrowd\Include\DetourObstacleAvoidance.h"
|
||||
#include "Detour\Include\DetourNavMesh.h"
|
||||
#include "Detour\Include\DetourNavMeshQuery.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Detour\Include\DetourMath.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "Shared\Include\SharedMath.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
|
||||
@ -37,17 +37,17 @@ void integrate(dtCrowdAgent* ag, const float dt)
|
||||
// Fake dynamic constraint.
|
||||
const float maxDelta = ag->params.maxAcceleration * dt;
|
||||
float dv[3];
|
||||
dtVsub(dv, ag->nvel, ag->vel);
|
||||
float ds = dtVlen(dv);
|
||||
rdVsub(dv, ag->nvel, ag->vel);
|
||||
float ds = rdVlen(dv);
|
||||
if (ds > maxDelta)
|
||||
dtVscale(dv, dv, maxDelta/ds);
|
||||
dtVadd(ag->vel, ag->vel, dv);
|
||||
rdVscale(dv, dv, maxDelta/ds);
|
||||
rdVadd(ag->vel, ag->vel, dv);
|
||||
|
||||
// Integrate
|
||||
if (dtVlen(ag->vel) > 0.0001f)
|
||||
dtVmad(ag->npos, ag->npos, ag->vel, dt);
|
||||
if (rdVlen(ag->vel) > 0.0001f)
|
||||
rdVmad(ag->npos, ag->npos, ag->vel, dt);
|
||||
else
|
||||
dtVset(ag->vel,0,0,0);
|
||||
rdVset(ag->vel,0,0,0);
|
||||
}
|
||||
|
||||
bool overOffmeshConnection(const dtCrowdAgent* ag, const float radius)
|
||||
@ -58,7 +58,7 @@ bool overOffmeshConnection(const dtCrowdAgent* ag, const float radius)
|
||||
const bool offMeshConnection = (ag->cornerFlags[ag->ncorners-1] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ? true : false;
|
||||
if (offMeshConnection)
|
||||
{
|
||||
const float distSq = dtVdist2DSqr(ag->npos, &ag->cornerVerts[(ag->ncorners-1)*3]);
|
||||
const float distSq = rdVdist2DSqr(ag->npos, &ag->cornerVerts[(ag->ncorners-1)*3]);
|
||||
if (distSq < radius*radius)
|
||||
return true;
|
||||
}
|
||||
@ -73,7 +73,7 @@ float getDistanceToGoal(const dtCrowdAgent* ag, const float range)
|
||||
|
||||
const bool endOfPath = (ag->cornerFlags[ag->ncorners-1] & DT_STRAIGHTPATH_END) ? true : false;
|
||||
if (endOfPath)
|
||||
return dtMin(dtVdist2D(ag->npos, &ag->cornerVerts[(ag->ncorners-1)*3]), range);
|
||||
return rdMin(rdVdist2D(ag->npos, &ag->cornerVerts[(ag->ncorners-1)*3]), range);
|
||||
|
||||
return range;
|
||||
}
|
||||
@ -82,43 +82,43 @@ void calcSmoothSteerDirection(const dtCrowdAgent* ag, float* dir)
|
||||
{
|
||||
if (!ag->ncorners)
|
||||
{
|
||||
dtVset(dir, 0,0,0);
|
||||
rdVset(dir, 0,0,0);
|
||||
return;
|
||||
}
|
||||
|
||||
const int ip0 = 0;
|
||||
const int ip1 = dtMin(1, ag->ncorners-1);
|
||||
const int ip1 = rdMin(1, ag->ncorners-1);
|
||||
const float* p0 = &ag->cornerVerts[ip0*3];
|
||||
const float* p1 = &ag->cornerVerts[ip1*3];
|
||||
|
||||
float dir0[3], dir1[3];
|
||||
dtVsub(dir0, p0, ag->npos);
|
||||
dtVsub(dir1, p1, ag->npos);
|
||||
rdVsub(dir0, p0, ag->npos);
|
||||
rdVsub(dir1, p1, ag->npos);
|
||||
dir0[2] = 0;
|
||||
dir1[2] = 0;
|
||||
|
||||
float len0 = dtVlen(dir0);
|
||||
float len1 = dtVlen(dir1);
|
||||
float len0 = rdVlen(dir0);
|
||||
float len1 = rdVlen(dir1);
|
||||
if (len1 > 0.001f)
|
||||
dtVscale(dir1,dir1,1.0f/len1);
|
||||
rdVscale(dir1,dir1,1.0f/len1);
|
||||
|
||||
dir[0] = dir0[0] - dir1[0]*len0*0.5f;
|
||||
dir[1] = dir0[1] - dir1[1]*len0*0.5f;
|
||||
dir[2] = 0;
|
||||
|
||||
dtVnormalize(dir);
|
||||
rdVnormalize(dir);
|
||||
}
|
||||
|
||||
void calcStraightSteerDirection(const dtCrowdAgent* ag, float* dir)
|
||||
{
|
||||
if (!ag->ncorners)
|
||||
{
|
||||
dtVset(dir, 0,0,0);
|
||||
rdVset(dir, 0,0,0);
|
||||
return;
|
||||
}
|
||||
dtVsub(dir, &ag->cornerVerts[0], ag->npos);
|
||||
rdVsub(dir, &ag->cornerVerts[0], ag->npos);
|
||||
dir[2] = 0;
|
||||
dtVnormalize(dir);
|
||||
rdVnormalize(dir);
|
||||
}
|
||||
|
||||
int addNeighbour(const int idx, const float dist,
|
||||
@ -144,7 +144,7 @@ int addNeighbour(const int idx, const float dist,
|
||||
break;
|
||||
|
||||
const int tgt = i+1;
|
||||
const int n = dtMin(nneis-i, maxNeis-tgt);
|
||||
const int n = rdMin(nneis-i, maxNeis-tgt);
|
||||
|
||||
rdAssert(tgt+n <= maxNeis);
|
||||
|
||||
@ -158,7 +158,7 @@ int addNeighbour(const int idx, const float dist,
|
||||
nei->idx = idx;
|
||||
nei->dist = dist;
|
||||
|
||||
return dtMin(nneis+1, maxNeis);
|
||||
return rdMin(nneis+1, maxNeis);
|
||||
}
|
||||
|
||||
int getNeighbours(const float* pos, const float height, const float range,
|
||||
@ -181,12 +181,12 @@ int getNeighbours(const float* pos, const float height, const float range,
|
||||
|
||||
// Check for overlap.
|
||||
float diff[3];
|
||||
dtVsub(diff, pos, ag->npos);
|
||||
if (dtMathFabsf(diff[2]) >= (height+ag->params.height)/2.0f)
|
||||
rdVsub(diff, pos, ag->npos);
|
||||
if (rdMathFabsf(diff[2]) >= (height+ag->params.height)/2.0f)
|
||||
continue;
|
||||
diff[2] = 0;
|
||||
const float distSqr = dtVlenSqr(diff);
|
||||
if (distSqr > dtSqr(range))
|
||||
const float distSqr = rdVlenSqr(diff);
|
||||
if (distSqr > rdSqr(range))
|
||||
continue;
|
||||
|
||||
n = addNeighbour(ids[i], distSqr, result, n, maxResult);
|
||||
@ -216,7 +216,7 @@ int addToOptQueue(dtCrowdAgent* newag, dtCrowdAgent** agents, const int nagents,
|
||||
break;
|
||||
|
||||
const int tgt = i+1;
|
||||
const int n = dtMin(nagents-i, maxAgents-tgt);
|
||||
const int n = rdMin(nagents-i, maxAgents-tgt);
|
||||
|
||||
rdAssert(tgt+n <= maxAgents);
|
||||
|
||||
@ -227,7 +227,7 @@ int addToOptQueue(dtCrowdAgent* newag, dtCrowdAgent** agents, const int nagents,
|
||||
|
||||
agents[slot] = newag;
|
||||
|
||||
return dtMin(nagents+1, maxAgents);
|
||||
return rdMin(nagents+1, maxAgents);
|
||||
}
|
||||
|
||||
int addToPathQueue(dtCrowdAgent* newag, dtCrowdAgent** agents, const int nagents, const int maxAgents)
|
||||
@ -252,7 +252,7 @@ int addToPathQueue(dtCrowdAgent* newag, dtCrowdAgent** agents, const int nagents
|
||||
break;
|
||||
|
||||
const int tgt = i+1;
|
||||
const int n = dtMin(nagents-i, maxAgents-tgt);
|
||||
const int n = rdMin(nagents-i, maxAgents-tgt);
|
||||
|
||||
rdAssert(tgt+n <= maxAgents);
|
||||
|
||||
@ -263,5 +263,5 @@ int addToPathQueue(dtCrowdAgent* newag, dtCrowdAgent** agents, const int nagents
|
||||
|
||||
agents[slot] = newag;
|
||||
|
||||
return dtMin(nagents+1, maxAgents);
|
||||
return rdMin(nagents+1, maxAgents);
|
||||
}
|
@ -20,7 +20,7 @@
|
||||
#include <string.h>
|
||||
#include "DetourCrowd\Include\DetourLocalBoundary.h"
|
||||
#include "Detour\Include\DetourNavMeshQuery.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ dtLocalBoundary::dtLocalBoundary() :
|
||||
m_nsegs(0),
|
||||
m_npolys(0)
|
||||
{
|
||||
dtVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
rdVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
}
|
||||
|
||||
dtLocalBoundary::~dtLocalBoundary()
|
||||
@ -37,7 +37,7 @@ dtLocalBoundary::~dtLocalBoundary()
|
||||
|
||||
void dtLocalBoundary::reset()
|
||||
{
|
||||
dtVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
rdVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
m_npolys = 0;
|
||||
m_nsegs = 0;
|
||||
}
|
||||
@ -67,7 +67,7 @@ void dtLocalBoundary::addSegment(const float dist, const float* s)
|
||||
if (dist <= m_segs[i].d)
|
||||
break;
|
||||
const int tgt = i+1;
|
||||
const int n = dtMin(m_nsegs-i, MAX_LOCAL_SEGS-tgt);
|
||||
const int n = rdMin(m_nsegs-i, MAX_LOCAL_SEGS-tgt);
|
||||
rdAssert(tgt+n <= MAX_LOCAL_SEGS);
|
||||
if (n > 0)
|
||||
memmove(&m_segs[tgt], &m_segs[i], sizeof(Segment)*n);
|
||||
@ -88,13 +88,13 @@ void dtLocalBoundary::update(dtPolyRef ref, const float* pos, const float collis
|
||||
|
||||
if (!ref)
|
||||
{
|
||||
dtVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
rdVset(m_center, FLT_MAX,FLT_MAX,FLT_MAX);
|
||||
m_nsegs = 0;
|
||||
m_npolys = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
dtVcopy(m_center, pos);
|
||||
rdVcopy(m_center, pos);
|
||||
|
||||
// First query non-overlapping polygons.
|
||||
navquery->findLocalNeighbourhood(ref, pos, collisionQueryRange,
|
||||
@ -112,8 +112,8 @@ void dtLocalBoundary::update(dtPolyRef ref, const float* pos, const float collis
|
||||
const float* s = &segs[k*6];
|
||||
// Skip too distant segments.
|
||||
float tseg;
|
||||
const float distSqr = dtDistancePtSegSqr2D(pos, s, s+3, tseg);
|
||||
if (distSqr > dtSqr(collisionQueryRange))
|
||||
const float distSqr = rdDistancePtSegSqr2D(pos, s, s+3, tseg);
|
||||
if (distSqr > rdSqr(collisionQueryRange))
|
||||
continue;
|
||||
addSegment(distSqr, s);
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
//
|
||||
|
||||
#include "DetourCrowd\Include\DetourObstacleAvoidance.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Detour\Include\DetourMath.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "Shared\Include\SharedMath.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
#include <string.h>
|
||||
@ -31,18 +31,18 @@ static int sweepCircleCircle(const float* c0, const float r0, const float* v,
|
||||
{
|
||||
static const float EPS = 0.0001f;
|
||||
float s[3];
|
||||
dtVsub(s,c1,c0);
|
||||
rdVsub(s,c1,c0);
|
||||
float r = r0+r1;
|
||||
float c = dtVdot2D(s,s) - r*r;
|
||||
float a = dtVdot2D(v,v);
|
||||
float c = rdVdot2D(s,s) - r*r;
|
||||
float a = rdVdot2D(v,v);
|
||||
if (a < EPS) return 0; // not moving
|
||||
|
||||
// Overlap, calc time to exit.
|
||||
float b = dtVdot2D(v,s);
|
||||
float b = rdVdot2D(v,s);
|
||||
float d = b*b - a*c;
|
||||
if (d < 0.0f) return 0; // no intersection.
|
||||
a = 1.0f / a;
|
||||
const float rd = dtMathSqrtf(d);
|
||||
const float rd = rdMathSqrtf(d);
|
||||
tmin = (b - rd) * a;
|
||||
tmax = (b + rd) * a;
|
||||
return 1;
|
||||
@ -53,14 +53,14 @@ static int isectRaySeg(const float* ap, const float* u,
|
||||
float& t)
|
||||
{
|
||||
float v[3], w[3];
|
||||
dtVsub(v,bq,bp);
|
||||
dtVsub(w,ap,bp);
|
||||
float d = dtVperp2D(u,v);
|
||||
if (dtMathFabsf(d) < 1e-6f) return 0;
|
||||
rdVsub(v,bq,bp);
|
||||
rdVsub(w,ap,bp);
|
||||
float d = rdVperp2D(u,v);
|
||||
if (rdMathFabsf(d) < 1e-6f) return 0;
|
||||
d = 1.0f/d;
|
||||
t = dtVperp2D(v,w) * d;
|
||||
t = rdVperp2D(v,w) * d;
|
||||
if (t < 0 || t > 1) return 0;
|
||||
float s = dtVperp2D(u,w) * d;
|
||||
float s = rdVperp2D(u,w) * d;
|
||||
if (s < 0 || s > 1) return 0;
|
||||
return 1;
|
||||
}
|
||||
@ -153,7 +153,7 @@ void dtObstacleAvoidanceDebugData::addSample(const float* vel, const float ssize
|
||||
rdAssert(m_vcpen);
|
||||
rdAssert(m_spen);
|
||||
rdAssert(m_tpen);
|
||||
dtVcopy(&m_vel[m_nsamples*3], vel);
|
||||
rdVcopy(&m_vel[m_nsamples*3], vel);
|
||||
m_ssize[m_nsamples] = ssize;
|
||||
m_pen[m_nsamples] = pen;
|
||||
m_vpen[m_nsamples] = vpen;
|
||||
@ -170,13 +170,13 @@ static void normalizeArray(float* arr, const int n)
|
||||
float maxPen = -FLT_MAX;
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
minPen = dtMin(minPen, arr[i]);
|
||||
maxPen = dtMax(maxPen, arr[i]);
|
||||
minPen = rdMin(minPen, arr[i]);
|
||||
maxPen = rdMax(maxPen, arr[i]);
|
||||
}
|
||||
const float penRange = maxPen-minPen;
|
||||
const float s = penRange > 0.001f ? (1.0f / penRange) : 1;
|
||||
for (int i = 0; i < n; ++i)
|
||||
arr[i] = dtClamp((arr[i]-minPen)*s, 0.0f, 1.0f);
|
||||
arr[i] = rdClamp((arr[i]-minPen)*s, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
void dtObstacleAvoidanceDebugData::normalizeSamples()
|
||||
@ -255,10 +255,10 @@ void dtObstacleAvoidanceQuery::addCircle(const float* pos, const float rad,
|
||||
return;
|
||||
|
||||
dtObstacleCircle* cir = &m_circles[m_ncircles++];
|
||||
dtVcopy(cir->p, pos);
|
||||
rdVcopy(cir->p, pos);
|
||||
cir->rad = rad;
|
||||
dtVcopy(cir->vel, vel);
|
||||
dtVcopy(cir->dvel, dvel);
|
||||
rdVcopy(cir->vel, vel);
|
||||
rdVcopy(cir->dvel, dvel);
|
||||
}
|
||||
|
||||
void dtObstacleAvoidanceQuery::addSegment(const float* p, const float* q)
|
||||
@ -267,8 +267,8 @@ void dtObstacleAvoidanceQuery::addSegment(const float* p, const float* q)
|
||||
return;
|
||||
|
||||
dtObstacleSegment* seg = &m_segments[m_nsegments++];
|
||||
dtVcopy(seg->p, p);
|
||||
dtVcopy(seg->q, q);
|
||||
rdVcopy(seg->p, p);
|
||||
rdVcopy(seg->q, q);
|
||||
}
|
||||
|
||||
void dtObstacleAvoidanceQuery::prepare(const float* pos, const float* dvel)
|
||||
@ -284,11 +284,11 @@ void dtObstacleAvoidanceQuery::prepare(const float* pos, const float* dvel)
|
||||
|
||||
const float orig[3] = {0,0,0};
|
||||
float dv[3];
|
||||
dtVsub(cir->dp,pb,pa);
|
||||
dtVnormalize(cir->dp);
|
||||
dtVsub(dv, cir->dvel, dvel);
|
||||
rdVsub(cir->dp,pb,pa);
|
||||
rdVnormalize(cir->dp);
|
||||
rdVsub(dv, cir->dvel, dvel);
|
||||
|
||||
const float a = dtTriArea2D(orig, cir->dp,dv);
|
||||
const float a = rdTriArea2D(orig, cir->dp,dv);
|
||||
if (a < 0.01f)
|
||||
{
|
||||
cir->np[0] = -cir->dp[1];
|
||||
@ -308,7 +308,7 @@ void dtObstacleAvoidanceQuery::prepare(const float* pos, const float* dvel)
|
||||
// Precalc if the agent is really close to the segment.
|
||||
const float r = 0.01f;
|
||||
float t;
|
||||
seg->touch = dtDistancePtSegSqr2D(pos, seg->p, seg->q, t) < dtSqr(r);
|
||||
seg->touch = rdDistancePtSegSqr2D(pos, seg->p, seg->q, t) < rdSqr(r);
|
||||
}
|
||||
}
|
||||
|
||||
@ -326,8 +326,8 @@ float dtObstacleAvoidanceQuery::processSample(const float* vcand, const float cs
|
||||
dtObstacleAvoidanceDebugData* debug)
|
||||
{
|
||||
// penalty for straying away from the desired and current velocities
|
||||
const float vpen = m_params.weightDesVel * (dtVdist2D(vcand, dvel) * m_invVmax);
|
||||
const float vcpen = m_params.weightCurVel * (dtVdist2D(vcand, vel) * m_invVmax);
|
||||
const float vpen = m_params.weightDesVel * (rdVdist2D(vcand, dvel) * m_invVmax);
|
||||
const float vcpen = m_params.weightCurVel * (rdVdist2D(vcand, vel) * m_invVmax);
|
||||
|
||||
// find the threshold hit time to bail out based on the early out penalty
|
||||
// (see how the penalty is calculated below to understnad)
|
||||
@ -347,12 +347,12 @@ float dtObstacleAvoidanceQuery::processSample(const float* vcand, const float cs
|
||||
|
||||
// RVO
|
||||
float vab[3];
|
||||
dtVscale(vab, vcand, 2);
|
||||
dtVsub(vab, vab, vel);
|
||||
dtVsub(vab, vab, cir->vel);
|
||||
rdVscale(vab, vcand, 2);
|
||||
rdVsub(vab, vab, vel);
|
||||
rdVsub(vab, vab, cir->vel);
|
||||
|
||||
// Side
|
||||
side += dtClamp(dtMin(dtVdot2D(cir->dp,vab)*0.5f+0.5f, dtVdot2D(cir->np,vab)*2), 0.0f, 1.0f);
|
||||
side += rdClamp(rdMin(rdVdot2D(cir->dp,vab)*0.5f+0.5f, rdVdot2D(cir->np,vab)*2), 0.0f, 1.0f);
|
||||
nside++;
|
||||
|
||||
float htmin = 0, htmax = 0;
|
||||
@ -387,11 +387,11 @@ float dtObstacleAvoidanceQuery::processSample(const float* vcand, const float cs
|
||||
{
|
||||
// Special case when the agent is very close to the segment.
|
||||
float sdir[3], snorm[3];
|
||||
dtVsub(sdir, seg->q, seg->p);
|
||||
rdVsub(sdir, seg->q, seg->p);
|
||||
snorm[0] = -sdir[1];
|
||||
snorm[1] = sdir[0];
|
||||
// If the velocity is pointing towards the segment, no collision.
|
||||
if (dtVdot2D(snorm, vcand) < 0.0f)
|
||||
if (rdVdot2D(snorm, vcand) < 0.0f)
|
||||
continue;
|
||||
// Else immediate collision.
|
||||
htmin = 0.0f;
|
||||
@ -442,7 +442,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float r
|
||||
m_vmax = vmax;
|
||||
m_invVmax = vmax > 0 ? 1.0f / vmax : FLT_MAX;
|
||||
|
||||
dtVset(nvel, 0,0,0);
|
||||
rdVset(nvel, 0,0,0);
|
||||
|
||||
if (debug)
|
||||
debug->reset();
|
||||
@ -464,14 +464,14 @@ int dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float r
|
||||
vcand[1] = cvy + y*cs - half;
|
||||
vcand[2] = 0;
|
||||
|
||||
if (dtSqr(vcand[0])+dtSqr(vcand[1]) > dtSqr(vmax+cs/2)) continue;
|
||||
if (rdSqr(vcand[0])+rdSqr(vcand[1]) > rdSqr(vmax+cs/2)) continue;
|
||||
|
||||
const float penalty = processSample(vcand, cs, pos,rad,vel,dvel, minPenalty, debug);
|
||||
ns++;
|
||||
if (penalty < minPenalty)
|
||||
{
|
||||
minPenalty = penalty;
|
||||
dtVcopy(nvel, vcand);
|
||||
rdVcopy(nvel, vcand);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -483,7 +483,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityGrid(const float* pos, const float r
|
||||
// vector normalization that ignores the z-component.
|
||||
inline void dtNormalize2D(float* v)
|
||||
{
|
||||
float d = dtMathSqrtf(v[0] * v[0] + v[1] * v[1]);
|
||||
float d = rdMathSqrtf(v[0] * v[0] + v[1] * v[1]);
|
||||
if (d==0)
|
||||
return;
|
||||
d = 1.0f / d;
|
||||
@ -514,7 +514,7 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
m_vmax = vmax;
|
||||
m_invVmax = vmax > 0 ? 1.0f / vmax : FLT_MAX;
|
||||
|
||||
dtVset(nvel, 0,0,0);
|
||||
rdVset(nvel, 0,0,0);
|
||||
|
||||
if (debug)
|
||||
debug->reset();
|
||||
@ -527,15 +527,15 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
const int nrings= (int)m_params.adaptiveRings;
|
||||
const int depth = (int)m_params.adaptiveDepth;
|
||||
|
||||
const int nd = dtClamp(ndivs, 1, DT_MAX_PATTERN_DIVS);
|
||||
const int nr = dtClamp(nrings, 1, DT_MAX_PATTERN_RINGS);
|
||||
const float da = (1.0f/nd) * DT_PI*2;
|
||||
const int nd = rdClamp(ndivs, 1, DT_MAX_PATTERN_DIVS);
|
||||
const int nr = rdClamp(nrings, 1, DT_MAX_PATTERN_RINGS);
|
||||
const float da = (1.0f/nd) * RD_PI*2;
|
||||
const float ca = cosf(da);
|
||||
const float sa = sinf(da);
|
||||
|
||||
// desired direction
|
||||
float ddir[6];
|
||||
dtVcopy(ddir, dvel);
|
||||
rdVcopy(ddir, dvel);
|
||||
dtNormalize2D(ddir);
|
||||
dtRorate2D (ddir+3, ddir, da*0.5f); // rotated by da/2
|
||||
|
||||
@ -579,14 +579,14 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
// Start sampling.
|
||||
float cr = vmax * (1.0f - m_params.velBias);
|
||||
float res[3];
|
||||
dtVset(res, dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias);
|
||||
rdVset(res, dvel[0] * m_params.velBias, 0, dvel[2] * m_params.velBias);
|
||||
int ns = 0;
|
||||
|
||||
for (int k = 0; k < depth; ++k)
|
||||
{
|
||||
float minPenalty = FLT_MAX;
|
||||
float bvel[3];
|
||||
dtVset(bvel, 0,0,0);
|
||||
rdVset(bvel, 0,0,0);
|
||||
|
||||
for (int i = 0; i < npat; ++i)
|
||||
{
|
||||
@ -595,23 +595,23 @@ int dtObstacleAvoidanceQuery::sampleVelocityAdaptive(const float* pos, const flo
|
||||
vcand[1] = res[1] + pat[i*2+1]*cr;
|
||||
vcand[2] = 0;
|
||||
|
||||
if (dtSqr(vcand[0])+dtSqr(vcand[1]) > dtSqr(vmax+0.001f)) continue;
|
||||
if (rdSqr(vcand[0])+rdSqr(vcand[1]) > rdSqr(vmax+0.001f)) continue;
|
||||
|
||||
const float penalty = processSample(vcand,cr/10, pos,rad,vel,dvel, minPenalty, debug);
|
||||
ns++;
|
||||
if (penalty < minPenalty)
|
||||
{
|
||||
minPenalty = penalty;
|
||||
dtVcopy(bvel, vcand);
|
||||
rdVcopy(bvel, vcand);
|
||||
}
|
||||
}
|
||||
|
||||
dtVcopy(res, bvel);
|
||||
rdVcopy(res, bvel);
|
||||
|
||||
cr *= 0.5f;
|
||||
}
|
||||
|
||||
dtVcopy(nvel, res);
|
||||
rdVcopy(nvel, res);
|
||||
|
||||
return ns;
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#include <string.h>
|
||||
#include "DetourCrowd\Include\DetourPathCorridor.h"
|
||||
#include "Detour\Include\DetourNavMeshQuery.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
|
||||
@ -55,8 +55,8 @@ int dtMergeCorridorStartMoved(dtPolyRef* path, const int npath, const int maxPat
|
||||
|
||||
// Adjust beginning of the buffer to include the visited.
|
||||
const int req = nvisited - furthestVisited;
|
||||
const int orig = dtMin(furthestPath+1, npath);
|
||||
int size = dtMax(0, npath-orig);
|
||||
const int orig = rdMin(furthestPath+1, npath);
|
||||
int size = rdMax(0, npath-orig);
|
||||
if (req+size > maxPath)
|
||||
size = maxPath-req;
|
||||
if (size > 0)
|
||||
@ -99,7 +99,7 @@ int dtMergeCorridorEndMoved(dtPolyRef* path, const int npath, const int maxPath,
|
||||
// Concatenate paths.
|
||||
const int ppos = furthestPath+1;
|
||||
const int vpos = furthestVisited+1;
|
||||
const int count = dtMin(nvisited-vpos, maxPath-ppos);
|
||||
const int count = rdMin(nvisited-vpos, maxPath-ppos);
|
||||
rdAssert(ppos+count <= maxPath);
|
||||
if (count)
|
||||
memcpy(path+ppos, visited+vpos, sizeof(dtPolyRef)*count);
|
||||
@ -142,7 +142,7 @@ int dtMergeCorridorStartShortcut(dtPolyRef* path, const int npath, const int max
|
||||
return npath;
|
||||
|
||||
const int orig = furthestPath;
|
||||
int size = dtMax(0, npath-orig);
|
||||
int size = rdMax(0, npath-orig);
|
||||
if (req+size > maxPath)
|
||||
size = maxPath-req;
|
||||
if (size)
|
||||
@ -230,8 +230,8 @@ bool dtPathCorridor::init(const int maxPath)
|
||||
void dtPathCorridor::reset(dtPolyRef ref, const float* pos)
|
||||
{
|
||||
rdAssert(m_path);
|
||||
dtVcopy(m_pos, pos);
|
||||
dtVcopy(m_target, pos);
|
||||
rdVcopy(m_pos, pos);
|
||||
rdVcopy(m_target, pos);
|
||||
m_path[0] = ref;
|
||||
m_npath = 1;
|
||||
}
|
||||
@ -265,7 +265,7 @@ int dtPathCorridor::findCorners(float* cornerVerts, unsigned char* cornerFlags,
|
||||
while (ncorners)
|
||||
{
|
||||
if ((cornerFlags[0] & DT_STRAIGHTPATH_OFFMESH_CONNECTION) ||
|
||||
dtVdist2DSqr(&cornerVerts[0], m_pos) > dtSqr(MIN_TARGET_DIST))
|
||||
rdVdist2DSqr(&cornerVerts[0], m_pos) > rdSqr(MIN_TARGET_DIST))
|
||||
break;
|
||||
ncorners--;
|
||||
if (ncorners)
|
||||
@ -314,20 +314,20 @@ void dtPathCorridor::optimizePathVisibility(const float* next, const float pathO
|
||||
|
||||
// Clamp the ray to max distance.
|
||||
float goal[3];
|
||||
dtVcopy(goal, next);
|
||||
float dist = dtVdist2D(m_pos, goal);
|
||||
rdVcopy(goal, next);
|
||||
float dist = rdVdist2D(m_pos, goal);
|
||||
|
||||
// If too close to the goal, do not try to optimize.
|
||||
if (dist < 0.01f)
|
||||
return;
|
||||
|
||||
// Overshoot a little. This helps to optimize open fields in tiled meshes.
|
||||
dist = dtMin(dist+0.01f, pathOptimizationRange);
|
||||
dist = rdMin(dist+0.01f, pathOptimizationRange);
|
||||
|
||||
// Adjust ray length.
|
||||
float delta[3];
|
||||
dtVsub(delta, goal, m_pos);
|
||||
dtVmad(goal, m_pos, delta, pathOptimizationRange/dist);
|
||||
rdVsub(delta, goal, m_pos);
|
||||
rdVmad(goal, m_pos, delta, pathOptimizationRange/dist);
|
||||
|
||||
static const int MAX_RES = 32;
|
||||
dtPolyRef res[MAX_RES];
|
||||
@ -414,7 +414,7 @@ bool dtPathCorridor::moveOverOffmeshConnection(dtPolyRef offMeshConRef, dtPolyRe
|
||||
dtStatus status = nav->getOffMeshConnectionPolyEndPoints(refs[0], refs[1], startPos, endPos);
|
||||
if (dtStatusSucceed(status))
|
||||
{
|
||||
dtVcopy(m_pos, endPos);
|
||||
rdVcopy(m_pos, endPos);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -455,7 +455,7 @@ bool dtPathCorridor::movePosition(const float* npos, dtNavMeshQuery* navquery, c
|
||||
float h = m_pos[2];
|
||||
navquery->getPolyHeight(m_path[0], result, &h);
|
||||
result[2] = h;
|
||||
dtVcopy(m_pos, result);
|
||||
rdVcopy(m_pos, result);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -495,7 +495,7 @@ bool dtPathCorridor::moveTargetPosition(const float* npos, dtNavMeshQuery* navqu
|
||||
navquery->getPolyHeight(m_path[m_npath-1], result, &h);
|
||||
result[2] = h;*/
|
||||
|
||||
dtVcopy(m_target, result);
|
||||
rdVcopy(m_target, result);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -514,7 +514,7 @@ void dtPathCorridor::setCorridor(const float* target, const dtPolyRef* path, con
|
||||
rdAssert(npath > 0);
|
||||
rdAssert(npath <= m_maxPath);
|
||||
|
||||
dtVcopy(m_target, target);
|
||||
rdVcopy(m_target, target);
|
||||
memcpy(m_path, path, sizeof(dtPolyRef)*npath);
|
||||
m_npath = npath;
|
||||
}
|
||||
@ -523,7 +523,7 @@ bool dtPathCorridor::fixPathStart(dtPolyRef safeRef, const float* safePos)
|
||||
{
|
||||
rdAssert(m_path);
|
||||
|
||||
dtVcopy(m_pos, safePos);
|
||||
rdVcopy(m_pos, safePos);
|
||||
if (m_npath < 3 && m_npath > 0)
|
||||
{
|
||||
m_path[2] = m_path[m_npath-1];
|
||||
@ -561,7 +561,7 @@ bool dtPathCorridor::trimInvalidPath(dtPolyRef safeRef, const float* safePos,
|
||||
else if (n == 0)
|
||||
{
|
||||
// The first polyref is bad, use current safe values.
|
||||
dtVcopy(m_pos, safePos);
|
||||
rdVcopy(m_pos, safePos);
|
||||
m_path[0] = safeRef;
|
||||
m_npath = 1;
|
||||
}
|
||||
@ -573,7 +573,7 @@ bool dtPathCorridor::trimInvalidPath(dtPolyRef safeRef, const float* safePos,
|
||||
|
||||
// Clamp target pos to last poly
|
||||
float tgt[3];
|
||||
dtVcopy(tgt, m_target);
|
||||
rdVcopy(tgt, m_target);
|
||||
navquery->closestPointOnPolyBoundary(m_path[m_npath-1], tgt, m_target);
|
||||
|
||||
return true;
|
||||
@ -586,7 +586,7 @@ bool dtPathCorridor::trimInvalidPath(dtPolyRef safeRef, const float* safePos,
|
||||
bool dtPathCorridor::isValid(const int maxLookAhead, dtNavMeshQuery* navquery, const dtQueryFilter* filter)
|
||||
{
|
||||
// Check that all polygons still pass query filter.
|
||||
const int n = dtMin(m_npath, maxLookAhead);
|
||||
const int n = rdMin(m_npath, maxLookAhead);
|
||||
for (int i = 0; i < n; ++i)
|
||||
{
|
||||
if (!navquery->isValidPolyRef(m_path[i], filter))
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "Detour\Include\DetourNavMesh.h"
|
||||
#include "Detour\Include\DetourNavMeshQuery.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
|
||||
|
||||
dtPathQueue::dtPathQueue() :
|
||||
@ -155,9 +155,9 @@ dtPathQueueRef dtPathQueue::request(dtPolyRef startRef, dtPolyRef endRef,
|
||||
|
||||
PathQuery& q = m_queue[slot];
|
||||
q.ref = ref;
|
||||
dtVcopy(q.startPos, startPos);
|
||||
rdVcopy(q.startPos, startPos);
|
||||
q.startRef = startRef;
|
||||
dtVcopy(q.endPos, endPos);
|
||||
rdVcopy(q.endPos, endPos);
|
||||
q.endRef = endRef;
|
||||
|
||||
q.status = 0;
|
||||
@ -190,7 +190,7 @@ dtStatus dtPathQueue::getPathResult(dtPathQueueRef ref, dtPolyRef* path, int* pa
|
||||
q.ref = DT_PATHQ_INVALID;
|
||||
q.status = 0;
|
||||
// Copy path
|
||||
int n = dtMin(q.npath, maxPath);
|
||||
int n = rdMin(q.npath, maxPath);
|
||||
memcpy(path, q.path, sizeof(dtPolyRef)*n);
|
||||
*pathSize = n;
|
||||
return details | DT_SUCCESS;
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <new>
|
||||
#include "Shared\Include\SharedMath.h"
|
||||
#include "Shared\Include\SharedCommon.h"
|
||||
#include "DetourCrowd\Include\DetourProximityGrid.h"
|
||||
#include "Detour\Include\DetourCommon.h"
|
||||
#include "Detour\Include\DetourMath.h"
|
||||
#include "Shared\Include\SharedAlloc.h"
|
||||
#include "Shared\Include\SharedAssert.h"
|
||||
|
||||
@ -72,7 +72,7 @@ bool dtProximityGrid::init(const int poolSize, const float cellSize)
|
||||
m_invCellSize = 1.0f / m_cellSize;
|
||||
|
||||
// Allocate hashs buckets
|
||||
m_bucketsSize = dtNextPow2(poolSize);
|
||||
m_bucketsSize = rdNextPow2(poolSize);
|
||||
m_buckets = (unsigned short*)rdAlloc(sizeof(unsigned short)*m_bucketsSize, RD_ALLOC_PERM);
|
||||
if (!m_buckets)
|
||||
return false;
|
||||
@ -103,15 +103,15 @@ void dtProximityGrid::addItem(const unsigned short id,
|
||||
const float minx, const float miny,
|
||||
const float maxx, const float maxy)
|
||||
{
|
||||
const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
|
||||
const int iminx = (int)rdMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)rdMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)rdMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)rdMathFloorf(maxy * m_invCellSize);
|
||||
|
||||
m_bounds[0] = dtMin(m_bounds[0], iminx);
|
||||
m_bounds[1] = dtMin(m_bounds[1], iminy);
|
||||
m_bounds[2] = dtMax(m_bounds[2], imaxx);
|
||||
m_bounds[3] = dtMax(m_bounds[3], imaxy);
|
||||
m_bounds[0] = rdMin(m_bounds[0], iminx);
|
||||
m_bounds[1] = rdMin(m_bounds[1], iminy);
|
||||
m_bounds[2] = rdMax(m_bounds[2], imaxx);
|
||||
m_bounds[3] = rdMax(m_bounds[3], imaxy);
|
||||
|
||||
for (int y = iminy; y <= imaxy; ++y)
|
||||
{
|
||||
@ -137,10 +137,10 @@ int dtProximityGrid::queryItems(const float minx, const float miny,
|
||||
const float maxx, const float maxy,
|
||||
unsigned short* ids, const int maxIds) const
|
||||
{
|
||||
const int iminx = (int)dtMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)dtMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)dtMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)dtMathFloorf(maxy * m_invCellSize);
|
||||
const int iminx = (int)rdMathFloorf(minx * m_invCellSize);
|
||||
const int iminy = (int)rdMathFloorf(miny * m_invCellSize);
|
||||
const int imaxx = (int)rdMathFloorf(maxx * m_invCellSize);
|
||||
const int imaxy = (int)rdMathFloorf(maxy * m_invCellSize);
|
||||
|
||||
int n = 0;
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "DetourTileCache/Include/DetourTileCache.h"
|
||||
#include "DetourTileCache/Include/DetourTileCacheBuilder.h"
|
||||
#include "Detour/Include/DetourNavMeshBuilder.h"
|
||||
#include "Detour/Include/DetourNavMesh.h"
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Shared/Include/SharedAlloc.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include <string.h>
|
||||
@ -140,7 +140,7 @@ dtStatus dtTileCache::init(const dtTileCacheParams* params,
|
||||
}
|
||||
|
||||
// Init tiles
|
||||
m_tileLutSize = dtNextPow2(m_params.maxTiles/4);
|
||||
m_tileLutSize = rdNextPow2(m_params.maxTiles/4);
|
||||
if (!m_tileLutSize) m_tileLutSize = 1;
|
||||
m_tileLutMask = m_tileLutSize-1;
|
||||
|
||||
@ -161,7 +161,7 @@ dtStatus dtTileCache::init(const dtTileCacheParams* params,
|
||||
}
|
||||
|
||||
// Init ID generator values.
|
||||
m_tileBits = dtIlog2(dtNextPow2((unsigned int)m_params.maxTiles));
|
||||
m_tileBits = rdIlog2(rdNextPow2((unsigned int)m_params.maxTiles));
|
||||
m_saltBits = 32 - m_tileBits;
|
||||
|
||||
return DT_SUCCESS;
|
||||
@ -268,7 +268,7 @@ dtStatus dtTileCache::addTile(unsigned char* data, const int dataSize, unsigned
|
||||
m_posLookup[h] = tile;
|
||||
|
||||
// Init tile.
|
||||
const int headerSize = dtAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
const int headerSize = rdAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
tile->header = (dtTileCacheLayerHeader*)data;
|
||||
tile->data = data;
|
||||
tile->dataSize = dataSize;
|
||||
@ -368,7 +368,7 @@ dtStatus dtTileCache::addObstacle(const float* pos, const float radius, const fl
|
||||
ob->salt = salt;
|
||||
ob->state = DT_OBSTACLE_PROCESSING;
|
||||
ob->type = DT_OBSTACLE_CYLINDER;
|
||||
dtVcopy(ob->cylinder.pos, pos);
|
||||
rdVcopy(ob->cylinder.pos, pos);
|
||||
ob->cylinder.radius = radius;
|
||||
ob->cylinder.height = height;
|
||||
|
||||
@ -403,8 +403,8 @@ dtStatus dtTileCache::addBoxObstacle(const float* bmin, const float* bmax, dtObs
|
||||
ob->salt = salt;
|
||||
ob->state = DT_OBSTACLE_PROCESSING;
|
||||
ob->type = DT_OBSTACLE_BOX;
|
||||
dtVcopy(ob->box.bmin, bmin);
|
||||
dtVcopy(ob->box.bmax, bmax);
|
||||
rdVcopy(ob->box.bmin, bmin);
|
||||
rdVcopy(ob->box.bmax, bmax);
|
||||
|
||||
ObstacleRequest* req = &m_reqs[m_nreqs++];
|
||||
memset(req, 0, sizeof(ObstacleRequest));
|
||||
@ -437,8 +437,8 @@ dtStatus dtTileCache::addBoxObstacle(const float* center, const float* halfExten
|
||||
ob->salt = salt;
|
||||
ob->state = DT_OBSTACLE_PROCESSING;
|
||||
ob->type = DT_OBSTACLE_ORIENTED_BOX;
|
||||
dtVcopy(ob->orientedBox.center, center);
|
||||
dtVcopy(ob->orientedBox.halfExtents, halfExtents);
|
||||
rdVcopy(ob->orientedBox.center, center);
|
||||
rdVcopy(ob->orientedBox.halfExtents, halfExtents);
|
||||
|
||||
float coshalf= cosf(0.5f*yRadians);
|
||||
float sinhalf = sinf(-0.5f*yRadians);
|
||||
@ -481,10 +481,10 @@ dtStatus dtTileCache::queryTiles(const float* bmin, const float* bmax,
|
||||
|
||||
const float tw = m_params.width * m_params.cs;
|
||||
const float th = m_params.height * m_params.cs;
|
||||
const int tx0 = (int)dtMathFloorf((bmin[0]-m_params.orig[0]) / tw);
|
||||
const int tx1 = (int)dtMathFloorf((bmax[0]-m_params.orig[0]) / tw);
|
||||
const int ty0 = (int)dtMathFloorf((bmin[1]-m_params.orig[1]) / th);
|
||||
const int ty1 = (int)dtMathFloorf((bmax[1]-m_params.orig[1]) / th);
|
||||
const int tx0 = (int)rdMathFloorf((bmin[0]-m_params.orig[0]) / tw);
|
||||
const int tx1 = (int)rdMathFloorf((bmax[0]-m_params.orig[0]) / tw);
|
||||
const int ty0 = (int)rdMathFloorf((bmin[1]-m_params.orig[1]) / th);
|
||||
const int ty1 = (int)rdMathFloorf((bmax[1]-m_params.orig[1]) / th);
|
||||
|
||||
for (int ty = ty0; ty <= ty1; ++ty)
|
||||
{
|
||||
@ -498,7 +498,7 @@ dtStatus dtTileCache::queryTiles(const float* bmin, const float* bmax,
|
||||
float tbmin[3], tbmax[3];
|
||||
calcTightTileBounds(tile->header, tbmin, tbmax);
|
||||
|
||||
if (dtOverlapBounds(bmin,bmax, tbmin,tbmax))
|
||||
if (rdOverlapBounds(bmin,bmax, tbmin,tbmax))
|
||||
{
|
||||
if (n < maxResults)
|
||||
results[n++] = tiles[i];
|
||||
@ -742,8 +742,8 @@ dtStatus dtTileCache::buildNavMeshTile(const dtCompressedTileRef ref, dtNavMesh*
|
||||
params.cs = m_params.cs;
|
||||
params.ch = m_params.ch;
|
||||
params.buildBvTree = false;
|
||||
dtVcopy(params.bmin, tile->header->bmin);
|
||||
dtVcopy(params.bmax, tile->header->bmax);
|
||||
rdVcopy(params.bmin, tile->header->bmin);
|
||||
rdVcopy(params.bmax, tile->header->bmax);
|
||||
|
||||
if (m_tmproc)
|
||||
{
|
||||
@ -799,14 +799,14 @@ void dtTileCache::getObstacleBounds(const struct dtTileCacheObstacle* ob, float*
|
||||
}
|
||||
else if (ob->type == DT_OBSTACLE_BOX)
|
||||
{
|
||||
dtVcopy(bmin, ob->box.bmin);
|
||||
dtVcopy(bmax, ob->box.bmax);
|
||||
rdVcopy(bmin, ob->box.bmin);
|
||||
rdVcopy(bmax, ob->box.bmax);
|
||||
}
|
||||
else if (ob->type == DT_OBSTACLE_ORIENTED_BOX)
|
||||
{
|
||||
const dtObstacleOrientedBox &orientedBox = ob->orientedBox;
|
||||
|
||||
float maxr = 1.41f*dtMax(orientedBox.halfExtents[0], orientedBox.halfExtents[1]);
|
||||
float maxr = 1.41f*rdMax(orientedBox.halfExtents[0], orientedBox.halfExtents[1]);
|
||||
bmin[0] = orientedBox.center[0] - maxr;
|
||||
bmax[0] = orientedBox.center[0] + maxr;
|
||||
bmin[1] = orientedBox.center[1] - maxr;
|
||||
|
@ -16,10 +16,10 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Detour/Include/DetourStatus.h"
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
#include "Shared/Include/SharedAssert.h"
|
||||
#include "Detour/Include/DetourStatus.h"
|
||||
#include "DetourTileCache/Include/DetourTileCacheBuilder.h"
|
||||
#include <string.h>
|
||||
|
||||
@ -152,7 +152,7 @@ inline bool isConnected(const dtTileCacheLayer& layer,
|
||||
const int ia, const int ib, const int walkableClimb)
|
||||
{
|
||||
if (layer.areas[ia] != layer.areas[ib]) return false;
|
||||
if (dtAbs((int)layer.heights[ia] - (int)layer.heights[ib]) > walkableClimb) return false;
|
||||
if (rdAbs((int)layer.heights[ia] - (int)layer.heights[ib]) > walkableClimb) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -707,9 +707,9 @@ static unsigned char getCornerHeight(dtTileCacheLayer& layer,
|
||||
{
|
||||
const int idx = px + py*w;
|
||||
const int lh = (int)layer.heights[idx];
|
||||
if (dtAbs(lh-z) <= walkableClimb && layer.areas[idx] != DT_TILECACHE_NULL_AREA)
|
||||
if (rdAbs(lh-z) <= walkableClimb && layer.areas[idx] != DT_TILECACHE_NULL_AREA)
|
||||
{
|
||||
height = dtMax(height, (unsigned char)lh);
|
||||
height = rdMax(height, (unsigned char)lh);
|
||||
portal &= (layer.cons[idx] >> 4);
|
||||
if (preg != 0xff && preg != layer.regs[idx])
|
||||
allSameReg = false;
|
||||
@ -849,7 +849,7 @@ static unsigned short addVertex(unsigned short x, unsigned short y, unsigned sho
|
||||
while (i != DT_TILECACHE_NULL_IDX)
|
||||
{
|
||||
const unsigned short* v = &verts[i*3];
|
||||
if (v[0] == x && v[1] == y && (dtAbs(v[2] - z) <= 2))
|
||||
if (v[0] == x && v[1] == y && (rdAbs(v[2] - z) <= 2))
|
||||
return i;
|
||||
i = nextVert[i]; // next
|
||||
}
|
||||
@ -984,7 +984,7 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc,
|
||||
unsigned short zmin = (unsigned short)va[2];
|
||||
unsigned short zmax = (unsigned short)vb[2];
|
||||
if (zmin > zmax)
|
||||
dtSwap(zmin, zmax);
|
||||
rdSwap(zmin, zmax);
|
||||
|
||||
for (int m = 0; m < edgeCount; ++m)
|
||||
{
|
||||
@ -999,7 +999,7 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc,
|
||||
unsigned short ezmin = eva[2];
|
||||
unsigned short ezmax = evb[2];
|
||||
if (ezmin > ezmax)
|
||||
dtSwap(ezmin, ezmax);
|
||||
rdSwap(ezmin, ezmax);
|
||||
if (overlapRangeExl(zmin,zmax, ezmin, ezmax))
|
||||
{
|
||||
// Reuse the other polyedge to store dir.
|
||||
@ -1015,7 +1015,7 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc,
|
||||
unsigned short xmin = (unsigned short)va[0];
|
||||
unsigned short xmax = (unsigned short)vb[0];
|
||||
if (xmin > xmax)
|
||||
dtSwap(xmin, xmax);
|
||||
rdSwap(xmin, xmax);
|
||||
for (int m = 0; m < edgeCount; ++m)
|
||||
{
|
||||
rcEdge& e = edges[m];
|
||||
@ -1029,7 +1029,7 @@ static bool buildMeshAdjacency(dtTileCacheAlloc* alloc,
|
||||
unsigned short exmin = eva[0];
|
||||
unsigned short exmax = evb[0];
|
||||
if (exmin > exmax)
|
||||
dtSwap(exmin, exmax);
|
||||
rdSwap(exmin, exmax);
|
||||
if (overlapRangeExl(xmin,xmax, exmin, exmax))
|
||||
{
|
||||
// Reuse the other polyedge to store dir.
|
||||
@ -1353,13 +1353,13 @@ static int getPolyMergeValue(unsigned short* pa, unsigned short* pb,
|
||||
unsigned short va0 = pa[i];
|
||||
unsigned short va1 = pa[(i+1) % na];
|
||||
if (va0 > va1)
|
||||
dtSwap(va0, va1);
|
||||
rdSwap(va0, va1);
|
||||
for (int j = 0; j < nb; ++j)
|
||||
{
|
||||
unsigned short vb0 = pb[j];
|
||||
unsigned short vb1 = pb[(j+1) % nb];
|
||||
if (vb0 > vb1)
|
||||
dtSwap(vb0, vb1);
|
||||
rdSwap(vb0, vb1);
|
||||
if (va0 == vb0 && va1 == vb1)
|
||||
{
|
||||
ea = i;
|
||||
@ -1497,7 +1497,7 @@ static bool canRemoveVertex(dtTileCachePolyMesh& mesh, const unsigned short rem)
|
||||
// Arrange edge so that a=rem.
|
||||
int a = p[j], b = p[k];
|
||||
if (b == rem)
|
||||
dtSwap(a,b);
|
||||
rdSwap(a,b);
|
||||
|
||||
// Check if the edge exists
|
||||
bool exists = false;
|
||||
@ -1806,7 +1806,7 @@ dtStatus dtBuildTileCachePolyMesh(dtTileCacheAlloc* alloc,
|
||||
if (lcset.conts[i].nverts < 3) continue;
|
||||
maxVertices += lcset.conts[i].nverts;
|
||||
maxTris += lcset.conts[i].nverts - 2;
|
||||
maxVertsPerCont = dtMax(maxVertsPerCont, lcset.conts[i].nverts);
|
||||
maxVertsPerCont = rdMax(maxVertsPerCont, lcset.conts[i].nverts);
|
||||
}
|
||||
|
||||
// TODO: warn about too many vertices?
|
||||
@ -2010,7 +2010,7 @@ dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const fl
|
||||
bmax[0] = pos[0] + radius;
|
||||
bmax[1] = pos[1] + radius;
|
||||
bmax[2] = pos[2] + height;
|
||||
const float r2 = dtSqr(radius/cs + 0.5f);
|
||||
const float r2 = rdSqr(radius/cs + 0.5f);
|
||||
|
||||
const int w = (int)layer.header->width;
|
||||
const int h = (int)layer.header->height;
|
||||
@ -2020,12 +2020,12 @@ dtStatus dtMarkCylinderArea(dtTileCacheLayer& layer, const float* orig, const fl
|
||||
const float px = (pos[0]-orig[0])*ics;
|
||||
const float py = (pos[1]-orig[1])*ics;
|
||||
|
||||
int minx = (int)dtMathFloorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)dtMathFloorf((bmin[1]-orig[1])*ich);
|
||||
int minz = (int)dtMathFloorf((bmin[2]-orig[2])*ics);
|
||||
int maxx = (int)dtMathFloorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)dtMathFloorf((bmax[1]-orig[1])*ich);
|
||||
int maxz = (int)dtMathFloorf((bmax[2]-orig[2])*ics);
|
||||
int minx = (int)rdMathFloorf((bmin[0]-orig[0])*ics);
|
||||
int miny = (int)rdMathFloorf((bmin[1]-orig[1])*ich);
|
||||
int minz = (int)rdMathFloorf((bmin[2]-orig[2])*ics);
|
||||
int maxx = (int)rdMathFloorf((bmax[0]-orig[0])*ics);
|
||||
int maxy = (int)rdMathFloorf((bmax[1]-orig[1])*ich);
|
||||
int maxz = (int)rdMathFloorf((bmax[2]-orig[2])*ics);
|
||||
|
||||
if (maxx < 0) return DT_SUCCESS;
|
||||
if (minx >= w) return DT_SUCCESS;
|
||||
@ -2105,7 +2105,7 @@ dtStatus dtMarkBoxArea(dtTileCacheLayer& layer, const float* orig, const float c
|
||||
float cx = (center[0] - orig[0])*ics;
|
||||
float cy = (center[1] - orig[1])*ics;
|
||||
|
||||
float maxr = 1.41f*dtMax(halfExtents[0], halfExtents[1]);
|
||||
float maxr = 1.41f*rdMax(halfExtents[0], halfExtents[1]);
|
||||
int minx = (int)floorf(cx - maxr*ics);
|
||||
int maxx = (int)floorf(cx + maxr*ics);
|
||||
int miny = (int)floorf(cy - maxr*ics);
|
||||
@ -2155,7 +2155,7 @@ dtStatus dtBuildTileCacheLayer(dtTileCacheCompressor* comp,
|
||||
const unsigned char* cons,
|
||||
unsigned char** outData, int* outDataSize)
|
||||
{
|
||||
const int headerSize = dtAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
const int headerSize = rdAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
const int gridSize = (int)header->width * (int)header->height;
|
||||
const int maxDataSize = headerSize + comp->maxCompressedSize(gridSize*3);
|
||||
unsigned char* data = (unsigned char*)rdAlloc(maxDataSize, RD_ALLOC_PERM);
|
||||
@ -2226,8 +2226,8 @@ dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompress
|
||||
if (compressedHeader->version != DT_TILECACHE_VERSION)
|
||||
return DT_FAILURE | DT_WRONG_VERSION;
|
||||
|
||||
const int layerSize = dtAlign4(sizeof(dtTileCacheLayer));
|
||||
const int headerSize = dtAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
const int layerSize = rdAlign4(sizeof(dtTileCacheLayer));
|
||||
const int headerSize = rdAlign4(sizeof(dtTileCacheLayerHeader));
|
||||
const int gridSize = (int)compressedHeader->width * (int)compressedHeader->height;
|
||||
const int bufferSize = layerSize + headerSize + gridSize*4;
|
||||
|
||||
@ -2268,13 +2268,13 @@ dtStatus dtDecompressTileCacheLayer(dtTileCacheAlloc* alloc, dtTileCacheCompress
|
||||
|
||||
bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize)
|
||||
{
|
||||
dtIgnoreUnused(dataSize);
|
||||
rdIgnoreUnused(dataSize);
|
||||
dtTileCacheLayerHeader* header = (dtTileCacheLayerHeader*)data;
|
||||
|
||||
int swappedMagic = DT_TILECACHE_MAGIC;
|
||||
int swappedVersion = DT_TILECACHE_VERSION;
|
||||
dtSwapEndian(&swappedMagic);
|
||||
dtSwapEndian(&swappedVersion);
|
||||
rdSwapEndian(&swappedMagic);
|
||||
rdSwapEndian(&swappedVersion);
|
||||
|
||||
if ((header->magic != DT_TILECACHE_MAGIC || header->version != DT_TILECACHE_VERSION) &&
|
||||
(header->magic != swappedMagic || header->version != swappedVersion))
|
||||
@ -2282,19 +2282,19 @@ bool dtTileCacheHeaderSwapEndian(unsigned char* data, const int dataSize)
|
||||
return false;
|
||||
}
|
||||
|
||||
dtSwapEndian(&header->magic);
|
||||
dtSwapEndian(&header->version);
|
||||
dtSwapEndian(&header->tx);
|
||||
dtSwapEndian(&header->ty);
|
||||
dtSwapEndian(&header->tlayer);
|
||||
dtSwapEndian(&header->bmin[0]);
|
||||
dtSwapEndian(&header->bmin[1]);
|
||||
dtSwapEndian(&header->bmin[2]);
|
||||
dtSwapEndian(&header->bmax[0]);
|
||||
dtSwapEndian(&header->bmax[1]);
|
||||
dtSwapEndian(&header->bmax[2]);
|
||||
dtSwapEndian(&header->hmin);
|
||||
dtSwapEndian(&header->hmax);
|
||||
rdSwapEndian(&header->magic);
|
||||
rdSwapEndian(&header->version);
|
||||
rdSwapEndian(&header->tx);
|
||||
rdSwapEndian(&header->ty);
|
||||
rdSwapEndian(&header->tlayer);
|
||||
rdSwapEndian(&header->bmin[0]);
|
||||
rdSwapEndian(&header->bmin[1]);
|
||||
rdSwapEndian(&header->bmin[2]);
|
||||
rdSwapEndian(&header->bmax[0]);
|
||||
rdSwapEndian(&header->bmax[1]);
|
||||
rdSwapEndian(&header->bmax[2]);
|
||||
rdSwapEndian(&header->hmin);
|
||||
rdSwapEndian(&header->hmax);
|
||||
|
||||
// width, height, minx, maxx, miny, maxy are unsigned char, no need to swap.
|
||||
|
||||
|
221
src/thirdparty/recast/Recast/Include/Recast.h
vendored
221
src/thirdparty/recast/Recast/Include/Recast.h
vendored
@ -18,12 +18,8 @@
|
||||
|
||||
#ifndef RECAST_H
|
||||
#define RECAST_H
|
||||
|
||||
/// The value of PI used by Recast.
|
||||
static const float RC_PI = 3.14159265f;
|
||||
|
||||
/// Used to ignore unused function parameters and silence any compiler warnings.
|
||||
template<class T> void rcIgnoreUnused(const T&) { }
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
|
||||
/// Recast log categories.
|
||||
/// @see rcContext
|
||||
@ -166,23 +162,23 @@ protected:
|
||||
/// @param[in] category The category of the message.
|
||||
/// @param[in] msg The formatted message.
|
||||
/// @param[in] len The length of the formatted message.
|
||||
virtual void doLog(const rcLogCategory category, const char* msg, const int len) { rcIgnoreUnused(category); rcIgnoreUnused(msg); rcIgnoreUnused(len); }
|
||||
virtual void doLog(const rcLogCategory category, const char* msg, const int len) { rdIgnoreUnused(category); rdIgnoreUnused(msg); rdIgnoreUnused(len); }
|
||||
|
||||
/// Clears all timers. (Resets all to unused.)
|
||||
virtual void doResetTimers() {}
|
||||
|
||||
/// Starts the specified performance timer.
|
||||
/// @param[in] label The category of timer.
|
||||
virtual void doStartTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }
|
||||
virtual void doStartTimer(const rcTimerLabel label) { rdIgnoreUnused(label); }
|
||||
|
||||
/// Stops the specified performance timer.
|
||||
/// @param[in] label The category of the timer.
|
||||
virtual void doStopTimer(const rcTimerLabel label) { rcIgnoreUnused(label); }
|
||||
virtual void doStopTimer(const rcTimerLabel label) { rdIgnoreUnused(label); }
|
||||
|
||||
/// Returns the total accumulated time of the specified performance timer.
|
||||
/// @param[in] label The category of the timer.
|
||||
/// @return The accumulated time of the timer, or -1 if timers are disabled or the timer has never been started.
|
||||
virtual int doGetAccumulatedTime(const rcTimerLabel label) const { rcIgnoreUnused(label); return -1; }
|
||||
virtual int doGetAccumulatedTime(const rcTimerLabel label) const { rdIgnoreUnused(label); return -1; }
|
||||
|
||||
/// True if logging is enabled.
|
||||
bool m_logEnabled;
|
||||
@ -641,207 +637,6 @@ static const unsigned char RC_WALKABLE_AREA = 63;
|
||||
/// to another span. (Has no neighbor.)
|
||||
static const int RC_NOT_CONNECTED = 0x3f;
|
||||
|
||||
/// @name General helper functions
|
||||
/// @{
|
||||
|
||||
/// Swaps the values of the two parameters.
|
||||
/// @param[in,out] a Value A
|
||||
/// @param[in,out] b Value B
|
||||
template<class T> inline void rcSwap(T& a, T& b) { T t = a; a = b; b = t; }
|
||||
|
||||
/// Returns the minimum of two values.
|
||||
/// @param[in] a Value A
|
||||
/// @param[in] b Value B
|
||||
/// @return The minimum of the two values.
|
||||
template<class T> inline T rcMin(T a, T b) { return a < b ? a : b; }
|
||||
|
||||
/// Returns the maximum of two values.
|
||||
/// @param[in] a Value A
|
||||
/// @param[in] b Value B
|
||||
/// @return The maximum of the two values.
|
||||
template<class T> inline T rcMax(T a, T b) { return a > b ? a : b; }
|
||||
|
||||
/// Returns the absolute value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The absolute value of the specified value.
|
||||
template<class T> inline T rcAbs(T a) { return a < 0 ? -a : a; }
|
||||
|
||||
/// Returns the square of the value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The square of the value.
|
||||
template<class T> inline T rcSqr(T a) { return a*a; }
|
||||
|
||||
/// Clamps the value to the specified range.
|
||||
/// @param[in] value The value to clamp.
|
||||
/// @param[in] minInclusive The minimum permitted return value.
|
||||
/// @param[in] maxInclusive The maximum permitted return value.
|
||||
/// @return The value, clamped to the specified range.
|
||||
template<class T> inline T rcClamp(T value, T minInclusive, T maxInclusive)
|
||||
{
|
||||
return value < minInclusive ? minInclusive: (value > maxInclusive ? maxInclusive : value);
|
||||
}
|
||||
|
||||
/// Returns the square root of the value.
|
||||
/// @param[in] x The value.
|
||||
/// @return The square root of the vlaue.
|
||||
float rcSqrt(float x);
|
||||
|
||||
/// @}
|
||||
/// @name Vector helper functions.
|
||||
/// @{
|
||||
|
||||
/// Derives the cross product of two vectors. (@p v1 x @p v2)
|
||||
/// @param[out] dest The cross product. [(x, y, z)]
|
||||
/// @param[in] v1 A Vector [(x, y, z)]
|
||||
/// @param[in] v2 A vector [(x, y, z)]
|
||||
inline void rcVcross(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
||||
dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
||||
dest[2] = v1[0]*v2[1] - v1[1]*v2[0];
|
||||
}
|
||||
|
||||
/// Derives the dot product of two vectors. (@p v1 . @p v2)
|
||||
/// @param[in] v1 A Vector [(x, y, z)]
|
||||
/// @param[in] v2 A vector [(x, y, z)]
|
||||
/// @return The dot product.
|
||||
inline float rcVdot(const float* v1, const float* v2)
|
||||
{
|
||||
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
|
||||
}
|
||||
|
||||
/// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s))
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)]
|
||||
/// @param[in] s The amount to scale @p v2 by before adding to @p v1.
|
||||
inline void rcVmad(float* dest, const float* v1, const float* v2, const float s)
|
||||
{
|
||||
dest[0] = v1[0]+v2[0]*s;
|
||||
dest[1] = v1[1]+v2[1]*s;
|
||||
dest[2] = v1[2]+v2[2]*s;
|
||||
}
|
||||
|
||||
/// Performs a vector addition. (@p v1 + @p v2)
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to add to @p v1. [(x, y, z)]
|
||||
inline void rcVadd(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[0]+v2[0];
|
||||
dest[1] = v1[1]+v2[1];
|
||||
dest[2] = v1[2]+v2[2];
|
||||
}
|
||||
|
||||
/// Performs a vector subtraction. (@p v1 - @p v2)
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to subtract from @p v1. [(x, y, z)]
|
||||
inline void rcVsub(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[0]-v2[0];
|
||||
dest[1] = v1[1]-v2[1];
|
||||
dest[2] = v1[2]-v2[2];
|
||||
}
|
||||
|
||||
/// Selects the minimum value of each element from the specified vectors.
|
||||
/// @param[in,out] mn A vector. (Will be updated with the result.) [(x, y, z)]
|
||||
/// @param[in] v A vector. [(x, y, z)]
|
||||
inline void rcVmin(float* mn, const float* v)
|
||||
{
|
||||
mn[0] = rcMin(mn[0], v[0]);
|
||||
mn[1] = rcMin(mn[1], v[1]);
|
||||
mn[2] = rcMin(mn[2], v[2]);
|
||||
}
|
||||
|
||||
/// Selects the maximum value of each element from the specified vectors.
|
||||
/// @param[in,out] mx A vector. (Will be updated with the result.) [(x, y, z)]
|
||||
/// @param[in] v A vector. [(x, y, z)]
|
||||
inline void rcVmax(float* mx, const float* v)
|
||||
{
|
||||
mx[0] = rcMax(mx[0], v[0]);
|
||||
mx[1] = rcMax(mx[1], v[1]);
|
||||
mx[2] = rcMax(mx[2], v[2]);
|
||||
}
|
||||
|
||||
/// Sets the vector elements to the specified values.
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] x The x-value of the vector.
|
||||
/// @param[in] y The y-value of the vector.
|
||||
/// @param[in] z The z-value of the vector.
|
||||
inline void rcVset(float* dest, const float x, const float y, const float z)
|
||||
{
|
||||
dest[0] = x; dest[1] = y; dest[2] = z;
|
||||
}
|
||||
|
||||
/// Performs a vector copy.
|
||||
/// @param[out] dest The result. [(x, y, z)]
|
||||
/// @param[in] v The vector to copy. [(x, y, z)]
|
||||
inline void rcVcopy(float* dest, const float* v)
|
||||
{
|
||||
dest[0] = v[0];
|
||||
dest[1] = v[1];
|
||||
dest[2] = v[2];
|
||||
}
|
||||
|
||||
/// Performs a vector swap.
|
||||
/// @param[out] dest The result. [(x, y, z)]
|
||||
/// @param[in] v The vector to swap. [(x, y, z)]
|
||||
inline void rcVswap(float* dest, const float* v)
|
||||
{
|
||||
dest[0] = v[0];
|
||||
dest[2] = v[1];
|
||||
dest[1] = v[2];
|
||||
}
|
||||
|
||||
/// Returns the distance between two points.
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
/// @return The distance between the two points.
|
||||
inline float rcVdist(const float* v1, const float* v2)
|
||||
{
|
||||
float dx = v2[0] - v1[0];
|
||||
float dy = v2[1] - v1[1];
|
||||
float dz = v2[2] - v1[2];
|
||||
return rcSqrt(dx*dx + dy*dy + dz*dz);
|
||||
}
|
||||
|
||||
/// Returns the square of the distance between two points.
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
/// @return The square of the distance between the two points.
|
||||
inline float rcVdistSqr(const float* v1, const float* v2)
|
||||
{
|
||||
float dx = v2[0] - v1[0];
|
||||
float dy = v2[1] - v1[1];
|
||||
float dz = v2[2] - v1[2];
|
||||
return dx*dx + dy*dy + dz*dz;
|
||||
}
|
||||
|
||||
/// Normalizes the vector.
|
||||
/// @param[in,out] v The vector to normalize. [(x, y, z)]
|
||||
inline void rcVnormalize(float* v)
|
||||
{
|
||||
float d = 1.0f / rcSqrt(rcSqr(v[0]) + rcSqr(v[1]) + rcSqr(v[2]));
|
||||
v[0] *= d;
|
||||
v[1] *= d;
|
||||
v[2] *= d;
|
||||
}
|
||||
|
||||
/// Performs a 'sloppy' collocation check of the specified points.
|
||||
/// @param[in] p0 A point. [(x, y, z)]
|
||||
/// @param[in] p1 A point. [(x, y, z)]
|
||||
/// @return True if the points are considered to be at the same location.
|
||||
///
|
||||
/// Basically, this function will return true if the specified points are
|
||||
/// close enough to each other to be considered collocated.
|
||||
inline bool rcVequal(const float* p0, const float* p1)
|
||||
{
|
||||
static const float thr = rcSqr(1.0f/16384.0f);
|
||||
const float d = rcVdistSqr(p0, p1);
|
||||
return d < thr;
|
||||
}
|
||||
|
||||
/// @}
|
||||
/// @name Heightfield Functions
|
||||
/// @see rcHeightfield
|
||||
@ -1037,7 +832,7 @@ bool rcRasterizeTriangles(rcContext* context,
|
||||
/// Allows the formation of walkable regions that will flow over low lying
|
||||
/// objects such as curbs, and up structures such as stairways.
|
||||
///
|
||||
/// Two neighboring spans are walkable if: <tt>rcAbs(currentSpan.smax - neighborSpan.smax) < waklableClimb</tt>
|
||||
/// Two neighboring spans are walkable if: <tt>rdAbs(currentSpan.smax - neighborSpan.smax) < waklableClimb</tt>
|
||||
///
|
||||
/// @warning Will override the effect of #rcFilterLedgeSpans. So if both filters are used, call
|
||||
/// #rcFilterLedgeSpans after calling this filter.
|
||||
@ -1058,7 +853,7 @@ void rcFilterLowHangingWalkableObstacles(rcContext* context, int walkableClimb,
|
||||
/// This method removes the impact of the overestimation of conservative voxelization
|
||||
/// so the resulting mesh will not have regions hanging in the air over ledges.
|
||||
///
|
||||
/// A span is a ledge if: <tt>rcAbs(currentSpan.smax - neighborSpan.smax) > walkableClimb</tt>
|
||||
/// A span is a ledge if: <tt>rdAbs(currentSpan.smax - neighborSpan.smax) > walkableClimb</tt>
|
||||
///
|
||||
/// @see rcHeightfield, rcConfig
|
||||
///
|
||||
|
57
src/thirdparty/recast/Recast/Source/Recast.cpp
vendored
57
src/thirdparty/recast/Recast/Source/Recast.cpp
vendored
@ -50,11 +50,6 @@ void rcDelete(T* ptr)
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
float rcSqrt(float x)
|
||||
{
|
||||
return sqrtf(x);
|
||||
}
|
||||
|
||||
void rcContext::log(const rcLogCategory category, const char* format, ...)
|
||||
{
|
||||
if (!m_logEnabled)
|
||||
@ -287,13 +282,13 @@ rcPolyMeshDetail::rcPolyMeshDetail()
|
||||
void rcCalcBounds(const float* verts, int numVerts, float* minBounds, float* maxBounds)
|
||||
{
|
||||
// Calculate bounding box.
|
||||
rcVcopy(minBounds, verts);
|
||||
rcVcopy(maxBounds, verts);
|
||||
rdVcopy(minBounds, verts);
|
||||
rdVcopy(maxBounds, verts);
|
||||
for (int i = 1; i < numVerts; ++i)
|
||||
{
|
||||
const float* v = &verts[i * 3];
|
||||
rcVmin(minBounds, v);
|
||||
rcVmax(maxBounds, v);
|
||||
rdVmin(minBounds, v);
|
||||
rdVmax(maxBounds, v);
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,12 +302,12 @@ bool rcCreateHeightfield(rcContext* context, rcHeightfield& heightfield, int siz
|
||||
const float* minBounds, const float* maxBounds,
|
||||
float cellSize, float cellHeight)
|
||||
{
|
||||
rcIgnoreUnused(context);
|
||||
rdIgnoreUnused(context);
|
||||
|
||||
heightfield.width = sizeX;
|
||||
heightfield.height = sizeZ;
|
||||
rcVcopy(heightfield.bmin, minBounds);
|
||||
rcVcopy(heightfield.bmax, maxBounds);
|
||||
rdVcopy(heightfield.bmin, minBounds);
|
||||
rdVcopy(heightfield.bmax, maxBounds);
|
||||
heightfield.cs = cellSize;
|
||||
heightfield.ch = cellHeight;
|
||||
heightfield.spans = (rcSpan**)rdAlloc(sizeof(rcSpan*) * heightfield.width * heightfield.height, RD_ALLOC_PERM);
|
||||
@ -327,10 +322,10 @@ bool rcCreateHeightfield(rcContext* context, rcHeightfield& heightfield, int siz
|
||||
static void calcTriNormal(const float* v0, const float* v1, const float* v2, float* faceNormal)
|
||||
{
|
||||
float e0[3], e1[3];
|
||||
rcVsub(e0, v1, v0);
|
||||
rcVsub(e1, v2, v0);
|
||||
rcVcross(faceNormal, e0, e1);
|
||||
rcVnormalize(faceNormal);
|
||||
rdVsub(e0, v1, v0);
|
||||
rdVsub(e1, v2, v0);
|
||||
rdVcross(faceNormal, e0, e1);
|
||||
rdVnormalize(faceNormal);
|
||||
}
|
||||
|
||||
void rcMarkWalkableTriangles(rcContext* context, const float walkableSlopeAngle,
|
||||
@ -338,10 +333,10 @@ void rcMarkWalkableTriangles(rcContext* context, const float walkableSlopeAngle,
|
||||
const int* tris, const int numTris,
|
||||
unsigned char* triAreaIDs)
|
||||
{
|
||||
rcIgnoreUnused(context);
|
||||
rcIgnoreUnused(numVerts);
|
||||
rdIgnoreUnused(context);
|
||||
rdIgnoreUnused(numVerts);
|
||||
|
||||
const float walkableThr = cosf(walkableSlopeAngle / 180.0f * RC_PI);
|
||||
const float walkableThr = cosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
|
||||
float norm[3];
|
||||
|
||||
@ -362,11 +357,11 @@ void rcClearUnwalkableTriangles(rcContext* context, const float walkableSlopeAng
|
||||
const int* tris, int numTris,
|
||||
unsigned char* triAreaIDs)
|
||||
{
|
||||
rcIgnoreUnused(context);
|
||||
rcIgnoreUnused(numVerts);
|
||||
rdIgnoreUnused(context);
|
||||
rdIgnoreUnused(numVerts);
|
||||
|
||||
// The minimum Z value for a face normal of a triangle with a walkable slope.
|
||||
const float walkableLimitZ = cosf(walkableSlopeAngle / 180.0f * RC_PI);
|
||||
const float walkableLimitZ = cosf(walkableSlopeAngle / 180.0f * RD_PI);
|
||||
|
||||
float faceNormal[3];
|
||||
for (int i = 0; i < numTris; ++i)
|
||||
@ -383,7 +378,7 @@ void rcClearUnwalkableTriangles(rcContext* context, const float walkableSlopeAng
|
||||
|
||||
int rcGetHeightFieldSpanCount(rcContext* context, const rcHeightfield& heightfield)
|
||||
{
|
||||
rcIgnoreUnused(context);
|
||||
rdIgnoreUnused(context);
|
||||
|
||||
const int numCols = heightfield.width * heightfield.height;
|
||||
int spanCount = 0;
|
||||
@ -418,8 +413,8 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
|
||||
compactHeightfield.walkableHeight = walkableHeight;
|
||||
compactHeightfield.walkableClimb = walkableClimb;
|
||||
compactHeightfield.maxRegions = 0;
|
||||
rcVcopy(compactHeightfield.bmin, heightfield.bmin);
|
||||
rcVcopy(compactHeightfield.bmax, heightfield.bmax);
|
||||
rdVcopy(compactHeightfield.bmin, heightfield.bmin);
|
||||
rdVcopy(compactHeightfield.bmax, heightfield.bmax);
|
||||
compactHeightfield.bmax[2] += walkableHeight * heightfield.ch;
|
||||
compactHeightfield.cs = heightfield.cs;
|
||||
compactHeightfield.ch = heightfield.ch;
|
||||
@ -470,8 +465,8 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
|
||||
{
|
||||
const int bot = (int)span->smax;
|
||||
const int top = span->next ? (int)span->next->smin : MAX_HEIGHT;
|
||||
compactHeightfield.spans[currentCellIndex].z = (unsigned short)rcClamp(bot, 0, 0xffff);
|
||||
compactHeightfield.spans[currentCellIndex].h = (unsigned char)rcClamp(top - bot, 0, 0xff);
|
||||
compactHeightfield.spans[currentCellIndex].z = (unsigned short)rdClamp(bot, 0, 0xffff);
|
||||
compactHeightfield.spans[currentCellIndex].h = (unsigned char)rdClamp(top - bot, 0, 0xff);
|
||||
compactHeightfield.areas[currentCellIndex] = span->area;
|
||||
currentCellIndex++;
|
||||
cell.count++;
|
||||
@ -509,18 +504,18 @@ bool rcBuildCompactHeightfield(rcContext* context, const int walkableHeight, con
|
||||
for (int k = (int)neighborCell.index, nk = (int)(neighborCell.index + neighborCell.count); k < nk; ++k)
|
||||
{
|
||||
const rcCompactSpan& neighborSpan = compactHeightfield.spans[k];
|
||||
const int bot = rcMax(span.z, neighborSpan.z);
|
||||
const int top = rcMin(span.z + span.h, neighborSpan.z + neighborSpan.h);
|
||||
const int bot = rdMax(span.z, neighborSpan.z);
|
||||
const int top = rdMin(span.z + span.h, neighborSpan.z + neighborSpan.h);
|
||||
|
||||
// Check that the gap between the spans is walkable,
|
||||
// and that the climb height between the gaps is not too high.
|
||||
if ((top - bot) >= walkableHeight && rcAbs((int)neighborSpan.z - (int)span.z) <= walkableClimb)
|
||||
if ((top - bot) >= walkableHeight && rdAbs((int)neighborSpan.z - (int)span.z) <= walkableClimb)
|
||||
{
|
||||
// Mark direction as walkable.
|
||||
const int layerIndex = k - (int)neighborCell.index;
|
||||
if (layerIndex < 0 || layerIndex > MAX_LAYERS)
|
||||
{
|
||||
maxLayerIndex = rcMax(maxLayerIndex, layerIndex);
|
||||
maxLayerIndex = rdMax(maxLayerIndex, layerIndex);
|
||||
continue;
|
||||
}
|
||||
rcSetCon(span, dir, layerIndex);
|
||||
|
@ -109,7 +109,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int ay = y + rcGetDirOffsetY(0);
|
||||
const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 0);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[ai]+2, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
|
||||
@ -119,7 +119,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int aax = ax + rcGetDirOffsetX(3);
|
||||
const int aay = ay + rcGetDirOffsetY(3);
|
||||
const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 3);
|
||||
nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[aai]+3, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
}
|
||||
@ -131,7 +131,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int ay = y + rcGetDirOffsetY(3);
|
||||
const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 3);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[ai]+2, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
|
||||
@ -141,7 +141,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int aax = ax + rcGetDirOffsetX(2);
|
||||
const int aay = ay + rcGetDirOffsetY(2);
|
||||
const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 2);
|
||||
nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[aai]+3, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
}
|
||||
@ -167,7 +167,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int ay = y + rcGetDirOffsetY(2);
|
||||
const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 2);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[ai]+2, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
|
||||
@ -177,7 +177,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int aax = ax + rcGetDirOffsetX(1);
|
||||
const int aay = ay + rcGetDirOffsetY(1);
|
||||
const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 1);
|
||||
nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[aai]+3, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
}
|
||||
@ -189,7 +189,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int ay = y + rcGetDirOffsetY(1);
|
||||
const int ai = (int)chf.cells[ax+ay*w].index + rcGetCon(s, 1);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
nd = (unsigned char)rcMin((int)dist[ai]+2, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[ai]+2, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
|
||||
@ -199,7 +199,7 @@ bool rcErodeWalkableArea(rcContext* ctx, int radius, rcCompactHeightfield& chf)
|
||||
const int aax = ax + rcGetDirOffsetX(0);
|
||||
const int aay = ay + rcGetDirOffsetY(0);
|
||||
const int aai = (int)chf.cells[aax+aay*w].index + rcGetCon(as, 0);
|
||||
nd = (unsigned char)rcMin((int)dist[aai]+3, 255);
|
||||
nd = (unsigned char)rdMin((int)dist[aai]+3, 255);
|
||||
if (nd < dist[i])
|
||||
dist[i] = nd;
|
||||
}
|
||||
@ -387,12 +387,12 @@ void rcMarkConvexPolyArea(rcContext* ctx, const float* verts, const int nverts,
|
||||
rcScopedTimer timer(ctx, RC_TIMER_MARK_CONVEXPOLY_AREA);
|
||||
|
||||
float bmin[3], bmax[3];
|
||||
rcVcopy(bmin, verts);
|
||||
rcVcopy(bmax, verts);
|
||||
rdVcopy(bmin, verts);
|
||||
rdVcopy(bmax, verts);
|
||||
for (int i = 1; i < nverts; ++i)
|
||||
{
|
||||
rcVmin(bmin, &verts[i*3]);
|
||||
rcVmax(bmax, &verts[i*3]);
|
||||
rdVmin(bmin, &verts[i*3]);
|
||||
rdVmax(bmax, &verts[i*3]);
|
||||
}
|
||||
bmin[2] = hmin;
|
||||
bmax[2] = hmax;
|
||||
@ -463,7 +463,7 @@ int rcOffsetPoly(const float* verts, const int nverts, const float offset,
|
||||
float d0 = dx0*dx0 + dy0*dy0;
|
||||
if (d0 > 1e-6f)
|
||||
{
|
||||
d0 = 1.0f/rcSqrt(d0);
|
||||
d0 = 1.0f/rdMathSqrtf(d0);
|
||||
dx0 *= d0;
|
||||
dy0 *= d0;
|
||||
}
|
||||
@ -472,7 +472,7 @@ int rcOffsetPoly(const float* verts, const int nverts, const float offset,
|
||||
float d1 = dx1*dx1 + dy1*dy1;
|
||||
if (d1 > 1e-6f)
|
||||
{
|
||||
d1 = 1.0f/rcSqrt(d1);
|
||||
d1 = 1.0f/rdMathSqrtf(d1);
|
||||
dx1 *= d1;
|
||||
dy1 *= d1;
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ static int getCornerHeight(int x, int y, int i, int dir,
|
||||
const int ay = y + rcGetDirOffsetY(dir);
|
||||
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dir);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
ch = rcMax(ch, (int)as.z);
|
||||
ch = rdMax(ch, (int)as.z);
|
||||
regs[1] = chf.spans[ai].reg | (chf.areas[ai] << 16);
|
||||
if (rcGetCon(as, dirp) != RC_NOT_CONNECTED)
|
||||
{
|
||||
@ -53,7 +53,7 @@ static int getCornerHeight(int x, int y, int i, int dir,
|
||||
const int ay2 = ay + rcGetDirOffsetY(dirp);
|
||||
const int ai2 = (int)chf.cells[ax2+ay2*chf.width].index + rcGetCon(as, dirp);
|
||||
const rcCompactSpan& as2 = chf.spans[ai2];
|
||||
ch = rcMax(ch, (int)as2.z);
|
||||
ch = rdMax(ch, (int)as2.z);
|
||||
regs[2] = chf.spans[ai2].reg | (chf.areas[ai2] << 16);
|
||||
}
|
||||
}
|
||||
@ -63,7 +63,7 @@ static int getCornerHeight(int x, int y, int i, int dir,
|
||||
const int ay = y + rcGetDirOffsetY(dirp);
|
||||
const int ai = (int)chf.cells[ax+ay*chf.width].index + rcGetCon(s, dirp);
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
ch = rcMax(ch, (int)as.z);
|
||||
ch = rdMax(ch, (int)as.z);
|
||||
regs[3] = chf.spans[ai].reg | (chf.areas[ai] << 16);
|
||||
if (rcGetCon(as, dir) != RC_NOT_CONNECTED)
|
||||
{
|
||||
@ -71,7 +71,7 @@ static int getCornerHeight(int x, int y, int i, int dir,
|
||||
const int ay2 = ay + rcGetDirOffsetY(dir);
|
||||
const int ai2 = (int)chf.cells[ax2+ay2*chf.width].index + rcGetCon(as, dir);
|
||||
const rcCompactSpan& as2 = chf.spans[ai2];
|
||||
ch = rcMax(ch, (int)as2.z);
|
||||
ch = rdMax(ch, (int)as2.z);
|
||||
regs[2] = chf.spans[ai2].reg | (chf.areas[ai2] << 16);
|
||||
}
|
||||
}
|
||||
@ -317,8 +317,8 @@ static void simplifyContour(rdIntArray& points, rdIntArray& simplified,
|
||||
cinc = pn-1;
|
||||
ci = (bi+cinc) % pn;
|
||||
endi = ai;
|
||||
rcSwap(ax, bx);
|
||||
rcSwap(ay, by);
|
||||
rdSwap(ax, bx);
|
||||
rdSwap(ay, by);
|
||||
}
|
||||
|
||||
// Tessellate only outer edges or edges between areas.
|
||||
@ -832,8 +832,8 @@ bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,
|
||||
|
||||
rcScopedTimer timer(ctx, RC_TIMER_BUILD_CONTOURS);
|
||||
|
||||
rcVcopy(cset.bmin, chf.bmin);
|
||||
rcVcopy(cset.bmax, chf.bmax);
|
||||
rdVcopy(cset.bmin, chf.bmin);
|
||||
rdVcopy(cset.bmax, chf.bmax);
|
||||
if (borderSize > 0)
|
||||
{
|
||||
// If the heightfield was build with bordersize, remove the offset.
|
||||
@ -850,7 +850,7 @@ bool rcBuildContours(rcContext* ctx, const rcCompactHeightfield& chf,
|
||||
cset.borderSize = chf.borderSize;
|
||||
cset.maxError = maxError;
|
||||
|
||||
int maxContours = rcMax((int)chf.maxRegions, 8);
|
||||
int maxContours = rdMax((int)chf.maxRegions, 8);
|
||||
cset.conts = (rcContour*)rdAlloc(sizeof(rcContour)*maxContours, RD_ALLOC_PERM);
|
||||
if (!cset.conts)
|
||||
return false;
|
||||
|
@ -45,7 +45,7 @@ void rcFilterLowHangingWalkableObstacles(rcContext* context, const int walkableC
|
||||
// span just below it, mark the span above it walkable too.
|
||||
if (!walkable && previousWasWalkable)
|
||||
{
|
||||
if (rcAbs((int)span->smax - (int)previousSpan->smax) <= walkableClimb)
|
||||
if (rdAbs((int)span->smax - (int)previousSpan->smax) <= walkableClimb)
|
||||
{
|
||||
span->area = previousArea;
|
||||
}
|
||||
@ -100,7 +100,7 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
|
||||
// Skip neighbours which are out of bounds.
|
||||
if (dx < 0 || dy < 0 || dx >= xSize || dy >= zSize)
|
||||
{
|
||||
minNeighborHeight = rcMin(minNeighborHeight, -walkableClimb - bot);
|
||||
minNeighborHeight = rdMin(minNeighborHeight, -walkableClimb - bot);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -110,9 +110,9 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
|
||||
int neighborTop = neighborSpan ? (int)neighborSpan->smin : MAX_HEIGHT;
|
||||
|
||||
// Skip neighbour if the gap between the spans is too small.
|
||||
if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight)
|
||||
if (rdMin(top, neighborTop) - rdMax(bot, neighborBot) > walkableHeight)
|
||||
{
|
||||
minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot);
|
||||
minNeighborHeight = rdMin(minNeighborHeight, neighborBot - bot);
|
||||
}
|
||||
|
||||
// Rest of the spans.
|
||||
@ -122,12 +122,12 @@ void rcFilterLedgeSpans(rcContext* context, const int walkableHeight, const int
|
||||
neighborTop = neighborSpan->next ? (int)neighborSpan->next->smin : MAX_HEIGHT;
|
||||
|
||||
// Skip neighbour if the gap between the spans is too small.
|
||||
if (rcMin(top, neighborTop) - rcMax(bot, neighborBot) > walkableHeight)
|
||||
if (rdMin(top, neighborTop) - rdMax(bot, neighborBot) > walkableHeight)
|
||||
{
|
||||
minNeighborHeight = rcMin(minNeighborHeight, neighborBot - bot);
|
||||
minNeighborHeight = rdMin(minNeighborHeight, neighborBot - bot);
|
||||
|
||||
// Find min/max accessible neighbour height.
|
||||
if (rcAbs(neighborBot - bot) <= walkableClimb)
|
||||
if (rdAbs(neighborBot - bot) <= walkableClimb)
|
||||
{
|
||||
if (neighborBot < accessibleNeighborMinHeight) accessibleNeighborMinHeight = neighborBot;
|
||||
if (neighborBot > accessibleNeighborMaxHeight) accessibleNeighborMaxHeight = neighborBot;
|
||||
|
@ -250,8 +250,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
const unsigned char ri = srcReg[i];
|
||||
if (ri == 0xff) continue;
|
||||
|
||||
regs[ri].zmin = rcMin(regs[ri].zmin, s.z);
|
||||
regs[ri].zmax = rcMax(regs[ri].zmax, s.z);
|
||||
regs[ri].zmin = rdMin(regs[ri].zmin, s.z);
|
||||
regs[ri].zmax = rdMax(regs[ri].zmax, s.z);
|
||||
|
||||
// Collect all region layers.
|
||||
if (nlregs < RC_MAX_LAYERS)
|
||||
@ -342,8 +342,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
if (contains(root.layers, root.nlayers, nei))
|
||||
continue;
|
||||
// Skip if the height range would become too large.
|
||||
const int zmin = rcMin(root.zmin, regn.zmin);
|
||||
const int zmax = rcMax(root.zmax, regn.zmax);
|
||||
const int zmin = rdMin(root.zmin, regn.zmin);
|
||||
const int zmax = rdMax(root.zmax, regn.zmax);
|
||||
if ((zmax - zmin) >= 255)
|
||||
continue;
|
||||
|
||||
@ -363,8 +363,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
return false;
|
||||
}
|
||||
}
|
||||
root.zmin = rcMin(root.zmin, regn.zmin);
|
||||
root.zmax = rcMax(root.zmax, regn.zmax);
|
||||
root.zmin = rdMin(root.zmin, regn.zmin);
|
||||
root.zmax = rdMax(root.zmax, regn.zmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -396,8 +396,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
if (!overlapRange(ri.zmin,ri.zmax+mergeHeight, rj.zmin,rj.zmax+mergeHeight))
|
||||
continue;
|
||||
// Skip if the height range would become too large.
|
||||
const int zmin = rcMin(ri.zmin, rj.zmin);
|
||||
const int zmax = rcMax(ri.zmax, rj.zmax);
|
||||
const int zmin = rdMin(ri.zmin, rj.zmin);
|
||||
const int zmax = rdMax(ri.zmax, rj.zmax);
|
||||
if ((zmax - zmin) >= 255)
|
||||
continue;
|
||||
|
||||
@ -449,8 +449,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
}
|
||||
|
||||
// Update height bounds.
|
||||
ri.zmin = rcMin(ri.zmin, rj.zmin);
|
||||
ri.zmax = rcMax(ri.zmax, rj.zmax);
|
||||
ri.zmin = rdMin(ri.zmin, rj.zmin);
|
||||
ri.zmax = rdMax(ri.zmax, rj.zmax);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -487,8 +487,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
|
||||
// Build contracted bbox for layers.
|
||||
float bmin[3], bmax[3];
|
||||
rcVcopy(bmin, chf.bmin);
|
||||
rcVcopy(bmax, chf.bmax);
|
||||
rdVcopy(bmin, chf.bmin);
|
||||
rdVcopy(bmax, chf.bmax);
|
||||
bmin[0] += borderSize*chf.cs;
|
||||
bmin[1] += borderSize*chf.cs;
|
||||
bmax[0] -= borderSize*chf.cs;
|
||||
@ -555,8 +555,8 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
layer->ch = chf.ch;
|
||||
|
||||
// Adjust the bbox to fit the heightfield.
|
||||
rcVcopy(layer->bmin, bmin);
|
||||
rcVcopy(layer->bmax, bmax);
|
||||
rdVcopy(layer->bmin, bmin);
|
||||
rdVcopy(layer->bmax, bmax);
|
||||
layer->bmin[2] = bmin[2] + hmin*chf.ch;
|
||||
layer->bmax[2] = bmin[2] + hmax*chf.ch;
|
||||
layer->hmin = hmin;
|
||||
@ -588,10 +588,10 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
continue;
|
||||
|
||||
// Update data bounds.
|
||||
layer->minx = rcMin(layer->minx, x);
|
||||
layer->maxx = rcMax(layer->maxx, x);
|
||||
layer->miny = rcMin(layer->miny, y);
|
||||
layer->maxy = rcMax(layer->maxy, y);
|
||||
layer->minx = rdMin(layer->minx, x);
|
||||
layer->maxx = rdMax(layer->maxx, x);
|
||||
layer->miny = rdMin(layer->miny, y);
|
||||
layer->maxy = rdMax(layer->maxy, y);
|
||||
|
||||
// Store height and area type.
|
||||
const int idx = x+y*lw;
|
||||
@ -616,7 +616,7 @@ bool rcBuildHeightfieldLayers(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
// Update height so that it matches on both sides of the portal.
|
||||
const rcCompactSpan& as = chf.spans[ai];
|
||||
if (as.z > hmin)
|
||||
layer->heights[idx] = rcMax(layer->heights[idx], (unsigned char)(as.z - hmin));
|
||||
layer->heights[idx] = rdMax(layer->heights[idx], (unsigned char)(as.z - hmin));
|
||||
}
|
||||
// Valid connection mask
|
||||
if (chf.areas[ai] != RC_NULL_AREA && lid == alid)
|
||||
|
@ -143,7 +143,7 @@ static unsigned short addVertex(unsigned short x, unsigned short y, unsigned sho
|
||||
while (i != -1)
|
||||
{
|
||||
const unsigned short* v = &verts[i*3];
|
||||
if (v[0] == x && v[1] == y && (rcAbs(v[2] - z) <= 2))
|
||||
if (v[0] == x && v[1] == y && (rdAbs(v[2] - z) <= 2))
|
||||
return (unsigned short)i;
|
||||
i = nextVert[i]; // next
|
||||
}
|
||||
@ -530,13 +530,13 @@ static int getPolyMergeValue(unsigned short* pa, unsigned short* pb,
|
||||
unsigned short va0 = pa[i];
|
||||
unsigned short va1 = pa[(i+1) % na];
|
||||
if (va0 > va1)
|
||||
rcSwap(va0, va1);
|
||||
rdSwap(va0, va1);
|
||||
for (int j = 0; j < nb; ++j)
|
||||
{
|
||||
unsigned short vb0 = pb[j];
|
||||
unsigned short vb1 = pb[(j+1) % nb];
|
||||
if (vb0 > vb1)
|
||||
rcSwap(vb0, vb1);
|
||||
rdSwap(vb0, vb1);
|
||||
if (va0 == vb0 && va1 == vb1)
|
||||
{
|
||||
ea = i;
|
||||
@ -675,7 +675,7 @@ static bool canRemoveVertex(rcContext* ctx, rcPolyMesh& mesh, const unsigned sho
|
||||
// Arrange edge so that a=rem.
|
||||
int a = p[j], b = p[k];
|
||||
if (b == rem)
|
||||
rcSwap(a,b);
|
||||
rdSwap(a,b);
|
||||
|
||||
// Check if the edge exists
|
||||
bool exists = false;
|
||||
@ -1058,8 +1058,8 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
||||
|
||||
rcScopedTimer timer(ctx, RC_TIMER_BUILD_POLYMESH);
|
||||
|
||||
rcVcopy(mesh.bmin, cset.bmin);
|
||||
rcVcopy(mesh.bmax, cset.bmax);
|
||||
rdVcopy(mesh.bmin, cset.bmin);
|
||||
rdVcopy(mesh.bmax, cset.bmax);
|
||||
mesh.cs = cset.cs;
|
||||
mesh.ch = cset.ch;
|
||||
mesh.borderSize = cset.borderSize;
|
||||
@ -1074,7 +1074,7 @@ bool rcBuildPolyMesh(rcContext* ctx, rcContourSet& cset, const int nvp, rcPolyMe
|
||||
if (cset.conts[i].nverts < 3) continue;
|
||||
maxVertices += cset.conts[i].nverts;
|
||||
maxTris += cset.conts[i].nverts - 2;
|
||||
maxVertsPerCont = rcMax(maxVertsPerCont, cset.conts[i].nverts);
|
||||
maxVertsPerCont = rdMax(maxVertsPerCont, cset.conts[i].nverts);
|
||||
}
|
||||
|
||||
if (maxVertices >= 0xfffe)
|
||||
@ -1394,17 +1394,17 @@ bool rcMergePolyMeshes(rcContext* ctx, rcPolyMesh** meshes, const int nmeshes, r
|
||||
mesh.nvp = meshes[0]->nvp;
|
||||
mesh.cs = meshes[0]->cs;
|
||||
mesh.ch = meshes[0]->ch;
|
||||
rcVcopy(mesh.bmin, meshes[0]->bmin);
|
||||
rcVcopy(mesh.bmax, meshes[0]->bmax);
|
||||
rdVcopy(mesh.bmin, meshes[0]->bmin);
|
||||
rdVcopy(mesh.bmax, meshes[0]->bmax);
|
||||
|
||||
int maxVerts = 0;
|
||||
int maxPolys = 0;
|
||||
int maxVertsPerMesh = 0;
|
||||
for (int i = 0; i < nmeshes; ++i)
|
||||
{
|
||||
rcVmin(mesh.bmin, meshes[i]->bmin);
|
||||
rcVmax(mesh.bmax, meshes[i]->bmax);
|
||||
maxVertsPerMesh = rcMax(maxVertsPerMesh, meshes[i]->nverts);
|
||||
rdVmin(mesh.bmin, meshes[i]->bmin);
|
||||
rdVmax(mesh.bmax, meshes[i]->bmax);
|
||||
maxVertsPerMesh = rdMax(maxVertsPerMesh, meshes[i]->nverts);
|
||||
maxVerts += meshes[i]->nverts;
|
||||
maxPolys += meshes[i]->npolys;
|
||||
}
|
||||
@ -1575,8 +1575,8 @@ bool rcCopyPolyMesh(rcContext* ctx, const rcPolyMesh& src, rcPolyMesh& dst)
|
||||
dst.npolys = src.npolys;
|
||||
dst.maxpolys = src.npolys;
|
||||
dst.nvp = src.nvp;
|
||||
rcVcopy(dst.bmin, src.bmin);
|
||||
rcVcopy(dst.bmax, src.bmax);
|
||||
rdVcopy(dst.bmin, src.bmin);
|
||||
rdVcopy(dst.bmax, src.bmax);
|
||||
dst.cs = src.cs;
|
||||
dst.ch = src.ch;
|
||||
dst.borderSize = src.borderSize;
|
||||
|
@ -72,8 +72,8 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3,
|
||||
// Calculate the circle relative to p1, to avoid some precision issues.
|
||||
const float v1[3] = {0,0,0};
|
||||
float v2[3], v3[3];
|
||||
rcVsub(v2, p2,p1);
|
||||
rcVsub(v3, p3,p1);
|
||||
rdVsub(v2, p2,p1);
|
||||
rdVsub(v3, p3,p1);
|
||||
|
||||
const float cp = vcross2(v1, v2, v3);
|
||||
if (fabsf(cp) > EPS)
|
||||
@ -85,11 +85,11 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3,
|
||||
c[1] = (v1Sq*(v3[0]-v2[0]) + v2Sq*(v1[0]-v3[0]) + v3Sq*(v2[0]-v1[0])) / (2*cp);
|
||||
c[2] = 0;
|
||||
r = vdist2(c, v1);
|
||||
rcVadd(c, c, p1);
|
||||
rdVadd(c, c, p1);
|
||||
return true;
|
||||
}
|
||||
|
||||
rcVcopy(c, p1);
|
||||
rdVcopy(c, p1);
|
||||
r = 0;
|
||||
return false;
|
||||
}
|
||||
@ -97,9 +97,9 @@ static bool circumCircle(const float* p1, const float* p2, const float* p3,
|
||||
static float distPtTri(const float* p, const float* a, const float* b, const float* c)
|
||||
{
|
||||
float v0[3], v1[3], v2[3];
|
||||
rcVsub(v0, c,a);
|
||||
rcVsub(v1, b,a);
|
||||
rcVsub(v2, p,a);
|
||||
rdVsub(v0, c,a);
|
||||
rdVsub(v1, b,a);
|
||||
rdVsub(v2, p,a);
|
||||
|
||||
const float dot00 = vdot2(v0, v0);
|
||||
const float dot01 = vdot2(v0, v1);
|
||||
@ -195,7 +195,7 @@ static float distToPoly(int nvert, const float* verts, const float* p)
|
||||
if (((vi[1] > p[1]) != (vj[1] > p[1])) &&
|
||||
(p[0] < (vj[0]-vi[0]) * (p[1]-vi[1]) / (vj[1]-vi[1]) + vi[0]) )
|
||||
c = !c;
|
||||
dmin = rcMin(dmin, distancePtSeg2d(p, vj, vi));
|
||||
dmin = rdMin(dmin, distancePtSeg2d(p, vj, vi));
|
||||
}
|
||||
return c ? -dmin : dmin;
|
||||
}
|
||||
@ -207,8 +207,8 @@ static unsigned short getHeight(const float fx, const float fy, const float fz,
|
||||
{
|
||||
int ix = (int)floorf(fx*ics + 0.01f);
|
||||
int iy = (int)floorf(fy*ics + 0.01f);
|
||||
ix = rcClamp(ix-hp.xmin, 0, hp.width - 1);
|
||||
iy = rcClamp(iy-hp.ymin, 0, hp.height - 1);
|
||||
ix = rdClamp(ix-hp.xmin, 0, hp.width - 1);
|
||||
iy = rdClamp(iy-hp.ymin, 0, hp.height - 1);
|
||||
unsigned short h = hp.data[ix+iy*hp.width];
|
||||
if (h == RC_UNSET_HEIGHT)
|
||||
{
|
||||
@ -649,11 +649,11 @@ static float polyMinExtent(const float* verts, const int nverts)
|
||||
{
|
||||
if (j == i || j == ni) continue;
|
||||
float d = distancePtSeg2d(&verts[j*3], p1,p2);
|
||||
maxEdgeDist = rcMax(maxEdgeDist, d);
|
||||
maxEdgeDist = rdMax(maxEdgeDist, d);
|
||||
}
|
||||
minDist = rcMin(minDist, maxEdgeDist);
|
||||
minDist = rdMin(minDist, maxEdgeDist);
|
||||
}
|
||||
return rcSqrt(minDist);
|
||||
return rdMathSqrtf(minDist);
|
||||
}
|
||||
|
||||
// Last time I checked the if version got compiled using cmov, which was a lot faster than module (with idiv).
|
||||
@ -795,7 +795,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
nverts = nin;
|
||||
|
||||
for (int i = 0; i < nin; ++i)
|
||||
rcVcopy(&verts[i*3], &in[i*3]);
|
||||
rdVcopy(&verts[i*3], &in[i*3]);
|
||||
|
||||
edges.clear();
|
||||
tris.clear();
|
||||
@ -822,7 +822,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
if (vj[1] > vi[1])
|
||||
{
|
||||
rcSwap(vj,vi);
|
||||
rdSwap(vj,vi);
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
@ -830,7 +830,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
if (vj[0] > vi[0])
|
||||
{
|
||||
rcSwap(vj,vi);
|
||||
rdSwap(vj,vi);
|
||||
swapped = true;
|
||||
}
|
||||
}
|
||||
@ -876,7 +876,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
}
|
||||
// If the max deviation is larger than accepted error,
|
||||
// add new point, else continue to next segment.
|
||||
if (maxi != -1 && maxd > rcSqr(sampleMaxError))
|
||||
if (maxi != -1 && maxd > rdSqr(sampleMaxError))
|
||||
{
|
||||
for (int m = nidx; m > k; --m)
|
||||
idx[m] = idx[m-1];
|
||||
@ -895,7 +895,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
for (int k = nidx-2; k > 0; --k)
|
||||
{
|
||||
rcVcopy(&verts[nverts*3], &edge[idx[k]*3]);
|
||||
rdVcopy(&verts[nverts*3], &edge[idx[k]*3]);
|
||||
hull[nhull++] = nverts;
|
||||
nverts++;
|
||||
}
|
||||
@ -904,7 +904,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
for (int k = 1; k < nidx-1; ++k)
|
||||
{
|
||||
rcVcopy(&verts[nverts*3], &edge[idx[k]*3]);
|
||||
rdVcopy(&verts[nverts*3], &edge[idx[k]*3]);
|
||||
hull[nhull++] = nverts;
|
||||
nverts++;
|
||||
}
|
||||
@ -937,12 +937,12 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
// Create sample locations in a grid.
|
||||
float bmin[3], bmax[3];
|
||||
rcVcopy(bmin, in);
|
||||
rcVcopy(bmax, in);
|
||||
rdVcopy(bmin, in);
|
||||
rdVcopy(bmax, in);
|
||||
for (int i = 1; i < nin; ++i)
|
||||
{
|
||||
rcVmin(bmin, &in[i*3]);
|
||||
rcVmax(bmax, &in[i*3]);
|
||||
rdVmin(bmin, &in[i*3]);
|
||||
rdVmax(bmax, &in[i*3]);
|
||||
}
|
||||
int x0 = (int)floorf(bmin[0]/sampleDist);
|
||||
int x1 = (int)ceilf(bmax[0]/sampleDist);
|
||||
@ -995,7 +995,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
{
|
||||
bestd = d;
|
||||
besti = i;
|
||||
rcVcopy(bestpt,pt);
|
||||
rdVcopy(bestpt,pt);
|
||||
}
|
||||
}
|
||||
// If the max error is within accepted threshold, stop tessellating.
|
||||
@ -1004,7 +1004,7 @@ static bool buildPolyDetail(rcContext* ctx, const float* in, const int nin,
|
||||
// Mark sample as added.
|
||||
samples[besti*4+3] = 1;
|
||||
// Add the new sample point.
|
||||
rcVcopy(&verts[nverts*3],bestpt);
|
||||
rdVcopy(&verts[nverts*3],bestpt);
|
||||
nverts++;
|
||||
|
||||
// Create new triangulation.
|
||||
@ -1058,7 +1058,7 @@ static void seedArrayWithPolyCenter(rcContext* ctx, const rcCompactHeightfield&
|
||||
for (int i = (int)c.index, ni = (int)(c.index+c.count); i < ni && dmin > 0; ++i)
|
||||
{
|
||||
const rcCompactSpan& s = chf.spans[i];
|
||||
int d = rcAbs(az - (int)s.z);
|
||||
int d = rdAbs(az - (int)s.z);
|
||||
if (d < dmin)
|
||||
{
|
||||
startCellX = ax;
|
||||
@ -1119,7 +1119,7 @@ static void seedArrayWithPolyCenter(rcContext* ctx, const rcCompactHeightfield&
|
||||
directDir = rcGetDirForOffset(pcx > cx ? 1 : -1, 0);
|
||||
|
||||
// Push the direct dir last so we start with this on next iteration
|
||||
rcSwap(dirs[directDir], dirs[3]);
|
||||
rdSwap(dirs[directDir], dirs[3]);
|
||||
|
||||
const rcCompactSpan& cs = chf.spans[ci];
|
||||
for (int i = 0; i < 4; i++)
|
||||
@ -1145,7 +1145,7 @@ static void seedArrayWithPolyCenter(rcContext* ctx, const rcCompactHeightfield&
|
||||
array.push((int)chf.cells[(newX+bs)+(newY+bs)*chf.width].index + rcGetCon(cs, dir));
|
||||
}
|
||||
|
||||
rcSwap(dirs[directDir], dirs[3]);
|
||||
rdSwap(dirs[directDir], dirs[3]);
|
||||
}
|
||||
|
||||
array.clear();
|
||||
@ -1306,7 +1306,7 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa
|
||||
const float ch = mesh.ch;
|
||||
const float* orig = mesh.bmin;
|
||||
const int borderSize = mesh.borderSize;
|
||||
const int heightSearchRadius = rcMax(1, (int)ceilf(mesh.maxEdgeError));
|
||||
const int heightSearchRadius = rdMax(1, (int)ceilf(mesh.maxEdgeError));
|
||||
|
||||
rdIntArray edges(64);
|
||||
rdIntArray tris(512);
|
||||
@ -1346,19 +1346,19 @@ bool rcBuildPolyMeshDetail(rcContext* ctx, const rcPolyMesh& mesh, const rcCompa
|
||||
{
|
||||
if(p[j] == RC_MESH_NULL_IDX) break;
|
||||
const unsigned short* v = &mesh.verts[p[j]*3];
|
||||
xmin = rcMin(xmin, (int)v[0]);
|
||||
xmax = rcMax(xmax, (int)v[0]);
|
||||
ymin = rcMin(ymin, (int)v[1]);
|
||||
ymax = rcMax(ymax, (int)v[1]);
|
||||
xmin = rdMin(xmin, (int)v[0]);
|
||||
xmax = rdMax(xmax, (int)v[0]);
|
||||
ymin = rdMin(ymin, (int)v[1]);
|
||||
ymax = rdMax(ymax, (int)v[1]);
|
||||
nPolyVerts++;
|
||||
}
|
||||
xmin = rcMax(0,xmin-1);
|
||||
xmax = rcMin(chf.width,xmax+1);
|
||||
ymin = rcMax(0,ymin-1);
|
||||
ymax = rcMin(chf.height,ymax+1);
|
||||
xmin = rdMax(0,xmin-1);
|
||||
xmax = rdMin(chf.width,xmax+1);
|
||||
ymin = rdMax(0,ymin-1);
|
||||
ymax = rdMin(chf.height,ymax+1);
|
||||
if (xmin >= xmax || ymin >= ymax) continue;
|
||||
maxhw = rcMax(maxhw, xmax-xmin);
|
||||
maxhh = rcMax(maxhh, ymax-ymin);
|
||||
maxhw = rdMax(maxhw, xmax-xmin);
|
||||
maxhh = rdMax(maxhh, ymax-ymin);
|
||||
}
|
||||
|
||||
hp.data = (unsigned short*)rdAlloc(sizeof(unsigned short)*maxhw*maxhh, RD_ALLOC_TEMP);
|
||||
@ -1570,7 +1570,7 @@ bool rcMergePolyMeshDetails(rcContext* ctx, rcPolyMeshDetail** meshes, const int
|
||||
|
||||
for (int k = 0; k < dm->nverts; ++k)
|
||||
{
|
||||
rcVcopy(&mesh.verts[mesh.nverts*3], &dm->verts[k*3]);
|
||||
rdVcopy(&mesh.verts[mesh.nverts*3], &dm->verts[k*3]);
|
||||
mesh.nverts++;
|
||||
}
|
||||
for (int k = 0; k < dm->ntris; ++k)
|
||||
|
@ -151,10 +151,10 @@ static bool addSpan(rcHeightfield& hf,
|
||||
}
|
||||
|
||||
// Merge flags.
|
||||
if (rcAbs((int)newSpan->smax - (int)currentSpan->smax) <= flagMergeThreshold)
|
||||
if (rdAbs((int)newSpan->smax - (int)currentSpan->smax) <= flagMergeThreshold)
|
||||
{
|
||||
// Higher area ID numbers indicate higher resolution priority.
|
||||
newSpan->area = rcMax(newSpan->area, currentSpan->area);
|
||||
newSpan->area = rdMax(newSpan->area, currentSpan->area);
|
||||
}
|
||||
|
||||
// Remove the current span since it's now merged with newSpan.
|
||||
@ -250,7 +250,7 @@ static void dividePoly(const float* inVerts, int inVertsCount,
|
||||
outVerts1[poly1Vert * 3 + 0] = inVerts[inVertB * 3 + 0] + (inVerts[inVertA * 3 + 0] - inVerts[inVertB * 3 + 0]) * s;
|
||||
outVerts1[poly1Vert * 3 + 1] = inVerts[inVertB * 3 + 1] + (inVerts[inVertA * 3 + 1] - inVerts[inVertB * 3 + 1]) * s;
|
||||
outVerts1[poly1Vert * 3 + 2] = inVerts[inVertB * 3 + 2] + (inVerts[inVertA * 3 + 2] - inVerts[inVertB * 3 + 2]) * s;
|
||||
rcVcopy(&outVerts2[poly2Vert * 3], &outVerts1[poly1Vert * 3]);
|
||||
rdVcopy(&outVerts2[poly2Vert * 3], &outVerts1[poly1Vert * 3]);
|
||||
poly1Vert++;
|
||||
poly2Vert++;
|
||||
|
||||
@ -258,12 +258,12 @@ static void dividePoly(const float* inVerts, int inVertsCount,
|
||||
// since these were already added above
|
||||
if (inVertAxisDelta[inVertA] > 0)
|
||||
{
|
||||
rcVcopy(&outVerts1[poly1Vert * 3], &inVerts[inVertA * 3]);
|
||||
rdVcopy(&outVerts1[poly1Vert * 3], &inVerts[inVertA * 3]);
|
||||
poly1Vert++;
|
||||
}
|
||||
else if (inVertAxisDelta[inVertA] < 0)
|
||||
{
|
||||
rcVcopy(&outVerts2[poly2Vert * 3], &inVerts[inVertA * 3]);
|
||||
rdVcopy(&outVerts2[poly2Vert * 3], &inVerts[inVertA * 3]);
|
||||
poly2Vert++;
|
||||
}
|
||||
}
|
||||
@ -272,14 +272,14 @@ static void dividePoly(const float* inVerts, int inVertsCount,
|
||||
// add the inVertA point to the right polygon. Addition is done even for points on the dividing line
|
||||
if (inVertAxisDelta[inVertA] >= 0)
|
||||
{
|
||||
rcVcopy(&outVerts1[poly1Vert * 3], &inVerts[inVertA * 3]);
|
||||
rdVcopy(&outVerts1[poly1Vert * 3], &inVerts[inVertA * 3]);
|
||||
poly1Vert++;
|
||||
if (inVertAxisDelta[inVertA] != 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
rcVcopy(&outVerts2[poly2Vert * 3], &inVerts[inVertA * 3]);
|
||||
rdVcopy(&outVerts2[poly2Vert * 3], &inVerts[inVertA * 3]);
|
||||
poly2Vert++;
|
||||
}
|
||||
}
|
||||
@ -312,14 +312,14 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
{
|
||||
// Calculate the bounding box of the triangle.
|
||||
float triBBMin[3];
|
||||
rcVcopy(triBBMin, v0);
|
||||
rcVmin(triBBMin, v1);
|
||||
rcVmin(triBBMin, v2);
|
||||
rdVcopy(triBBMin, v0);
|
||||
rdVmin(triBBMin, v1);
|
||||
rdVmin(triBBMin, v2);
|
||||
|
||||
float triBBMax[3];
|
||||
rcVcopy(triBBMax, v0);
|
||||
rcVmax(triBBMax, v1);
|
||||
rcVmax(triBBMax, v2);
|
||||
rdVcopy(triBBMax, v0);
|
||||
rdVmax(triBBMax, v1);
|
||||
rdVmax(triBBMax, v2);
|
||||
|
||||
// If the triangle does not touch the bounding box of the heightfield, skip the triangle.
|
||||
if (!overlapBounds(triBBMin, triBBMax, hfBBMin, hfBBMax))
|
||||
@ -336,8 +336,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
int y1 = (int)((triBBMax[1] - hfBBMin[1]) * inverseCellSize);
|
||||
|
||||
// use -1 rather than 0 to cut the polygon properly at the start of the tile
|
||||
y0 = rcClamp(y0, -1, h - 1);
|
||||
y1 = rcClamp(y1, 0, h - 1);
|
||||
y0 = rdClamp(y0, -1, h - 1);
|
||||
y1 = rdClamp(y1, 0, h - 1);
|
||||
|
||||
// Clip the triangle into all grid cells it touches.
|
||||
float buf[7 * 3 * 4];
|
||||
@ -346,9 +346,9 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
float* p1 = inRow + 7 * 3;
|
||||
float* p2 = p1 + 7 * 3;
|
||||
|
||||
rcVcopy(&in[0], v0);
|
||||
rcVcopy(&in[1 * 3], v1);
|
||||
rcVcopy(&in[2 * 3], v2);
|
||||
rdVcopy(&in[0], v0);
|
||||
rdVcopy(&in[1 * 3], v1);
|
||||
rdVcopy(&in[2 * 3], v2);
|
||||
int nvRow;
|
||||
int nvIn = 3;
|
||||
|
||||
@ -357,7 +357,7 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
// Clip polygon to row. Store the remaining polygon as well
|
||||
const float cellY = hfBBMin[1] + (float)y * cellSize;
|
||||
dividePoly(in, nvIn, inRow, &nvRow, p1, &nvIn, cellY + cellSize, RC_AXIS_Y);
|
||||
rcSwap(in, p1);
|
||||
rdSwap(in, p1);
|
||||
|
||||
if (nvRow < 3)
|
||||
{
|
||||
@ -388,8 +388,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
{
|
||||
continue;
|
||||
}
|
||||
x0 = rcClamp(x0, -1, w - 1);
|
||||
x1 = rcClamp(x1, 0, w - 1);
|
||||
x0 = rdClamp(x0, -1, w - 1);
|
||||
x1 = rdClamp(x1, 0, w - 1);
|
||||
|
||||
int nv;
|
||||
int nv2 = nvRow;
|
||||
@ -399,7 +399,7 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
// Clip polygon to column. store the remaining polygon as well
|
||||
const float cx = hfBBMin[0] + (float)x * cellSize;
|
||||
dividePoly(inRow, nv2, p1, &nv, p2, &nv2, cx + cellSize, RC_AXIS_X);
|
||||
rcSwap(inRow, p2);
|
||||
rdSwap(inRow, p2);
|
||||
|
||||
if (nv < 3)
|
||||
{
|
||||
@ -415,8 +415,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
float spanMax = p1[2];
|
||||
for (int vert = 1; vert < nv; ++vert)
|
||||
{
|
||||
spanMin = rcMin(spanMin, p1[vert * 3 + 2]);
|
||||
spanMax = rcMax(spanMax, p1[vert * 3 + 2]);
|
||||
spanMin = rdMin(spanMin, p1[vert * 3 + 2]);
|
||||
spanMax = rdMax(spanMax, p1[vert * 3 + 2]);
|
||||
}
|
||||
spanMin -= hfBBMin[2];
|
||||
spanMax -= hfBBMin[2];
|
||||
@ -442,8 +442,8 @@ static bool rasterizeTri(const float* v0, const float* v1, const float* v2,
|
||||
}
|
||||
|
||||
// Snap the span to the heightfield height grid.
|
||||
unsigned short spanMinCellIndex = (unsigned short)rcClamp((int)floorf(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMaxCellIndex = (unsigned short)rcClamp((int)ceilf(spanMax * inverseCellHeight), (int)spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMinCellIndex = (unsigned short)rdClamp((int)floorf(spanMin * inverseCellHeight), 0, RC_SPAN_MAX_HEIGHT);
|
||||
unsigned short spanMaxCellIndex = (unsigned short)rdClamp((int)ceilf(spanMax * inverseCellHeight), (int)spanMinCellIndex + 1, RC_SPAN_MAX_HEIGHT);
|
||||
|
||||
if (!addSpan(hf, x, y, spanMinCellIndex, spanMaxCellIndex, areaID, flagMergeThreshold))
|
||||
{
|
||||
|
@ -186,7 +186,7 @@ static void calculateDistanceField(rcCompactHeightfield& chf, unsigned short* sr
|
||||
|
||||
maxDist = 0;
|
||||
for (int i = 0; i < chf.spanCount; ++i)
|
||||
maxDist = rcMax(src[i], maxDist);
|
||||
maxDist = rdMax(src[i], maxDist);
|
||||
|
||||
}
|
||||
|
||||
@ -1081,8 +1081,8 @@ static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea,
|
||||
reg.spanCount++;
|
||||
reg.areaType = area;
|
||||
|
||||
reg.zmin = rcMin(reg.zmin, s.z);
|
||||
reg.zmax = rcMax(reg.zmax, s.z);
|
||||
reg.zmin = rdMin(reg.zmin, s.z);
|
||||
reg.zmax = rdMax(reg.zmax, s.z);
|
||||
|
||||
// Collect all region layers.
|
||||
lregs.push(ri);
|
||||
@ -1184,8 +1184,8 @@ static bool mergeAndFilterLayerRegions(rcContext* ctx, int minRegionArea,
|
||||
// Merge current layers to root.
|
||||
for (int k = 0; k < regn.floors.size(); ++k)
|
||||
addUniqueFloorRegion(root, regn.floors[k]);
|
||||
root.zmin = rcMin(root.zmin, regn.zmin);
|
||||
root.zmax = rcMax(root.zmax, regn.zmax);
|
||||
root.zmin = rdMin(root.zmin, regn.zmin);
|
||||
root.zmax = rdMax(root.zmax, regn.zmax);
|
||||
root.spanCount += regn.spanCount;
|
||||
regn.spanCount = 0;
|
||||
root.connectsToBorder = root.connectsToBorder || regn.connectsToBorder;
|
||||
@ -1296,7 +1296,7 @@ bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf)
|
||||
|
||||
// Blur
|
||||
if (boxBlur(chf, 1, src, dst) != src)
|
||||
rcSwap(src, dst);
|
||||
rdSwap(src, dst);
|
||||
|
||||
// Store distance.
|
||||
chf.dist = src;
|
||||
@ -1374,7 +1374,7 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
}
|
||||
memset(srcReg,0,sizeof(unsigned short)*chf.spanCount);
|
||||
|
||||
const int nsweeps = rcMax(chf.width,chf.height);
|
||||
const int nsweeps = rdMax(chf.width,chf.height);
|
||||
rdScopedDelete<rcSweepSpan> sweeps((rcSweepSpan*)rdAlloc(sizeof(rcSweepSpan)*nsweeps, RD_ALLOC_TEMP));
|
||||
if (!sweeps)
|
||||
{
|
||||
@ -1387,8 +1387,8 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
if (borderSize > 0)
|
||||
{
|
||||
// Make sure border will not overflow.
|
||||
const int bw = rcMin(w, borderSize);
|
||||
const int bh = rcMin(h, borderSize);
|
||||
const int bw = rdMin(w, borderSize);
|
||||
const int bh = rdMin(h, borderSize);
|
||||
// Paint regions
|
||||
paintRectRegion(0, bw, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
|
||||
paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
|
||||
@ -1574,8 +1574,8 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
if (borderSize > 0)
|
||||
{
|
||||
// Make sure border will not overflow.
|
||||
const int bw = rcMin(w, borderSize);
|
||||
const int bh = rcMin(h, borderSize);
|
||||
const int bw = rdMin(w, borderSize);
|
||||
const int bh = rdMin(h, borderSize);
|
||||
|
||||
// Paint regions
|
||||
paintRectRegion(0, bw, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
|
||||
@ -1683,7 +1683,7 @@ bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
}
|
||||
memset(srcReg,0,sizeof(unsigned short)*chf.spanCount);
|
||||
|
||||
const int nsweeps = rcMax(chf.width,chf.height);
|
||||
const int nsweeps = rdMax(chf.width,chf.height);
|
||||
rdScopedDelete<rcSweepSpan> sweeps((rcSweepSpan*)rdAlloc(sizeof(rcSweepSpan)*nsweeps, RD_ALLOC_TEMP));
|
||||
if (!sweeps)
|
||||
{
|
||||
@ -1696,8 +1696,8 @@ bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf,
|
||||
if (borderSize > 0)
|
||||
{
|
||||
// Make sure border will not overflow.
|
||||
const int bw = rcMin(w, borderSize);
|
||||
const int bh = rcMin(h, borderSize);
|
||||
const int bw = rdMin(w, borderSize);
|
||||
const int bh = rdMin(h, borderSize);
|
||||
// Paint regions
|
||||
paintRectRegion(0, bw, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
|
||||
paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++;
|
||||
|
@ -41,7 +41,7 @@ typedef void* (rdAllocFunc)(size_t size, rdAllocHint hint);
|
||||
/// @see rdAllocSetCustom
|
||||
typedef void (rdFreeFunc)(void* ptr);
|
||||
|
||||
/// Sets the base custom allocation functions to be used by Recast.
|
||||
/// Sets the base custom allocation functions to be used by Recast & Detour.
|
||||
/// @param[in] allocFunc The memory allocation function to be used by #rdAlloc
|
||||
/// @param[in] freeFunc The memory de-allocation function to be used by #rdFree
|
||||
///
|
||||
@ -69,7 +69,7 @@ void rdFree(void* ptr);
|
||||
|
||||
/// An implementation of operator new usable for placement new. The default one is part of STL (which we don't use).
|
||||
/// rdNewTag is a dummy type used to differentiate our operator from the STL one, in case users import both Recast
|
||||
/// and STL.
|
||||
/// & Detour and STL.
|
||||
struct rdNewTag {};
|
||||
inline void* operator new(size_t, const rdNewTag&, void* p) { return p; }
|
||||
inline void operator delete(void*, const rdNewTag&, void*) {}
|
||||
|
@ -36,11 +36,11 @@
|
||||
/// @see rdAssertFailSetCustom
|
||||
typedef void (rdAssertFailFunc)(const char* expression, const char* file, int line);
|
||||
|
||||
/// Sets the base custom assertion failure function to be used by Detour.
|
||||
/// Sets the base custom assertion failure function to be used by Recast & Detour.
|
||||
/// @param[in] assertFailFunc The function to be invoked in case of failure of #rdAssert
|
||||
void rdAssertFailSetCustom(rdAssertFailFunc *assertFailFunc);
|
||||
|
||||
/// Gets the base custom assertion failure function to be used by Detour.
|
||||
/// Gets the base custom assertion failure function to be used by Recast & Detour.
|
||||
rdAssertFailFunc* rdAssertFailGetCustom();
|
||||
|
||||
# include <assert.h>
|
||||
|
@ -16,14 +16,14 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#ifndef DETOURCOMMON_H
|
||||
#define DETOURCOMMON_H
|
||||
#ifndef RECASTDETOURCOMMON_H
|
||||
#define RECASTDETOURCOMMON_H
|
||||
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include <stddef.h>
|
||||
|
||||
/**
|
||||
@defgroup detour Detour
|
||||
@defgroup shared Shared
|
||||
|
||||
Members in this module are used to create, manipulate, and query navigation
|
||||
meshes.
|
||||
@ -38,41 +38,41 @@ feature to find minor members.
|
||||
/// Used to ignore a function parameter. VS complains about unused parameters
|
||||
/// and this silences the warning.
|
||||
/// @param [in] _ Unused parameter
|
||||
template<class T> void dtIgnoreUnused(const T&) { }
|
||||
template<class T> void rdIgnoreUnused(const T&) { }
|
||||
|
||||
/// Swaps the values of the two parameters.
|
||||
/// @param[in,out] a Value A
|
||||
/// @param[in,out] b Value B
|
||||
template<class T> inline void dtSwap(T& a, T& b) { T t = a; a = b; b = t; }
|
||||
template<class T> inline void rdSwap(T& a, T& b) { T t = a; a = b; b = t; }
|
||||
|
||||
/// Returns the minimum of two values.
|
||||
/// @param[in] a Value A
|
||||
/// @param[in] b Value B
|
||||
/// @return The minimum of the two values.
|
||||
template<class T> inline T dtMin(T a, T b) { return a < b ? a : b; }
|
||||
template<class T> inline T rdMin(T a, T b) { return a < b ? a : b; }
|
||||
|
||||
/// Returns the maximum of two values.
|
||||
/// @param[in] a Value A
|
||||
/// @param[in] b Value B
|
||||
/// @return The maximum of the two values.
|
||||
template<class T> inline T dtMax(T a, T b) { return a > b ? a : b; }
|
||||
|
||||
/// Returns the absolute value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The absolute value of the specified value.
|
||||
template<class T> inline T dtAbs(T a) { return a < 0 ? -a : a; }
|
||||
|
||||
/// Returns the square of the value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The square of the value.
|
||||
template<class T> inline T dtSqr(T a) { return a*a; }
|
||||
template<class T> inline T rdMax(T a, T b) { return a > b ? a : b; }
|
||||
|
||||
/// Clamps the value to the specified range.
|
||||
/// @param[in] v The value to clamp.
|
||||
/// @param[in] mn The minimum permitted return value.
|
||||
/// @param[in] mx The maximum permitted return value.
|
||||
/// @return The value, clamped to the specified range.
|
||||
template<class T> inline T dtClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
|
||||
template<class T> inline T rdClamp(T v, T mn, T mx) { return v < mn ? mn : (v > mx ? mx : v); }
|
||||
|
||||
/// Returns the absolute value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The absolute value of the specified value.
|
||||
template<class T> inline T rdAbs(T a) { return a < 0 ? -a : a; }
|
||||
|
||||
/// Returns the square of the value.
|
||||
/// @param[in] a The value.
|
||||
/// @return The square of the value.
|
||||
template<class T> inline T rdSqr(T a) { return a * a; }
|
||||
|
||||
/// @}
|
||||
/// @name Vector helper functions.
|
||||
@ -82,7 +82,7 @@ template<class T> inline T dtClamp(T v, T mn, T mx) { return v < mn ? mn : (v >
|
||||
/// @param[out] dest The cross product. [(x, y, z)]
|
||||
/// @param[in] v1 A Vector [(x, y, z)]
|
||||
/// @param[in] v2 A vector [(x, y, z)]
|
||||
inline void dtVcross(float* dest, const float* v1, const float* v2)
|
||||
inline void rdVcross(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[1]*v2[2] - v1[2]*v2[1];
|
||||
dest[1] = v1[2]*v2[0] - v1[0]*v2[2];
|
||||
@ -93,7 +93,7 @@ inline void dtVcross(float* dest, const float* v1, const float* v2)
|
||||
/// @param[in] v1 A Vector [(x, y, z)]
|
||||
/// @param[in] v2 A vector [(x, y, z)]
|
||||
/// @return The dot product.
|
||||
inline float dtVdot(const float* v1, const float* v2)
|
||||
inline float rdVdot(const float* v1, const float* v2)
|
||||
{
|
||||
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
|
||||
}
|
||||
@ -103,7 +103,7 @@ inline float dtVdot(const float* v1, const float* v2)
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)]
|
||||
/// @param[in] s The amount to scale @p v2 by before adding to @p v1.
|
||||
inline void dtVmad(float* dest, const float* v1, const float* v2, const float s)
|
||||
inline void rdVmad(float* dest, const float* v1, const float* v2, const float s)
|
||||
{
|
||||
dest[0] = v1[0]+v2[0]*s;
|
||||
dest[1] = v1[1]+v2[1]*s;
|
||||
@ -115,7 +115,7 @@ inline void dtVmad(float* dest, const float* v1, const float* v2, const float s)
|
||||
/// @param[in] v1 The starting vector.
|
||||
/// @param[in] v2 The destination vector.
|
||||
/// @param[in] t The interpolation factor. [Limits: 0 <= value <= 1.0]
|
||||
inline void dtVlerp(float* dest, const float* v1, const float* v2, const float t)
|
||||
inline void rdVlerp(float* dest, const float* v1, const float* v2, const float t)
|
||||
{
|
||||
dest[0] = v1[0]+(v2[0]-v1[0])*t;
|
||||
dest[1] = v1[1]+(v2[1]-v1[1])*t;
|
||||
@ -126,7 +126,7 @@ inline void dtVlerp(float* dest, const float* v1, const float* v2, const float t
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to add to @p v1. [(x, y, z)]
|
||||
inline void dtVadd(float* dest, const float* v1, const float* v2)
|
||||
inline void rdVadd(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[0]+v2[0];
|
||||
dest[1] = v1[1]+v2[1];
|
||||
@ -137,7 +137,7 @@ inline void dtVadd(float* dest, const float* v1, const float* v2)
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v1 The base vector. [(x, y, z)]
|
||||
/// @param[in] v2 The vector to subtract from @p v1. [(x, y, z)]
|
||||
inline void dtVsub(float* dest, const float* v1, const float* v2)
|
||||
inline void rdVsub(float* dest, const float* v1, const float* v2)
|
||||
{
|
||||
dest[0] = v1[0]-v2[0];
|
||||
dest[1] = v1[1]-v2[1];
|
||||
@ -148,7 +148,7 @@ inline void dtVsub(float* dest, const float* v1, const float* v2)
|
||||
/// @param[out] dest The result vector. [(x, y, z)]
|
||||
/// @param[in] v The vector to scale. [(x, y, z)]
|
||||
/// @param[in] t The scaling factor.
|
||||
inline void dtVscale(float* dest, const float* v, const float t)
|
||||
inline void rdVscale(float* dest, const float* v, const float t)
|
||||
{
|
||||
dest[0] = v[0]*t;
|
||||
dest[1] = v[1]*t;
|
||||
@ -158,21 +158,21 @@ inline void dtVscale(float* dest, const float* v, const float t)
|
||||
/// Selects the minimum value of each element from the specified vectors.
|
||||
/// @param[in,out] mn A vector. (Will be updated with the result.) [(x, y, z)]
|
||||
/// @param[in] v A vector. [(x, y, z)]
|
||||
inline void dtVmin(float* mn, const float* v)
|
||||
inline void rdVmin(float* mn, const float* v)
|
||||
{
|
||||
mn[0] = dtMin(mn[0], v[0]);
|
||||
mn[1] = dtMin(mn[1], v[1]);
|
||||
mn[2] = dtMin(mn[2], v[2]);
|
||||
mn[0] = rdMin(mn[0], v[0]);
|
||||
mn[1] = rdMin(mn[1], v[1]);
|
||||
mn[2] = rdMin(mn[2], v[2]);
|
||||
}
|
||||
|
||||
/// Selects the maximum value of each element from the specified vectors.
|
||||
/// @param[in,out] mx A vector. (Will be updated with the result.) [(x, y, z)]
|
||||
/// @param[in] v A vector. [(x, y, z)]
|
||||
inline void dtVmax(float* mx, const float* v)
|
||||
inline void rdVmax(float* mx, const float* v)
|
||||
{
|
||||
mx[0] = dtMax(mx[0], v[0]);
|
||||
mx[1] = dtMax(mx[1], v[1]);
|
||||
mx[2] = dtMax(mx[2], v[2]);
|
||||
mx[0] = rdMax(mx[0], v[0]);
|
||||
mx[1] = rdMax(mx[1], v[1]);
|
||||
mx[2] = rdMax(mx[2], v[2]);
|
||||
}
|
||||
|
||||
/// Sets the vector elements to the specified values.
|
||||
@ -180,7 +180,7 @@ inline void dtVmax(float* mx, const float* v)
|
||||
/// @param[in] x The x-value of the vector.
|
||||
/// @param[in] y The y-value of the vector.
|
||||
/// @param[in] z The z-value of the vector.
|
||||
inline void dtVset(float* dest, const float x, const float y, const float z)
|
||||
inline void rdVset(float* dest, const float x, const float y, const float z)
|
||||
{
|
||||
dest[0] = x; dest[1] = y; dest[2] = z;
|
||||
}
|
||||
@ -188,7 +188,7 @@ inline void dtVset(float* dest, const float x, const float y, const float z)
|
||||
/// Performs a vector copy.
|
||||
/// @param[out] dest The result. [(x, y, z)]
|
||||
/// @param[in] a The vector to copy. [(x, y, z)]
|
||||
inline void dtVcopy(float* dest, const float* a)
|
||||
inline void rdVcopy(float* dest, const float* a)
|
||||
{
|
||||
dest[0] = a[0];
|
||||
dest[1] = a[1];
|
||||
@ -198,15 +198,15 @@ inline void dtVcopy(float* dest, const float* a)
|
||||
/// Derives the scalar length of the vector.
|
||||
/// @param[in] v The vector. [(x, y, z)]
|
||||
/// @return The scalar length of the vector.
|
||||
inline float dtVlen(const float* v)
|
||||
inline float rdVlen(const float* v)
|
||||
{
|
||||
return dtMathSqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
return rdMathSqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
||||
}
|
||||
|
||||
/// Derives the square of the scalar length of the vector. (len * len)
|
||||
/// @param[in] v The vector. [(x, y, z)]
|
||||
/// @return The square of the scalar length of the vector.
|
||||
inline float dtVlenSqr(const float* v)
|
||||
inline float rdVlenSqr(const float* v)
|
||||
{
|
||||
return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
|
||||
}
|
||||
@ -215,19 +215,19 @@ inline float dtVlenSqr(const float* v)
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
/// @return The distance between the two points.
|
||||
inline float dtVdist(const float* v1, const float* v2)
|
||||
inline float rdVdist(const float* v1, const float* v2)
|
||||
{
|
||||
const float dx = v2[0] - v1[0];
|
||||
const float dy = v2[1] - v1[1];
|
||||
const float dz = v2[2] - v1[2];
|
||||
return dtMathSqrtf(dx*dx + dy*dy + dz*dz);
|
||||
return rdMathSqrtf(dx*dx + dy*dy + dz*dz);
|
||||
}
|
||||
|
||||
/// Returns the square of the distance between two points.
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
/// @return The square of the distance between the two points.
|
||||
inline float dtVdistSqr(const float* v1, const float* v2)
|
||||
inline float rdVdistSqr(const float* v1, const float* v2)
|
||||
{
|
||||
const float dx = v2[0] - v1[0];
|
||||
const float dy = v2[1] - v1[1];
|
||||
@ -241,18 +241,18 @@ inline float dtVdistSqr(const float* v1, const float* v2)
|
||||
/// @return The distance between the point on the xy-plane.
|
||||
///
|
||||
/// The vectors are projected onto the xy-plane, so the z-values are ignored.
|
||||
inline float dtVdist2D(const float* v1, const float* v2)
|
||||
inline float rdVdist2D(const float* v1, const float* v2)
|
||||
{
|
||||
const float dx = v2[0] - v1[0];
|
||||
const float dy = v2[1] - v1[1];
|
||||
return dtMathSqrtf(dx*dx + dy*dy);
|
||||
return rdMathSqrtf(dx*dx + dy*dy);
|
||||
}
|
||||
|
||||
/// Derives the square of the distance between the specified points on the xy-plane.
|
||||
/// @param[in] v1 A point. [(x, y, z)]
|
||||
/// @param[in] v2 A point. [(x, y, z)]
|
||||
/// @return The square of the distance between the point on the xy-plane.
|
||||
inline float dtVdist2DSqr(const float* v1, const float* v2)
|
||||
inline float rdVdist2DSqr(const float* v1, const float* v2)
|
||||
{
|
||||
const float dx = v2[0] - v1[0];
|
||||
const float dy = v2[1] - v1[1];
|
||||
@ -261,9 +261,9 @@ inline float dtVdist2DSqr(const float* v1, const float* v2)
|
||||
|
||||
/// Normalizes the vector.
|
||||
/// @param[in,out] v The vector to normalize. [(x, y, z)]
|
||||
inline void dtVnormalize(float* v)
|
||||
inline void rdVnormalize(float* v)
|
||||
{
|
||||
float d = 1.0f / dtMathSqrtf(dtSqr(v[0]) + dtSqr(v[1]) + dtSqr(v[2]));
|
||||
float d = 1.0f / rdMathSqrtf(rdSqr(v[0]) + rdSqr(v[1]) + rdSqr(v[2]));
|
||||
v[0] *= d;
|
||||
v[1] *= d;
|
||||
v[2] *= d;
|
||||
@ -276,10 +276,10 @@ inline void dtVnormalize(float* v)
|
||||
///
|
||||
/// Basically, this function will return true if the specified points are
|
||||
/// close enough to each other to be considered collocated.
|
||||
inline bool dtVequal(const float* p0, const float* p1)
|
||||
inline bool rdVequal(const float* p0, const float* p1)
|
||||
{
|
||||
static const float thr = dtSqr(1.0f/16384.0f);
|
||||
const float d = dtVdistSqr(p0, p1);
|
||||
static const float thr = rdSqr(1.0f/16384.0f);
|
||||
const float d = rdVdistSqr(p0, p1);
|
||||
return d < thr;
|
||||
}
|
||||
|
||||
@ -287,21 +287,21 @@ inline bool dtVequal(const float* p0, const float* p1)
|
||||
/// @param[in] v A point. [(x, y, z)]
|
||||
/// @return True if all of the point's components are finite, i.e. not NaN
|
||||
/// or any of the infinities.
|
||||
inline bool dtVisfinite(const float* v)
|
||||
inline bool rdVisfinite(const float* v)
|
||||
{
|
||||
bool result =
|
||||
dtMathIsfinite(v[0]) &&
|
||||
dtMathIsfinite(v[1]) &&
|
||||
dtMathIsfinite(v[2]);
|
||||
rdMathIsfinite(v[0]) &&
|
||||
rdMathIsfinite(v[1]) &&
|
||||
rdMathIsfinite(v[2]);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Checks that the specified vector's 2D components are finite.
|
||||
/// @param[in] v A point. [(x, y, z)]
|
||||
inline bool dtVisfinite2D(const float* v)
|
||||
inline bool rdVisfinite2D(const float* v)
|
||||
{
|
||||
bool result = dtMathIsfinite(v[0]) && dtMathIsfinite(v[2]);
|
||||
bool result = rdMathIsfinite(v[0]) && rdMathIsfinite(v[2]);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ inline bool dtVisfinite2D(const float* v)
|
||||
/// @return The dot product on the xy-plane.
|
||||
///
|
||||
/// The vectors are projected onto the xy-plane, so the z-values are ignored.
|
||||
inline float dtVdot2D(const float* u, const float* v)
|
||||
inline float rdVdot2D(const float* u, const float* v)
|
||||
{
|
||||
return u[0]*v[0] + u[1]*v[1];
|
||||
}
|
||||
@ -322,7 +322,7 @@ inline float dtVdot2D(const float* u, const float* v)
|
||||
/// @return The perp dot product on the xy-plane.
|
||||
///
|
||||
/// The vectors are projected onto the xy-plane, so the z-values are ignored.
|
||||
inline float dtVperp2D(const float* u, const float* v)
|
||||
inline float rdVperp2D(const float* u, const float* v)
|
||||
{
|
||||
return u[0]*v[1] - u[1]*v[0];
|
||||
}
|
||||
@ -336,7 +336,7 @@ inline float dtVperp2D(const float* u, const float* v)
|
||||
/// @param[in] b Vertex B. [(x, y, z)]
|
||||
/// @param[in] c Vertex C. [(x, y, z)]
|
||||
/// @return The signed xy-plane area of the triangle.
|
||||
inline float dtTriArea2D(const float* a, const float* b, const float* c)
|
||||
inline float rdTriArea2D(const float* a, const float* b, const float* c)
|
||||
{
|
||||
const float abx = b[0] - a[0];
|
||||
const float aby = b[1] - a[1];
|
||||
@ -352,7 +352,7 @@ inline float dtTriArea2D(const float* a, const float* b, const float* c)
|
||||
/// @param[in] bmax Maximum bounds of box B. [(x, y, z)]
|
||||
/// @return True if the two AABB's overlap.
|
||||
/// @see dtOverlapBounds
|
||||
inline bool dtOverlapQuantBounds(const unsigned short amin[3], const unsigned short amax[3],
|
||||
inline bool rdOverlapQuantBounds(const unsigned short amin[3], const unsigned short amax[3],
|
||||
const unsigned short bmin[3], const unsigned short bmax[3])
|
||||
{
|
||||
bool overlap = true;
|
||||
@ -369,7 +369,7 @@ inline bool dtOverlapQuantBounds(const unsigned short amin[3], const unsigned sh
|
||||
/// @param[in] bmax Maximum bounds of box B. [(x, y, z)]
|
||||
/// @return True if the two AABB's overlap.
|
||||
/// @see dtOverlapQuantBounds
|
||||
inline bool dtOverlapBounds(const float* amin, const float* amax,
|
||||
inline bool rdOverlapBounds(const float* amin, const float* amax,
|
||||
const float* bmin, const float* bmax)
|
||||
{
|
||||
bool overlap = true;
|
||||
@ -385,7 +385,7 @@ inline bool dtOverlapBounds(const float* amin, const float* amax,
|
||||
/// @param[in] a Vertex A of triangle ABC. [(x, y, z)]
|
||||
/// @param[in] b Vertex B of triangle ABC. [(x, y, z)]
|
||||
/// @param[in] c Vertex C of triangle ABC. [(x, y, z)]
|
||||
void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
void rdClosestPtPointTriangle(float* closest, const float* p,
|
||||
const float* a, const float* b, const float* c);
|
||||
|
||||
/// Derives the y-axis height of the closest point on the triangle from the specified reference point.
|
||||
@ -394,37 +394,37 @@ void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
/// @param[in] b Vertex B of triangle ABC. [(x, y, z)]
|
||||
/// @param[in] c Vertex C of triangle ABC. [(x, y, z)]
|
||||
/// @param[out] h The resulting height.
|
||||
bool dtClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h);
|
||||
bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h);
|
||||
|
||||
bool dtIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
bool rdIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
const float* verts, int nverts,
|
||||
float& tmin, float& tmax,
|
||||
int& segMin, int& segMax);
|
||||
|
||||
bool dtIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
bool rdIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
const float* bp, const float* bq,
|
||||
float& s, float& t);
|
||||
|
||||
float distancePtLine2d(const float* pt, const float* p, const float* q);
|
||||
float rdDistancePtLine2d(const float* pt, const float* p, const float* q);
|
||||
|
||||
/// 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]
|
||||
/// @return True if the point is inside the polygon.
|
||||
bool dtPointInPolygon(const float* pt, const float* verts, const int nverts);
|
||||
bool rdPointInPolygon(const float* pt, const float* verts, const int nverts);
|
||||
|
||||
bool dtDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nverts,
|
||||
bool rdDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nverts,
|
||||
float* ed, float* et);
|
||||
|
||||
float dtDistancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t);
|
||||
float rdDistancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t);
|
||||
|
||||
/// Derives the centroid of a convex polygon.
|
||||
/// @param[out] tc The centroid of the polgyon. [(x, y, z)]
|
||||
/// @param[out] tc The centroid of the polygon. [(x, y, z)]
|
||||
/// @param[in] idx The polygon indices. [(vertIndex) * @p nidx]
|
||||
/// @param[in] nidx The number of indices in the polygon. [Limit: >= 3]
|
||||
/// @param[in] verts The polygon vertices. [(x, y, z) * vertCount]
|
||||
void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts);
|
||||
void rdCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts);
|
||||
|
||||
/// Determines if the two convex polygons overlap on the xy-plane.
|
||||
/// @param[in] polya Polygon A vertices. [(x, y, z) * @p npolya]
|
||||
@ -432,14 +432,14 @@ void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const floa
|
||||
/// @param[in] polyb Polygon B vertices. [(x, y, z) * @p npolyb]
|
||||
/// @param[in] npolyb The number of vertices in polygon B.
|
||||
/// @return True if the two polygons overlap.
|
||||
bool dtOverlapPolyPoly2D(const float* polya, const int npolya,
|
||||
bool rdOverlapPolyPoly2D(const float* polya, const int npolya,
|
||||
const float* polyb, const int npolyb);
|
||||
|
||||
/// @}
|
||||
/// @name Miscellaneous functions.
|
||||
/// @{
|
||||
|
||||
inline unsigned int dtNextPow2(unsigned int v)
|
||||
inline unsigned int rdNextPow2(unsigned int v)
|
||||
{
|
||||
v--;
|
||||
v |= v >> 1;
|
||||
@ -451,7 +451,7 @@ inline unsigned int dtNextPow2(unsigned int v)
|
||||
return v;
|
||||
}
|
||||
|
||||
inline unsigned int dtIlog2(unsigned int v)
|
||||
inline unsigned int rdIlog2(unsigned int v)
|
||||
{
|
||||
unsigned int r;
|
||||
unsigned int shift;
|
||||
@ -463,52 +463,52 @@ inline unsigned int dtIlog2(unsigned int v)
|
||||
return r;
|
||||
}
|
||||
|
||||
inline int dtAlign4(int x) { return (x+3) & ~3; }
|
||||
inline int rdAlign4(int x) { return (x+3) & ~3; }
|
||||
|
||||
inline int dtOppositeTile(int side) { return (side+4) & 0x7; }
|
||||
inline int rdOppositeTile(int side) { return (side+4) & 0x7; }
|
||||
|
||||
inline void dtSwapByte(unsigned char* a, unsigned char* b)
|
||||
inline void rdSwapByte(unsigned char* a, unsigned char* b)
|
||||
{
|
||||
unsigned char tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
inline void dtSwapEndian(unsigned short* v)
|
||||
inline void rdSwapEndian(unsigned short* v)
|
||||
{
|
||||
unsigned char* x = (unsigned char*)v;
|
||||
dtSwapByte(x+0, x+1);
|
||||
rdSwapByte(x+0, x+1);
|
||||
}
|
||||
|
||||
inline void dtSwapEndian(short* v)
|
||||
inline void rdSwapEndian(short* v)
|
||||
{
|
||||
unsigned char* x = (unsigned char*)v;
|
||||
dtSwapByte(x+0, x+1);
|
||||
rdSwapByte(x+0, x+1);
|
||||
}
|
||||
|
||||
inline void dtSwapEndian(unsigned int* v)
|
||||
inline void rdSwapEndian(unsigned int* v)
|
||||
{
|
||||
unsigned char* x = (unsigned char*)v;
|
||||
dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
|
||||
rdSwapByte(x+0, x+3); rdSwapByte(x+1, x+2);
|
||||
}
|
||||
|
||||
inline void dtSwapEndian(int* v)
|
||||
inline void rdSwapEndian(int* v)
|
||||
{
|
||||
unsigned char* x = (unsigned char*)v;
|
||||
dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
|
||||
rdSwapByte(x+0, x+3); rdSwapByte(x+1, x+2);
|
||||
}
|
||||
|
||||
inline void dtSwapEndian(float* v)
|
||||
inline void rdSwapEndian(float* v)
|
||||
{
|
||||
unsigned char* x = (unsigned char*)v;
|
||||
dtSwapByte(x+0, x+3); dtSwapByte(x+1, x+2);
|
||||
rdSwapByte(x+0, x+3); rdSwapByte(x+1, x+2);
|
||||
}
|
||||
|
||||
void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
void rdRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
const float s, const float t, float* out);
|
||||
|
||||
template<typename TypeToRetrieveAs>
|
||||
TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(const unsigned char*& buffer, const size_t distanceToAdvance)
|
||||
TypeToRetrieveAs* rdGetThenAdvanceBufferPointer(const unsigned char*& buffer, const size_t distanceToAdvance)
|
||||
{
|
||||
TypeToRetrieveAs* returnPointer = reinterpret_cast<TypeToRetrieveAs*>(buffer);
|
||||
buffer += distanceToAdvance;
|
||||
@ -516,7 +516,7 @@ TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(const unsigned char*& buffer, co
|
||||
}
|
||||
|
||||
template<typename TypeToRetrieveAs>
|
||||
TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(unsigned char*& buffer, const size_t distanceToAdvance)
|
||||
TypeToRetrieveAs* rdGetThenAdvanceBufferPointer(unsigned char*& buffer, const size_t distanceToAdvance)
|
||||
{
|
||||
TypeToRetrieveAs* returnPointer = reinterpret_cast<TypeToRetrieveAs*>(buffer);
|
||||
buffer += distanceToAdvance;
|
||||
@ -526,7 +526,7 @@ TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(unsigned char*& buffer, const si
|
||||
|
||||
/// @}
|
||||
|
||||
#endif // DETOURCOMMON_H
|
||||
#endif // RECASTDETOURCOMMON_H
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -535,7 +535,7 @@ TypeToRetrieveAs* dtGetThenAdvanceBufferPointer(unsigned char*& buffer, const si
|
||||
|
||||
/**
|
||||
|
||||
@fn float dtTriArea2D(const float* a, const float* b, const float* c)
|
||||
@fn float rdTriArea2D(const float* a, const float* b, const float* c)
|
||||
@par
|
||||
|
||||
The vertices are projected onto the xy-plane, so the z-values are ignored.
|
31
src/thirdparty/recast/Shared/Include/SharedMath.h
vendored
Normal file
31
src/thirdparty/recast/Shared/Include/SharedMath.h
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/**
|
||||
@defgroup shared Shared
|
||||
|
||||
Members in this module are wrappers around the standard math library
|
||||
*/
|
||||
|
||||
#ifndef RECASTDETOURMATH_H
|
||||
#define RECASTDETOURMATH_H
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/// The value of PI used by Recast & Detour.
|
||||
static const float RD_PI = 3.14159265f;
|
||||
|
||||
/// The total number of bits in an bit cell integer.
|
||||
static const int RD_BITS_PER_BIT_CELL = 32;
|
||||
|
||||
// TODO: move to common!
|
||||
inline int rdBitCellBit(const int bitNum) { return (1 << ((bitNum) & (RD_BITS_PER_BIT_CELL-1))); }
|
||||
|
||||
inline float rdMathFabsf(float x) { return fabsf(x); }
|
||||
inline float rdMathSqrtf(float x) { return sqrtf(x); }
|
||||
inline float rdMathFloorf(float x) { return floorf(x); }
|
||||
inline float rdMathCeilf(float x) { return ceilf(x); }
|
||||
inline float rdMathRoundf(float x) { return roundf(x); }
|
||||
inline float rdMathCosf(float x) { return cosf(x); }
|
||||
inline float rdMathSinf(float x) { return sinf(x); }
|
||||
inline float rdMathAtan2f(float y, float x) { return atan2f(y, x); }
|
||||
inline bool rdMathIsfinite(float x) { return isfinite(x); }
|
||||
|
||||
#endif // RECASTDETOURMATH_H
|
@ -16,37 +16,37 @@
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
|
||||
#include "Detour/Include/DetourCommon.h"
|
||||
#include "Detour/Include/DetourMath.h"
|
||||
#include "Shared/Include/SharedMath.h"
|
||||
#include "Shared/Include/SharedCommon.h"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
void rdClosestPtPointTriangle(float* closest, const float* p,
|
||||
const float* a, const float* b, const float* c)
|
||||
{
|
||||
// Check if P in vertex region outside A
|
||||
float ab[3], ac[3], ap[3];
|
||||
dtVsub(ab, b, a);
|
||||
dtVsub(ac, c, a);
|
||||
dtVsub(ap, p, a);
|
||||
float d1 = dtVdot(ab, ap);
|
||||
float d2 = dtVdot(ac, ap);
|
||||
rdVsub(ab, b, a);
|
||||
rdVsub(ac, c, a);
|
||||
rdVsub(ap, p, a);
|
||||
float d1 = rdVdot(ab, ap);
|
||||
float d2 = rdVdot(ac, ap);
|
||||
if (d1 <= 0.0f && d2 <= 0.0f)
|
||||
{
|
||||
// barycentric coordinates (1,0,0)
|
||||
dtVcopy(closest, a);
|
||||
rdVcopy(closest, a);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if P in vertex region outside B
|
||||
float bp[3];
|
||||
dtVsub(bp, p, b);
|
||||
float d3 = dtVdot(ab, bp);
|
||||
float d4 = dtVdot(ac, bp);
|
||||
rdVsub(bp, p, b);
|
||||
float d3 = rdVdot(ab, bp);
|
||||
float d4 = rdVdot(ac, bp);
|
||||
if (d3 >= 0.0f && d4 <= d3)
|
||||
{
|
||||
// barycentric coordinates (0,1,0)
|
||||
dtVcopy(closest, b);
|
||||
rdVcopy(closest, b);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -64,13 +64,13 @@ void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
|
||||
// Check if P in vertex region outside C
|
||||
float cp[3];
|
||||
dtVsub(cp, p, c);
|
||||
float d5 = dtVdot(ab, cp);
|
||||
float d6 = dtVdot(ac, cp);
|
||||
rdVsub(cp, p, c);
|
||||
float d5 = rdVdot(ab, cp);
|
||||
float d6 = rdVdot(ac, cp);
|
||||
if (d6 >= 0.0f && d5 <= d6)
|
||||
{
|
||||
// barycentric coordinates (0,0,1)
|
||||
dtVcopy(closest, c);
|
||||
rdVcopy(closest, c);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ void dtClosestPtPointTriangle(float* closest, const float* p,
|
||||
closest[2] = a[2] + ab[2] * v + ac[2] * w;
|
||||
}
|
||||
|
||||
bool dtIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
bool rdIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
const float* verts, int nverts,
|
||||
float& tmin, float& tmax,
|
||||
int& segMin, int& segMax)
|
||||
@ -120,15 +120,15 @@ bool dtIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
segMax = -1;
|
||||
|
||||
float dir[3];
|
||||
dtVsub(dir, p1, p0);
|
||||
rdVsub(dir, p1, p0);
|
||||
|
||||
for (int i = 0, j = nverts-1; i < nverts; j=i++)
|
||||
{
|
||||
float edge[3], diff[3];
|
||||
dtVsub(edge, &verts[i*3], &verts[j*3]);
|
||||
dtVsub(diff, p0, &verts[j*3]);
|
||||
const float n = dtVperp2D(edge, diff);
|
||||
const float d = dtVperp2D(dir, edge);
|
||||
rdVsub(edge, &verts[i*3], &verts[j*3]);
|
||||
rdVsub(diff, p0, &verts[j*3]);
|
||||
const float n = rdVperp2D(edge, diff);
|
||||
const float d = rdVperp2D(dir, edge);
|
||||
if (fabsf(d) < EPS)
|
||||
{
|
||||
// S is nearly parallel to this edge
|
||||
@ -167,7 +167,7 @@ bool dtIntersectSegmentPoly2D(const float* p0, const float* p1,
|
||||
return true;
|
||||
}
|
||||
|
||||
float dtDistancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t)
|
||||
float rdDistancePtSegSqr2D(const float* pt, const float* p, const float* q, float& t)
|
||||
{
|
||||
float pqx = q[0] - p[0];
|
||||
float pqy = q[1] - p[1];
|
||||
@ -183,7 +183,7 @@ float dtDistancePtSegSqr2D(const float* pt, const float* p, const float* q, floa
|
||||
return dx*dx + dy*dy;
|
||||
}
|
||||
|
||||
void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts)
|
||||
void rdCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const float* verts)
|
||||
{
|
||||
tc[0] = 0.0f;
|
||||
tc[1] = 0.0f;
|
||||
@ -201,14 +201,14 @@ void dtCalcPolyCenter(float* tc, const unsigned short* idx, int nidx, const floa
|
||||
tc[2] *= s;
|
||||
}
|
||||
|
||||
bool dtClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h)
|
||||
bool rdClosestHeightPointTriangle(const float* p, const float* a, const float* b, const float* c, float& h)
|
||||
{
|
||||
const float EPS = 1e-6f;
|
||||
float v0[3], v1[3], v2[3];
|
||||
|
||||
dtVsub(v0, c, a);
|
||||
dtVsub(v1, b, a);
|
||||
dtVsub(v2, p, a);
|
||||
rdVsub(v0, c, a);
|
||||
rdVsub(v1, b, a);
|
||||
rdVsub(v2, p, a);
|
||||
|
||||
// Compute scaled barycentric coordinates
|
||||
float denom = v0[0] * v1[1] - v0[1] * v1[0];
|
||||
@ -235,7 +235,7 @@ bool dtClosestHeightPointTriangle(const float* p, const float* a, const float* b
|
||||
/// @par
|
||||
///
|
||||
/// All points are projected onto the xy-plane, so the z-values are ignored.
|
||||
bool dtPointInPolygon(const float* pt, const float* verts, const int nverts)
|
||||
bool rdPointInPolygon(const float* pt, const float* verts, const int nverts)
|
||||
{
|
||||
// TODO: Replace pnpoly with triArea2D tests?
|
||||
int i, j;
|
||||
@ -251,7 +251,7 @@ bool dtPointInPolygon(const float* pt, const float* verts, const int nverts)
|
||||
return c;
|
||||
}
|
||||
|
||||
bool dtDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nverts,
|
||||
bool rdDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nverts,
|
||||
float* ed, float* et)
|
||||
{
|
||||
// TODO: Replace pnpoly with triArea2D tests?
|
||||
@ -264,7 +264,7 @@ bool dtDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nve
|
||||
if (((vi[1] > pt[1]) != (vj[1] > pt[1])) &&
|
||||
(pt[0] < (vj[0]-vi[0]) * (pt[1]-vi[1]) / (vj[1]-vi[1]) + vi[0]) )
|
||||
c = !c;
|
||||
ed[j] = dtDistancePtSegSqr2D(pt, vj, vi, et[j]);
|
||||
ed[j] = rdDistancePtSegSqr2D(pt, vj, vi, et[j]);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
@ -272,12 +272,12 @@ bool dtDistancePtPolyEdgesSqr(const float* pt, const float* verts, const int nve
|
||||
static void projectPoly(const float* axis, const float* poly, const int npoly,
|
||||
float& rmin, float& rmax)
|
||||
{
|
||||
rmin = rmax = dtVdot2D(axis, &poly[0]);
|
||||
rmin = rmax = rdVdot2D(axis, &poly[0]);
|
||||
for (int i = 1; i < npoly; ++i)
|
||||
{
|
||||
const float d = dtVdot2D(axis, &poly[i*3]);
|
||||
rmin = dtMin(rmin, d);
|
||||
rmax = dtMax(rmax, d);
|
||||
const float d = rdVdot2D(axis, &poly[i*3]);
|
||||
rmin = rdMin(rmin, d);
|
||||
rmax = rdMax(rmax, d);
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,7 +291,7 @@ inline bool overlapRange(const float amin, const float amax,
|
||||
/// @par
|
||||
///
|
||||
/// All vertices are projected onto the xy-plane, so the z-values are ignored.
|
||||
bool dtOverlapPolyPoly2D(const float* polya, const int npolya,
|
||||
bool rdOverlapPolyPoly2D(const float* polya, const int npolya,
|
||||
const float* polyb, const int npolyb)
|
||||
{
|
||||
const float eps = 1e-4f;
|
||||
@ -329,14 +329,14 @@ bool dtOverlapPolyPoly2D(const float* polya, const int npolya,
|
||||
|
||||
// Returns a random point in a convex polygon.
|
||||
// Adapted from Graphics Gems article.
|
||||
void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
void rdRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
const float s, const float t, float* out)
|
||||
{
|
||||
// Calc triangle areas
|
||||
float areasum = 0.0f;
|
||||
for (int i = 2; i < npts; i++) {
|
||||
areas[i] = dtTriArea2D(&pts[0], &pts[i*3], &pts[(i-1)*3]);
|
||||
areasum += dtMax(0.001f, areas[i]);
|
||||
areas[i] = rdTriArea2D(&pts[0], &pts[i*3], &pts[(i-1)*3]);
|
||||
areasum += rdMax(0.001f, areas[i]);
|
||||
}
|
||||
// Find sub triangle weighted by area.
|
||||
const float thr = s*areasum;
|
||||
@ -354,7 +354,7 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
acc += dacc;
|
||||
}
|
||||
|
||||
float v = dtMathSqrtf(t);
|
||||
float v = rdMathSqrtf(t);
|
||||
|
||||
const float a = 1 - v;
|
||||
const float b = (1 - u) * v;
|
||||
@ -370,14 +370,14 @@ void dtRandomPointInConvexPoly(const float* pts, const int npts, float* areas,
|
||||
|
||||
inline float vperpXY(const float* a, const float* b) { return a[0]*b[1] - a[1]*b[0]; }
|
||||
|
||||
bool dtIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
bool rdIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
const float* bp, const float* bq,
|
||||
float& s, float& t)
|
||||
{
|
||||
float u[3], v[3], w[3];
|
||||
dtVsub(u,aq,ap);
|
||||
dtVsub(v,bq,bp);
|
||||
dtVsub(w,ap,bp);
|
||||
rdVsub(u,aq,ap);
|
||||
rdVsub(v,bq,bp);
|
||||
rdVsub(w,ap,bp);
|
||||
float d = vperpXY(u,v);
|
||||
if (fabsf(d) < 1e-6f) return false;
|
||||
s = vperpXY(v,w) / d;
|
||||
@ -385,7 +385,7 @@ bool dtIntersectSegSeg2D(const float* ap, const float* aq,
|
||||
return true;
|
||||
}
|
||||
|
||||
float distancePtLine2d(const float* pt, const float* p, const float* q)
|
||||
float rdDistancePtLine2d(const float* pt, const float* p, const float* q)
|
||||
{
|
||||
float pqx = q[0] - p[0];
|
||||
float pqy = q[1] - p[1];
|
Loading…
x
Reference in New Issue
Block a user