From b1b2bb9e3e0b1f3fb0a04d3cfcb250619a4dcdc7 Mon Sep 17 00:00:00 2001 From: ikpil Date: Wed, 12 Apr 2023 23:33:15 +0900 Subject: [PATCH] remove Vector3 vSet --- src/DotRecast.Core/RecastMath.cs | 8 +------- src/DotRecast.Core/Vector3f.cs | 1 + src/DotRecast.Detour.Crowd/Crowd.cs | 20 +++++++++---------- src/DotRecast.Detour.Crowd/CrowdAgent.cs | 2 +- .../ObstacleAvoidanceQuery.cs | 8 +++----- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/DotRecast.Core/RecastMath.cs b/src/DotRecast.Core/RecastMath.cs index d8b13dd..6079494 100644 --- a/src/DotRecast.Core/RecastMath.cs +++ b/src/DotRecast.Core/RecastMath.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using System; +using System.Numerics; namespace DotRecast.Core { @@ -227,13 +228,6 @@ namespace DotRecast.Core @out.y = @in[1]; @out.z = @in[2]; } - - public static void vCopy(float[] @out, float[] @in, int i) - { - @out[0] = @in[i]; - @out[1] = @in[i + 1]; - @out[2] = @in[i + 2]; - } public static void vCopy(ref Vector3f @out, float[] @in, int i) { diff --git a/src/DotRecast.Core/Vector3f.cs b/src/DotRecast.Core/Vector3f.cs index 9aab844..49cba79 100644 --- a/src/DotRecast.Core/Vector3f.cs +++ b/src/DotRecast.Core/Vector3f.cs @@ -28,6 +28,7 @@ namespace DotRecast.Core public float z { get; set; } public static Vector3f Zero { get; } = new Vector3f(0, 0, 0); + public static Vector3f Up { get; } = new Vector3f(0, 1, 0); public static Vector3f Of(float[] f) { diff --git a/src/DotRecast.Detour.Crowd/Crowd.cs b/src/DotRecast.Detour.Crowd/Crowd.cs index b2da701..59af4ce 100644 --- a/src/DotRecast.Detour.Crowd/Crowd.cs +++ b/src/DotRecast.Detour.Crowd/Crowd.cs @@ -254,9 +254,9 @@ namespace DotRecast.Detour.Crowd ag.topologyOptTime = 0; ag.targetReplanTime = 0; - vSet(ref ag.dvel, 0, 0, 0); - vSet(ref ag.nvel, 0, 0, 0); - vSet(ref ag.vel, 0, 0, 0); + ag.dvel = Vector3f.Zero; + ag.nvel = Vector3f.Zero; + ag.vel = Vector3f.Zero; vCopy(ref ag.npos, nearest); ag.desiredSpeed = 0; @@ -340,8 +340,8 @@ namespace DotRecast.Detour.Crowd { // Initialize request. agent.targetRef = 0; - vSet(ref agent.targetPos, 0, 0, 0); - vSet(ref agent.dvel, 0, 0, 0); + agent.targetPos = Vector3f.Zero; + agent.dvel = Vector3f.Zero; agent.targetPathQueryResult = null; agent.targetReplan = false; agent.targetState = CrowdAgent.MoveRequestState.DT_CROWDAGENT_TARGET_NONE; @@ -974,8 +974,8 @@ namespace DotRecast.Detour.Crowd // Copy data for debug purposes. if (debugAgent == ag) { - vSet(ref debug.optStart, 0, 0, 0); - vSet(ref debug.optEnd, 0, 0, 0); + debug.optStart = Vector3f.Zero; + debug.optEnd = Vector3f.Zero; } } } @@ -1234,7 +1234,7 @@ namespace DotRecast.Detour.Crowd continue; } - vSet(ref ag.disp, 0, 0, 0); + ag.disp = Vector3f.Zero; float w = 0; @@ -1361,8 +1361,8 @@ namespace DotRecast.Detour.Crowd } // Update velocity. - vSet(ref ag.vel, 0, 0, 0); - vSet(ref ag.dvel, 0, 0, 0); + ag.vel = Vector3f.Zero; + ag.dvel = Vector3f.Zero; } _telemetry.stop("updateOffMeshConnections"); diff --git a/src/DotRecast.Detour.Crowd/CrowdAgent.cs b/src/DotRecast.Detour.Crowd/CrowdAgent.cs index 317afac..7f3326d 100644 --- a/src/DotRecast.Detour.Crowd/CrowdAgent.cs +++ b/src/DotRecast.Detour.Crowd/CrowdAgent.cs @@ -149,7 +149,7 @@ namespace DotRecast.Detour.Crowd if (vLen(vel) > 0.0001f) npos = vMad(npos, vel, dt); else - vSet(ref vel, 0, 0, 0); + vel = Vector3f.Zero; } public bool overOffmeshConnection(float radius) diff --git a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs index cb33b73..937916e 100644 --- a/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs +++ b/src/DotRecast.Detour.Crowd/ObstacleAvoidanceQuery.cs @@ -401,8 +401,7 @@ namespace DotRecast.Detour.Crowd m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : float.MaxValue; - Vector3f nvel = new Vector3f(); - vSet(ref nvel, 0f, 0f, 0f); + Vector3f nvel = Vector3f.Zero; if (debug != null) debug.reset(); @@ -472,8 +471,7 @@ namespace DotRecast.Detour.Crowd m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : float.MaxValue; - Vector3f nvel = new Vector3f(); - vSet(ref nvel, 0f, 0f, 0f); + Vector3f nvel = Vector3f.Zero; if (debug != null) debug.reset(); @@ -546,7 +544,7 @@ namespace DotRecast.Detour.Crowd { float minPenalty = float.MaxValue; Vector3f bvel = new Vector3f(); - vSet(ref bvel, 0, 0, 0); + bvel = Vector3f.Zero; for (int i = 0; i < npat; ++i) {