From 59f6ea52dc10491b46df62421cbdcf96f967696e Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:35:20 +0200 Subject: [PATCH] Recast: optimize getPolyCenter Copy the already computed poly center value (cached in dtPoly::center). --- src/naveditor/NavMeshTesterTool.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/naveditor/NavMeshTesterTool.cpp b/src/naveditor/NavMeshTesterTool.cpp index bc7a2726..28d8143e 100644 --- a/src/naveditor/NavMeshTesterTool.cpp +++ b/src/naveditor/NavMeshTesterTool.cpp @@ -960,18 +960,8 @@ static void getPolyCenter(dtNavMesh* navMesh, dtPolyRef ref, float* center) dtStatus status = navMesh->getTileAndPolyByRef(ref, &tile, &poly); if (dtStatusFailed(status)) return; - - for (int i = 0; i < (int)poly->vertCount; ++i) - { - const float* v = &tile->verts[poly->verts[i]*3]; - center[0] += v[0]; - center[1] += v[1]; - center[2] += v[2]; - } - const float s = 1.0f / poly->vertCount; - center[0] *= s; - center[1] *= s; - center[2] *= s; + + dtVcopy(center, poly->center); }