diff --git a/src/DotRecast.Core/RcMath.cs b/src/DotRecast.Core/RcMath.cs index 7022073..63f1370 100644 --- a/src/DotRecast.Core/RcMath.cs +++ b/src/DotRecast.Core/RcMath.cs @@ -304,17 +304,6 @@ namespace DotRecast.Core } } - public static void VNormalize(ref Vector3f v) - { - float d = (float)(1.0f / Math.Sqrt(Sqr(v.x) + Sqr(v.y) + Sqr(v.z))); - if (d != 0) - { - v.x *= d; - v.y *= d; - v.z *= d; - } - } - /// Performs a 'sloppy' colocation check of the specified points. /// @param[in] p0 A point. [(x, y, z)] diff --git a/src/DotRecast.Core/Vector3f.cs b/src/DotRecast.Core/Vector3f.cs index d8ba976..3d92d0b 100644 --- a/src/DotRecast.Core/Vector3f.cs +++ b/src/DotRecast.Core/Vector3f.cs @@ -172,5 +172,17 @@ namespace DotRecast.Core (v1.x * v2.y) - (v1.y * v2.x) ); } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Normalize() + { + float d = (float)(1.0f / Math.Sqrt(RcMath.Sqr(x) + RcMath.Sqr(y) + RcMath.Sqr(z))); + if (d != 0) + { + x *= d; + y *= d; + z *= d; + } + } } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Crowd/CrowdAgent.cs b/src/DotRecast.Detour.Crowd/CrowdAgent.cs index 79af187..ffc5611 100644 --- a/src/DotRecast.Detour.Crowd/CrowdAgent.cs +++ b/src/DotRecast.Detour.Crowd/CrowdAgent.cs @@ -182,8 +182,7 @@ namespace DotRecast.Detour.Crowd dir.x = dir0.x - dir1.x * len0 * 0.5f; dir.y = 0; dir.z = dir0.z - dir1.z * len0 * 0.5f; - - VNormalize(ref dir); + dir.Normalize(); } return dir; @@ -196,7 +195,7 @@ namespace DotRecast.Detour.Crowd { dir = corners[0].GetPos().Subtract(npos); dir.y = 0; - VNormalize(ref dir); + dir.Normalize(); } return dir; diff --git a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs index 55e2056..c32bb57 100644 --- a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs +++ b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs @@ -128,7 +128,7 @@ namespace DotRecast.Detour.Crowd Vector3f orig = new Vector3f(); Vector3f dv = new Vector3f(); cir.dp = pb.Subtract(pa); - VNormalize(ref cir.dp); + cir.dp.Normalize(); dv = cir.dvel.Subtract(dvel); float a = TriArea2D(orig, cir.dp, dv); diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs index ecea8a6..4e565f7 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs @@ -18,9 +18,9 @@ namespace DotRecast.Detour.Extras.Jumplink { this.trajectory = trajectory; ax = edge.sq.Subtract(edge.sp); - VNormalize(ref ax); + ax.Normalize(); VSet(ref az, ax.z, 0, -ax.x); - VNormalize(ref az); + az.Normalize(); VSet(ref ay, 0, 1, 0); } } diff --git a/src/DotRecast.Detour/LegacyNavMeshQuery.cs b/src/DotRecast.Detour/LegacyNavMeshQuery.cs index 33e3713..e830013 100644 --- a/src/DotRecast.Detour/LegacyNavMeshQuery.cs +++ b/src/DotRecast.Detour/LegacyNavMeshQuery.cs @@ -848,7 +848,7 @@ namespace DotRecast.Detour hitNormal.x = tangent.z; hitNormal.y = 0; hitNormal.z = -tangent.x; - VNormalize(ref hitNormal); + hitNormal.Normalize(); } return Results.Success(new FindDistanceToWallResult((float)Math.Sqrt(radiusSqr), hitPos, hitNormal)); diff --git a/src/DotRecast.Detour/NavMeshQuery.cs b/src/DotRecast.Detour/NavMeshQuery.cs index cdbb82b..f723c5a 100644 --- a/src/DotRecast.Detour/NavMeshQuery.cs +++ b/src/DotRecast.Detour/NavMeshQuery.cs @@ -2400,7 +2400,7 @@ namespace DotRecast.Detour hit.hitNormal.x = dz; hit.hitNormal.y = 0; hit.hitNormal.z = -dx; - VNormalize(ref hit.hitNormal); + hit.hitNormal.Normalize(); return Results.Success(hit); } @@ -3372,7 +3372,7 @@ namespace DotRecast.Detour hitNormal.x = tangent.z; hitNormal.y = 0; hitNormal.z = -tangent.x; - VNormalize(ref hitNormal); + hitNormal.Normalize(); } return Results.Success(new FindDistanceToWallResult((float)Math.Sqrt(radiusSqr), hitPos, hitNormal)); diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs index 598093c..e69e4a5 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdTool.cs @@ -314,7 +314,7 @@ public class CrowdTool : Tool { Vector3f vel = tgt.Subtract(pos); vel.y = 0.0f; - VNormalize(ref vel); + vel.Normalize(); return VScale(vel, speed); } diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs index 3c63a1f..dfe867a 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateTool.cs @@ -201,7 +201,7 @@ public class DynamicUpdateTool : Tool 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble()) ); - VNormalize(ref a); + a.Normalize(); float len = 1f + (float)random.NextDouble() * 20f; a.x *= len; a.y *= len; @@ -247,7 +247,7 @@ public class DynamicUpdateTool : Tool Vector3f baseCenter = Vector3f.Of(p.x, p.y + 3, p.z); Vector3f baseUp = Vector3f.Of(0, 1, 0); Vector3f forward = Vector3f.Of((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); - VNormalize(ref forward); + forward.Normalize(); Vector3f side = Vector3f.Cross(forward, baseUp); BoxCollider @base = new BoxCollider(baseCenter, Detour.Dynamic.Colliders.BoxCollider.GetHalfEdges(baseUp, forward, baseExtent), SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, dynaMesh.config.walkableClimb); diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs index 13b0804..df6dee3 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshTool.cs @@ -858,7 +858,7 @@ public class TestNavmeshTool : Tool Vector3f delta = s3.Subtract(s.vmin); Vector3f p0 = VMad(s.vmin, delta, 0.5f); Vector3f norm = Vector3f.Of(delta.z, 0, -delta.x); - VNormalize(ref norm); + norm.Normalize(); Vector3f p1 = VMad(p0, norm, agentRadius * 0.5f); // Skip backfacing segments. if (wallSegments.GetSegmentRef(j) != 0) diff --git a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs index 44feb56..8a4e5fa 100644 --- a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs +++ b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs @@ -155,7 +155,7 @@ public class AbstractCrowdTest { Vector3f vel = tgt.Subtract(pos); vel.y = 0.0f; - VNormalize(ref vel); + vel.Normalize(); vel = VScale(vel, speed); return vel; }