diff --git a/src/DotRecast.Core/RcMath.cs b/src/DotRecast.Core/RcMath.cs index 64dfbf4..4472f3c 100644 --- a/src/DotRecast.Core/RcMath.cs +++ b/src/DotRecast.Core/RcMath.cs @@ -121,12 +121,6 @@ namespace DotRecast.Core } - public static void VSet(ref Vector3f @out, float a, float b, float c) - { - @out.x = a; - @out.y = b; - @out.z = c; - } public static void VCopy(ref Vector3f @out, float[] @in) { diff --git a/src/DotRecast.Core/Vector3f.cs b/src/DotRecast.Core/Vector3f.cs index 30a7fd7..a092047 100644 --- a/src/DotRecast.Core/Vector3f.cs +++ b/src/DotRecast.Core/Vector3f.cs @@ -103,6 +103,14 @@ namespace DotRecast.Core } } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void Set(float a, float b, float c) + { + x = a; + y = b; + z = c; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public readonly float Length() { diff --git a/src/DotRecast.Detour.Crowd/Crowd.cs b/src/DotRecast.Detour.Crowd/Crowd.cs index 23fa350..53cdfc6 100644 --- a/src/DotRecast.Detour.Crowd/Crowd.cs +++ b/src/DotRecast.Detour.Crowd/Crowd.cs @@ -165,7 +165,7 @@ namespace DotRecast.Detour.Crowd public Crowd(CrowdConfig config, NavMesh nav, Func queryFilterFactory) { _config = config; - VSet(ref _ext, config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); + _ext.Set(config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); _obstacleQuery = new ObstacleAvoidanceQuery(config.maxObstacleAvoidanceCircles, config.maxObstacleAvoidanceSegments); @@ -1261,11 +1261,11 @@ namespace DotRecast.Detour.Crowd // Agents on top of each other, try to choose diverging separation directions. if (idx0 > idx1) { - VSet(ref diff, -ag.dvel.z, 0, ag.dvel.x); + diff.Set(-ag.dvel.z, 0, ag.dvel.x); } else { - VSet(ref diff, ag.dvel.z, 0, -ag.dvel.x); + diff.Set(ag.dvel.z, 0, -ag.dvel.x); } pen = 0.01f; diff --git a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs index e8021b6..3ebb436 100644 --- a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs +++ b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs @@ -341,9 +341,7 @@ namespace DotRecast.Detour.Crowd { for (int x = 0; x < m_params.gridSize; ++x) { - Vector3f vcand = new Vector3f(); - VSet(ref vcand, cvx + x * cs - half, 0f, cvz + y * cs - half); - + Vector3f vcand = Vector3f.Of(cvx + x * cs - half, 0f, cvz + y * cs - half); if (Sqr(vcand.x) + Sqr(vcand.z) > Sqr(vmax + cs / 2)) continue; @@ -462,8 +460,7 @@ namespace DotRecast.Detour.Crowd // Start sampling. float cr = vmax * (1.0f - m_params.velBias); - Vector3f res = new Vector3f(); - VSet(ref res, dvel.x * m_params.velBias, 0, dvel.z * m_params.velBias); + Vector3f res = Vector3f.Of(dvel.x * m_params.velBias, 0, dvel.z * m_params.velBias); int ns = 0; for (int k = 0; k < depth; ++k) { @@ -473,8 +470,7 @@ namespace DotRecast.Detour.Crowd for (int i = 0; i < npat; ++i) { - Vector3f vcand = new Vector3f(); - VSet(ref vcand, res.x + pat[i * 2 + 0] * cr, 0f, res.z + pat[i * 2 + 1] * cr); + Vector3f vcand = Vector3f.Of(res.x + pat[i * 2 + 0] * cr, 0f, res.z + pat[i * 2 + 1] * cr); if (Sqr(vcand.x) + Sqr(vcand.z) > Sqr(vmax + 0.001f)) continue; diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs index 4e565f7..9e83686 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs @@ -19,9 +19,9 @@ namespace DotRecast.Detour.Extras.Jumplink this.trajectory = trajectory; ax = edge.sq.Subtract(edge.sp); ax.Normalize(); - VSet(ref az, ax.z, 0, -ax.x); + az.Set(ax.z, 0, -ax.x); az.Normalize(); - VSet(ref ay, 0, 1, 0); + ay.Set(0, 1, 0); } } } \ No newline at end of file