From f232d5638d9fb414af3abe71e578e133472b69f8 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 22 Apr 2023 12:27:52 +0900 Subject: [PATCH] change float[] -> Vector3f --- src/DotRecast.Detour.TileCache/TileCache.cs | 6 +++--- src/DotRecast.Recast/RecastFilledVolumeRasterization.cs | 4 ++-- src/DotRecast.Recast/RecastVectors.cs | 5 +++++ test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs | 6 ++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/DotRecast.Detour.TileCache/TileCache.cs b/src/DotRecast.Detour.TileCache/TileCache.cs index d917aa6..c462369 100644 --- a/src/DotRecast.Detour.TileCache/TileCache.cs +++ b/src/DotRecast.Detour.TileCache/TileCache.cs @@ -371,13 +371,13 @@ namespace DotRecast.Detour.TileCache } // Aabb obstacle - public long addBoxObstacle(float[] bmin, float[] bmax) + public long addBoxObstacle(Vector3f bmin, Vector3f bmax) { TileCacheObstacle ob = allocObstacle(); ob.type = TileCacheObstacle.TileCacheObstacleType.BOX; - vCopy(ref ob.bmin, bmin); - vCopy(ref ob.bmax, bmax); + ob.bmin = bmin; + ob.bmax = bmax; return addObstacleRequest(ob).refs; } diff --git a/src/DotRecast.Recast/RecastFilledVolumeRasterization.cs b/src/DotRecast.Recast/RecastFilledVolumeRasterization.cs index e893eef..e2812e2 100644 --- a/src/DotRecast.Recast/RecastFilledVolumeRasterization.cs +++ b/src/DotRecast.Recast/RecastFilledVolumeRasterization.cs @@ -684,7 +684,7 @@ namespace DotRecast.Recast } // rectangle vertex - float[] point = new float[] { 0, rectangle[1], 0 }; + var point = Vector3f.Of(0, rectangle[1], 0); for (int i = 0; i < 4; i++) { point[0] = ((i & 1) == 0) ? rectangle[0] : rectangle[2]; @@ -740,7 +740,7 @@ namespace DotRecast.Recast return null; } - private static float? rayTriangleIntersection(float[] point, int plane, float[][] planes) + private static float? rayTriangleIntersection(Vector3f point, int plane, float[][] planes) { float t = (planes[plane][3] - dot(planes[plane], point)) / planes[plane][1]; float[] s = { point[0], point[1] + t, point[2] }; diff --git a/src/DotRecast.Recast/RecastVectors.cs b/src/DotRecast.Recast/RecastVectors.cs index a6fd393..382e720 100644 --- a/src/DotRecast.Recast/RecastVectors.cs +++ b/src/DotRecast.Recast/RecastVectors.cs @@ -168,6 +168,11 @@ namespace DotRecast.Recast return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; } + public static float dot(float[] v1, Vector3f v2) + { + return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; + } + public static float dot(Vector3f v1, Vector3f v2) { return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]; diff --git a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs index 29fda75..1421c19 100644 --- a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs @@ -80,8 +80,10 @@ public class TempObstaclesTest : AbstractTileCacheTest MeshTile tile = tiles[0]; Assert.That(tile.data.header.vertCount, Is.EqualTo(16)); Assert.That(tile.data.header.polyCount, Is.EqualTo(6)); - long o = tc.addBoxObstacle(new float[] { -2.315208f, 9.998184f, -20.807983f }, - new float[] { -1.315208f, 11.998184f, -19.807983f }); + long o = tc.addBoxObstacle( + Vector3f.Of(-2.315208f, 9.998184f, -20.807983f), + Vector3f.Of(-1.315208f, 11.998184f, -19.807983f) + ); bool upToDate = tc.update(); Assert.That(upToDate, Is.True); tiles = tc.getNavMesh().getTilesAt(1, 4);