From dd9a5e55fc73ba5c5df9f987aaead786a8ace558 Mon Sep 17 00:00:00 2001 From: ikpil Date: Sat, 28 Oct 2023 13:47:57 +0900 Subject: [PATCH] refactor: test version SIMD System.Numerics.Vector3, Vector2 --- src/DotRecast.Core/Numerics/RcVec2f.cs | 108 ++-- src/DotRecast.Core/Numerics/RcVec3f.cs | 472 +++++++++--------- src/DotRecast.Core/Numerics/RcVecUtils.cs | 67 +-- src/DotRecast.Core/RcConvexUtils.cs | 13 +- src/DotRecast.Core/RcIntersections.cs | 27 +- src/DotRecast.Core/RcObjImporter.cs | 5 +- src/DotRecast.Core/RcSegmentVert.cs | 5 +- src/DotRecast.Detour.Crowd/DtCrowd.cs | 71 +-- src/DotRecast.Detour.Crowd/DtCrowdAgent.cs | 39 +- .../DtCrowdAgentAnimation.cs | 7 +- .../DtCrowdAgentDebugInfo.cs | 5 +- .../DtCrowdTelemetry.cs | 1 + src/DotRecast.Detour.Crowd/DtLocalBoundary.cs | 9 +- .../DtObstacleAvoidanceDebugData.cs | 7 +- .../DtObstacleAvoidanceQuery.cs | 67 +-- .../DtObstacleCircle.cs | 11 +- .../DtObstacleSegment.cs | 5 +- src/DotRecast.Detour.Crowd/DtPathCorridor.cs | 27 +- src/DotRecast.Detour.Crowd/DtPathQuery.cs | 5 +- src/DotRecast.Detour.Crowd/DtPathQueue.cs | 3 +- src/DotRecast.Detour.Crowd/DtSegment.cs | 3 +- .../Colliders/DtBoxCollider.cs | 29 +- .../Colliders/DtCapsuleCollider.cs | 9 +- .../Colliders/DtCylinderCollider.cs | 9 +- .../Colliders/DtSphereCollider.cs | 7 +- src/DotRecast.Detour.Dynamic/DtVoxelQuery.cs | 11 +- .../Io/DtVoxelFile.cs | 3 +- .../Io/DtVoxelFileReader.cs | 5 +- .../Io/DtVoxelFileWriter.cs | 1 + .../Io/DtVoxelTile.cs | 7 +- src/DotRecast.Detour.Extras/BVTreeBuilder.cs | 5 +- .../Jumplink/AbstractGroundSampler.cs | 5 +- .../Jumplink/ClimbTrajectory.cs | 5 +- .../Jumplink/EdgeExtractor.cs | 3 +- .../Jumplink/EdgeSampler.cs | 17 +- .../Jumplink/EdgeSamplerFactory.cs | 17 +- .../Jumplink/GroundSample.cs | 3 +- .../Jumplink/GroundSegment.cs | 5 +- .../Jumplink/JumpEdge.cs | 5 +- .../Jumplink/JumpLinkBuilder.cs | 11 +- .../Jumplink/JumpTrajectory.cs | 5 +- .../Jumplink/NavMeshGroundSampler.cs | 7 +- .../Jumplink/Trajectory.cs | 3 +- .../Jumplink/TrajectorySampler.cs | 7 +- .../Unity/Astar/GraphMeta.cs | 1 + .../Unity/Astar/NodeLink2.cs | 7 +- .../Unity/Astar/NodeLink2Reader.cs | 5 +- .../Unity/Astar/OffMeshLinkCreator.cs | 1 + .../Unity/Astar/ZipBinaryReader.cs | 1 + src/DotRecast.Detour.TileCache/DtTileCache.cs | 21 +- .../DtTileCacheBuilder.cs | 11 +- .../DtTileCacheLayerBuilder.cs | 5 +- .../DtTileCacheLayerHeader.cs | 5 +- .../DtTileCacheObstacle.cs | 11 +- .../DtTileCacheParams.cs | 3 +- .../DtConvexConvexIntersections.cs | 25 +- .../DtDefaultQueryHeuristic.cs | 5 +- .../DtFindNearestPolyQuery.cs | 11 +- src/DotRecast.Detour/DtMeshHeader.cs | 5 +- src/DotRecast.Detour/DtNavMesh.cs | 83 +-- src/DotRecast.Detour/DtNavMeshBuilder.cs | 7 +- src/DotRecast.Detour/DtNavMeshCreateParams.cs | 5 +- src/DotRecast.Detour/DtNavMeshParams.cs | 3 +- src/DotRecast.Detour/DtNavMeshQuery.cs | 165 +++--- src/DotRecast.Detour/DtNavMeshRaycast.cs | 5 +- .../DtNoOpDtPolygonByCircleConstraint.cs | 3 +- src/DotRecast.Detour/DtNode.cs | 3 +- src/DotRecast.Detour/DtPathUtils.cs | 9 +- src/DotRecast.Detour/DtPolyPoint.cs | 5 +- src/DotRecast.Detour/DtQueryData.cs | 5 +- src/DotRecast.Detour/DtQueryDefaultFilter.cs | 5 +- src/DotRecast.Detour/DtQueryEmptyFilter.cs | 3 +- src/DotRecast.Detour/DtQueryNoOpFilter.cs | 3 +- src/DotRecast.Detour/DtRaycastHit.cs | 3 +- src/DotRecast.Detour/DtStraightPath.cs | 5 +- .../DtStrictDtPolygonByCircleConstraint.cs | 5 +- src/DotRecast.Detour/DtUtils.cs | 69 +-- .../IDtPolygonByCircleConstraint.cs | 3 +- src/DotRecast.Detour/IDtQueryFilter.cs | 3 +- src/DotRecast.Detour/IDtQueryHeuristic.cs | 3 +- src/DotRecast.Detour/Io/DtMeshSetWriter.cs | 1 + .../Io/DtNavMeshParamWriter.cs | 1 + src/DotRecast.Recast.Demo/Draw/DebugDraw.cs | 43 +- src/DotRecast.Recast.Demo/Draw/GLU.cs | 3 +- src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs | 5 +- .../Draw/ModernOpenGLDraw.cs | 5 +- .../Draw/NavMeshRenderer.cs | 17 +- .../Draw/OpenGLVertex.cs | 5 +- .../Draw/RecastDebugDraw.cs | 57 +-- .../Messages/RaycastEvent.cs | 5 +- src/DotRecast.Recast.Demo/RecastDemo.cs | 47 +- .../Tools/ConvexVolumeSampleTool.cs | 5 +- .../Tools/CrowdAgentProfilingSampleTool.cs | 9 +- .../Tools/CrowdSampleTool.cs | 41 +- .../Tools/DynamicUpdateSampleTool.cs | 15 +- .../Tools/GizmoRenderer.cs | 21 +- .../Tools/ISampleTool.cs | 5 +- .../Tools/JumpLinkBuilderSampleTool.cs | 15 +- .../Tools/ObstacleSampleTool.cs | 9 +- .../Tools/OffMeshConnectionSampleTool.cs | 7 +- .../Tools/TestNavmeshSampleTool.cs | 51 +- .../Tools/TileSampleTool.cs | 11 +- .../Geom/DemoInputGeomProvider.cs | 23 +- .../Gizmos/RcBoxGizmo.cs | 27 +- .../Gizmos/RcCapsuleGizmo.cs | 39 +- .../Gizmos/RcCylinderGizmo.cs | 43 +- .../Gizmos/RcGizmoFactory.cs | 9 +- .../Gizmos/RcSphereGizmo.cs | 5 +- .../Tools/RcConvexVolumeTool.cs | 17 +- .../Tools/RcCrowdAgentData.cs | 5 +- .../Tools/RcCrowdAgentProfilingTool.cs | 15 +- .../Tools/RcCrowdTool.cs | 31 +- .../Tools/RcDynamicUpdateTool.cs | 89 ++-- .../Tools/RcJumpLinkBuilderTool.cs | 7 +- .../Tools/RcObstacleTool.cs | 11 +- .../Tools/RcOffMeshConnectionTool.cs | 5 +- .../Tools/RcTestNavMeshTool.cs | 53 +- .../Tools/RcTileTool.cs | 13 +- src/DotRecast.Recast/Geom/BoundsItem.cs | 5 +- .../Geom/IInputGeomProvider.cs | 7 +- src/DotRecast.Recast/Geom/RcChunkyTriMesh.cs | 11 +- .../Geom/RcChunkyTriMeshNode.cs | 5 +- .../Geom/RcOffMeshConnection.cs | 3 +- .../Geom/SimpleInputGeomProvider.cs | 15 +- src/DotRecast.Recast/RcAreas.cs | 29 +- src/DotRecast.Recast/RcBuilder.cs | 15 +- src/DotRecast.Recast/RcBuilderConfig.cs | 9 +- src/DotRecast.Recast/RcCommons.cs | 15 +- src/DotRecast.Recast/RcCompactHeightfield.cs | 5 +- src/DotRecast.Recast/RcContourSet.cs | 5 +- .../RcFilledVolumeRasterization.cs | 95 ++-- src/DotRecast.Recast/RcHeightfield.cs | 7 +- src/DotRecast.Recast/RcHeightfieldLayer.cs | 5 +- src/DotRecast.Recast/RcHeightfieldLayerSet.cs | 1 + src/DotRecast.Recast/RcLayers.cs | 5 +- src/DotRecast.Recast/RcMeshDetails.cs | 43 +- src/DotRecast.Recast/RcMeshs.cs | 5 +- src/DotRecast.Recast/RcPolyMesh.cs | 5 +- src/DotRecast.Recast/RcPolyMeshRaycast.cs | 7 +- src/DotRecast.Recast/RcRasterizations.cs | 9 +- test/DotRecast.Core.Test/Vector3Tests.cs | 55 +- .../AbstractCrowdTest.cs | 41 +- .../PathCorridorTest.cs | 33 +- .../RecastTestMeshBuilder.cs | 1 + .../DynamicNavMeshTest.cs | 9 +- .../Io/VoxelFileReaderTest.cs | 9 +- .../Io/VoxelFileReaderWriterTest.cs | 9 +- .../VoxelQueryTest.cs | 15 +- .../UnityAStarPathfindingImporterTest.cs | 21 +- .../AbstractDetourTest.cs | 25 +- .../FindDistanceToWallTest.cs | 27 +- .../FindLocalNeighbourhoodTest.cs | 3 +- .../FindNearestPolyTest.cs | 21 +- test/DotRecast.Detour.Test/FindPathTest.cs | 79 +-- .../FindPolysAroundCircleTest.cs | 3 +- .../FindPolysAroundShapeTest.cs | 7 +- .../Io/MeshSetReaderWriterTest.cs | 5 +- .../MoveAlongSurfaceTest.cs | 17 +- .../PolygonByCircleConstraintTest.cs | 11 +- test/DotRecast.Detour.Test/RandomPointTest.cs | 1 + .../RecastTestMeshBuilder.cs | 1 + .../TestTiledNavMeshBuilder.cs | 1 + .../TiledFindPathTest.cs | 9 +- .../TempObstaclesTest.cs | 7 +- .../TestTileLayerBuilder.cs | 5 +- .../TileCacheFindPathTest.cs | 7 +- .../TileCacheNavigationTest.cs | 13 +- .../DotRecast.Recast.Test/RecastLayersTest.cs | 1 + .../RecastSoloMeshTest.cs | 5 +- 169 files changed, 1666 insertions(+), 1499 deletions(-) diff --git a/src/DotRecast.Core/Numerics/RcVec2f.cs b/src/DotRecast.Core/Numerics/RcVec2f.cs index 8d0e4a9..b4d4b9a 100644 --- a/src/DotRecast.Core/Numerics/RcVec2f.cs +++ b/src/DotRecast.Core/Numerics/RcVec2f.cs @@ -3,58 +3,58 @@ using System.Runtime.CompilerServices; namespace DotRecast.Core.Numerics { - public struct RcVec2f - { - public float X; - public float Y; - - public static RcVec2f Zero { get; } = new RcVec2f { X = 0, Y = 0 }; - - public RcVec2f(float x, float y) - { - X = x; - Y = y; - } - - public override bool Equals(object obj) - { - if (!(obj is RcVec2f)) - return false; - - return Equals((RcVec2f)obj); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(RcVec2f other) - { - return X.Equals(other.X) && - Y.Equals(other.Y); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() - { - int hash = X.GetHashCode(); - hash = RcHashCodes.CombineHashCodes(hash, Y.GetHashCode()); - return hash; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(RcVec2f left, RcVec2f right) - { - return left.Equals(right); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(RcVec2f left, RcVec2f right) - { - return !left.Equals(right); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override string ToString() - { - return $"{X}, {Y}"; - } - } + // public struct Vector2 + // { + // public float X; + // public float Y; + // + // public static Vector2 Zero { get; } = new Vector2 { X = 0, Y = 0 }; + // + // public Vector2(float x, float y) + // { + // X = x; + // Y = y; + // } + // + // public override bool Equals(object obj) + // { + // if (!(obj is Vector2)) + // return false; + // + // return Equals((Vector2)obj); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public bool Equals(Vector2 other) + // { + // return X.Equals(other.X) && + // Y.Equals(other.Y); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public override int GetHashCode() + // { + // int hash = X.GetHashCode(); + // hash = RcHashCodes.CombineHashCodes(hash, Y.GetHashCode()); + // return hash; + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static bool operator ==(Vector2 left, Vector2 right) + // { + // return left.Equals(right); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static bool operator !=(Vector2 left, Vector2 right) + // { + // return !left.Equals(right); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public override string ToString() + // { + // return $"{X}, {Y}"; + // } + // } } \ No newline at end of file diff --git a/src/DotRecast.Core/Numerics/RcVec3f.cs b/src/DotRecast.Core/Numerics/RcVec3f.cs index 95f29d9..3851496 100644 --- a/src/DotRecast.Core/Numerics/RcVec3f.cs +++ b/src/DotRecast.Core/Numerics/RcVec3f.cs @@ -21,240 +21,240 @@ using System.Runtime.CompilerServices; namespace DotRecast.Core.Numerics { - public struct RcVec3f - { - public float X; - public float Y; - public float Z; - - public static RcVec3f Zero { get; } = new RcVec3f(0.0f, 0.0f, 0.0f); - public static RcVec3f One { get; } = new RcVec3f(1.0f); - public static RcVec3f UnitX { get; } = new RcVec3f(1.0f, 0.0f, 0.0f); - public static RcVec3f UnitY { get; } = new RcVec3f(0.0f, 1.0f, 0.0f); - public static RcVec3f UnitZ { get; } = new RcVec3f(0.0f, 0.0f, 1.0f); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RcVec3f(float x, float y, float z) - { - X = x; - Y = y; - Z = z; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public RcVec3f(float f) - { - X = f; - Y = f; - Z = f; - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly float Length() - { - float lengthSquared = LengthSquared(); - return MathF.Sqrt(lengthSquared); - } - - /// Derives the square of the scalar length of the vector. (len * len) - /// @param[in] v The vector. [(x, y, z)] - /// @return The square of the scalar length of the vector. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly float LengthSquared() - { - return Dot(this, this); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Subtract(RcVec3f left, RcVec3f right) - { - return left - right; - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Add(RcVec3f left, RcVec3f right) - { - return left + right; - } - - - public override bool Equals(object obj) - { - if (!(obj is RcVec3f)) - return false; - - return Equals((RcVec3f)obj); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public bool Equals(RcVec3f other) - { - return X.Equals(other.X) && - Y.Equals(other.Y) && - Z.Equals(other.Z); - } - - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public override int GetHashCode() - { - return HashCode.Combine(X, Y, Z); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Min(RcVec3f value1, RcVec3f value2) - { - return new RcVec3f( - (value1.X < value2.X) ? value1.X : value2.X, - (value1.Y < value2.Y) ? value1.Y : value2.Y, - (value1.Z < value2.Z) ? value1.Z : value2.Z - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Max(RcVec3f value1, RcVec3f value2) - { - return new RcVec3f( - (value1.X > value2.X) ? value1.X : value2.X, - (value1.Y > value2.Y) ? value1.Y : value2.Y, - (value1.Z > value2.Z) ? value1.Z : value2.Z - ); - } - - public override string ToString() - { - return $"{X}, {Y}, {Z}"; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator ==(RcVec3f left, RcVec3f right) - { - return left.Equals(right); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool operator !=(RcVec3f left, RcVec3f right) - { - return !left.Equals(right); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f operator -(RcVec3f left, RcVec3f right) - { - return new RcVec3f( - left.X - right.X, - left.Y - right.Y, - left.Z - right.Z - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f operator +(RcVec3f left, RcVec3f right) - { - return new RcVec3f( - left.X + right.X, - left.Y + right.Y, - left.Z + right.Z - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f operator *(RcVec3f left, RcVec3f right) - { - return new RcVec3f( - left.X * right.X, - left.Y * right.Y, - left.Z * right.Z - ); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f operator *(RcVec3f left, float right) - { - return left * new RcVec3f(right); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f operator *(float left, RcVec3f right) - { - return right * left; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Lerp(RcVec3f value1, RcVec3f value2, float amount) - { - return (value1 * (1f - amount)) + (value2 * amount); - // return new RcVec3f( - // value1.X + (value2.X - value1.X) * amount, - // value1.Y + (value2.Y - value1.Y) * amount, - // value1.Z + (value2.Z - value1.Z) * amount - // ); - } - - /// Returns the distance between two points. - /// @param[in] v1 A point. [(x, y, z)] - /// @param[in] v2 A point. [(x, y, z)] - /// @return The distance between the two points. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Distance(RcVec3f value1, RcVec3f value2) - { - float distanceSquared = DistanceSquared(value1, value2); - return MathF.Sqrt(distanceSquared); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float DistanceSquared(RcVec3f value1, RcVec3f value2) - { - var difference = value1 - value2; - return Dot(difference, difference); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot(RcVec3f vector1, RcVec3f vector2) - { - return (vector1.X * vector2.X) + - (vector1.Y * vector2.Y) + - (vector1.Z * vector2.Z); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void CopyTo(float[] array) - { - CopyTo(array, 0); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public readonly void CopyTo(float[] array, int n) - { - array[n + 0] = X; - array[n + 1] = Y; - array[n + 2] = Z; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Cross(RcVec3f v1, RcVec3f v2) - { - return new RcVec3f( - (v1.Y * v2.Z) - (v1.Z * v2.Y), - (v1.Z * v2.X) - (v1.X * v2.Z), - (v1.X * v2.Y) - (v1.Y * v2.X) - ); - } - - /// Normalizes the vector. - /// @param[in,out] v The vector to normalize. [(x, y, z)] - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Normalize(RcVec3f v) - { - float d = 1.0f / MathF.Sqrt(RcMath.Sqr(v.X) + RcMath.Sqr(v.Y) + RcMath.Sqr(v.Z)); - - return new RcVec3f( - v.X *= d, - v.Y *= d, - v.Z *= d - ); - } - } + // public struct Vector3 + // { + // public float X; + // public float Y; + // public float Z; + // + // public static Vector3 Zero { get; } = new Vector3(0.0f, 0.0f, 0.0f); + // public static Vector3 One { get; } = new Vector3(1.0f); + // public static Vector3 UnitX { get; } = new Vector3(1.0f, 0.0f, 0.0f); + // public static Vector3 UnitY { get; } = new Vector3(0.0f, 1.0f, 0.0f); + // public static Vector3 UnitZ { get; } = new Vector3(0.0f, 0.0f, 1.0f); + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public Vector3(float x, float y, float z) + // { + // X = x; + // Y = y; + // Z = z; + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public Vector3(float f) + // { + // X = f; + // Y = f; + // Z = f; + // } + // + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public readonly float Length() + // { + // float lengthSquared = LengthSquared(); + // return MathF.Sqrt(lengthSquared); + // } + // + // /// Derives the square of the scalar length of the vector. (len * len) + // /// @param[in] v The vector. [(x, y, z)] + // /// @return The square of the scalar length of the vector. + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public readonly float LengthSquared() + // { + // return Dot(this, this); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Subtract(Vector3 left, Vector3 right) + // { + // return left - right; + // } + // + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Add(Vector3 left, Vector3 right) + // { + // return left + right; + // } + // + // + // public override bool Equals(object obj) + // { + // if (!(obj is Vector3)) + // return false; + // + // return Equals((Vector3)obj); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public bool Equals(Vector3 other) + // { + // return X.Equals(other.X) && + // Y.Equals(other.Y) && + // Z.Equals(other.Z); + // } + // + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public override int GetHashCode() + // { + // return HashCode.Combine(X, Y, Z); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Min(Vector3 value1, Vector3 value2) + // { + // return new Vector3( + // (value1.X < value2.X) ? value1.X : value2.X, + // (value1.Y < value2.Y) ? value1.Y : value2.Y, + // (value1.Z < value2.Z) ? value1.Z : value2.Z + // ); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Max(Vector3 value1, Vector3 value2) + // { + // return new Vector3( + // (value1.X > value2.X) ? value1.X : value2.X, + // (value1.Y > value2.Y) ? value1.Y : value2.Y, + // (value1.Z > value2.Z) ? value1.Z : value2.Z + // ); + // } + // + // public override string ToString() + // { + // return $"{X}, {Y}, {Z}"; + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static bool operator ==(Vector3 left, Vector3 right) + // { + // return left.Equals(right); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static bool operator !=(Vector3 left, Vector3 right) + // { + // return !left.Equals(right); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 operator -(Vector3 left, Vector3 right) + // { + // return new Vector3( + // left.X - right.X, + // left.Y - right.Y, + // left.Z - right.Z + // ); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 operator +(Vector3 left, Vector3 right) + // { + // return new Vector3( + // left.X + right.X, + // left.Y + right.Y, + // left.Z + right.Z + // ); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 operator *(Vector3 left, Vector3 right) + // { + // return new Vector3( + // left.X * right.X, + // left.Y * right.Y, + // left.Z * right.Z + // ); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 operator *(Vector3 left, float right) + // { + // return left * new Vector3(right); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 operator *(float left, Vector3 right) + // { + // return right * left; + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Lerp(Vector3 value1, Vector3 value2, float amount) + // { + // return (value1 * (1f - amount)) + (value2 * amount); + // // return new Vector3( + // // value1.X + (value2.X - value1.X) * amount, + // // value1.Y + (value2.Y - value1.Y) * amount, + // // value1.Z + (value2.Z - value1.Z) * amount + // // ); + // } + // + // /// Returns the distance between two points. + // /// @param[in] v1 A point. [(x, y, z)] + // /// @param[in] v2 A point. [(x, y, z)] + // /// @return The distance between the two points. + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static float Distance(Vector3 value1, Vector3 value2) + // { + // float distanceSquared = DistanceSquared(value1, value2); + // return MathF.Sqrt(distanceSquared); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static float DistanceSquared(Vector3 value1, Vector3 value2) + // { + // var difference = value1 - value2; + // return Dot(difference, difference); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static float Dot(Vector3 vector1, Vector3 vector2) + // { + // return (vector1.X * vector2.X) + + // (vector1.Y * vector2.Y) + + // (vector1.Z * vector2.Z); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public readonly void CopyTo(float[] array) + // { + // CopyTo(array, 0); + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public readonly void CopyTo(float[] array, int n) + // { + // array[n + 0] = X; + // array[n + 1] = Y; + // array[n + 2] = Z; + // } + // + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Cross(Vector3 v1, Vector3 v2) + // { + // return new Vector3( + // (v1.Y * v2.Z) - (v1.Z * v2.Y), + // (v1.Z * v2.X) - (v1.X * v2.Z), + // (v1.X * v2.Y) - (v1.Y * v2.X) + // ); + // } + // + // /// Normalizes the vector. + // /// @param[in,out] v The vector to normalize. [(x, y, z)] + // [MethodImpl(MethodImplOptions.AggressiveInlining)] + // public static Vector3 Normalize(Vector3 v) + // { + // float d = 1.0f / MathF.Sqrt(RcMath.Sqr(v.X) + RcMath.Sqr(v.Y) + RcMath.Sqr(v.Z)); + // + // return new Vector3( + // v.X *= d, + // v.Y *= d, + // v.Z *= d + // ); + // } + // } } \ No newline at end of file diff --git a/src/DotRecast.Core/Numerics/RcVecUtils.cs b/src/DotRecast.Core/Numerics/RcVecUtils.cs index bbe9efd..13a3d22 100644 --- a/src/DotRecast.Core/Numerics/RcVecUtils.cs +++ b/src/DotRecast.Core/Numerics/RcVecUtils.cs @@ -1,4 +1,5 @@ using System; +using System.Numerics; using System.Runtime.CompilerServices; namespace DotRecast.Core.Numerics @@ -8,19 +9,19 @@ namespace DotRecast.Core.Numerics public const float EPSILON = 1e-6f; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Create(float[] values) + public static Vector3 Create(float[] values) { return Create(values, 0); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Create(float[] values, int n) + public static Vector3 Create(float[] values, int n) { - return new RcVec3f(values[n + 0], values[n + 1], values[n + 2]); + return new Vector3(values[n + 0], values[n + 1], values[n + 2]); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Get(this RcVec2f v, int i) + public static float Get(this Vector2 v, int i) { switch (i) { @@ -31,7 +32,7 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Get(this RcVec3f v, int i) + public static float Get(this Vector3 v, int i) { switch (i) { @@ -43,7 +44,7 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Scale(this RcVec3f v, float scale) + public static Vector3 Scale(this Vector3 v, float scale) { return v * scale; } @@ -56,23 +57,23 @@ namespace DotRecast.Core.Numerics /// The vectors are projected onto the xz-plane, so the y-values are /// ignored. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot2D(this RcVec3f @this, RcVec3f v) + public static float Dot2D(this Vector3 @this, Vector3 v) { return @this.X * v.X + @this.Z * v.Z; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot2D(this RcVec3f @this, float[] v, int vi) + public static float Dot2D(this Vector3 @this, float[] v, int vi) { return @this.X * v[vi] + @this.Z * v[vi + 2]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Add(RcVec3f a, float[] verts, int i) + public static Vector3 Add(Vector3 a, float[] verts, int i) { - return new RcVec3f( + return new Vector3( a.X + verts[i], a.Y + verts[i + 1], a.Z + verts[i + 2] @@ -81,9 +82,9 @@ namespace DotRecast.Core.Numerics [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Subtract(float[] verts, int i, int j) + public static Vector3 Subtract(float[] verts, int i, int j) { - return new RcVec3f( + return new Vector3( verts[i] - verts[j], verts[i + 1] - verts[j + 1], verts[i + 2] - verts[j + 2] @@ -92,9 +93,9 @@ namespace DotRecast.Core.Numerics [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Subtract(RcVec3f i, float[] verts, int j) + public static Vector3 Subtract(Vector3 i, float[] verts, int j) { - return new RcVec3f( + return new Vector3( i.X - verts[j], i.Y - verts[j + 1], i.Z - verts[j + 2] @@ -127,7 +128,7 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dot(float[] v1, RcVec3f vector2) + public static float Dot(float[] v1, Vector3 vector2) { return v1[0] * vector2.X + v1[1] * vector2.Y + @@ -139,7 +140,7 @@ namespace DotRecast.Core.Numerics /// @param[in] v2 A point. [(x, y, z)] /// @return The distance between the two points. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float DistanceSquared(RcVec3f v1, float[] v2, int i) + public static float DistanceSquared(Vector3 v1, float[] v2, int i) { float dx = v2[i] - v1.X; float dy = v2[i + 1] - v1.Y; @@ -151,13 +152,13 @@ namespace DotRecast.Core.Numerics /// If the magnitude is zero, the vector is unchanged. /// @param[in,out] v The vector to normalize. [(x, y, z)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f SafeNormalize(RcVec3f v) + public static Vector3 SafeNormalize(Vector3 v) { float sqMag = RcMath.Sqr(v.X) + RcMath.Sqr(v.Y) + RcMath.Sqr(v.Z); if (sqMag > EPSILON) { float inverseMag = 1.0f / MathF.Sqrt(sqMag); - return new RcVec3f( + return new Vector3( v.X *= inverseMag, v.Y *= inverseMag, v.Z *= inverseMag @@ -168,9 +169,9 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Min(RcVec3f v, float[] @in, int i) + public static Vector3 Min(Vector3 v, float[] @in, int i) { - return new RcVec3f( + return new Vector3( (v.X < @in[i + 0]) ? v.X : @in[i + 0], (v.Y < @in[i + 1]) ? v.Y : @in[i + 1], (v.Z < @in[i + 2]) ? v.Z : @in[i + 2] @@ -178,9 +179,9 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Max(RcVec3f v, float[] @in, int i) + public static Vector3 Max(Vector3 v, float[] @in, int i) { - return new RcVec3f( + return new Vector3( (v.X > @in[i + 0]) ? v.X : @in[i + 0], (v.Y > @in[i + 1]) ? v.Y : @in[i + 1], (v.Z > @in[i + 2]) ? v.Z : @in[i + 2] @@ -195,7 +196,7 @@ namespace DotRecast.Core.Numerics /// The vectors are projected onto the xz-plane, so the y-values are /// ignored. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dist2D(RcVec3f v1, RcVec3f v2) + public static float Dist2D(Vector3 v1, Vector3 v2) { float dx = v2.X - v1.X; float dz = v2.Z - v1.Z; @@ -203,7 +204,7 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dist2DSqr(RcVec3f v1, RcVec3f v2) + public static float Dist2DSqr(Vector3 v1, Vector3 v2) { float dx = v2.X - v1.X; float dz = v2.Z - v1.Z; @@ -211,7 +212,7 @@ namespace DotRecast.Core.Numerics } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Dist2DSqr(RcVec3f p, float[] verts, int i) + public static float Dist2DSqr(Vector3 p, float[] verts, int i) { float dx = verts[i] - p.X; float dz = verts[i + 2] - p.Z; @@ -226,7 +227,7 @@ namespace DotRecast.Core.Numerics /// The vectors are projected onto the xz-plane, so the y-values are /// ignored. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float Perp2D(RcVec3f u, RcVec3f v) + public static float Perp2D(Vector3 u, Vector3 v) { return u.Z * v.X - u.X * v.Z; } @@ -236,7 +237,7 @@ namespace DotRecast.Core.Numerics /// @return True if all of the point's components are finite, i.e. not NaN /// or any of the infinities. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFinite(this RcVec3f v) + public static bool IsFinite(this Vector3 v) { return float.IsFinite(v.X) && float.IsFinite(v.Y) && float.IsFinite(v.Z); } @@ -244,13 +245,13 @@ namespace DotRecast.Core.Numerics /// Checks that the specified vector's 2D components are finite. /// @param[in] v A point. [(x, y, z)] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static bool IsFinite2D(this RcVec3f v) + public static bool IsFinite2D(this Vector3 v) { return float.IsFinite(v.X) && float.IsFinite(v.Z); } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static float PerpXZ(RcVec3f a, RcVec3f b) + public static float PerpXZ(Vector3 a, Vector3 b) { return (a.X * b.Z) - (a.Z * b.X); } @@ -262,9 +263,9 @@ namespace DotRecast.Core.Numerics /// @param[in] v2 The destination vector. /// @param[in] t The interpolation factor. [Limits: 0 <= value <= 1.0] [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Lerp(float[] verts, int v1, int v2, float t) + public static Vector3 Lerp(float[] verts, int v1, int v2, float t) { - return new RcVec3f( + return new Vector3( verts[v1 + 0] + (verts[v2 + 0] - verts[v1 + 0]) * t, verts[v1 + 1] + (verts[v2 + 1] - verts[v1 + 1]) * t, verts[v1 + 2] + (verts[v2 + 2] - verts[v1 + 2]) * t @@ -277,9 +278,9 @@ namespace DotRecast.Core.Numerics /// @param[in] v2 The vector to scale and add to @p v1. [(x, y, z)] /// @param[in] s The amount to scale @p v2 by before adding to @p v1. [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RcVec3f Mad(RcVec3f v1, RcVec3f v2, float s) + public static Vector3 Mad(Vector3 v1, Vector3 v2, float s) { - return new RcVec3f() + return new Vector3() { X = v1.X + (v2.X * s), Y = v1.Y + (v2.Y * s), diff --git a/src/DotRecast.Core/RcConvexUtils.cs b/src/DotRecast.Core/RcConvexUtils.cs index e1a300b..cac5e4f 100644 --- a/src/DotRecast.Core/RcConvexUtils.cs +++ b/src/DotRecast.Core/RcConvexUtils.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Core { @@ -27,7 +28,7 @@ namespace DotRecast.Core // Calculates convex hull on xz-plane of points on 'pts', // stores the indices of the resulting hull in 'out' and // returns number of points on hull. - public static List Convexhull(List pts) + public static List Convexhull(List pts) { int npts = pts.Count; List @out = new List(); @@ -49,9 +50,9 @@ namespace DotRecast.Core endpt = 0; for (int j = 1; j < npts; ++j) { - RcVec3f a = pts[hull]; - RcVec3f b = pts[endpt]; - RcVec3f c = pts[j]; + Vector3 a = pts[hull]; + Vector3 b = pts[endpt]; + Vector3 c = pts[j]; if (hull == endpt || Left(a, b, c)) { endpt = j; @@ -65,7 +66,7 @@ namespace DotRecast.Core } // Returns true if 'a' is more lower-left than 'b'. - private static bool Cmppt(RcVec3f a, RcVec3f b) + private static bool Cmppt(Vector3 a, Vector3 b) { if (a.X < b.X) { @@ -91,7 +92,7 @@ namespace DotRecast.Core } // Returns true if 'c' is left of line 'a'-'b'. - private static bool Left(RcVec3f a, RcVec3f b, RcVec3f c) + private static bool Left(Vector3 a, Vector3 b, Vector3 c) { float u1 = b.X - a.X; float v1 = b.Z - a.Z; diff --git a/src/DotRecast.Core/RcIntersections.cs b/src/DotRecast.Core/RcIntersections.cs index 9c5928d..76d756c 100644 --- a/src/DotRecast.Core/RcIntersections.cs +++ b/src/DotRecast.Core/RcIntersections.cs @@ -20,26 +20,27 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Core { public static class RcIntersections { - public static bool IntersectSegmentTriangle(RcVec3f sp, RcVec3f sq, RcVec3f a, RcVec3f b, RcVec3f c, out float t) + public static bool IntersectSegmentTriangle(Vector3 sp, Vector3 sq, Vector3 a, Vector3 b, Vector3 c, out float t) { t = 0; float v, w; - RcVec3f ab = RcVec3f.Subtract(b, a); - RcVec3f ac = RcVec3f.Subtract(c, a); - RcVec3f qp = RcVec3f.Subtract(sp, sq); + Vector3 ab = Vector3.Subtract(b, a); + Vector3 ac = Vector3.Subtract(c, a); + Vector3 qp = Vector3.Subtract(sp, sq); // Compute triangle normal. Can be precalculated or cached if // intersecting multiple segments against the same triangle - RcVec3f norm = RcVec3f.Cross(ab, ac); + Vector3 norm = Vector3.Cross(ab, ac); // Compute denominator d. If d <= 0, segment is parallel to or points // away from triangle, so exit early - float d = RcVec3f.Dot(qp, norm); + float d = Vector3.Dot(qp, norm); if (d <= 0.0f) { return false; @@ -48,8 +49,8 @@ namespace DotRecast.Core // Compute intersection t value of pq with plane of triangle. A ray // intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay // dividing by d until intersection has been found to pierce triangle - RcVec3f ap = RcVec3f.Subtract(sp, a); - t = RcVec3f.Dot(ap, norm); + Vector3 ap = Vector3.Subtract(sp, a); + t = Vector3.Dot(ap, norm); if (t < 0.0f) { return false; @@ -61,14 +62,14 @@ namespace DotRecast.Core } // Compute barycentric coordinate components and test if within bounds - RcVec3f e = RcVec3f.Cross(qp, ap); - v = RcVec3f.Dot(ac, e); + Vector3 e = Vector3.Cross(qp, ap); + v = Vector3.Dot(ac, e); if (v < 0.0f || v > d) { return false; } - w = -RcVec3f.Dot(ab, e); + w = -Vector3.Dot(ab, e); if (w < 0.0f || v + w > d) { return false; @@ -80,11 +81,11 @@ namespace DotRecast.Core return true; } - public static bool IsectSegAABB(RcVec3f sp, RcVec3f sq, RcVec3f amin, RcVec3f amax, out float tmin, out float tmax) + public static bool IsectSegAABB(Vector3 sp, Vector3 sq, Vector3 amin, Vector3 amax, out float tmin, out float tmax) { const float EPS = 1e-6f; - RcVec3f d = new RcVec3f(); + Vector3 d = new Vector3(); d.X = sq.X - sp.X; d.Y = sq.Y - sp.Y; d.Z = sq.Z - sp.Z; diff --git a/src/DotRecast.Core/RcObjImporter.cs b/src/DotRecast.Core/RcObjImporter.cs index 761255c..2288f33 100644 --- a/src/DotRecast.Core/RcObjImporter.cs +++ b/src/DotRecast.Core/RcObjImporter.cs @@ -21,6 +21,7 @@ using System; using System.Globalization; using System.IO; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Core { @@ -71,7 +72,7 @@ namespace DotRecast.Core } } - private static RcVec3f ReadVector3f(string line) + private static Vector3 ReadVector3f(string line) { string[] v = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); if (v.Length < 4) @@ -80,7 +81,7 @@ namespace DotRecast.Core } // fix - https://github.com/ikpil/DotRecast/issues/7 - return new RcVec3f( + return new Vector3( float.Parse(v[1], CultureInfo.InvariantCulture), float.Parse(v[2], CultureInfo.InvariantCulture), float.Parse(v[3], CultureInfo.InvariantCulture) diff --git a/src/DotRecast.Core/RcSegmentVert.cs b/src/DotRecast.Core/RcSegmentVert.cs index 7cab398..ccb2136 100644 --- a/src/DotRecast.Core/RcSegmentVert.cs +++ b/src/DotRecast.Core/RcSegmentVert.cs @@ -1,11 +1,12 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Core { public struct RcSegmentVert { - public RcVec3f vmin; - public RcVec3f vmax; + public Vector3 vmin; + public Vector3 vmax; public RcSegmentVert(float v0, float v1, float v2, float v3, float v4, float v5) { diff --git a/src/DotRecast.Detour.Crowd/DtCrowd.cs b/src/DotRecast.Detour.Crowd/DtCrowd.cs index 0b7ef02..7fed331 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowd.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowd.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd @@ -145,7 +146,7 @@ namespace DotRecast.Detour.Crowd private readonly DtObstacleAvoidanceParams[] _obstacleQueryParams = new DtObstacleAvoidanceParams[DT_CROWD_MAX_OBSTAVOIDANCE_PARAMS]; private readonly DtObstacleAvoidanceQuery _obstacleQuery; private DtProximityGrid _grid; - private readonly RcVec3f _ext = new RcVec3f(); + private readonly Vector3 _ext = new Vector3(); private readonly IDtQueryFilter[] _filters = new IDtQueryFilter[DT_CROWD_MAX_QUERY_FILTER_TYPE]; private DtNavMeshQuery _navQuery; private DtNavMesh _navMesh; @@ -161,7 +162,7 @@ namespace DotRecast.Detour.Crowd public DtCrowd(DtCrowdConfig config, DtNavMesh nav, Func queryFilterFactory) { _config = config; - _ext = new RcVec3f(config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); + _ext = new Vector3(config.maxAgentRadius * 2.0f, config.maxAgentRadius * 1.5f, config.maxAgentRadius * 2.0f); _obstacleQuery = new DtObstacleAvoidanceQuery(config.maxObstacleAvoidanceCircles, config.maxObstacleAvoidanceSegments); @@ -243,7 +244,7 @@ namespace DotRecast.Detour.Crowd * The configuration of the agent. * @return The newly created agent object */ - public DtCrowdAgent AddAgent(RcVec3f pos, DtCrowdAgentParams option) + public DtCrowdAgent AddAgent(Vector3 pos, DtCrowdAgentParams option) { DtCrowdAgent ag = new DtCrowdAgent(_agentId.GetAndIncrement()); _agents.Add(ag); @@ -264,9 +265,9 @@ namespace DotRecast.Detour.Crowd ag.topologyOptTime = 0; ag.targetReplanTime = 0; - ag.dvel = RcVec3f.Zero; - ag.nvel = RcVec3f.Zero; - ag.vel = RcVec3f.Zero; + ag.dvel = Vector3.Zero; + ag.nvel = Vector3.Zero; + ag.vel = Vector3.Zero; ag.npos = nearestPt; ag.desiredSpeed = 0; @@ -296,7 +297,7 @@ namespace DotRecast.Detour.Crowd _agents.Remove(agent); } - private bool RequestMoveTargetReplan(DtCrowdAgent ag, long refs, RcVec3f pos) + private bool RequestMoveTargetReplan(DtCrowdAgent ag, long refs, Vector3 pos) { ag.SetTarget(refs, pos); ag.targetReplan = true; @@ -314,7 +315,7 @@ namespace DotRecast.Detour.Crowd /// The position will be constrained to the surface of the navigation mesh. /// /// The request will be processed during the next #Update(). - public bool RequestMoveTarget(DtCrowdAgent agent, long refs, RcVec3f pos) + public bool RequestMoveTarget(DtCrowdAgent agent, long refs, Vector3 pos) { if (refs == 0) { @@ -331,7 +332,7 @@ namespace DotRecast.Detour.Crowd /// @param[in] idx The agent index. [Limits: 0 <= value < #GetAgentCount()] /// @param[in] vel The movement velocity. [(x, y, z)] /// @return True if the request was successfully submitted. - public bool RequestMoveVelocity(DtCrowdAgent agent, RcVec3f vel) + public bool RequestMoveVelocity(DtCrowdAgent agent, Vector3 vel) { // Initialize request. agent.targetRef = 0; @@ -350,8 +351,8 @@ namespace DotRecast.Detour.Crowd { // Initialize request. agent.targetRef = 0; - agent.targetPos = RcVec3f.Zero; - agent.dvel = RcVec3f.Zero; + agent.targetPos = Vector3.Zero; + agent.dvel = Vector3.Zero; agent.targetPathQueryResult = null; agent.targetReplan = false; agent.targetState = DtMoveRequestState.DT_CROWDAGENT_TARGET_NONE; @@ -368,7 +369,7 @@ namespace DotRecast.Detour.Crowd return _agents; } - public RcVec3f GetQueryExtents() + public Vector3 GetQueryExtents() { return _ext; } @@ -463,7 +464,7 @@ namespace DotRecast.Detour.Crowd bool replan = false; // First check that the current location is valid. - RcVec3f agentPos = new RcVec3f(); + Vector3 agentPos = new Vector3(); long agentRef = ag.corridor.GetFirstPoly(); agentPos = ag.npos; if (!_navQuery.IsValidPolyRef(agentRef, _filters[ag.option.queryFilterType])) @@ -603,7 +604,7 @@ namespace DotRecast.Detour.Crowd status = _navQuery.FinalizeSlicedFindPath(ref reqPath); } - RcVec3f reqPos = new RcVec3f(); + Vector3 reqPos = new Vector3(); if (status.Succeeded() && reqPath.Count > 0) { // In progress or succeed. @@ -857,7 +858,7 @@ namespace DotRecast.Detour.Crowd foreach (DtCrowdAgent ag in agents) { - RcVec3f p = ag.npos; + Vector3 p = ag.npos; float r = ag.option.radius; _grid.AddItem(ag, p.X - r, p.Z - r, p.X + r, p.Z + r); } @@ -890,7 +891,7 @@ namespace DotRecast.Detour.Crowd } - private int GetNeighbours(RcVec3f pos, float height, float range, DtCrowdAgent skip, ref List result, DtProximityGrid grid) + private int GetNeighbours(Vector3 pos, float height, float range, DtCrowdAgent skip, ref List result, DtProximityGrid grid) { result.Clear(); @@ -904,7 +905,7 @@ namespace DotRecast.Detour.Crowd } // Check for overlap. - RcVec3f diff = RcVec3f.Subtract(pos, ag.npos); + Vector3 diff = Vector3.Subtract(pos, ag.npos); if (MathF.Abs(diff.Y) >= (height + ag.option.height) / 2.0f) { continue; @@ -949,7 +950,7 @@ namespace DotRecast.Detour.Crowd // and short cut to there. if ((ag.option.updateFlags & DtCrowdAgentUpdateFlags.DT_CROWD_OPTIMIZE_VIS) != 0 && ag.corners.Count > 0) { - RcVec3f target = ag.corners[Math.Min(1, ag.corners.Count - 1)].pos; + Vector3 target = ag.corners[Math.Min(1, ag.corners.Count - 1)].pos; ag.corridor.OptimizePathVisibility(target, ag.option.pathOptimizationRange, _navQuery, _filters[ag.option.queryFilterType]); @@ -965,8 +966,8 @@ namespace DotRecast.Detour.Crowd // Copy data for debug purposes. if (debugAgent == ag) { - debug.optStart = RcVec3f.Zero; - debug.optEnd = RcVec3f.Zero; + debug.optStart = Vector3.Zero; + debug.optEnd = Vector3.Zero; } } } @@ -1036,7 +1037,7 @@ namespace DotRecast.Detour.Crowd continue; } - RcVec3f dvel = new RcVec3f(); + Vector3 dvel = new Vector3(); if (ag.targetState == DtMoveRequestState.DT_CROWDAGENT_TARGET_VELOCITY) { @@ -1071,13 +1072,13 @@ namespace DotRecast.Detour.Crowd float separationWeight = ag.option.separationWeight; float w = 0; - RcVec3f disp = new RcVec3f(); + Vector3 disp = new Vector3(); for (int j = 0; j < ag.neis.Count; ++j) { DtCrowdAgent nei = ag.neis[j].agent; - RcVec3f diff = RcVec3f.Subtract(ag.npos, nei.npos); + Vector3 diff = Vector3.Subtract(ag.npos, nei.npos); diff.Y = 0; float distSqr = diff.LengthSquared(); @@ -1143,9 +1144,9 @@ namespace DotRecast.Detour.Crowd // Append neighbour segments as obstacles. for (int j = 0; j < ag.boundary.GetSegmentCount(); ++j) { - RcVec3f[] s = ag.boundary.GetSegment(j); - RcVec3f s3 = s[1]; - //RcArrays.Copy(s, 3, s3, 0, 3); + Vector3[] s = ag.boundary.GetSegment(j); + Vector3 s3 = s[1]; + //RcArray.Copy(s, 3, s3, 0, 3); if (DtUtils.TriArea2D(ag.npos, s[0], s3) < 0.0f) { continue; @@ -1216,7 +1217,7 @@ namespace DotRecast.Detour.Crowd continue; } - ag.disp = RcVec3f.Zero; + ag.disp = Vector3.Zero; float w = 0; @@ -1224,7 +1225,7 @@ namespace DotRecast.Detour.Crowd { DtCrowdAgent nei = ag.neis[j].agent; long idx1 = nei.idx; - RcVec3f diff = RcVec3f.Subtract(ag.npos, nei.npos); + Vector3 diff = Vector3.Subtract(ag.npos, nei.npos); diff.Y = 0; float dist = diff.LengthSquared(); @@ -1240,11 +1241,11 @@ namespace DotRecast.Detour.Crowd // Agents on top of each other, try to choose diverging separation directions. if (idx0 > idx1) { - diff = new RcVec3f(-ag.dvel.Z, 0, ag.dvel.X); + diff = new Vector3(-ag.dvel.Z, 0, ag.dvel.X); } else { - diff = new RcVec3f(ag.dvel.Z, 0, -ag.dvel.X); + diff = new Vector3(ag.dvel.Z, 0, -ag.dvel.X); } pen = 0.01f; @@ -1273,7 +1274,7 @@ namespace DotRecast.Detour.Crowd continue; } - ag.npos = RcVec3f.Add(ag.npos, ag.disp); + ag.npos = Vector3.Add(ag.npos, ag.disp); } } } @@ -1332,17 +1333,17 @@ namespace DotRecast.Detour.Crowd if (anim.t < ta) { float u = Tween(anim.t, 0.0f, ta); - ag.npos = RcVec3f.Lerp(anim.initPos, anim.startPos, u); + ag.npos = Vector3.Lerp(anim.initPos, anim.startPos, u); } else { float u = Tween(anim.t, ta, tb); - ag.npos = RcVec3f.Lerp(anim.startPos, anim.endPos, u); + ag.npos = Vector3.Lerp(anim.startPos, anim.endPos, u); } // Update velocity. - ag.vel = RcVec3f.Zero; - ag.dvel = RcVec3f.Zero; + ag.vel = Vector3.Zero; + ag.dvel = Vector3.Zero; } } diff --git a/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs b/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs index 032d92d..39f0de5 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { @@ -52,23 +53,23 @@ namespace DotRecast.Detour.Crowd /// The desired speed. public float desiredSpeed; - public RcVec3f npos = new RcVec3f(); + public Vector3 npos = new Vector3(); /// < The current agent position. [(x, y, z)] - public RcVec3f disp = new RcVec3f(); + public Vector3 disp = new Vector3(); /// < A temporary value used to accumulate agent displacement during iterative /// collision resolution. [(x, y, z)] - public RcVec3f dvel = new RcVec3f(); + public Vector3 dvel = new Vector3(); /// < The desired velocity of the agent. Based on the current path, calculated /// from /// scratch each frame. [(x, y, z)] - public RcVec3f nvel = new RcVec3f(); + public Vector3 nvel = new Vector3(); /// < The desired velocity adjusted by obstacle avoidance, calculated from scratch each /// frame. [(x, y, z)] - public RcVec3f vel = new RcVec3f(); + public Vector3 vel = new Vector3(); /// < The actual velocity of the agent. The change from nvel -> vel is /// constrained by max acceleration. [(x, y, z)] @@ -84,7 +85,7 @@ namespace DotRecast.Detour.Crowd public long targetRef; /// < Target polyref of the movement request. - public RcVec3f targetPos = new RcVec3f(); + public Vector3 targetPos = new Vector3(); /// < Target position of the movement request (or velocity in case of /// DT_CROWDAGENT_TARGET_VELOCITY). @@ -113,17 +114,17 @@ namespace DotRecast.Detour.Crowd { // Fake dynamic constraint. float maxDelta = option.maxAcceleration * dt; - RcVec3f dv = RcVec3f.Subtract(nvel, vel); + Vector3 dv = Vector3.Subtract(nvel, vel); float ds = dv.Length(); if (ds > maxDelta) dv = dv.Scale(maxDelta / ds); - vel = RcVec3f.Add(vel, dv); + vel = Vector3.Add(vel, dv); // Integrate if (vel.Length() > 0.0001f) npos = RcVecUtils.Mad(npos, vel, dt); else - vel = RcVec3f.Zero; + vel = Vector3.Zero; } public bool OverOffmeshConnection(float radius) @@ -157,9 +158,9 @@ namespace DotRecast.Detour.Crowd return range; } - public RcVec3f CalcSmoothSteerDirection() + public Vector3 CalcSmoothSteerDirection() { - RcVec3f dir = new RcVec3f(); + Vector3 dir = new Vector3(); if (0 < corners.Count) { int ip0 = 0; @@ -167,8 +168,8 @@ namespace DotRecast.Detour.Crowd var p0 = corners[ip0].pos; var p1 = corners[ip1].pos; - var dir0 = RcVec3f.Subtract(p0, npos); - var dir1 = RcVec3f.Subtract(p1, npos); + var dir0 = Vector3.Subtract(p0, npos); + var dir1 = Vector3.Subtract(p1, npos); dir0.Y = 0; dir1.Y = 0; @@ -180,26 +181,26 @@ 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; - dir = RcVec3f.Normalize(dir); + dir = Vector3.Normalize(dir); } return dir; } - public RcVec3f CalcStraightSteerDirection() + public Vector3 CalcStraightSteerDirection() { - RcVec3f dir = new RcVec3f(); + Vector3 dir = new Vector3(); if (0 < corners.Count) { - dir = RcVec3f.Subtract(corners[0].pos, npos); + dir = Vector3.Subtract(corners[0].pos, npos); dir.Y = 0; - dir = RcVec3f.Normalize(dir); + dir = Vector3.Normalize(dir); } return dir; } - public void SetTarget(long refs, RcVec3f pos) + public void SetTarget(long refs, Vector3 pos) { targetRef = refs; targetPos = pos; diff --git a/src/DotRecast.Detour.Crowd/DtCrowdAgentAnimation.cs b/src/DotRecast.Detour.Crowd/DtCrowdAgentAnimation.cs index 21a5252..02b1d43 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdAgentAnimation.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdAgentAnimation.cs @@ -19,15 +19,16 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { public class DtCrowdAgentAnimation { public bool active; - public RcVec3f initPos = new RcVec3f(); - public RcVec3f startPos = new RcVec3f(); - public RcVec3f endPos = new RcVec3f(); + public Vector3 initPos = new Vector3(); + public Vector3 startPos = new Vector3(); + public Vector3 endPos = new Vector3(); public long polyRef; public float t, tmax; } diff --git a/src/DotRecast.Detour.Crowd/DtCrowdAgentDebugInfo.cs b/src/DotRecast.Detour.Crowd/DtCrowdAgentDebugInfo.cs index cf204a0..6954a97 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdAgentDebugInfo.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdAgentDebugInfo.cs @@ -19,14 +19,15 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { public class DtCrowdAgentDebugInfo { public DtCrowdAgent agent; - public RcVec3f optStart = new RcVec3f(); - public RcVec3f optEnd = new RcVec3f(); + public Vector3 optStart = new Vector3(); + public Vector3 optEnd = new Vector3(); public DtObstacleAvoidanceDebugData vod; } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs b/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs index aadfb79..7b70167 100644 --- a/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs +++ b/src/DotRecast.Detour.Crowd/DtCrowdTelemetry.cs @@ -24,6 +24,7 @@ using System.Linq; using System.Reflection.Emit; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { diff --git a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs index fbe331c..7466b2b 100644 --- a/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs +++ b/src/DotRecast.Detour.Crowd/DtLocalBoundary.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd @@ -31,7 +32,7 @@ namespace DotRecast.Detour.Crowd { public const int MAX_LOCAL_SEGS = 8; - private RcVec3f m_center = new RcVec3f(); + private Vector3 m_center = new Vector3(); private List m_segs = new List(); private List m_polys = new List(); private List m_parents = new List(); @@ -90,7 +91,7 @@ namespace DotRecast.Detour.Crowd } } - public void Update(long startRef, RcVec3f pos, float collisionQueryRange, DtNavMeshQuery navquery, IDtQueryFilter filter) + public void Update(long startRef, Vector3 pos, float collisionQueryRange, DtNavMeshQuery navquery, IDtQueryFilter filter) { if (startRef == 0) { @@ -154,12 +155,12 @@ namespace DotRecast.Detour.Crowd return true; } - public RcVec3f GetCenter() + public Vector3 GetCenter() { return m_center; } - public RcVec3f[] GetSegment(int j) + public Vector3[] GetSegment(int j) { return m_segs[j].s; } diff --git a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceDebugData.cs b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceDebugData.cs index a4cd86b..0f44af8 100644 --- a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceDebugData.cs +++ b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceDebugData.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { @@ -78,7 +79,7 @@ namespace DotRecast.Detour.Crowd NormalizeArray(m_tpen, m_nsamples); } - public void AddSample(RcVec3f vel, float ssize, float pen, float vpen, float vcpen, float spen, float tpen) + public void AddSample(Vector3 vel, float ssize, float pen, float vpen, float vcpen, float spen, float tpen) { if (m_nsamples >= m_maxSamples) return; @@ -99,9 +100,9 @@ namespace DotRecast.Detour.Crowd return m_nsamples; } - public RcVec3f GetSampleVelocity(int i) + public Vector3 GetSampleVelocity(int i) { - RcVec3f vel = new RcVec3f(); + Vector3 vel = new Vector3(); vel.X = m_vel[i * 3]; vel.Y = m_vel[i * 3 + 1]; vel.Z = m_vel[i * 3 + 2]; diff --git a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs index 1b6e240..44d1675 100644 --- a/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs +++ b/src/DotRecast.Detour.Crowd/DtObstacleAvoidanceQuery.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd @@ -71,7 +72,7 @@ namespace DotRecast.Detour.Crowd m_nsegments = 0; } - public void AddCircle(RcVec3f pos, float rad, RcVec3f vel, RcVec3f dvel) + public void AddCircle(Vector3 pos, float rad, Vector3 vel, Vector3 dvel) { if (m_ncircles >= m_maxCircles) return; @@ -83,7 +84,7 @@ namespace DotRecast.Detour.Crowd cir.dvel = dvel; } - public void AddSegment(RcVec3f p, RcVec3f q) + public void AddSegment(Vector3 p, Vector3 q) { if (m_nsegments >= m_maxSegments) return; @@ -113,7 +114,7 @@ namespace DotRecast.Detour.Crowd return m_segments[i]; } - private void Prepare(RcVec3f pos, RcVec3f dvel) + private void Prepare(Vector3 pos, Vector3 dvel) { // Prepare obstacles for (int i = 0; i < m_ncircles; ++i) @@ -121,14 +122,14 @@ namespace DotRecast.Detour.Crowd DtObstacleCircle cir = m_circles[i]; // Side - RcVec3f pa = pos; - RcVec3f pb = cir.p; + Vector3 pa = pos; + Vector3 pb = cir.p; - RcVec3f orig = new RcVec3f(); - RcVec3f dv = new RcVec3f(); - cir.dp = RcVec3f.Subtract(pb, pa); - cir.dp = RcVec3f.Normalize(cir.dp); - dv = RcVec3f.Subtract(cir.dvel, dvel); + Vector3 orig = new Vector3(); + Vector3 dv = new Vector3(); + cir.dp = Vector3.Subtract(pb, pa); + cir.dp = Vector3.Normalize(cir.dp); + dv = Vector3.Subtract(cir.dvel, dvel); float a = DtUtils.TriArea2D(orig, cir.dp, dv); if (a < 0.01f) @@ -154,14 +155,14 @@ namespace DotRecast.Detour.Crowd } } - private bool SweepCircleCircle(RcVec3f c0, float r0, RcVec3f v, RcVec3f c1, float r1, out float tmin, out float tmax) + private bool SweepCircleCircle(Vector3 c0, float r0, Vector3 v, Vector3 c1, float r1, out float tmin, out float tmax) { const float EPS = 0.0001f; tmin = 0; tmax = 0; - RcVec3f s = RcVec3f.Subtract(c1, c0); + Vector3 s = Vector3.Subtract(c1, c0); float r = r0 + r1; float c = s.Dot2D(s) - r * r; float a = v.Dot2D(v); @@ -183,10 +184,10 @@ namespace DotRecast.Detour.Crowd return true; } - private bool IsectRaySeg(RcVec3f ap, RcVec3f u, RcVec3f bp, RcVec3f bq, ref float t) + private bool IsectRaySeg(Vector3 ap, Vector3 u, Vector3 bp, Vector3 bq, ref float t) { - RcVec3f v = RcVec3f.Subtract(bq, bp); - RcVec3f w = RcVec3f.Subtract(ap, bp); + Vector3 v = Vector3.Subtract(bq, bp); + Vector3 w = Vector3.Subtract(ap, bp); float d = RcVecUtils.Perp2D(u, v); if (MathF.Abs(d) < 1e-6f) return false; @@ -213,7 +214,7 @@ namespace DotRecast.Detour.Crowd * @param minPenalty * threshold penalty for early out */ - private float ProcessSample(RcVec3f vcand, float cs, RcVec3f pos, float rad, RcVec3f vel, RcVec3f dvel, + private float ProcessSample(Vector3 vcand, float cs, Vector3 pos, float rad, Vector3 vel, Vector3 dvel, float minPenalty, DtObstacleAvoidanceDebugData debug) { // penalty for straying away from the desired and current velocities @@ -237,9 +238,9 @@ namespace DotRecast.Detour.Crowd DtObstacleCircle cir = m_circles[i]; // RVO - RcVec3f vab = vcand.Scale(2); - vab = RcVec3f.Subtract(vab, vel); - vab = RcVec3f.Subtract(vab, cir.vel); + Vector3 vab = vcand.Scale(2); + vab = Vector3.Subtract(vab, vel); + vab = Vector3.Subtract(vab, cir.vel); // Side side += Math.Clamp(Math.Min(cir.dp.Dot2D(vab) * 0.5f + 0.5f, cir.np.Dot2D(vab) * 2), 0.0f, 1.0f); @@ -275,8 +276,8 @@ namespace DotRecast.Detour.Crowd if (seg.touch) { // Special case when the agent is very close to the segment. - RcVec3f sdir = RcVec3f.Subtract(seg.q, seg.p); - RcVec3f snorm = new RcVec3f(); + Vector3 sdir = Vector3.Subtract(seg.q, seg.p); + Vector3 snorm = new Vector3(); snorm.X = -sdir.Z; snorm.Z = sdir.X; // If the velocity is pointing towards the segment, no collision. @@ -318,7 +319,7 @@ namespace DotRecast.Detour.Crowd return penalty; } - public int SampleVelocityGrid(RcVec3f pos, float rad, float vmax, RcVec3f vel, RcVec3f dvel, out RcVec3f nvel, + public int SampleVelocityGrid(Vector3 pos, float rad, float vmax, Vector3 vel, Vector3 dvel, out Vector3 nvel, DtObstacleAvoidanceParams option, DtObstacleAvoidanceDebugData debug) { Prepare(pos, dvel); @@ -327,7 +328,7 @@ namespace DotRecast.Detour.Crowd m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : float.MaxValue; - nvel = RcVec3f.Zero; + nvel = Vector3.Zero; if (debug != null) debug.Reset(); @@ -344,7 +345,7 @@ namespace DotRecast.Detour.Crowd { for (int x = 0; x < m_params.gridSize; ++x) { - RcVec3f vcand = new RcVec3f(cvx + x * cs - half, 0f, cvz + y * cs - half); + Vector3 vcand = new Vector3(cvx + x * cs - half, 0f, cvz + y * cs - half); if (RcMath.Sqr(vcand.X) + RcMath.Sqr(vcand.Z) > RcMath.Sqr(vmax + cs / 2)) continue; @@ -373,9 +374,9 @@ namespace DotRecast.Detour.Crowd } // vector normalization that ignores the y-component. - RcVec3f DtRotate2D(float[] v, float ang) + Vector3 DtRotate2D(float[] v, float ang) { - RcVec3f dest = new RcVec3f(); + Vector3 dest = new Vector3(); float c = MathF.Cos(ang); float s = MathF.Sin(ang); dest.X = v[0] * c - v[2] * s; @@ -386,7 +387,7 @@ namespace DotRecast.Detour.Crowd static readonly float DT_PI = 3.14159265f; - public int SampleVelocityAdaptive(RcVec3f pos, float rad, float vmax, RcVec3f vel, RcVec3f dvel, out RcVec3f nvel, + public int SampleVelocityAdaptive(Vector3 pos, float rad, float vmax, Vector3 vel, Vector3 dvel, out Vector3 nvel, DtObstacleAvoidanceParams option, DtObstacleAvoidanceDebugData debug) { @@ -396,7 +397,7 @@ namespace DotRecast.Detour.Crowd m_vmax = vmax; m_invVmax = vmax > 0 ? 1.0f / vmax : float.MaxValue; - nvel = RcVec3f.Zero; + nvel = Vector3.Zero; if (debug != null) debug.Reset(); @@ -421,7 +422,7 @@ namespace DotRecast.Detour.Crowd ddir[1] = dvel.Y; ddir[2] = dvel.Z; DtNormalize2D(ddir); - RcVec3f rotated = DtRotate2D(ddir, da * 0.5f); // rotated by da/2 + Vector3 rotated = DtRotate2D(ddir, da * 0.5f); // rotated by da/2 ddir[3] = rotated.X; ddir[4] = rotated.Y; ddir[5] = rotated.Z; @@ -464,17 +465,17 @@ namespace DotRecast.Detour.Crowd // Start sampling. float cr = vmax * (1.0f - m_params.velBias); - RcVec3f res = new RcVec3f(dvel.X * m_params.velBias, 0, dvel.Z * m_params.velBias); + Vector3 res = new Vector3(dvel.X * m_params.velBias, 0, dvel.Z * m_params.velBias); int ns = 0; for (int k = 0; k < depth; ++k) { float minPenalty = float.MaxValue; - RcVec3f bvel = new RcVec3f(); - bvel = RcVec3f.Zero; + Vector3 bvel = new Vector3(); + bvel = Vector3.Zero; for (int i = 0; i < npat; ++i) { - RcVec3f vcand = new RcVec3f(res.X + pat[i * 2 + 0] * cr, 0f, res.Z + pat[i * 2 + 1] * cr); + Vector3 vcand = new Vector3(res.X + pat[i * 2 + 0] * cr, 0f, res.Z + pat[i * 2 + 1] * cr); if (RcMath.Sqr(vcand.X) + RcMath.Sqr(vcand.Z) > RcMath.Sqr(vmax + 0.001f)) continue; diff --git a/src/DotRecast.Detour.Crowd/DtObstacleCircle.cs b/src/DotRecast.Detour.Crowd/DtObstacleCircle.cs index ba90aaf..56c2cb0 100644 --- a/src/DotRecast.Detour.Crowd/DtObstacleCircle.cs +++ b/src/DotRecast.Detour.Crowd/DtObstacleCircle.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { @@ -6,21 +7,21 @@ namespace DotRecast.Detour.Crowd public class DtObstacleCircle { /** Position of the obstacle */ - public RcVec3f p = new RcVec3f(); + public Vector3 p = new Vector3(); /** Velocity of the obstacle */ - public RcVec3f vel = new RcVec3f(); + public Vector3 vel = new Vector3(); /** Velocity of the obstacle */ - public RcVec3f dvel = new RcVec3f(); + public Vector3 dvel = new Vector3(); /** Radius of the obstacle */ public float rad; /** Use for side selection during sampling. */ - public RcVec3f dp = new RcVec3f(); + public Vector3 dp = new Vector3(); /** Use for side selection during sampling. */ - public RcVec3f np = new RcVec3f(); + public Vector3 np = new Vector3(); } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Crowd/DtObstacleSegment.cs b/src/DotRecast.Detour.Crowd/DtObstacleSegment.cs index 6eab18c..936f46f 100644 --- a/src/DotRecast.Detour.Crowd/DtObstacleSegment.cs +++ b/src/DotRecast.Detour.Crowd/DtObstacleSegment.cs @@ -1,14 +1,15 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { public class DtObstacleSegment { /** End points of the obstacle segment */ - public RcVec3f p = new RcVec3f(); + public Vector3 p = new Vector3(); /** End points of the obstacle segment */ - public RcVec3f q = new RcVec3f(); + public Vector3 q = new Vector3(); public bool touch; } diff --git a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index 866b373..328181f 100644 --- a/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd @@ -65,8 +66,8 @@ namespace DotRecast.Detour.Crowd */ public class DtPathCorridor { - private RcVec3f m_pos = new RcVec3f(); - private RcVec3f m_target = new RcVec3f(); + private Vector3 m_pos = new Vector3(); + private Vector3 m_target = new Vector3(); private List m_path; @@ -86,7 +87,7 @@ namespace DotRecast.Detour.Crowd * @param pos * The new position in the corridor. [(x, y, z)] */ - public void Reset(long refs, RcVec3f pos) + public void Reset(long refs, Vector3 pos) { m_path.Clear(); m_path.Add(refs); @@ -176,7 +177,7 @@ namespace DotRecast.Detour.Crowd * @param filter * The filter to apply to the operation. */ - public void OptimizePathVisibility(RcVec3f next, float pathOptimizationRange, DtNavMeshQuery navquery, IDtQueryFilter filter) + public void OptimizePathVisibility(Vector3 next, float pathOptimizationRange, DtNavMeshQuery navquery, IDtQueryFilter filter) { // Clamp the ray to max distance. float dist = RcVecUtils.Dist2D(m_pos, next); @@ -192,8 +193,8 @@ namespace DotRecast.Detour.Crowd dist = Math.Min(dist + 0.01f, pathOptimizationRange); // Adjust ray length. - var delta = RcVec3f.Subtract(next, m_pos); - RcVec3f goal = RcVecUtils.Mad(m_pos, delta, pathOptimizationRange / dist); + var delta = Vector3.Subtract(next, m_pos); + Vector3 goal = RcVecUtils.Mad(m_pos, delta, pathOptimizationRange / dist); var status = navquery.Raycast(m_path[0], m_pos, goal, filter, 0, 0, out var rayHit); if (status.Succeeded()) @@ -242,7 +243,7 @@ namespace DotRecast.Detour.Crowd return false; } - public bool MoveOverOffmeshConnection(long offMeshConRef, long[] refs, ref RcVec3f startPos, ref RcVec3f endPos, DtNavMeshQuery navquery) + public bool MoveOverOffmeshConnection(long offMeshConRef, long[] refs, ref Vector3 startPos, ref Vector3 endPos, DtNavMeshQuery navquery) { // Advance the path up to and over the off-mesh connection. long prevRef = 0, polyRef = m_path[0]; @@ -299,7 +300,7 @@ namespace DotRecast.Detour.Crowd * @param filter * The filter to apply to the operation. */ - public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) + public bool MovePosition(Vector3 npos, DtNavMeshQuery navquery, IDtQueryFilter filter) { // Move along navmesh and update new position. var visited = new List(); @@ -339,7 +340,7 @@ namespace DotRecast.Detour.Crowd * @param filter * The filter to apply to the operation. */ - public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter filter) + public bool MoveTargetPosition(Vector3 npos, DtNavMeshQuery navquery, IDtQueryFilter filter) { // Move along navmesh and update new position. var visited = new List(); @@ -370,13 +371,13 @@ namespace DotRecast.Detour.Crowd * @param path * The path corridor. */ - public void SetCorridor(RcVec3f target, List path) + public void SetCorridor(Vector3 target, List path) { m_target = target; m_path = new List(path); } - public void FixPathStart(long safeRef, RcVec3f safePos) + public void FixPathStart(long safeRef, Vector3 safePos) { m_pos = safePos; if (m_path.Count < 3 && m_path.Count > 0) @@ -460,7 +461,7 @@ namespace DotRecast.Detour.Crowd * * @return The current position within the corridor. */ - public RcVec3f GetPos() + public Vector3 GetPos() { return m_pos; } @@ -470,7 +471,7 @@ namespace DotRecast.Detour.Crowd * * @return The current target within the corridor. */ - public RcVec3f GetTarget() + public Vector3 GetTarget() { return m_target; } diff --git a/src/DotRecast.Detour.Crowd/DtPathQuery.cs b/src/DotRecast.Detour.Crowd/DtPathQuery.cs index b8d13dd..5537352 100644 --- a/src/DotRecast.Detour.Crowd/DtPathQuery.cs +++ b/src/DotRecast.Detour.Crowd/DtPathQuery.cs @@ -19,14 +19,15 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { public class DtPathQuery { /// Path find start and end location. - public RcVec3f startPos = new RcVec3f(); - public RcVec3f endPos = new RcVec3f(); + public Vector3 startPos = new Vector3(); + public Vector3 endPos = new Vector3(); public long startRef; public long endRef; diff --git a/src/DotRecast.Detour.Crowd/DtPathQueue.cs b/src/DotRecast.Detour.Crowd/DtPathQueue.cs index 5e8843b..691e06b 100644 --- a/src/DotRecast.Detour.Crowd/DtPathQueue.cs +++ b/src/DotRecast.Detour.Crowd/DtPathQueue.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd @@ -75,7 +76,7 @@ namespace DotRecast.Detour.Crowd } } - public DtPathQueryResult Request(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter) + public DtPathQueryResult Request(long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter) { if (queue.Count >= config.pathQueueSize) { diff --git a/src/DotRecast.Detour.Crowd/DtSegment.cs b/src/DotRecast.Detour.Crowd/DtSegment.cs index a7e3a95..353eb83 100644 --- a/src/DotRecast.Detour.Crowd/DtSegment.cs +++ b/src/DotRecast.Detour.Crowd/DtSegment.cs @@ -1,11 +1,12 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Crowd { public class DtSegment { /** Segment start/end */ - public RcVec3f[] s = new RcVec3f[2]; + public Vector3[] s = new Vector3[2]; /** Distance for pruning. */ public float d; diff --git a/src/DotRecast.Detour.Dynamic/Colliders/DtBoxCollider.cs b/src/DotRecast.Detour.Dynamic/Colliders/DtBoxCollider.cs index 239d216..705cf14 100644 --- a/src/DotRecast.Detour.Dynamic/Colliders/DtBoxCollider.cs +++ b/src/DotRecast.Detour.Dynamic/Colliders/DtBoxCollider.cs @@ -20,23 +20,24 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Colliders { public class DtBoxCollider : DtCollider { - private readonly RcVec3f center; - private readonly RcVec3f[] halfEdges; + private readonly Vector3 center; + private readonly Vector3[] halfEdges; - public DtBoxCollider(RcVec3f center, RcVec3f[] halfEdges, int area, float flagMergeThreshold) : + public DtBoxCollider(Vector3 center, Vector3[] halfEdges, int area, float flagMergeThreshold) : base(area, flagMergeThreshold, Bounds(center, halfEdges)) { this.center = center; this.halfEdges = halfEdges; } - private static float[] Bounds(RcVec3f center, RcVec3f[] halfEdges) + private static float[] Bounds(Vector3 center, Vector3[] halfEdges) { float[] bounds = new float[] { @@ -68,20 +69,20 @@ namespace DotRecast.Detour.Dynamic.Colliders hf, center, halfEdges, area, (int)MathF.Floor(flagMergeThreshold / hf.ch), telemetry); } - public static RcVec3f[] GetHalfEdges(RcVec3f up, RcVec3f forward, RcVec3f extent) + public static Vector3[] GetHalfEdges(Vector3 up, Vector3 forward, Vector3 extent) { - RcVec3f[] halfEdges = + Vector3[] halfEdges = { - RcVec3f.Zero, - new RcVec3f(up.X, up.Y, up.Z), - RcVec3f.Zero + Vector3.Zero, + new Vector3(up.X, up.Y, up.Z), + Vector3.Zero }; - halfEdges[1] = RcVec3f.Normalize(halfEdges[1]); - halfEdges[0] = RcVec3f.Cross(up, forward); - halfEdges[0] = RcVec3f.Normalize(halfEdges[0]); - halfEdges[2] = RcVec3f.Cross(halfEdges[0], up); - halfEdges[2] = RcVec3f.Normalize(halfEdges[2]); + halfEdges[1] = Vector3.Normalize(halfEdges[1]); + halfEdges[0] = Vector3.Cross(up, forward); + halfEdges[0] = Vector3.Normalize(halfEdges[0]); + halfEdges[2] = Vector3.Cross(halfEdges[0], up); + halfEdges[2] = Vector3.Normalize(halfEdges[2]); halfEdges[0].X *= extent.X; halfEdges[0].Y *= extent.X; halfEdges[0].Z *= extent.X; diff --git a/src/DotRecast.Detour.Dynamic/Colliders/DtCapsuleCollider.cs b/src/DotRecast.Detour.Dynamic/Colliders/DtCapsuleCollider.cs index 1745c76..3e2ace3 100644 --- a/src/DotRecast.Detour.Dynamic/Colliders/DtCapsuleCollider.cs +++ b/src/DotRecast.Detour.Dynamic/Colliders/DtCapsuleCollider.cs @@ -20,17 +20,18 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Colliders { public class DtCapsuleCollider : DtCollider { - private readonly RcVec3f start; - private readonly RcVec3f end; + private readonly Vector3 start; + private readonly Vector3 end; private readonly float radius; - public DtCapsuleCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold) + public DtCapsuleCollider(Vector3 start, Vector3 end, float radius, int area, float flagMergeThreshold) : base(area, flagMergeThreshold, Bounds(start, end, radius)) { this.start = start; @@ -43,7 +44,7 @@ namespace DotRecast.Detour.Dynamic.Colliders RcFilledVolumeRasterization.RasterizeCapsule(hf, start, end, radius, area, (int)MathF.Floor(flagMergeThreshold / hf.ch), telemetry); } - private static float[] Bounds(RcVec3f start, RcVec3f end, float radius) + private static float[] Bounds(Vector3 start, Vector3 end, float radius) { return new float[] { diff --git a/src/DotRecast.Detour.Dynamic/Colliders/DtCylinderCollider.cs b/src/DotRecast.Detour.Dynamic/Colliders/DtCylinderCollider.cs index 2067a2b..52282d7 100644 --- a/src/DotRecast.Detour.Dynamic/Colliders/DtCylinderCollider.cs +++ b/src/DotRecast.Detour.Dynamic/Colliders/DtCylinderCollider.cs @@ -20,17 +20,18 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Colliders { public class DtCylinderCollider : DtCollider { - private readonly RcVec3f start; - private readonly RcVec3f end; + private readonly Vector3 start; + private readonly Vector3 end; private readonly float radius; - public DtCylinderCollider(RcVec3f start, RcVec3f end, float radius, int area, float flagMergeThreshold) : + public DtCylinderCollider(Vector3 start, Vector3 end, float radius, int area, float flagMergeThreshold) : base(area, flagMergeThreshold, Bounds(start, end, radius)) { this.start = start; @@ -44,7 +45,7 @@ namespace DotRecast.Detour.Dynamic.Colliders telemetry); } - private static float[] Bounds(RcVec3f start, RcVec3f end, float radius) + private static float[] Bounds(Vector3 start, Vector3 end, float radius) { return new float[] { diff --git a/src/DotRecast.Detour.Dynamic/Colliders/DtSphereCollider.cs b/src/DotRecast.Detour.Dynamic/Colliders/DtSphereCollider.cs index f90b6d8..a24223a 100644 --- a/src/DotRecast.Detour.Dynamic/Colliders/DtSphereCollider.cs +++ b/src/DotRecast.Detour.Dynamic/Colliders/DtSphereCollider.cs @@ -20,16 +20,17 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Colliders { public class DtSphereCollider : DtCollider { - private readonly RcVec3f center; + private readonly Vector3 center; private readonly float radius; - public DtSphereCollider(RcVec3f center, float radius, int area, float flagMergeThreshold) + public DtSphereCollider(Vector3 center, float radius, int area, float flagMergeThreshold) : base(area, flagMergeThreshold, Bounds(center, radius)) { this.center = center; @@ -42,7 +43,7 @@ namespace DotRecast.Detour.Dynamic.Colliders telemetry); } - private static float[] Bounds(RcVec3f center, float radius) + private static float[] Bounds(Vector3 center, float radius) { return new float[] { diff --git a/src/DotRecast.Detour.Dynamic/DtVoxelQuery.cs b/src/DotRecast.Detour.Dynamic/DtVoxelQuery.cs index 48ffdcb..0d40860 100644 --- a/src/DotRecast.Detour.Dynamic/DtVoxelQuery.cs +++ b/src/DotRecast.Detour.Dynamic/DtVoxelQuery.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic @@ -30,12 +31,12 @@ namespace DotRecast.Detour.Dynamic */ public class DtVoxelQuery { - private readonly RcVec3f origin; + private readonly Vector3 origin; private readonly float tileWidth; private readonly float tileDepth; private readonly Func heightfieldProvider; - public DtVoxelQuery(RcVec3f origin, float tileWidth, float tileDepth, Func heightfieldProvider) + public DtVoxelQuery(Vector3 origin, float tileWidth, float tileDepth, Func heightfieldProvider) { this.origin = origin; this.tileWidth = tileWidth; @@ -48,12 +49,12 @@ namespace DotRecast.Detour.Dynamic * * @return Optional with hit parameter (t) or empty if no hit found */ - public bool Raycast(RcVec3f start, RcVec3f end, out float hit) + public bool Raycast(Vector3 start, Vector3 end, out float hit) { return TraverseTiles(start, end, out hit); } - private bool TraverseTiles(RcVec3f start, RcVec3f end, out float hit) + private bool TraverseTiles(Vector3 start, Vector3 end, out float hit) { float relStartX = start.X - origin.X; float relStartZ = start.Z - origin.Z; @@ -108,7 +109,7 @@ namespace DotRecast.Detour.Dynamic return false; } - private bool TraversHeightfield(int x, int z, RcVec3f start, RcVec3f end, float tMin, float tMax, out float hit) + private bool TraversHeightfield(int x, int z, Vector3 start, Vector3 end, float tMin, float tMax, out float hit) { RcHeightfield hf = heightfieldProvider.Invoke(x, z); if (null != hf) diff --git a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFile.cs b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFile.cs index 9f53c59..c4c451e 100644 --- a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFile.cs +++ b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFile.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Io @@ -54,7 +55,7 @@ namespace DotRecast.Detour.Dynamic.Io public bool useTiles; public int tileSizeX; public int tileSizeZ; - public RcVec3f rotation = new RcVec3f(); + public Vector3 rotation = new Vector3(); public float[] bounds = new float[6]; public readonly List tiles = new List(); diff --git a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileReader.cs b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileReader.cs index c63f285..0111d26 100644 --- a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileReader.cs +++ b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileReader.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Io; namespace DotRecast.Detour.Dynamic.Io @@ -108,11 +109,11 @@ namespace DotRecast.Detour.Dynamic.Io int width = buf.GetInt(); int depth = buf.GetInt(); int borderSize = buf.GetInt(); - RcVec3f boundsMin = new RcVec3f(); + Vector3 boundsMin = new Vector3(); boundsMin.X = buf.GetFloat(); boundsMin.Y = buf.GetFloat(); boundsMin.Z = buf.GetFloat(); - RcVec3f boundsMax = new RcVec3f(); + Vector3 boundsMax = new Vector3(); boundsMax.X = buf.GetFloat(); boundsMax.Y = buf.GetFloat(); boundsMax.Z = buf.GetFloat(); diff --git a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileWriter.cs b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileWriter.cs index 70ed7b2..72493b4 100644 --- a/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileWriter.cs +++ b/src/DotRecast.Detour.Dynamic/Io/DtVoxelFileWriter.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Io; namespace DotRecast.Detour.Dynamic.Io diff --git a/src/DotRecast.Detour.Dynamic/Io/DtVoxelTile.cs b/src/DotRecast.Detour.Dynamic/Io/DtVoxelTile.cs index b50addc..9ca025b 100644 --- a/src/DotRecast.Detour.Dynamic/Io/DtVoxelTile.cs +++ b/src/DotRecast.Detour.Dynamic/Io/DtVoxelTile.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Dynamic.Io @@ -32,13 +33,13 @@ namespace DotRecast.Detour.Dynamic.Io public readonly int borderSize; public int width; public int depth; - public readonly RcVec3f boundsMin; - public RcVec3f boundsMax; + public readonly Vector3 boundsMin; + public Vector3 boundsMax; public float cellSize; public float cellHeight; public readonly byte[] spanData; - public DtVoxelTile(int tileX, int tileZ, int width, int depth, RcVec3f boundsMin, RcVec3f boundsMax, float cellSize, + public DtVoxelTile(int tileX, int tileZ, int width, int depth, Vector3 boundsMin, Vector3 boundsMax, float cellSize, float cellHeight, int borderSize, RcByteBuffer buffer) { this.tileX = tileX; diff --git a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs index 55aedf6..0946c7c 100644 --- a/src/DotRecast.Detour.Extras/BVTreeBuilder.cs +++ b/src/DotRecast.Detour.Extras/BVTreeBuilder.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras { @@ -40,8 +41,8 @@ namespace DotRecast.Detour.Extras BVItem it = new BVItem(); items[i] = it; it.i = i; - RcVec3f bmin = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); - RcVec3f bmax = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); + Vector3 bmin = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); + Vector3 bmax = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3); for (int j = 1; j < data.polys[i].vertCount; j++) { bmin = RcVecUtils.Min(bmin, data.verts, data.polys[i].verts[j] * 3); diff --git a/src/DotRecast.Detour.Extras/Jumplink/AbstractGroundSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/AbstractGroundSampler.cs index 8efafd2..c40889e 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/AbstractGroundSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/AbstractGroundSampler.cs @@ -1,12 +1,13 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Extras.Jumplink { public abstract class AbstractGroundSampler : IGroundSampler { - public delegate bool ComputeNavMeshHeight(RcVec3f pt, float cellSize, out float height); + public delegate bool ComputeNavMeshHeight(Vector3 pt, float cellSize, out float height); protected void SampleGround(JumpLinkBuilderConfig acfg, EdgeSampler es, ComputeNavMeshHeight heightFunc) { @@ -33,7 +34,7 @@ namespace DotRecast.Detour.Extras.Jumplink GroundSample s = new GroundSample(); seg.gsamples[i] = s; - RcVec3f pt = RcVec3f.Lerp(seg.p, seg.q, u); + Vector3 pt = Vector3.Lerp(seg.p, seg.q, u); bool success = heightFunc.Invoke(pt, seg.height, out var height); s.p.X = pt.X; s.p.Y = height; diff --git a/src/DotRecast.Detour.Extras/Jumplink/ClimbTrajectory.cs b/src/DotRecast.Detour.Extras/Jumplink/ClimbTrajectory.cs index e11ac57..1c770b4 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/ClimbTrajectory.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/ClimbTrajectory.cs @@ -1,13 +1,14 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { public class ClimbTrajectory : Trajectory { - public override RcVec3f Apply(RcVec3f start, RcVec3f end, float u) + public override Vector3 Apply(Vector3 start, Vector3 end, float u) { - return new RcVec3f() + return new Vector3() { X = Lerp(start.X, end.X, Math.Min(2f * u, 1f)), Y = Lerp(start.Y, end.Y, Math.Max(0f, 2f * u - 1f)), diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeExtractor.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeExtractor.cs index 3b6f852..98b8bc6 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeExtractor.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeExtractor.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; using static DotRecast.Recast.RcConstants; @@ -13,7 +14,7 @@ namespace DotRecast.Detour.Extras.Jumplink List edges = new List(); if (mesh != null) { - RcVec3f orig = mesh.bmin; + Vector3 orig = mesh.bmin; float cs = mesh.cs; float ch = mesh.ch; for (int i = 0; i < mesh.npolys; i++) diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs index 9a5a468..811e1b5 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSampler.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { @@ -9,20 +10,20 @@ namespace DotRecast.Detour.Extras.Jumplink public readonly List end = new List(); public readonly Trajectory trajectory; - public readonly RcVec3f ax = new RcVec3f(); - public readonly RcVec3f ay = new RcVec3f(); - public readonly RcVec3f az = new RcVec3f(); + public readonly Vector3 ax = new Vector3(); + public readonly Vector3 ay = new Vector3(); + public readonly Vector3 az = new Vector3(); public EdgeSampler(JumpEdge edge, Trajectory trajectory) { this.trajectory = trajectory; - ax = RcVec3f.Subtract(edge.sq, edge.sp); - ax = RcVec3f.Normalize(ax); + ax = Vector3.Subtract(edge.sq, edge.sp); + ax = Vector3.Normalize(ax); - az = new RcVec3f(ax.Z, 0, -ax.X); - az = RcVec3f.Normalize(az); + az = new Vector3(ax.Z, 0, -ax.X); + az = Vector3.Normalize(az); - ay = new RcVec3f(0, 1, 0); + ay = new Vector3(0, 1, 0); } } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs b/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs index 3b0b976..3a31061 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/EdgeSamplerFactory.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { @@ -29,8 +30,8 @@ namespace DotRecast.Detour.Extras.Jumplink { EdgeSampler es = new EdgeSampler(edge, new JumpTrajectory(acfg.jumpHeight)); es.start.height = acfg.agentClimb * 2; - RcVec3f offset = new RcVec3f(); - Trans2d(ref offset, es.az, es.ay, new RcVec2f { X = acfg.startDistance, Y = -acfg.agentClimb, }); + Vector3 offset = new Vector3(); + Trans2d(ref offset, es.az, es.ay, new Vector2 { X = acfg.startDistance, Y = -acfg.agentClimb, }); Vadd(ref es.start.p, edge.sp, offset); Vadd(ref es.start.q, edge.sq, offset); @@ -42,7 +43,7 @@ namespace DotRecast.Detour.Extras.Jumplink { float v = (float)j / (float)(nsamples - 1); float ox = 2 * acfg.agentRadius + dx * v; - Trans2d(ref offset, es.az, es.ay, new RcVec2f { X = ox, Y = acfg.minHeight }); + Trans2d(ref offset, es.az, es.ay, new Vector2 { X = ox, Y = acfg.minHeight }); GroundSegment end = new GroundSegment(); end.height = acfg.heightRange; Vadd(ref end.p, edge.sp, offset); @@ -57,12 +58,12 @@ namespace DotRecast.Detour.Extras.Jumplink { EdgeSampler es = new EdgeSampler(edge, new ClimbTrajectory()); es.start.height = acfg.agentClimb * 2; - RcVec3f offset = new RcVec3f(); - Trans2d(ref offset, es.az, es.ay, new RcVec2f() { X = acfg.startDistance, Y = -acfg.agentClimb }); + Vector3 offset = new Vector3(); + Trans2d(ref offset, es.az, es.ay, new Vector2() { X = acfg.startDistance, Y = -acfg.agentClimb }); Vadd(ref es.start.p, edge.sp, offset); Vadd(ref es.start.q, edge.sq, offset); - Trans2d(ref offset, es.az, es.ay, new RcVec2f() { X = acfg.endDistance, Y = acfg.minHeight }); + Trans2d(ref offset, es.az, es.ay, new Vector2() { X = acfg.endDistance, Y = acfg.minHeight }); GroundSegment end = new GroundSegment(); end.height = acfg.heightRange; Vadd(ref end.p, edge.sp, offset); @@ -78,7 +79,7 @@ namespace DotRecast.Detour.Extras.Jumplink dest[2] = v1[2] + v2[2]; } - private void Vadd(ref RcVec3f dest, RcVec3f v1, RcVec3f v2) + private void Vadd(ref Vector3 dest, Vector3 v1, Vector3 v2) { dest.X = v1.X + v2.X; dest.Y = v1.Y + v2.Y; @@ -93,7 +94,7 @@ namespace DotRecast.Detour.Extras.Jumplink dst[2] = ax[2] * pt[0] + ay[2] * pt[1]; } - private void Trans2d(ref RcVec3f dst, RcVec3f ax, RcVec3f ay, RcVec2f pt) + private void Trans2d(ref Vector3 dst, Vector3 ax, Vector3 ay, Vector2 pt) { dst.X = ax.X * pt.X + ay.X * pt.Y; dst.Y = ax.Y * pt.X + ay.Y * pt.Y; diff --git a/src/DotRecast.Detour.Extras/Jumplink/GroundSample.cs b/src/DotRecast.Detour.Extras/Jumplink/GroundSample.cs index 41cffc1..a864499 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/GroundSample.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/GroundSample.cs @@ -1,10 +1,11 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { public class GroundSample { - public RcVec3f p = new RcVec3f(); + public Vector3 p = new Vector3(); public bool validTrajectory; public bool validHeight; } diff --git a/src/DotRecast.Detour.Extras/Jumplink/GroundSegment.cs b/src/DotRecast.Detour.Extras/Jumplink/GroundSegment.cs index 1268bba..ad8e274 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/GroundSegment.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/GroundSegment.cs @@ -1,11 +1,12 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { public class GroundSegment { - public RcVec3f p = new RcVec3f(); - public RcVec3f q = new RcVec3f(); + public Vector3 p = new Vector3(); + public Vector3 q = new Vector3(); public GroundSample[] gsamples; public float height; } diff --git a/src/DotRecast.Detour.Extras/Jumplink/JumpEdge.cs b/src/DotRecast.Detour.Extras/Jumplink/JumpEdge.cs index 36a889b..e093db0 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/JumpEdge.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/JumpEdge.cs @@ -1,10 +1,11 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { public class JumpEdge { - public RcVec3f sp = new RcVec3f(); - public RcVec3f sq = new RcVec3f(); + public Vector3 sp = new Vector3(); + public Vector3 sq = new Vector3(); } } \ No newline at end of file diff --git a/src/DotRecast.Detour.Extras/Jumplink/JumpLinkBuilder.cs b/src/DotRecast.Detour.Extras/Jumplink/JumpLinkBuilder.cs index dc8da9c..cce1bd6 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/JumpLinkBuilder.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/JumpLinkBuilder.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; namespace DotRecast.Detour.Extras.Jumplink @@ -54,11 +55,11 @@ namespace DotRecast.Detour.Extras.Jumplink List links = new List(); foreach (JumpSegment js in jumpSegments) { - RcVec3f sp = es.start.gsamples[js.startSample].p; - RcVec3f sq = es.start.gsamples[js.startSample + js.samples - 1].p; + Vector3 sp = es.start.gsamples[js.startSample].p; + Vector3 sq = es.start.gsamples[js.startSample + js.samples - 1].p; GroundSegment end = es.end[js.groundSegment]; - RcVec3f ep = end.gsamples[js.startSample].p; - RcVec3f eq = end.gsamples[js.startSample + js.samples - 1].p; + Vector3 ep = end.gsamples[js.startSample].p; + Vector3 eq = end.gsamples[js.startSample + js.samples - 1].p; float d = Math.Min(RcVecUtils.Dist2DSqr(sp, sq), RcVecUtils.Dist2DSqr(ep, eq)); if (d >= 4 * acfg.agentRadius * acfg.agentRadius) { @@ -72,7 +73,7 @@ namespace DotRecast.Detour.Extras.Jumplink for (int j = 0; j < link.nspine; ++j) { float u = ((float)j) / (link.nspine - 1); - RcVec3f p = es.trajectory.Apply(sp, ep, u); + Vector3 p = es.trajectory.Apply(sp, ep, u); link.spine0[j * 3] = p.X; link.spine0[j * 3 + 1] = p.Y; link.spine0[j * 3 + 2] = p.Z; diff --git a/src/DotRecast.Detour.Extras/Jumplink/JumpTrajectory.cs b/src/DotRecast.Detour.Extras/Jumplink/JumpTrajectory.cs index 07221db..d045bec 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/JumpTrajectory.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/JumpTrajectory.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { @@ -12,9 +13,9 @@ namespace DotRecast.Detour.Extras.Jumplink this.jumpHeight = jumpHeight; } - public override RcVec3f Apply(RcVec3f start, RcVec3f end, float u) + public override Vector3 Apply(Vector3 start, Vector3 end, float u) { - return new RcVec3f + return new Vector3 { X = Lerp(start.X, end.X, u), Y = InterpolateHeight(start.Y, end.Y, u), diff --git a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs index 870a192..ad2174e 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/NavMeshGroundSampler.cs @@ -1,5 +1,6 @@ using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; @@ -10,7 +11,7 @@ namespace DotRecast.Detour.Extras.Jumplink public override void Sample(JumpLinkBuilderConfig acfg, RcBuilderResult result, EdgeSampler es) { DtNavMeshQuery navMeshQuery = CreateNavMesh(result, acfg.agentRadius, acfg.agentHeight, acfg.agentClimb); - SampleGround(acfg, es, (RcVec3f pt, float heightRange, out float height) => GetNavMeshHeight(navMeshQuery, pt, acfg.cellSize, heightRange, out height)); + SampleGround(acfg, es, (Vector3 pt, float heightRange, out float height) => GetNavMeshHeight(navMeshQuery, pt, acfg.cellSize, heightRange, out height)); } private DtNavMeshQuery CreateNavMesh(RcBuilderResult r, float agentRadius, float agentHeight, float agentClimb) @@ -40,11 +41,11 @@ namespace DotRecast.Detour.Extras.Jumplink } - private bool GetNavMeshHeight(DtNavMeshQuery navMeshQuery, RcVec3f pt, float cs, float heightRange, out float height) + private bool GetNavMeshHeight(DtNavMeshQuery navMeshQuery, Vector3 pt, float cs, float heightRange, out float height) { height = default; - RcVec3f halfExtents = new RcVec3f { X = cs, Y = heightRange, Z = cs }; + Vector3 halfExtents = new Vector3 { X = cs, Y = heightRange, Z = cs }; float maxHeight = pt.Y + heightRange; RcAtomicBoolean found = new RcAtomicBoolean(); RcAtomicFloat minHeight = new RcAtomicFloat(pt.Y); diff --git a/src/DotRecast.Detour.Extras/Jumplink/Trajectory.cs b/src/DotRecast.Detour.Extras/Jumplink/Trajectory.cs index 4e3cc7d..0324eaa 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/Trajectory.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/Trajectory.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Jumplink { @@ -10,7 +11,7 @@ namespace DotRecast.Detour.Extras.Jumplink return u * g + (1f - u) * f; } - public virtual RcVec3f Apply(RcVec3f start, RcVec3f end, float u) + public virtual Vector3 Apply(Vector3 start, Vector3 end, float u) { throw new NotImplementedException(); } diff --git a/src/DotRecast.Detour.Extras/Jumplink/TrajectorySampler.cs b/src/DotRecast.Detour.Extras/Jumplink/TrajectorySampler.cs index dc2dc6f..8faa2e5 100644 --- a/src/DotRecast.Detour.Extras/Jumplink/TrajectorySampler.cs +++ b/src/DotRecast.Detour.Extras/Jumplink/TrajectorySampler.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; @@ -32,7 +33,7 @@ namespace DotRecast.Detour.Extras.Jumplink } } - private bool SampleTrajectory(JumpLinkBuilderConfig acfg, RcHeightfield solid, RcVec3f pa, RcVec3f pb, Trajectory tra) + private bool SampleTrajectory(JumpLinkBuilderConfig acfg, RcHeightfield solid, Vector3 pa, Vector3 pb, Trajectory tra) { float cs = Math.Min(acfg.cellSize, acfg.cellHeight); float d = RcVecUtils.Dist2D(pa, pb) + MathF.Abs(pa.Y - pb.Y); @@ -40,7 +41,7 @@ namespace DotRecast.Detour.Extras.Jumplink for (int i = 0; i < nsamples; ++i) { float u = (float)i / (float)(nsamples - 1); - RcVec3f p = tra.Apply(pa, pb, u); + Vector3 p = tra.Apply(pa, pb, u); if (CheckHeightfieldCollision(solid, p.X, p.Y + acfg.groundTolerance, p.Y + acfg.agentHeight, p.Z)) { return false; @@ -56,7 +57,7 @@ namespace DotRecast.Detour.Extras.Jumplink int h = solid.height; float cs = solid.cs; float ch = solid.ch; - RcVec3f orig = solid.bmin; + Vector3 orig = solid.bmin; int ix = (int)MathF.Floor((x - orig.X) / cs); int iz = (int)MathF.Floor((z - orig.Z) / cs); diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/GraphMeta.cs b/src/DotRecast.Detour.Extras/Unity/Astar/GraphMeta.cs index fe69eb2..93b3fe1 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/GraphMeta.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/GraphMeta.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Unity.Astar { diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2.cs b/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2.cs index 9f89e55..c60ba14 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Unity.Astar { @@ -25,10 +26,10 @@ namespace DotRecast.Detour.Extras.Unity.Astar public readonly long linkID; public readonly int startNode; public readonly int endNode; - public readonly RcVec3f clamped1; - public readonly RcVec3f clamped2; + public readonly Vector3 clamped1; + public readonly Vector3 clamped2; - public NodeLink2(long linkID, int startNode, int endNode, RcVec3f clamped1, RcVec3f clamped2) : base() + public NodeLink2(long linkID, int startNode, int endNode, Vector3 clamped1, Vector3 clamped2) : base() { this.linkID = linkID; this.startNode = startNode; diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2Reader.cs b/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2Reader.cs index 49add07..77e7b9a 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2Reader.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/NodeLink2Reader.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System.IO.Compression; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Unity.Astar { @@ -36,11 +37,11 @@ namespace DotRecast.Detour.Extras.Unity.Astar int endNode = indexToNode[buffer.GetInt()]; int connectedNode1 = buffer.GetInt(); int connectedNode2 = buffer.GetInt(); - RcVec3f clamped1 = new RcVec3f(); + Vector3 clamped1 = new Vector3(); clamped1.X = buffer.GetFloat(); clamped1.Y = buffer.GetFloat(); clamped1.Z = buffer.GetFloat(); - RcVec3f clamped2 = new RcVec3f(); + Vector3 clamped2 = new Vector3(); clamped2.X = buffer.GetFloat(); clamped2.Y = buffer.GetFloat(); clamped2.Z = buffer.GetFloat(); diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs index e19a130..ceb63a2 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/OffMeshLinkCreator.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Extras.Unity.Astar { diff --git a/src/DotRecast.Detour.Extras/Unity/Astar/ZipBinaryReader.cs b/src/DotRecast.Detour.Extras/Unity/Astar/ZipBinaryReader.cs index b7a2f9f..d41cda5 100644 --- a/src/DotRecast.Detour.Extras/Unity/Astar/ZipBinaryReader.cs +++ b/src/DotRecast.Detour.Extras/Unity/Astar/ZipBinaryReader.cs @@ -20,6 +20,7 @@ using System.IO; using System.IO.Compression; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Io; namespace DotRecast.Detour.Extras.Unity.Astar diff --git a/src/DotRecast.Detour.TileCache/DtTileCache.cs b/src/DotRecast.Detour.TileCache/DtTileCache.cs index 8d99f18..a2ac128 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCache.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCache.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache.Io; namespace DotRecast.Detour.TileCache @@ -346,7 +347,7 @@ namespace DotRecast.Detour.TileCache } // Cylinder obstacle - public long AddObstacle(RcVec3f pos, float radius, float height) + public long AddObstacle(Vector3 pos, float radius, float height) { DtTileCacheObstacle ob = AllocObstacle(); ob.type = DtTileCacheObstacleType.CYLINDER; @@ -359,7 +360,7 @@ namespace DotRecast.Detour.TileCache } // Aabb obstacle - public long AddBoxObstacle(RcVec3f bmin, RcVec3f bmax) + public long AddBoxObstacle(Vector3 bmin, Vector3 bmax) { DtTileCacheObstacle ob = AllocObstacle(); ob.type = DtTileCacheObstacleType.BOX; @@ -371,7 +372,7 @@ namespace DotRecast.Detour.TileCache } // Box obstacle: can be rotated in Y - public long AddBoxObstacle(RcVec3f center, RcVec3f extents, float yRadians) + public long AddBoxObstacle(Vector3 center, Vector3 extents, float yRadians) { DtTileCacheObstacle ob = AllocObstacle(); ob.type = DtTileCacheObstacleType.ORIENTED_BOX; @@ -437,7 +438,7 @@ namespace DotRecast.Detour.TileCache return m_obstacles[i]; } - private List QueryTiles(RcVec3f bmin, RcVec3f bmax) + private List QueryTiles(Vector3 bmin, Vector3 bmax) { List results = new List(); float tw = m_params.width * m_params.cs; @@ -454,8 +455,8 @@ namespace DotRecast.Detour.TileCache foreach (long i in tiles) { DtCompressedTile tile = m_tiles[DecodeTileIdTile(i)]; - RcVec3f tbmin = new RcVec3f(); - RcVec3f tbmax = new RcVec3f(); + Vector3 tbmin = new Vector3(); + Vector3 tbmax = new Vector3(); CalcTightTileBounds(tile.header, ref tbmin, ref tbmax); if (DtUtils.OverlapBounds(bmin, bmax, tbmin, tbmax)) { @@ -498,8 +499,8 @@ namespace DotRecast.Detour.TileCache if (req.action == DtObstacleRequestAction.REQUEST_ADD) { // Find touched tiles. - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); GetObstacleBounds(ob, ref bmin, ref bmax); ob.touched = QueryTiles(bmin, bmax); // Add tiles to update list. @@ -680,7 +681,7 @@ namespace DotRecast.Detour.TileCache return layer; } - void CalcTightTileBounds(DtTileCacheLayerHeader header, ref RcVec3f bmin, ref RcVec3f bmax) + void CalcTightTileBounds(DtTileCacheLayerHeader header, ref Vector3 bmin, ref Vector3 bmax) { float cs = m_params.cs; bmin.X = header.bmin.X + header.minx * cs; @@ -691,7 +692,7 @@ namespace DotRecast.Detour.TileCache bmax.Z = header.bmin.Z + (header.maxy + 1) * cs; } - public void GetObstacleBounds(DtTileCacheObstacle ob, ref RcVec3f bmin, ref RcVec3f bmax) + public void GetObstacleBounds(DtTileCacheObstacle ob, ref Vector3 bmin, ref Vector3 bmax) { if (ob.type == DtTileCacheObstacleType.CYLINDER) { diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs index db92e20..1fba821 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheBuilder.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache.Io; using DotRecast.Detour.TileCache.Io.Compress; @@ -1801,10 +1802,10 @@ namespace DotRecast.Detour.TileCache return mesh; } - public void MarkCylinderArea(DtTileCacheLayer layer, RcVec3f orig, float cs, float ch, RcVec3f pos, float radius, float height, int areaId) + public void MarkCylinderArea(DtTileCacheLayer layer, Vector3 orig, float cs, float ch, Vector3 pos, float radius, float height, int areaId) { - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); bmin.X = pos.X - radius; bmin.Y = pos.Y; bmin.Z = pos.Z - radius; @@ -1862,7 +1863,7 @@ namespace DotRecast.Detour.TileCache } } - public void MarkBoxArea(DtTileCacheLayer layer, RcVec3f orig, float cs, float ch, RcVec3f bmin, RcVec3f bmax, int areaId) + public void MarkBoxArea(DtTileCacheLayer layer, Vector3 orig, float cs, float ch, Vector3 bmin, Vector3 bmax, int areaId) { int w = layer.header.width; int h = layer.header.height; @@ -1990,7 +1991,7 @@ namespace DotRecast.Detour.TileCache return layer; } - public void MarkBoxArea(DtTileCacheLayer layer, RcVec3f orig, float cs, float ch, RcVec3f center, RcVec3f extents, + public void MarkBoxArea(DtTileCacheLayer layer, Vector3 orig, float cs, float ch, Vector3 center, Vector3 extents, float[] rotAux, int areaId) { int w = layer.header.width; diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs b/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs index 269de2a..c45347f 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheLayerBuilder.cs @@ -24,6 +24,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Recast; using DotRecast.Recast.Geom; @@ -87,8 +88,8 @@ namespace DotRecast.Detour.TileCache protected virtual RcHeightfieldLayerSet BuildHeightfieldLayerSet(IInputGeomProvider geom, RcConfig cfg, int tx, int ty) { RcBuilder rcBuilder = new RcBuilder(); - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); RcBuilderConfig builderCfg = new RcBuilderConfig(cfg, bmin, bmax, tx, ty); RcHeightfieldLayerSet lset = rcBuilder.BuildLayers(geom, builderCfg); return lset; diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheLayerHeader.cs b/src/DotRecast.Detour.TileCache/DtTileCacheLayerHeader.cs index 52a9d2c..87a1619 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheLayerHeader.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheLayerHeader.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.TileCache { @@ -31,8 +32,8 @@ namespace DotRecast.Detour.TileCache public int version; // < Data version public int tx, ty, tlayer; - public RcVec3f bmin = new RcVec3f(); - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmin = new Vector3(); + public Vector3 bmax = new Vector3(); public int hmin, hmax; // < Height min/max range public int width, height; // < Dimension of the layer. public int minx, maxx, miny, maxy; // < Usable sub-region. diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheObstacle.cs b/src/DotRecast.Detour.TileCache/DtTileCacheObstacle.cs index 3f4d4b5..24109ee 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheObstacle.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheObstacle.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.TileCache { @@ -27,12 +28,12 @@ namespace DotRecast.Detour.TileCache { public readonly int index; public DtTileCacheObstacleType type; - public RcVec3f pos = new RcVec3f(); - public RcVec3f bmin = new RcVec3f(); - public RcVec3f bmax = new RcVec3f(); + public Vector3 pos = new Vector3(); + public Vector3 bmin = new Vector3(); + public Vector3 bmax = new Vector3(); public float radius, height; - public RcVec3f center = new RcVec3f(); - public RcVec3f extents = new RcVec3f(); + public Vector3 center = new Vector3(); + public Vector3 extents = new Vector3(); public readonly float[] rotAux = new float[2]; // { Cos(0.5f*angle)*Sin(-0.5f*angle); Cos(0.5f*angle)*Cos(0.5f*angle) - 0.5 } public List touched = new List(); diff --git a/src/DotRecast.Detour.TileCache/DtTileCacheParams.cs b/src/DotRecast.Detour.TileCache/DtTileCacheParams.cs index 2ac24c9..b5bccee 100644 --- a/src/DotRecast.Detour.TileCache/DtTileCacheParams.cs +++ b/src/DotRecast.Detour.TileCache/DtTileCacheParams.cs @@ -19,12 +19,13 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.TileCache { public struct DtTileCacheParams { - public RcVec3f orig; + public Vector3 orig; public float cs, ch; public int width, height; public float walkableHeight; diff --git a/src/DotRecast.Detour/DtConvexConvexIntersections.cs b/src/DotRecast.Detour/DtConvexConvexIntersections.cs index c718c99..e074221 100644 --- a/src/DotRecast.Detour/DtConvexConvexIntersections.cs +++ b/src/DotRecast.Detour/DtConvexConvexIntersections.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -37,10 +38,10 @@ namespace DotRecast.Detour float[] inters = new float[Math.Max(m, n) * 3 * 3]; int ii = 0; /* Initialize variables. */ - RcVec3f a = new RcVec3f(); - RcVec3f b = new RcVec3f(); - RcVec3f a1 = new RcVec3f(); - RcVec3f b1 = new RcVec3f(); + Vector3 a = new Vector3(); + Vector3 b = new Vector3(); + Vector3 a1 = new Vector3(); + Vector3 b1 = new Vector3(); int aa = 0; int ba = 0; @@ -49,8 +50,8 @@ namespace DotRecast.Detour DtConvexConvexInFlag f = DtConvexConvexInFlag.Unknown; bool firstPoint = true; - RcVec3f ip = new RcVec3f(); - RcVec3f iq = new RcVec3f(); + Vector3 ip = new Vector3(); + Vector3 iq = new Vector3(); do { @@ -59,8 +60,8 @@ namespace DotRecast.Detour a1 = RcVecUtils.Create(p, 3 * ((ai + n - 1) % n)); // prev a b1 = RcVecUtils.Create(q, 3 * ((bi + m - 1) % m)); // prev b - RcVec3f A = RcVec3f.Subtract(a, a1); - RcVec3f B = RcVec3f.Subtract(b, b1); + Vector3 A = Vector3.Subtract(a, a1); + Vector3 B = Vector3.Subtract(b, b1); float cross = B.X * A.Z - A.X * B.Z; // TriArea2D({0, 0}, A, B); float aHB = DtUtils.TriArea2D(b1, b, a); @@ -176,7 +177,7 @@ namespace DotRecast.Detour return copied; } - private static int AddVertex(float[] inters, int ii, RcVec3f p) + private static int AddVertex(float[] inters, int ii, Vector3 p) { if (ii > 0) { @@ -212,7 +213,7 @@ namespace DotRecast.Detour return inflag; } - private static DtConvexConvexIntersection SegSegInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) + private static DtConvexConvexIntersection SegSegInt(Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref Vector3 p, ref Vector3 q) { if (DtUtils.IntersectSegSeg2D(a, b, c, d, out var s, out var t)) { @@ -228,7 +229,7 @@ namespace DotRecast.Detour return DtConvexConvexIntersection.None; } - private static DtConvexConvexIntersection ParallelInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) + private static DtConvexConvexIntersection ParallelInt(Vector3 a, Vector3 b, Vector3 c, Vector3 d, ref Vector3 p, ref Vector3 q) { if (Between(a, b, c) && Between(a, b, d)) { @@ -275,7 +276,7 @@ namespace DotRecast.Detour return DtConvexConvexIntersection.None; } - private static bool Between(RcVec3f a, RcVec3f b, RcVec3f c) + private static bool Between(Vector3 a, Vector3 b, Vector3 c) { if (MathF.Abs(a.X - b.X) > MathF.Abs(a.Z - b.Z)) { diff --git a/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs b/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs index 377d2df..c6ce3b1 100644 --- a/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs +++ b/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour @@ -34,9 +35,9 @@ namespace DotRecast.Detour this.scale = scale; } - public float GetCost(RcVec3f neighbourPos, RcVec3f endPos) + public float GetCost(Vector3 neighbourPos, Vector3 endPos) { - return RcVec3f.Distance(neighbourPos, endPos) * scale; + return Vector3.Distance(neighbourPos, endPos) * scale; } } } \ No newline at end of file diff --git a/src/DotRecast.Detour/DtFindNearestPolyQuery.cs b/src/DotRecast.Detour/DtFindNearestPolyQuery.cs index 3aed2aa..2ff3e81 100644 --- a/src/DotRecast.Detour/DtFindNearestPolyQuery.cs +++ b/src/DotRecast.Detour/DtFindNearestPolyQuery.cs @@ -1,18 +1,19 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { public class DtFindNearestPolyQuery : IDtPolyQuery { private readonly DtNavMeshQuery _query; - private readonly RcVec3f _center; + private readonly Vector3 _center; private long _nearestRef; - private RcVec3f _nearestPt; + private Vector3 _nearestPt; private bool _overPoly; private float _nearestDistanceSqr; - public DtFindNearestPolyQuery(DtNavMeshQuery query, RcVec3f center) + public DtFindNearestPolyQuery(DtNavMeshQuery query, Vector3 center) { this._query = query; this._center = center; @@ -28,7 +29,7 @@ namespace DotRecast.Detour // If a point is directly over a polygon and closer than // climb height, favor that instead of straight line nearest point. float d = 0; - RcVec3f diff = RcVec3f.Subtract(_center, closestPtPoly); + Vector3 diff = Vector3.Subtract(_center, closestPtPoly); if (posOverPoly) { d = MathF.Abs(diff.Y) - tile.data.header.walkableClimb; @@ -53,7 +54,7 @@ namespace DotRecast.Detour return _nearestRef; } - public RcVec3f NearestPt() + public Vector3 NearestPt() { return _nearestPt; } diff --git a/src/DotRecast.Detour/DtMeshHeader.cs b/src/DotRecast.Detour/DtMeshHeader.cs index de3d6a5..27af2e5 100644 --- a/src/DotRecast.Detour/DtMeshHeader.cs +++ b/src/DotRecast.Detour/DtMeshHeader.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -80,10 +81,10 @@ namespace DotRecast.Detour public float walkableClimb; /** The minimum bounds of the tile's AABB. [(x, y, z)] */ - public RcVec3f bmin = new RcVec3f(); + public Vector3 bmin = new Vector3(); /** The maximum bounds of the tile's AABB. [(x, y, z)] */ - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmax = new Vector3(); /** The bounding volume quantization factor. */ public float bvQuantFactor; diff --git a/src/DotRecast.Detour/DtNavMesh.cs b/src/DotRecast.Detour/DtNavMesh.cs index 2f2e494..0f8ebcc 100644 --- a/src/DotRecast.Detour/DtNavMesh.cs +++ b/src/DotRecast.Detour/DtNavMesh.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -69,7 +70,7 @@ namespace DotRecast.Detour private readonly DtNavMeshParams m_params; /// < Current initialization params. TODO: do not store this info twice. - private readonly RcVec3f m_orig; + private readonly Vector3 m_orig; /// < Origin of the tile (0,0) // float m_orig[3]; ///< Origin of the tile (0,0) @@ -257,7 +258,7 @@ namespace DotRecast.Detour * The world position for the query. [(x, y, z)] * @return 2-element int array with (tx,ty) tile location */ - public void CalcTileLoc(RcVec3f pos, out int tx, out int ty) + public void CalcTileLoc(Vector3 pos, out int tx, out int ty) { tx = (int)MathF.Floor((pos.X - m_orig.X) / m_tileWidth); ty = (int)MathF.Floor((pos.Z - m_orig.Z) / m_tileHeight); @@ -348,7 +349,7 @@ namespace DotRecast.Detour // TODO: These methods are duplicates from dtNavMeshQuery, but are needed // for off-mesh connection finding. - List QueryPolygonsInTile(DtMeshTile tile, RcVec3f qmin, RcVec3f qmax) + List QueryPolygonsInTile(DtMeshTile tile, Vector3 qmin, Vector3 qmax) { List polys = new List(); if (tile.data.bvTree != null) @@ -404,8 +405,8 @@ namespace DotRecast.Detour } else { - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); long @base = GetPolyRefBase(tile); for (int i = 0; i < tile.data.header.polyCount; ++i) { @@ -847,7 +848,7 @@ namespace DotRecast.Detour continue; } - var ext = new RcVec3f() + var ext = new Vector3() { X = targetCon.rad, Y = target.data.header.walkableClimb, @@ -912,14 +913,14 @@ namespace DotRecast.Detour cons.Clear(); - RcVec2f amin = RcVec2f.Zero; - RcVec2f amax = RcVec2f.Zero; + Vector2 amin = Vector2.Zero; + Vector2 amax = Vector2.Zero; CalcSlabEndPoints(verts, va, vb, ref amin, ref amax, side); float apos = GetSlabCoord(verts, va, side); // Remove links pointing to 'side' and compact the links array. - RcVec2f bmin = RcVec2f.Zero; - RcVec2f bmax = RcVec2f.Zero; + Vector2 bmin = Vector2.Zero; + Vector2 bmax = Vector2.Zero; int m = DT_EXT_LINK | side; int n = 0; long @base = GetPolyRefBase(tile); @@ -980,7 +981,7 @@ namespace DotRecast.Detour return 0; } - static void CalcSlabEndPoints(float[] verts, int va, int vb, ref RcVec2f bmin, ref RcVec2f bmax, int side) + static void CalcSlabEndPoints(float[] verts, int va, int vb, ref Vector2 bmin, ref Vector2 bmax, int side) { if (side == 0 || side == 4) { @@ -1018,7 +1019,7 @@ namespace DotRecast.Detour } } - bool OverlapSlabs(RcVec2f amin, RcVec2f amax, RcVec2f bmin, RcVec2f bmax, float px, float py) + bool OverlapSlabs(Vector2 amin, Vector2 amax, Vector2 bmin, Vector2 bmax, float px, float py) { // Check for horizontal overlap. // The segment is shrunken a little so that slabs which touch @@ -1078,7 +1079,7 @@ namespace DotRecast.Detour DtOffMeshConnection con = tile.data.offMeshCons[i]; DtPoly poly = tile.data.polys[con.poly]; - var ext = new RcVec3f() + var ext = new Vector3() { X = con.rad, Y = tile.data.header.walkableClimb, @@ -1138,7 +1139,7 @@ namespace DotRecast.Detour * @param pos * @return */ - RcVec3f ClosestPointOnDetailEdges(DtMeshTile tile, DtPoly poly, RcVec3f pos, bool onlyBoundary) + Vector3 ClosestPointOnDetailEdges(DtMeshTile tile, DtPoly poly, Vector3 pos, bool onlyBoundary) { int ANY_BOUNDARY_EDGE = (DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 0) | (DtDetailTriEdgeFlags.DT_DETAIL_EDGE_BOUNDARY << 2) | @@ -1146,8 +1147,8 @@ namespace DotRecast.Detour int ip = poly.index; float dmin = float.MaxValue; float tmin = 0; - RcVec3f pmin = new RcVec3f(); - RcVec3f pmax = new RcVec3f(); + Vector3 pmin = new Vector3(); + Vector3 pmax = new Vector3(); if (tile.data.detailMeshes != null) { @@ -1161,13 +1162,13 @@ namespace DotRecast.Detour continue; } - RcVec3f[] v = new RcVec3f[3]; + Vector3[] v = new Vector3[3]; for (int j = 0; j < 3; ++j) { if (tris[ti + j] < poly.vertCount) { int index = poly.verts[tris[ti + j]] * 3; - v[j] = new RcVec3f + v[j] = new Vector3 { X = tile.data.verts[index], Y = tile.data.verts[index + 1], @@ -1177,7 +1178,7 @@ namespace DotRecast.Detour else { int index = (pd.vertBase + (tris[ti + j] - poly.vertCount)) * 3; - v[j] = new RcVec3f + v[j] = new Vector3 { X = tile.data.detailVerts[index], Y = tile.data.detailVerts[index + 1], @@ -1209,7 +1210,7 @@ namespace DotRecast.Detour } else { - RcVec3f[] v = new RcVec3f[2]; + Vector3[] v = new Vector3[2]; for (int j = 0; j < poly.vertCount; ++j) { int k = (j + 1) % poly.vertCount; @@ -1231,10 +1232,10 @@ namespace DotRecast.Detour } } - return RcVec3f.Lerp(pmin, pmax, tmin); + return Vector3.Lerp(pmin, pmax, tmin); } - public bool GetPolyHeight(DtMeshTile tile, DtPoly poly, RcVec3f pos, out float height) + public bool GetPolyHeight(DtMeshTile tile, DtPoly poly, Vector3 pos, out float height) { height = 0; @@ -1266,13 +1267,13 @@ namespace DotRecast.Detour for (int j = 0; j < pd.triCount; ++j) { int t = (pd.triBase + j) * 4; - RcVec3f[] v = new RcVec3f[3]; + Vector3[] v = new Vector3[3]; for (int k = 0; k < 3; ++k) { if (tile.data.detailTris[t + k] < poly.vertCount) { int index = poly.verts[tile.data.detailTris[t + k]] * 3; - v[k] = new RcVec3f + v[k] = new Vector3 { X = tile.data.verts[index], Y = tile.data.verts[index + 1], @@ -1282,7 +1283,7 @@ namespace DotRecast.Detour else { int index = (pd.vertBase + (tile.data.detailTris[t + k] - poly.vertCount)) * 3; - v[k] = new RcVec3f + v[k] = new Vector3 { X = tile.data.detailVerts[index], Y = tile.data.detailVerts[index + 1], @@ -1300,7 +1301,7 @@ namespace DotRecast.Detour } else { - RcVec3f[] v = new RcVec3f[3]; + Vector3[] v = new Vector3[3]; v[0].X = tile.data.verts[poly.verts[0] * 3]; v[0].Y = tile.data.verts[poly.verts[0] * 3 + 1]; v[0].Z = tile.data.verts[poly.verts[0] * 3 + 2]; @@ -1330,7 +1331,7 @@ namespace DotRecast.Detour return true; } - public void ClosestPointOnPoly(long refs, RcVec3f pos, out RcVec3f closest, out bool posOverPoly) + public void ClosestPointOnPoly(long refs, Vector3 pos, out Vector3 closest, out bool posOverPoly) { GetTileAndPolyByRefUnsafe(refs, out var tile, out var poly); closest = pos; @@ -1348,11 +1349,11 @@ namespace DotRecast.Detour if (poly.GetPolyType() == DtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) { int i = poly.verts[0] * 3; - var v0 = new RcVec3f { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; + var v0 = new Vector3 { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; i = poly.verts[1] * 3; - var v1 = new RcVec3f { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; + var v1 = new Vector3 { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; DtUtils.DistancePtSegSqr2D(pos, v0, v1, out var t); - closest = RcVec3f.Lerp(v0, v1, t); + closest = Vector3.Lerp(v0, v1, t); return; } @@ -1361,13 +1362,13 @@ namespace DotRecast.Detour } /// Find nearest polygon within a tile. - private long FindNearestPolyInTile(DtMeshTile tile, RcVec3f center, RcVec3f halfExtents, out RcVec3f nearestPt) + private long FindNearestPolyInTile(DtMeshTile tile, Vector3 center, Vector3 halfExtents, out Vector3 nearestPt) { - nearestPt = RcVec3f.Zero; + nearestPt = Vector3.Zero; bool overPoly = false; - RcVec3f bmin = RcVec3f.Subtract(center, halfExtents); - RcVec3f bmax = RcVec3f.Add(center, halfExtents); + Vector3 bmin = Vector3.Subtract(center, halfExtents); + Vector3 bmax = Vector3.Add(center, halfExtents); // Get nearby polygons from proximity grid. List polys = QueryPolygonsInTile(tile, bmin, bmax); @@ -1383,7 +1384,7 @@ namespace DotRecast.Detour // If a point is directly over a polygon and closer than // climb height, favor that instead of straight line nearest point. - RcVec3f diff = RcVec3f.Subtract(center, closestPtPoly); + Vector3 diff = Vector3.Subtract(center, closestPtPoly); if (posOverPoly) { d = MathF.Abs(diff.Y) - tile.data.header.walkableClimb; @@ -1532,7 +1533,7 @@ namespace DotRecast.Detour /// inside a normal polygon. So an off-mesh connection is "entered" from a /// normal polygon at one of its endpoints. This is the polygon identified by /// the prevRef parameter. - public DtStatus GetOffMeshConnectionPolyEndPoints(long prevRef, long polyRef, ref RcVec3f startPos, ref RcVec3f endPos) + public DtStatus GetOffMeshConnectionPolyEndPoints(long prevRef, long polyRef, ref Vector3 startPos, ref Vector3 endPos) { if (polyRef == 0) { @@ -1735,9 +1736,9 @@ namespace DotRecast.Detour return DtStatus.DT_SUCCESS; } - public RcVec3f GetPolyCenter(long refs) + public Vector3 GetPolyCenter(long refs) { - RcVec3f center = RcVec3f.Zero; + Vector3 center = Vector3.Zero; var status = GetTileAndPolyByRef(refs, out var tile, out var poly); if (status.Succeeded()) @@ -1785,10 +1786,10 @@ namespace DotRecast.Detour return tiles; } - public void ComputeBounds(out RcVec3f bmin, out RcVec3f bmax) + public void ComputeBounds(out Vector3 bmin, out Vector3 bmax) { - bmin = new RcVec3f(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); - bmax = new RcVec3f(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); + bmin = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); + bmax = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); for (int t = 0; t < GetMaxTiles(); ++t) { DtMeshTile tile = GetTile(t); diff --git a/src/DotRecast.Detour/DtNavMeshBuilder.cs b/src/DotRecast.Detour/DtNavMeshBuilder.cs index 81258db..be4d491 100644 --- a/src/DotRecast.Detour/DtNavMeshBuilder.cs +++ b/src/DotRecast.Detour/DtNavMeshBuilder.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -220,7 +221,7 @@ namespace DotRecast.Detour const int XM = 1 << 2; const int ZM = 1 << 3; - public static int ClassifyOffMeshPoint(RcVec3f pt, RcVec3f bmin, RcVec3f bmax) + public static int ClassifyOffMeshPoint(Vector3 pt, Vector3 bmin, Vector3 bmax) { int outcode = 0; outcode |= (pt.X >= bmax.X) ? XP : 0; @@ -307,8 +308,8 @@ namespace DotRecast.Detour hmin -= option.walkableClimb; hmax += option.walkableClimb; - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); bmin = option.bmin; bmax = option.bmax; bmin.Y = hmin; diff --git a/src/DotRecast.Detour/DtNavMeshCreateParams.cs b/src/DotRecast.Detour/DtNavMeshCreateParams.cs index 741671f..cf44c56 100644 --- a/src/DotRecast.Detour/DtNavMeshCreateParams.cs +++ b/src/DotRecast.Detour/DtNavMeshCreateParams.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -90,8 +91,8 @@ namespace DotRecast.Detour public int tileX; // < The tile's x-grid location within the multi-tile destination mesh. (Along the x-axis.) public int tileZ; // < The tile's y-grid location within the multi-tile destination mesh. (Along the z-axis.) public int tileLayer; // < The tile's layer within the layered destination mesh. [Limit: >= 0] (Along the y-axis.) - public RcVec3f bmin; // < The minimum bounds of the tile. [(x, y, z)] [Unit: wu] - public RcVec3f bmax; // < The maximum bounds of the tile. [(x, y, z)] [Unit: wu] + public Vector3 bmin; // < The minimum bounds of the tile. [(x, y, z)] [Unit: wu] + public Vector3 bmax; // < The maximum bounds of the tile. [(x, y, z)] [Unit: wu] /// @} /// @name General Configuration Attributes diff --git a/src/DotRecast.Detour/DtNavMeshParams.cs b/src/DotRecast.Detour/DtNavMeshParams.cs index 81cf963..d2b5880 100644 --- a/src/DotRecast.Detour/DtNavMeshParams.cs +++ b/src/DotRecast.Detour/DtNavMeshParams.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -31,7 +32,7 @@ namespace DotRecast.Detour public struct DtNavMeshParams { /** The world space origin of the navigation mesh's tile space. [(x, y, z)] */ - public RcVec3f orig; + public Vector3 orig; /** The width of each tile. (Along the x-axis.) */ public float tileWidth; diff --git a/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/DotRecast.Detour/DtNavMeshQuery.cs index e94c92d..b55a316 100644 --- a/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -50,10 +51,10 @@ namespace DotRecast.Detour /// @param[out] randomRef The reference id of the random location. /// @param[out] randomPt The random location. /// @returns The status flags for the query. - public DtStatus FindRandomPoint(IDtQueryFilter filter, IRcRand frand, out long randomRef, out RcVec3f randomPt) + public DtStatus FindRandomPoint(IDtQueryFilter filter, IRcRand frand, out long randomRef, out Vector3 randomPt) { randomRef = 0; - randomPt = RcVec3f.Zero; + randomPt = Vector3.Zero; if (null == filter || null == frand) { @@ -170,8 +171,8 @@ namespace DotRecast.Detour * Function returning a random number [0..1). * @return Random location */ - public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, - IDtQueryFilter filter, IRcRand frand, out long randomRef, out RcVec3f randomPt) + public DtStatus FindRandomPointAroundCircle(long startRef, Vector3 centerPos, float maxRadius, + IDtQueryFilter filter, IRcRand frand, out long randomRef, out Vector3 randomPt) { return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtNoOpDtPolygonByCircleConstraint.Shared, out randomRef, out randomPt); } @@ -191,15 +192,15 @@ namespace DotRecast.Detour * Function returning a random number [0..1). * @return Random location */ - public DtStatus FindRandomPointWithinCircle(long startRef, RcVec3f centerPos, float maxRadius, - IDtQueryFilter filter, IRcRand frand, out long randomRef, out RcVec3f randomPt) + public DtStatus FindRandomPointWithinCircle(long startRef, Vector3 centerPos, float maxRadius, + IDtQueryFilter filter, IRcRand frand, out long randomRef, out Vector3 randomPt) { return FindRandomPointAroundCircle(startRef, centerPos, maxRadius, filter, frand, DtStrictDtPolygonByCircleConstraint.Shared, out randomRef, out randomPt); } - public DtStatus FindRandomPointAroundCircle(long startRef, RcVec3f centerPos, float maxRadius, + public DtStatus FindRandomPointAroundCircle(long startRef, Vector3 centerPos, float maxRadius, IDtQueryFilter filter, IRcRand frand, IDtPolygonByCircleConstraint constraint, - out long randomRef, out RcVec3f randomPt) + out long randomRef, out Vector3 randomPt) { randomRef = startRef; randomPt = centerPos; @@ -339,10 +340,10 @@ namespace DotRecast.Detour // Cost if (neighbourNode.flags == 0) { - neighbourNode.pos = RcVec3f.Lerp(va, vb, 0.5f); + neighbourNode.pos = Vector3.Lerp(va, vb, 0.5f); } - float total = bestNode.total + RcVec3f.Distance(bestNode.pos, neighbourNode.pos); + float total = bestNode.total + Vector3.Distance(bestNode.pos, neighbourNode.pos); // The node is already in open list and the new result is worse, skip. if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total) @@ -377,7 +378,7 @@ namespace DotRecast.Detour float t = frand.Next(); float[] areas = new float[randomPolyVerts.Length / 3]; - RcVec3f pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t); + Vector3 pt = DtUtils.RandomPointInConvexPoly(randomPolyVerts, randomPolyVerts.Length / 3, areas, s, t); ClosestPointOnPoly(randomPolyRef, pt, out var closest, out var _); randomRef = randomPolyRef; @@ -401,7 +402,7 @@ namespace DotRecast.Detour /// @param[out] closest /// @param[out] posOverPoly /// @returns The status flags for the query. - public DtStatus ClosestPointOnPoly(long refs, RcVec3f pos, out RcVec3f closest, out bool posOverPoly) + public DtStatus ClosestPointOnPoly(long refs, Vector3 pos, out Vector3 closest, out bool posOverPoly) { closest = pos; posOverPoly = false; @@ -432,7 +433,7 @@ namespace DotRecast.Detour /// @param[in] pos The position to check. [(x, y, z)] /// @param[out] closest The closest point. [(x, y, z)] /// @returns The status flags for the query. - public DtStatus ClosestPointOnPolyBoundary(long refs, RcVec3f pos, out RcVec3f closest) + public DtStatus ClosestPointOnPolyBoundary(long refs, Vector3 pos, out Vector3 closest) { closest = pos; var status = m_nav.GetTileAndPolyByRef(refs, out var tile, out var poly); @@ -492,7 +493,7 @@ namespace DotRecast.Detour /// @param[in] pos A position within the xz-bounds of the polygon. [(x, y, z)] /// @param[out] height The height at the surface of the polygon. /// @returns The status flags for the query. - public DtStatus GetPolyHeight(long refs, RcVec3f pos, out float height) + public DtStatus GetPolyHeight(long refs, Vector3 pos, out float height) { height = default; @@ -513,9 +514,9 @@ namespace DotRecast.Detour if (poly.GetPolyType() == DtPolyTypes.DT_POLYTYPE_OFFMESH_CONNECTION) { int i = poly.verts[0] * 3; - var v0 = new RcVec3f { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; + var v0 = new Vector3 { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; i = poly.verts[1] * 3; - var v1 = new RcVec3f { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; + var v1 = new Vector3 { X = tile.data.verts[i], Y = tile.data.verts[i + 1], Z = tile.data.verts[i + 2] }; DtUtils.DistancePtSegSqr2D(pos, v0, v1, out var t); height = v0.Y + (v1.Y - v0.Y) * t; @@ -541,8 +542,8 @@ namespace DotRecast.Detour /// @param[out] nearestPt The nearest point on the polygon. Unchanged if no polygon is found. [opt] [(x, y, z)] /// @param[out] isOverPoly Set to true if the point's X/Z coordinate lies inside the polygon, false otherwise. Unchanged if no polygon is found. [opt] /// @returns The status flags for the query. - public DtStatus FindNearestPoly(RcVec3f center, RcVec3f halfExtents, IDtQueryFilter filter, - out long nearestRef, out RcVec3f nearestPt, out bool isOverPoly) + public DtStatus FindNearestPoly(Vector3 center, Vector3 halfExtents, IDtQueryFilter filter, + out long nearestRef, out Vector3 nearestPt, out bool isOverPoly) { nearestRef = 0; nearestPt = center; @@ -564,7 +565,7 @@ namespace DotRecast.Detour } // FIXME: (PP) duplicate? - protected void QueryPolygonsInTile(DtMeshTile tile, RcVec3f qmin, RcVec3f qmax, IDtQueryFilter filter, IDtPolyQuery query) + protected void QueryPolygonsInTile(DtMeshTile tile, Vector3 qmin, Vector3 qmax, IDtQueryFilter filter, IDtPolyQuery query) { if (tile.data.bvTree != null) { @@ -621,8 +622,8 @@ namespace DotRecast.Detour } else { - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); long @base = m_nav.GetPolyRefBase(tile); for (int i = 0; i < tile.data.header.polyCount; ++i) { @@ -671,7 +672,7 @@ namespace DotRecast.Detour * The polygon filter to apply to the query. * @return The reference ids of the polygons that overlap the query box. */ - public DtStatus QueryPolygons(RcVec3f center, RcVec3f halfExtents, IDtQueryFilter filter, IDtPolyQuery query) + public DtStatus QueryPolygons(Vector3 center, Vector3 halfExtents, IDtQueryFilter filter, IDtPolyQuery query) { if (!center.IsFinite() || !halfExtents.IsFinite() || null == filter) { @@ -679,8 +680,8 @@ namespace DotRecast.Detour } // Find tiles the query touches. - RcVec3f bmin = RcVec3f.Subtract(center, halfExtents); - RcVec3f bmax = RcVec3f.Add(center, halfExtents); + Vector3 bmin = Vector3.Subtract(center, halfExtents); + Vector3 bmax = Vector3.Add(center, halfExtents); foreach (var t in QueryTiles(center, halfExtents)) { QueryPolygonsInTile(t, bmin, bmax, filter, query); @@ -692,15 +693,15 @@ namespace DotRecast.Detour /** * Finds tiles that overlap the search box. */ - public IList QueryTiles(RcVec3f center, RcVec3f halfExtents) + public IList QueryTiles(Vector3 center, Vector3 halfExtents) { if (!center.IsFinite() || !halfExtents.IsFinite()) { return RcImmutableArray.Empty; } - RcVec3f bmin = RcVec3f.Subtract(center, halfExtents); - RcVec3f bmax = RcVec3f.Add(center, halfExtents); + Vector3 bmin = Vector3.Subtract(center, halfExtents); + Vector3 bmax = Vector3.Add(center, halfExtents); m_nav.CalcTileLoc(bmin, out var minx, out var miny); m_nav.CalcTileLoc(bmax, out var maxx, out var maxy); @@ -736,7 +737,7 @@ namespace DotRecast.Detour * The polygon filter to apply to the query. * @return Found path */ - public DtStatus FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, ref List path, DtFindPathOption fpo) + public DtStatus FindPath(long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, ref List path, DtFindPathOption fpo) { if (null == path) return DtStatus.DT_FAILURE | DtStatus.DT_INVALID_PARAM; @@ -831,7 +832,7 @@ namespace DotRecast.Detour if ((options & DtFindPathOptions.DT_FINDPATH_ANY_ANGLE) != 0) { if ((parentRef != 0) && - (raycastLimitSqr >= float.MaxValue || RcVec3f.DistanceSquared(parentNode.pos, bestNode.pos) < raycastLimitSqr)) + (raycastLimitSqr >= float.MaxValue || Vector3.DistanceSquared(parentNode.pos, bestNode.pos) < raycastLimitSqr)) { tryLOS = true; } @@ -995,17 +996,17 @@ namespace DotRecast.Detour * query options (see: #FindPathOptions) * @return */ - public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options) + public DtStatus InitSlicedFindPath(long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, int options) { return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DtDefaultQueryHeuristic.Default, -1.0f); } - public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, float raycastLimit) + public DtStatus InitSlicedFindPath(long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, int options, float raycastLimit) { return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DtDefaultQueryHeuristic.Default, raycastLimit); } - public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, IDtQueryHeuristic heuristic, float raycastLimit) + public DtStatus InitSlicedFindPath(long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, int options, IDtQueryHeuristic heuristic, float raycastLimit) { // Init path state. m_query = new DtQueryData(); @@ -1149,7 +1150,7 @@ namespace DotRecast.Detour if ((m_query.options & DtFindPathOptions.DT_FINDPATH_ANY_ANGLE) != 0) { if ((parentRef != 0) && - (m_query.raycastLimitSqr >= float.MaxValue || RcVec3f.DistanceSquared(parentNode.pos, bestNode.pos) < m_query.raycastLimitSqr)) + (m_query.raycastLimitSqr >= float.MaxValue || Vector3.DistanceSquared(parentNode.pos, bestNode.pos) < m_query.raycastLimitSqr)) { tryLOS = true; } @@ -1405,7 +1406,7 @@ namespace DotRecast.Detour return DtStatus.DT_SUCCESS | details; } - protected DtStatus AppendVertex(RcVec3f pos, int flags, long refs, ref List straightPath, + protected DtStatus AppendVertex(Vector3 pos, int flags, long refs, ref List straightPath, int maxStraightPath) { if (straightPath.Count > 0 && DtUtils.VEqual(straightPath[straightPath.Count - 1].pos, pos)) @@ -1431,7 +1432,7 @@ namespace DotRecast.Detour return DtStatus.DT_IN_PROGRESS; } - protected DtStatus AppendPortals(int startIdx, int endIdx, RcVec3f endPos, List path, + protected DtStatus AppendPortals(int startIdx, int endIdx, Vector3 endPos, List path, ref List straightPath, int maxStraightPath, int options) { var startPos = straightPath[straightPath.Count - 1].pos; @@ -1472,7 +1473,7 @@ namespace DotRecast.Detour // Append intersection if (DtUtils.IntersectSegSeg2D(startPos, endPos, left, right, out var _, out var t)) { - var pt = RcVec3f.Lerp(left, right, t); + var pt = Vector3.Lerp(left, right, t); stat = AppendVertex(pt, 0, path[i + 1], ref straightPath, maxStraightPath); if (!stat.InProgress()) { @@ -1510,7 +1511,7 @@ namespace DotRecast.Detour /// @param[in] maxStraightPath The maximum number of points the straight path arrays can hold. [Limit: > 0] /// @param[in] options Query options. (see: #dtStraightPathOptions) /// @returns The status flags for the query. - public virtual DtStatus FindStraightPath(RcVec3f startPos, RcVec3f endPos, List path, + public virtual DtStatus FindStraightPath(Vector3 startPos, Vector3 endPos, List path, ref List straightPath, int maxStraightPath, int options) { @@ -1544,9 +1545,9 @@ namespace DotRecast.Detour if (path.Count > 1) { - RcVec3f portalApex = closestStartPos; - RcVec3f portalLeft = portalApex; - RcVec3f portalRight = portalApex; + Vector3 portalApex = closestStartPos; + Vector3 portalLeft = portalApex; + Vector3 portalRight = portalApex; int apexIndex = 0; int leftIndex = 0; int rightIndex = 0; @@ -1559,8 +1560,8 @@ namespace DotRecast.Detour for (int i = 0; i < path.Count; ++i) { - RcVec3f left; - RcVec3f right; + Vector3 left; + Vector3 right; int toType; if (i + 1 < path.Count) @@ -1769,11 +1770,11 @@ namespace DotRecast.Detour /// @param[out] visitedCount The number of polygons visited during the move. /// @param[in] maxVisitedSize The maximum number of polygons the @p visited array can hold. /// @returns The status flags for the query. - public DtStatus MoveAlongSurface(long startRef, RcVec3f startPos, RcVec3f endPos, + public DtStatus MoveAlongSurface(long startRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, - out RcVec3f resultPos, ref List visited) + out Vector3 resultPos, ref List visited) { - resultPos = RcVec3f.Zero; + resultPos = Vector3.Zero; if (null != visited) visited.Clear(); @@ -1796,14 +1797,14 @@ namespace DotRecast.Detour LinkedList stack = new LinkedList(); stack.AddLast(startNode); - RcVec3f bestPos = new RcVec3f(); + Vector3 bestPos = new Vector3(); float bestDist = float.MaxValue; DtNode bestNode = null; bestPos = startPos; // Search constraints - var searchPos = RcVec3f.Lerp(startPos, endPos, 0.5f); - float searchRadSqr = RcMath.Sqr(RcVec3f.Distance(startPos, endPos) / 2.0f + 0.001f); + var searchPos = Vector3.Lerp(startPos, endPos, 0.5f); + float searchRadSqr = RcMath.Sqr(Vector3.Distance(startPos, endPos) / 2.0f + 0.001f); float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3]; @@ -1945,10 +1946,10 @@ namespace DotRecast.Detour return DtStatus.DT_SUCCESS; } - protected DtStatus GetPortalPoints(long from, long to, out RcVec3f left, out RcVec3f right, out int fromType, out int toType) + protected DtStatus GetPortalPoints(long from, long to, out Vector3 left, out Vector3 right, out int fromType, out int toType) { - left = RcVec3f.Zero; - right = RcVec3f.Zero; + left = Vector3.Zero; + right = Vector3.Zero; fromType = 0; toType = 0; @@ -1974,10 +1975,10 @@ namespace DotRecast.Detour // Returns portal points between two polygons. protected DtStatus GetPortalPoints(long from, DtPoly fromPoly, DtMeshTile fromTile, long to, DtPoly toPoly, DtMeshTile toTile, - out RcVec3f left, out RcVec3f right) + out Vector3 left, out Vector3 right) { - left = RcVec3f.Zero; - right = RcVec3f.Zero; + left = Vector3.Zero; + right = Vector3.Zero; // Find the link that points to the 'to' polygon. DtLink link = null; @@ -2071,7 +2072,7 @@ namespace DotRecast.Detour } protected DtStatus GetEdgeMidPoint(long from, DtPoly fromPoly, DtMeshTile fromTile, long to, - DtPoly toPoly, DtMeshTile toTile, ref RcVec3f mid) + DtPoly toPoly, DtMeshTile toTile, ref Vector3 mid) { var ppStatus = GetPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, out var left, out var right); if (ppStatus.Failed()) @@ -2086,9 +2087,9 @@ namespace DotRecast.Detour return DtStatus.DT_SUCCESS; } - protected DtStatus GetEdgeIntersectionPoint(RcVec3f fromPos, long from, DtPoly fromPoly, DtMeshTile fromTile, - RcVec3f toPos, long to, DtPoly toPoly, DtMeshTile toTile, - ref RcVec3f pt) + protected DtStatus GetEdgeIntersectionPoint(Vector3 fromPos, long from, DtPoly fromPoly, DtMeshTile fromTile, + Vector3 toPos, long to, DtPoly toPoly, DtMeshTile toTile, + ref Vector3 pt) { var ppStatus = GetPortalPoints(from, fromPoly, fromTile, to, toPoly, toTile, out var left, out var right); if (ppStatus.Failed()) @@ -2102,7 +2103,7 @@ namespace DotRecast.Detour t = Math.Clamp(t2, 0.1f, 0.9f); } - pt = RcVec3f.Lerp(left, right, t); + pt = Vector3.Lerp(left, right, t); return DtStatus.DT_SUCCESS; } @@ -2159,7 +2160,7 @@ namespace DotRecast.Detour /// @param[out] pathCount The number of visited polygons. [opt] /// @param[in] maxPath The maximum number of polygons the @p path array can hold. /// @returns The status flags for the query. - public DtStatus Raycast(long startRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, + public DtStatus Raycast(long startRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, int options, long prevRef, out DtRaycastHit hit) { hit = null; @@ -2173,13 +2174,13 @@ namespace DotRecast.Detour hit = new DtRaycastHit(); - RcVec3f[] verts = new RcVec3f[m_nav.GetMaxVertsPerPoly() + 1]; + Vector3[] verts = new Vector3[m_nav.GetMaxVertsPerPoly() + 1]; - RcVec3f curPos = RcVec3f.Zero; - RcVec3f lastPos = RcVec3f.Zero; + Vector3 curPos = Vector3.Zero; + Vector3 lastPos = Vector3.Zero; curPos = startPos; - var dir = RcVec3f.Subtract(endPos, startPos); + var dir = Vector3.Subtract(endPos, startPos); DtMeshTile prevTile, tile, nextTile; DtPoly prevPoly, poly, nextPoly; @@ -2343,8 +2344,8 @@ namespace DotRecast.Detour curPos = RcVecUtils.Mad(startPos, dir, hit.t); var e1 = verts[segMax]; var e2 = verts[(segMax + 1) % nv]; - var eDir = RcVec3f.Subtract(e2, e1); - var diff = RcVec3f.Subtract(curPos, e1); + var eDir = Vector3.Subtract(e2, e1); + var diff = Vector3.Subtract(curPos, e1); float s = RcMath.Sqr(eDir.X) > RcMath.Sqr(eDir.Z) ? diff.X / eDir.X : diff.Z / eDir.Z; curPos.Y = e1.Y + eDir.Y * s; @@ -2363,7 +2364,7 @@ namespace DotRecast.Detour // int vb = b * 3; float dx = verts[b].X - verts[a].X; float dz = verts[b].Z - verts[a].X; - hit.hitNormal = RcVec3f.Normalize(new RcVec3f(dz, 0, -dx)); + hit.hitNormal = Vector3.Normalize(new Vector3(dz, 0, -dx)); return DtStatus.DT_SUCCESS; } @@ -2423,7 +2424,7 @@ namespace DotRecast.Detour /// @param[out] resultCount The number of polygons found. [opt] /// @param[in] maxResult The maximum number of polygons the result arrays can hold. /// @returns The status flags for the query. - public DtStatus FindPolysAroundCircle(long startRef, RcVec3f centerPos, float radius, IDtQueryFilter filter, + public DtStatus FindPolysAroundCircle(long startRef, Vector3 centerPos, float radius, IDtQueryFilter filter, ref List resultRef, ref List resultParent, ref List resultCost) { if (null != resultRef) @@ -2527,7 +2528,7 @@ namespace DotRecast.Detour // Cost if (neighbourNode.flags == 0) { - neighbourNode.pos = RcVec3f.Lerp(va, vb, 0.5f); + neighbourNode.pos = Vector3.Lerp(va, vb, 0.5f); } float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef, @@ -2594,7 +2595,7 @@ namespace DotRecast.Detour /// @param[out] resultCount The number of polygons found. /// @param[in] maxResult The maximum number of polygons the result arrays can hold. /// @returns The status flags for the query. - public DtStatus FindPolysAroundShape(long startRef, RcVec3f[] verts, IDtQueryFilter filter, + public DtStatus FindPolysAroundShape(long startRef, Vector3[] verts, IDtQueryFilter filter, ref List resultRef, ref List resultParent, ref List resultCost) { resultRef.Clear(); @@ -2611,7 +2612,7 @@ namespace DotRecast.Detour m_nodePool.Clear(); m_openList.Clear(); - RcVec3f centerPos = RcVec3f.Zero; + Vector3 centerPos = Vector3.Zero; for (int i = 0; i < nverts; ++i) { centerPos += verts[i]; @@ -2709,7 +2710,7 @@ namespace DotRecast.Detour // Cost if (neighbourNode.flags == 0) { - neighbourNode.pos = RcVec3f.Lerp(va, vb, 0.5f); + neighbourNode.pos = Vector3.Lerp(va, vb, 0.5f); } float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef, @@ -2772,7 +2773,7 @@ namespace DotRecast.Detour /// @param[out] resultRef The reference ids of the polygons touched by the circle. /// @param[out] resultParent The reference ids of the parent polygons for each result. /// @returns The status flags for the query. - public DtStatus FindLocalNeighbourhood(long startRef, RcVec3f centerPos, float radius, + public DtStatus FindLocalNeighbourhood(long startRef, Vector3 centerPos, float radius, IDtQueryFilter filter, ref List resultRef, ref List resultParent) { @@ -3100,13 +3101,13 @@ namespace DotRecast.Detour /// @param[out] hitNormal The normalized ray formed from the wall point to the /// source point. [(x, y, z)] /// @returns The status flags for the query. - public virtual DtStatus FindDistanceToWall(long startRef, RcVec3f centerPos, float maxRadius, + public virtual DtStatus FindDistanceToWall(long startRef, Vector3 centerPos, float maxRadius, IDtQueryFilter filter, - out float hitDist, out RcVec3f hitPos, out RcVec3f hitNormal) + out float hitDist, out Vector3 hitPos, out Vector3 hitNormal) { hitDist = 0; - hitPos = RcVec3f.Zero; - hitNormal = RcVec3f.Zero; + hitPos = Vector3.Zero; + hitNormal = Vector3.Zero; // Validate input if (!m_nav.IsValidPolyRef(startRef) || !centerPos.IsFinite() || maxRadius < 0 @@ -3130,8 +3131,8 @@ namespace DotRecast.Detour float radiusSqr = RcMath.Sqr(maxRadius); var hasBestV = false; - var bestvj = RcVec3f.Zero; - var bestvi = RcVec3f.Zero; + var bestvj = Vector3.Zero; + var bestvi = Vector3.Zero; var status = DtStatus.DT_SUCCESS; while (!m_openList.IsEmpty()) @@ -3270,7 +3271,7 @@ namespace DotRecast.Detour ref neighbourNode.pos); } - float total = bestNode.total + RcVec3f.Distance(bestNode.pos, neighbourNode.pos); + float total = bestNode.total + Vector3.Distance(bestNode.pos, neighbourNode.pos); // The node is already in open list and the new result is worse, skip. if ((neighbourNode.flags & DtNodeFlags.DT_NODE_OPEN) != 0 && total >= neighbourNode.total) @@ -3298,8 +3299,8 @@ namespace DotRecast.Detour // Calc hit normal. if (hasBestV) { - var tangent = RcVec3f.Subtract(bestvi, bestvj); - hitNormal = RcVec3f.Normalize(new RcVec3f(tangent.Z, 0, -tangent.X)); + var tangent = Vector3.Subtract(bestvi, bestvj); + hitNormal = Vector3.Normalize(new Vector3(tangent.Z, 0, -tangent.X)); } hitDist = MathF.Sqrt(radiusSqr); diff --git a/src/DotRecast.Detour/DtNavMeshRaycast.cs b/src/DotRecast.Detour/DtNavMeshRaycast.cs index ac1aaca..6768cf3 100644 --- a/src/DotRecast.Detour/DtNavMeshRaycast.cs +++ b/src/DotRecast.Detour/DtNavMeshRaycast.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -27,7 +28,7 @@ namespace DotRecast.Detour */ public static class DtNavMeshRaycast { - public static bool Raycast(DtNavMesh mesh, RcVec3f src, RcVec3f dst, out float hitTime) + public static bool Raycast(DtNavMesh mesh, Vector3 src, Vector3 dst, out float hitTime) { hitTime = 0.0f; for (int t = 0; t < mesh.GetMaxTiles(); ++t) @@ -45,7 +46,7 @@ namespace DotRecast.Detour return false; } - private static bool Raycast(DtMeshTile tile, RcVec3f sp, RcVec3f sq, out float hitTime) + private static bool Raycast(DtMeshTile tile, Vector3 sp, Vector3 sq, out float hitTime) { hitTime = 0.0f; for (int i = 0; i < tile.data.header.polyCount; ++i) diff --git a/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs b/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs index 01cc576..2521744 100644 --- a/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs +++ b/src/DotRecast.Detour/DtNoOpDtPolygonByCircleConstraint.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -10,7 +11,7 @@ namespace DotRecast.Detour { } - public float[] Apply(float[] polyVerts, RcVec3f circleCenter, float radius) + public float[] Apply(float[] polyVerts, Vector3 circleCenter, float radius) { return polyVerts; } diff --git a/src/DotRecast.Detour/DtNode.cs b/src/DotRecast.Detour/DtNode.cs index ed94100..3af5abd 100644 --- a/src/DotRecast.Detour/DtNode.cs +++ b/src/DotRecast.Detour/DtNode.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -28,7 +29,7 @@ namespace DotRecast.Detour public readonly int index; /** Position of the node. */ - public RcVec3f pos = new RcVec3f(); + public Vector3 pos = new Vector3(); /** Cost of reaching the given node. */ public float cost; diff --git a/src/DotRecast.Detour/DtPathUtils.cs b/src/DotRecast.Detour/DtPathUtils.cs index 8b0845f..2b927f1 100644 --- a/src/DotRecast.Detour/DtPathUtils.cs +++ b/src/DotRecast.Detour/DtPathUtils.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -28,12 +29,12 @@ namespace DotRecast.Detour { private const int MAX_STEER_POINTS = 3; - public static bool GetSteerTarget(DtNavMeshQuery navQuery, RcVec3f startPos, RcVec3f endPos, + public static bool GetSteerTarget(DtNavMeshQuery navQuery, Vector3 startPos, Vector3 endPos, float minTargetDist, List path, - out RcVec3f steerPos, out int steerPosFlag, out long steerPosRef) + out Vector3 steerPos, out int steerPosFlag, out long steerPosRef) { - steerPos = RcVec3f.Zero; + steerPos = Vector3.Zero; steerPosFlag = 0; steerPosRef = 0; @@ -68,7 +69,7 @@ namespace DotRecast.Detour return true; } - public static bool InRange(RcVec3f v1, RcVec3f v2, float r, float h) + public static bool InRange(Vector3 v1, Vector3 v2, float r, float h) { float dx = v2.X - v1.X; float dy = v2.Y - v1.Y; diff --git a/src/DotRecast.Detour/DtPolyPoint.cs b/src/DotRecast.Detour/DtPolyPoint.cs index 0ca78c0..bff4b2b 100644 --- a/src/DotRecast.Detour/DtPolyPoint.cs +++ b/src/DotRecast.Detour/DtPolyPoint.cs @@ -1,13 +1,14 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { public readonly struct DtPolyPoint { public readonly long refs; - public readonly RcVec3f pt; + public readonly Vector3 pt; - public DtPolyPoint(long polyRefs, RcVec3f polyPt) + public DtPolyPoint(long polyRefs, Vector3 polyPt) { refs = polyRefs; pt = polyPt; diff --git a/src/DotRecast.Detour/DtQueryData.cs b/src/DotRecast.Detour/DtQueryData.cs index 6d1e455..a037cc7 100644 --- a/src/DotRecast.Detour/DtQueryData.cs +++ b/src/DotRecast.Detour/DtQueryData.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -29,8 +30,8 @@ namespace DotRecast.Detour public float lastBestNodeCost; public long startRef; public long endRef; - public RcVec3f startPos; - public RcVec3f endPos; + public Vector3 startPos; + public Vector3 endPos; public IDtQueryFilter filter; public int options; public float raycastLimitSqr; diff --git a/src/DotRecast.Detour/DtQueryDefaultFilter.cs b/src/DotRecast.Detour/DtQueryDefaultFilter.cs index 4bbffa2..899b3f4 100644 --- a/src/DotRecast.Detour/DtQueryDefaultFilter.cs +++ b/src/DotRecast.Detour/DtQueryDefaultFilter.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -84,10 +85,10 @@ namespace DotRecast.Detour return (poly.flags & m_includeFlags) != 0 && (poly.flags & m_excludeFlags) == 0; } - public float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, + public float GetCost(Vector3 pa, Vector3 pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, DtPoly curPoly, long nextRef, DtMeshTile nextTile, DtPoly nextPoly) { - return RcVec3f.Distance(pa, pb) * m_areaCost[curPoly.GetArea()]; + return Vector3.Distance(pa, pb) * m_areaCost[curPoly.GetArea()]; } public int GetIncludeFlags() diff --git a/src/DotRecast.Detour/DtQueryEmptyFilter.cs b/src/DotRecast.Detour/DtQueryEmptyFilter.cs index 28a722c..d6ee134 100644 --- a/src/DotRecast.Detour/DtQueryEmptyFilter.cs +++ b/src/DotRecast.Detour/DtQueryEmptyFilter.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -15,7 +16,7 @@ namespace DotRecast.Detour return false; } - public float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, + public float GetCost(Vector3 pa, Vector3 pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, DtPoly curPoly, long nextRef, DtMeshTile nextTile, DtPoly nextPoly) { return 0; diff --git a/src/DotRecast.Detour/DtQueryNoOpFilter.cs b/src/DotRecast.Detour/DtQueryNoOpFilter.cs index f7e0574..2e2130f 100644 --- a/src/DotRecast.Detour/DtQueryNoOpFilter.cs +++ b/src/DotRecast.Detour/DtQueryNoOpFilter.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -15,7 +16,7 @@ namespace DotRecast.Detour return true; } - public float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, + public float GetCost(Vector3 pa, Vector3 pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, DtPoly curPoly, long nextRef, DtMeshTile nextTile, DtPoly nextPoly) { return 0; diff --git a/src/DotRecast.Detour/DtRaycastHit.cs b/src/DotRecast.Detour/DtRaycastHit.cs index cdd6219..1cc6f92 100644 --- a/src/DotRecast.Detour/DtRaycastHit.cs +++ b/src/DotRecast.Detour/DtRaycastHit.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -32,7 +33,7 @@ namespace DotRecast.Detour public float t; /** hitNormal The normal of the nearest wall hit. [(x, y, z)] */ - public RcVec3f hitNormal = new RcVec3f(); + public Vector3 hitNormal = new Vector3(); /** Visited polygons. */ public readonly List path = new List(); diff --git a/src/DotRecast.Detour/DtStraightPath.cs b/src/DotRecast.Detour/DtStraightPath.cs index 2ad3313..4495098 100644 --- a/src/DotRecast.Detour/DtStraightPath.cs +++ b/src/DotRecast.Detour/DtStraightPath.cs @@ -19,17 +19,18 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { //TODO: (PP) Add comments public readonly struct DtStraightPath { - public readonly RcVec3f pos; + public readonly Vector3 pos; public readonly int flags; public readonly long refs; - public DtStraightPath(RcVec3f pos, int flags, long refs) + public DtStraightPath(Vector3 pos, int flags, long refs) { this.pos = pos; this.flags = flags; diff --git a/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs b/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs index bf5266a..078b8c4 100644 --- a/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs +++ b/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -31,7 +32,7 @@ namespace DotRecast.Detour return temp; } - public float[] Apply(float[] verts, RcVec3f center, float radius) + public float[] Apply(float[] verts, Vector3 center, float radius) { float radiusSqr = radius * radius; int outsideVertex = -1; @@ -62,7 +63,7 @@ namespace DotRecast.Detour } - private float[] Circle(RcVec3f center, float radius) + private float[] Circle(Vector3 center, float radius) { float[] circle = new float[12 * 3]; for (int i = 0; i < CIRCLE_SEGMENTS * 3; i += 3) diff --git a/src/DotRecast.Detour/DtUtils.cs b/src/DotRecast.Detour/DtUtils.cs index 894710b..aee5ceb 100644 --- a/src/DotRecast.Detour/DtUtils.cs +++ b/src/DotRecast.Detour/DtUtils.cs @@ -1,6 +1,7 @@ using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -46,14 +47,14 @@ namespace DotRecast.Detour /// /// Basically, this function will return true if the specified points are /// close enough to eachother to be considered colocated. - public static bool VEqual(RcVec3f p0, RcVec3f p1) + public static bool VEqual(Vector3 p0, Vector3 p1) { return VEqual(p0, p1, EQUAL_THRESHOLD); } - public static bool VEqual(RcVec3f p0, RcVec3f p1, float thresholdSqr) + public static bool VEqual(Vector3 p0, Vector3 p1, float thresholdSqr) { - float d = RcVec3f.DistanceSquared(p0, p1); + float d = Vector3.DistanceSquared(p0, p1); return d < thresholdSqr; } @@ -80,7 +81,7 @@ namespace DotRecast.Detour /// @param[in] bmax Maximum bounds of box B. [(x, y, z)] /// @return True if the two AABB's overlap. /// @see dtOverlapQuantBounds - public static bool OverlapBounds(RcVec3f amin, RcVec3f amax, RcVec3f bmin, RcVec3f bmax) + public static bool OverlapBounds(Vector3 amin, Vector3 amax, Vector3 bmin, Vector3 bmax) { bool overlap = true; overlap = (amin.X > bmax.X || amax.X < bmin.X) ? false : overlap; @@ -105,10 +106,10 @@ namespace DotRecast.Detour int va = j * 3; int vb = i * 3; - RcVec3f n = new RcVec3f(polya[vb + 2] - polya[va + 2], 0, -(polya[vb + 0] - polya[va + 0])); + Vector3 n = new Vector3(polya[vb + 2] - polya[va + 2], 0, -(polya[vb + 0] - polya[va + 0])); - RcVec2f aminmax = ProjectPoly(n, polya, npolya); - RcVec2f bminmax = ProjectPoly(n, polyb, npolyb); + Vector2 aminmax = ProjectPoly(n, polya, npolya); + Vector2 bminmax = ProjectPoly(n, polyb, npolyb); if (!OverlapRange(aminmax.X, aminmax.Y, bminmax.X, bminmax.Y, eps)) { // Found separating axis @@ -121,10 +122,10 @@ namespace DotRecast.Detour int va = j * 3; int vb = i * 3; - RcVec3f n = new RcVec3f(polyb[vb + 2] - polyb[va + 2], 0, -(polyb[vb + 0] - polyb[va + 0])); + Vector3 n = new Vector3(polyb[vb + 2] - polyb[va + 2], 0, -(polyb[vb + 0] - polyb[va + 0])); - RcVec2f aminmax = ProjectPoly(n, polya, npolya); - RcVec2f bminmax = ProjectPoly(n, polyb, npolyb); + Vector2 aminmax = ProjectPoly(n, polya, npolya); + Vector2 bminmax = ProjectPoly(n, polyb, npolyb); if (!OverlapRange(aminmax.X, aminmax.Y, bminmax.X, bminmax.Y, eps)) { // Found separating axis @@ -154,7 +155,7 @@ namespace DotRecast.Detour return acx * abz - abx * acz; } - public static float TriArea2D(RcVec3f a, RcVec3f b, RcVec3f c) + public static float TriArea2D(Vector3 a, Vector3 b, Vector3 c) { float abx = b.X - a.X; float abz = b.Z - a.Z; @@ -165,7 +166,7 @@ namespace DotRecast.Detour // Returns a random point in a convex polygon. // Adapted from Graphics Gems article. - public static RcVec3f RandomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) + public static Vector3 RandomPointInConvexPoly(float[] pts, int npts, float[] areas, float s, float t) { // Calc triangle araes float areasum = 0.0f; @@ -202,7 +203,7 @@ namespace DotRecast.Detour int pb = (tri - 1) * 3; int pc = tri * 3; - return new RcVec3f() + return new Vector3() { X = a * pts[pa] + b * pts[pb] + c * pts[pc], Y = a * pts[pa + 1] + b * pts[pb + 1] + c * pts[pc + 1], @@ -210,14 +211,14 @@ namespace DotRecast.Detour }; } - public static bool ClosestHeightPointTriangle(RcVec3f p, RcVec3f a, RcVec3f b, RcVec3f c, out float h) + public static bool ClosestHeightPointTriangle(Vector3 p, Vector3 a, Vector3 b, Vector3 c, out float h) { const float EPS = 1e-6f; h = 0; - RcVec3f v0 = RcVec3f.Subtract(c, a); - RcVec3f v1 = RcVec3f.Subtract(b, a); - RcVec3f v2 = RcVec3f.Subtract(p, a); + Vector3 v0 = Vector3.Subtract(c, a); + Vector3 v1 = Vector3.Subtract(b, a); + Vector3 v2 = Vector3.Subtract(p, a); // Compute scaled barycentric coordinates float denom = v0.X * v1.Z - v0.Z * v1.X; @@ -246,7 +247,7 @@ namespace DotRecast.Detour return false; } - public static RcVec2f ProjectPoly(RcVec3f axis, float[] poly, int npoly) + public static Vector2 ProjectPoly(Vector3 axis, float[] poly, int npoly) { float rmin, rmax; rmin = rmax = axis.Dot2D(poly, 0); @@ -257,7 +258,7 @@ namespace DotRecast.Detour rmax = Math.Max(rmax, d); } - return new RcVec2f + return new Vector2 { X = rmin, Y = rmax, @@ -267,7 +268,7 @@ namespace DotRecast.Detour /// @par /// /// All points are projected onto the xz-plane, so the y-values are ignored. - public static bool PointInPolygon(RcVec3f pt, float[] verts, int nverts) + public static bool PointInPolygon(Vector3 pt, float[] verts, int nverts) { // TODO: Replace pnpoly with triArea2D tests? int i, j; @@ -286,7 +287,7 @@ namespace DotRecast.Detour return c; } - public static bool DistancePtPolyEdgesSqr(RcVec3f pt, float[] verts, int nverts, float[] ed, float[] et) + public static bool DistancePtPolyEdgesSqr(Vector3 pt, float[] verts, int nverts, float[] ed, float[] et) { // TODO: Replace pnpoly with triArea2D tests? int i, j; @@ -307,14 +308,14 @@ namespace DotRecast.Detour return c; } - public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t) + public static float DistancePtSegSqr2D(Vector3 pt, float[] verts, int p, int q, out float t) { var vp = RcVecUtils.Create(verts, p); var vq = RcVecUtils.Create(verts, q); return DistancePtSegSqr2D(pt, vp, vq, out t); } - public static float DistancePtSegSqr2D(RcVec3f pt, RcVec3f p, RcVec3f q, out float t) + public static float DistancePtSegSqr2D(Vector3 pt, Vector3 p, Vector3 q, out float t) { float pqx = q.X - p.X; float pqz = q.Z - p.Z; @@ -341,8 +342,8 @@ namespace DotRecast.Detour return dx * dx + dz * dz; } - public static bool IntersectSegmentPoly2D(RcVec3f p0, RcVec3f p1, - RcVec3f[] verts, int nverts, + public static bool IntersectSegmentPoly2D(Vector3 p0, Vector3 p1, + Vector3[] verts, int nverts, out float tmin, out float tmax, out int segMin, out int segMax) { @@ -353,15 +354,15 @@ namespace DotRecast.Detour segMin = -1; segMax = -1; - var dir = RcVec3f.Subtract(p1, p0); + var dir = Vector3.Subtract(p1, p0); var p0v = p0; for (int i = 0, j = nverts - 1; i < nverts; j = i++) { - RcVec3f vpj = verts[j]; - RcVec3f vpi = verts[i]; - var edge = RcVec3f.Subtract(vpi, vpj); - var diff = RcVec3f.Subtract(p0v, vpj); + Vector3 vpj = verts[j]; + Vector3 vpi = verts[i]; + var edge = Vector3.Subtract(vpi, vpj); + var diff = Vector3.Subtract(p0v, vpj); float n = RcVecUtils.Perp2D(edge, diff); float d = RcVecUtils.Perp2D(dir, edge); if (MathF.Abs(d) < EPS) @@ -417,14 +418,14 @@ namespace DotRecast.Detour } - public static bool IntersectSegSeg2D(RcVec3f ap, RcVec3f aq, RcVec3f bp, RcVec3f bq, out float s, out float t) + public static bool IntersectSegSeg2D(Vector3 ap, Vector3 aq, Vector3 bp, Vector3 bq, out float s, out float t) { s = 0; t = 0; - RcVec3f u = RcVec3f.Subtract(aq, ap); - RcVec3f v = RcVec3f.Subtract(bq, bp); - RcVec3f w = RcVec3f.Subtract(ap, bp); + Vector3 u = Vector3.Subtract(aq, ap); + Vector3 v = Vector3.Subtract(bq, bp); + Vector3 w = Vector3.Subtract(ap, bp); float d = RcVecUtils.PerpXZ(u, v); if (MathF.Abs(d) < 1e-6f) { diff --git a/src/DotRecast.Detour/IDtPolygonByCircleConstraint.cs b/src/DotRecast.Detour/IDtPolygonByCircleConstraint.cs index e0927a4..e1f63f2 100644 --- a/src/DotRecast.Detour/IDtPolygonByCircleConstraint.cs +++ b/src/DotRecast.Detour/IDtPolygonByCircleConstraint.cs @@ -19,11 +19,12 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { public interface IDtPolygonByCircleConstraint { - float[] Apply(float[] polyVerts, RcVec3f circleCenter, float radius); + float[] Apply(float[] polyVerts, Vector3 circleCenter, float radius); } } \ No newline at end of file diff --git a/src/DotRecast.Detour/IDtQueryFilter.cs b/src/DotRecast.Detour/IDtQueryFilter.cs index a51213d..8b50098 100644 --- a/src/DotRecast.Detour/IDtQueryFilter.cs +++ b/src/DotRecast.Detour/IDtQueryFilter.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { @@ -26,7 +27,7 @@ namespace DotRecast.Detour { bool PassFilter(long refs, DtMeshTile tile, DtPoly poly); - float GetCost(RcVec3f pa, RcVec3f pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, + float GetCost(Vector3 pa, Vector3 pb, long prevRef, DtMeshTile prevTile, DtPoly prevPoly, long curRef, DtMeshTile curTile, DtPoly curPoly, long nextRef, DtMeshTile nextTile, DtPoly nextPoly); } } \ No newline at end of file diff --git a/src/DotRecast.Detour/IDtQueryHeuristic.cs b/src/DotRecast.Detour/IDtQueryHeuristic.cs index aa71931..7ae1752 100644 --- a/src/DotRecast.Detour/IDtQueryHeuristic.cs +++ b/src/DotRecast.Detour/IDtQueryHeuristic.cs @@ -18,11 +18,12 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour { public interface IDtQueryHeuristic { - float GetCost(RcVec3f neighbourPos, RcVec3f endPos); + float GetCost(Vector3 neighbourPos, Vector3 endPos); } } \ No newline at end of file diff --git a/src/DotRecast.Detour/Io/DtMeshSetWriter.cs b/src/DotRecast.Detour/Io/DtMeshSetWriter.cs index 4568813..62e125c 100644 --- a/src/DotRecast.Detour/Io/DtMeshSetWriter.cs +++ b/src/DotRecast.Detour/Io/DtMeshSetWriter.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Io { diff --git a/src/DotRecast.Detour/Io/DtNavMeshParamWriter.cs b/src/DotRecast.Detour/Io/DtNavMeshParamWriter.cs index 9aab820..381a4f8 100644 --- a/src/DotRecast.Detour/Io/DtNavMeshParamWriter.cs +++ b/src/DotRecast.Detour/Io/DtNavMeshParamWriter.cs @@ -1,6 +1,7 @@ using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Detour.Io { diff --git a/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs index 875f17b..2158e18 100644 --- a/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/DebugDraw.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using Silk.NET.OpenGL; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Toolset.Builder; namespace DotRecast.Recast.Demo.Draw; @@ -92,7 +93,7 @@ public class DebugDraw GetOpenGlDraw().Vertex(pos, color); } - public void Vertex(RcVec3f pos, int color) + public void Vertex(Vector3 pos, int color) { GetOpenGlDraw().Vertex(pos, color); } @@ -102,7 +103,7 @@ public class DebugDraw GetOpenGlDraw().Vertex(x, y, z, color); } - public void Vertex(RcVec3f pos, int color, RcVec2f uv) + public void Vertex(Vector3 pos, int color, Vector2 uv) { GetOpenGlDraw().Vertex(pos, color, uv); } @@ -336,12 +337,12 @@ public class DebugDraw float dy = y1 - y0; float dz = z1 - z0; float len = MathF.Sqrt(dx * dx + dy * dy + dz * dz); - RcVec3f prev = new RcVec3f(); + Vector3 prev = new Vector3(); EvalArc(x0, y0, z0, dx, dy, dz, len * h, PAD, ref prev); for (int i = 1; i <= NUM_ARC_PTS; ++i) { float u = PAD + i * ARC_PTS_SCALE; - RcVec3f pt = new RcVec3f(); + Vector3 pt = new Vector3(); EvalArc(x0, y0, z0, dx, dy, dz, len * h, u, ref pt); Vertex(prev.X, prev.Y, prev.Z, col); Vertex(pt.X, pt.Y, pt.Z, col); @@ -353,8 +354,8 @@ public class DebugDraw // End arrows if (as0 > 0.001f) { - RcVec3f p = new RcVec3f(); - RcVec3f q = new RcVec3f(); + Vector3 p = new Vector3(); + Vector3 q = new Vector3(); EvalArc(x0, y0, z0, dx, dy, dz, len * h, PAD, ref p); EvalArc(x0, y0, z0, dx, dy, dz, len * h, PAD + 0.05f, ref q); AppendArrowHead(p, q, as0, col); @@ -362,15 +363,15 @@ public class DebugDraw if (as1 > 0.001f) { - RcVec3f p = new RcVec3f(); - RcVec3f q = new RcVec3f(); + Vector3 p = new Vector3(); + Vector3 q = new Vector3(); EvalArc(x0, y0, z0, dx, dy, dz, len * h, 1 - PAD, ref p); EvalArc(x0, y0, z0, dx, dy, dz, len * h, 1 - (PAD + 0.05f), ref q); AppendArrowHead(p, q, as1, col); } } - private void EvalArc(float x0, float y0, float z0, float dx, float dy, float dz, float h, float u, ref RcVec3f res) + private void EvalArc(float x0, float y0, float z0, float dx, float dy, float dz, float h, float u, ref Vector3 res) { res.X = x0 + dx * u; res.Y = y0 + dy * u + h * (1 - (u * 2 - 1) * (u * 2 - 1)); @@ -461,15 +462,15 @@ public class DebugDraw Vertex(x1, y1, z1, col); // End arrows - RcVec3f p = new RcVec3f(x0, y0, z0); - RcVec3f q = new RcVec3f(x1, y1, z1); + Vector3 p = new Vector3(x0, y0, z0); + Vector3 q = new Vector3(x1, y1, z1); if (as0 > 0.001f) AppendArrowHead(p, q, as0, col); if (as1 > 0.001f) AppendArrowHead(q, p, as1, col); } - void AppendArrowHead(RcVec3f p, RcVec3f q, float s, int col) + void AppendArrowHead(Vector3 p, Vector3 q, float s, int col) { const float eps = 0.001f; if (VdistSqr(p, q) < eps * eps) @@ -477,9 +478,9 @@ public class DebugDraw return; } - RcVec3f ax = new RcVec3f(); - RcVec3f ay = new RcVec3f(0, 1, 0); - RcVec3f az = new RcVec3f(); + Vector3 ax = new Vector3(); + Vector3 ay = new Vector3(0, 1, 0); + Vector3 az = new Vector3(); Vsub(ref az, q, p); Vnormalize(ref az); Vcross(ref ax, ay, az); @@ -495,14 +496,14 @@ public class DebugDraw Vertex(p.X + az.X * s - ax.X * s / 3, p.Y + az.Y * s - ax.Y * s / 3, p.Z + az.Z * s - ax.Z * s / 3, col); } - public void Vcross(ref RcVec3f dest, RcVec3f v1, RcVec3f v2) + public void Vcross(ref Vector3 dest, Vector3 v1, Vector3 v2) { dest.X = v1.Y * v2.Z - v1.Z * v2.Y; dest.Y = v1.Z * v2.X - v1.X * v2.Z; dest.Z = v1.X * v2.Y - v1.Y * v2.X; } - public void Vnormalize(ref RcVec3f v) + public void Vnormalize(ref Vector3 v) { float d = (float)(1.0f / Math.Sqrt(v.X * v.X + v.Y * v.Y + v.Z * v.Z)); v.X *= d; @@ -510,14 +511,14 @@ public class DebugDraw v.Z *= d; } - public void Vsub(ref RcVec3f dest, RcVec3f v1, RcVec3f v2) + public void Vsub(ref Vector3 dest, Vector3 v1, Vector3 v2) { dest.X = v1.X - v2.X; dest.Y = v1.Y - v2.Y; dest.Z = v1.Z - v2.Z; } - public float VdistSqr(RcVec3f v1, RcVec3f v2) + public float VdistSqr(Vector3 v1, Vector3 v2) { float x = v1.X - v2.X; float y = v1.Y - v2.Y; @@ -637,7 +638,7 @@ public class DebugDraw return _projectionMatrix; } - public RcMatrix4x4f ViewMatrix(RcVec3f cameraPos, RcVec2f cameraEulers) + public RcMatrix4x4f ViewMatrix(Vector3 cameraPos, Vector2 cameraEulers) { var rx = RcMatrix4x4f.CreateFromRotate(cameraEulers.X, 1, 0, 0); var ry = RcMatrix4x4f.CreateFromRotate(cameraEulers.Y, 0, 1, 0); @@ -746,7 +747,7 @@ public class DebugDraw return true; } - public bool FrustumTest(RcVec3f bmin, RcVec3f bmax) + public bool FrustumTest(Vector3 bmin, Vector3 bmax) { return FrustumTest(new float[] { bmin.X, bmin.Y, bmin.Z, bmax.X, bmax.Y, bmax.Z }); } diff --git a/src/DotRecast.Recast.Demo/Draw/GLU.cs b/src/DotRecast.Recast.Demo/Draw/GLU.cs index f14aa22..52d41bf 100644 --- a/src/DotRecast.Recast.Demo/Draw/GLU.cs +++ b/src/DotRecast.Recast.Demo/Draw/GLU.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Demo.Draw; @@ -65,7 +66,7 @@ public static class GLU matrix.M44 = 0.0f; } - public static int GlhUnProjectf(float winx, float winy, float winz, float[] modelview, float[] projection, int[] viewport, ref RcVec3f objectCoordinate) + public static int GlhUnProjectf(float winx, float winy, float winz, float[] modelview, float[] projection, int[] viewport, ref Vector3 objectCoordinate) { // Transformation matrices float[] m = new float[16], A = new float[16]; diff --git a/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs b/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs index 0558c41..50741e6 100644 --- a/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/IOpenGLDraw.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Demo.Draw; @@ -15,9 +16,9 @@ public interface IOpenGLDraw void Vertex(float x, float y, float z, int color); void Vertex(float[] pos, int color); - void Vertex(RcVec3f pos, int color); + void Vertex(Vector3 pos, int color); - void Vertex(RcVec3f pos, int color, RcVec2f uv); + void Vertex(Vector3 pos, int color, Vector2 uv); void Vertex(float x, float y, float z, int color, float u, float v); diff --git a/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs b/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs index 8ca2ed6..33923ab 100644 --- a/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/ModernOpenGLDraw.cs @@ -2,6 +2,7 @@ using System; using System.IO; using Silk.NET.OpenGL; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Demo.Draw; @@ -285,13 +286,13 @@ public class ModernOpenGLDraw : IOpenGLDraw vertices.Add(new OpenGLVertex(pos, color)); } - public void Vertex(RcVec3f pos, int color) + public void Vertex(Vector3 pos, int color) { vertices.Add(new OpenGLVertex(pos, color)); } - public void Vertex(RcVec3f pos, int color, RcVec2f uv) + public void Vertex(Vector3 pos, int color, Vector2 uv) { vertices.Add(new OpenGLVertex(pos, uv, color)); } diff --git a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs index 352d7bf..d09127d 100644 --- a/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs +++ b/src/DotRecast.Recast.Demo/Draw/NavMeshRenderer.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Recast.Toolset.Builder; using DotRecast.Recast.Toolset.Geom; @@ -80,8 +81,8 @@ public class NavMeshRenderer if (geom != null) { int gw = 0, gh = 0; - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); CalcGridSize(bmin, bmax, settings.cellSize, out gw, out gh); int tw = (gw + settings.tileSize - 1) / settings.tileSize; int th = (gh + settings.tileSize - 1) / settings.tileSize; @@ -210,8 +211,8 @@ public class NavMeshRenderer private void DrawGeomBounds(DemoInputGeomProvider geom) { // Draw bounds - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); _debugDraw.DebugDrawBoxWire(bmin.X, bmin.Y, bmin.Z, bmax.X, bmax.Y, bmax.Z, DebugDraw.DuRGBA(255, 255, 255, 128), 1.0f); _debugDraw.Begin(DebugDrawPrimitives.POINTS, 5.0f); @@ -260,8 +261,8 @@ public class NavMeshRenderer int col = DebugDraw.DuTransCol(DebugDraw.AreaToCol(vol.areaMod.GetMaskedValue()), 32); for (int j = 0, k = vol.verts.Length - 3; j < vol.verts.Length; k = j, j += 3) { - var va = new RcVec3f(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); - var vb = new RcVec3f(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); + var va = new Vector3(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); + var vb = new Vector3(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); _debugDraw.Vertex(vol.verts[0], vol.hmax, vol.verts[2], col); _debugDraw.Vertex(vb.X, vol.hmax, vb.Z, col); @@ -285,8 +286,8 @@ public class NavMeshRenderer int col = DebugDraw.DuTransCol(DebugDraw.AreaToCol(vol.areaMod.GetMaskedValue()), 220); for (int j = 0, k = vol.verts.Length - 3; j < vol.verts.Length; k = j, j += 3) { - var va = new RcVec3f(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); - var vb = new RcVec3f(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); + var va = new Vector3(vol.verts[k], vol.verts[k + 1], vol.verts[k + 2]); + var vb = new Vector3(vol.verts[j], vol.verts[j + 1], vol.verts[j + 2]); _debugDraw.Vertex(va.X, vol.hmin, va.Z, DebugDraw.DuDarkenCol(col)); _debugDraw.Vertex(vb.X, vol.hmin, vb.Z, DebugDraw.DuDarkenCol(col)); _debugDraw.Vertex(va.X, vol.hmax, va.Z, col); diff --git a/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs b/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs index 465d2e2..4715825 100644 --- a/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs +++ b/src/DotRecast.Recast.Demo/Draw/OpenGLVertex.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Runtime.InteropServices; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Demo.Draw; @@ -26,7 +27,7 @@ public struct OpenGLVertex [FieldOffset(20)] private readonly int color; - public OpenGLVertex(RcVec3f pos, RcVec2f uv, int color) : + public OpenGLVertex(Vector3 pos, Vector2 uv, int color) : this(pos.X, pos.Y, pos.Z, uv.X, uv.Y, color) { } @@ -36,7 +37,7 @@ public struct OpenGLVertex { } - public OpenGLVertex(RcVec3f pos, int color) : + public OpenGLVertex(Vector3 pos, int color) : this(pos.X, pos.Y, pos.Z, 0f, 0f, color) { } diff --git a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs index db61456..0650b7f 100644 --- a/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs +++ b/src/DotRecast.Recast.Demo/Draw/RecastDebugDraw.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Recast.Toolset.Builder; using Silk.NET.OpenGL; @@ -41,9 +42,9 @@ public class RecastDebugDraw : DebugDraw { float walkableThr = MathF.Cos(walkableSlopeAngle / 180.0f * MathF.PI); - RcVec2f uva = RcVec2f.Zero; - RcVec2f uvb = RcVec2f.Zero; - RcVec2f uvc = RcVec2f.Zero; + Vector2 uva = Vector2.Zero; + Vector2 uvb = Vector2.Zero; + Vector2 uvc = Vector2.Zero; Texture(true); @@ -51,7 +52,7 @@ public class RecastDebugDraw : DebugDraw Begin(DebugDrawPrimitives.TRIS); for (int i = 0; i < tris.Length; i += 3) { - RcVec3f norm = new RcVec3f(normals[i], normals[i + 1], normals[i + 2]); + Vector3 norm = new Vector3(normals[i], normals[i + 1], normals[i + 2]); int color; char a = (char)(220 * (2 + norm.X + norm.Y) / 4); @@ -64,9 +65,9 @@ public class RecastDebugDraw : DebugDraw color = DuRGBA(a, a, a, 255); } - RcVec3f va = new RcVec3f(verts[tris[i] * 3], verts[tris[i] * 3 + 1], verts[tris[i] * 3 + 2]); - RcVec3f vb = new RcVec3f(verts[tris[i + 1] * 3], verts[tris[i + 1] * 3 + 1], verts[tris[i + 1] * 3 + 2]); - RcVec3f vc = new RcVec3f(verts[tris[i + 2] * 3], verts[tris[i + 2] * 3 + 1], verts[tris[i + 2] * 3 + 2]); + Vector3 va = new Vector3(verts[tris[i] * 3], verts[tris[i] * 3 + 1], verts[tris[i] * 3 + 2]); + Vector3 vb = new Vector3(verts[tris[i + 1] * 3], verts[tris[i + 1] * 3 + 1], verts[tris[i + 1] * 3 + 2]); + Vector3 vc = new Vector3(verts[tris[i + 2] * 3], verts[tris[i + 2] * 3 + 1], verts[tris[i + 2] * 3 + 2]); int ax = 0, ay = 0; if (MathF.Abs(norm.Y) > MathF.Abs(norm.Get(ax))) @@ -186,11 +187,11 @@ public class RecastDebugDraw : DebugDraw } DtOffMeshConnection con = tile.data.offMeshCons[i - tile.data.header.offMeshBase]; - RcVec3f va = new RcVec3f( + Vector3 va = new Vector3( tile.data.verts[p.verts[0] * 3], tile.data.verts[p.verts[0] * 3 + 1], tile.data.verts[p.verts[0] * 3 + 2] ); - RcVec3f vb = new RcVec3f( + Vector3 vb = new Vector3( tile.data.verts[p.verts[1] * 3], tile.data.verts[p.verts[1] * 3 + 1], tile.data.verts[p.verts[1] * 3 + 2] ); @@ -352,11 +353,11 @@ public class RecastDebugDraw : DebugDraw } } - var v0 = new RcVec3f( + var v0 = new Vector3( tile.data.verts[p.verts[j] * 3], tile.data.verts[p.verts[j] * 3 + 1], tile.data.verts[p.verts[j] * 3 + 2] ); - var v1 = new RcVec3f( + var v1 = new Vector3( tile.data.verts[p.verts[(j + 1) % nj] * 3], tile.data.verts[p.verts[(j + 1) % nj] * 3 + 1], tile.data.verts[p.verts[(j + 1) % nj] * 3 + 2] @@ -370,20 +371,20 @@ public class RecastDebugDraw : DebugDraw for (int k = 0; k < pd.triCount; ++k) { int t = (pd.triBase + k) * 4; - RcVec3f[] tv = new RcVec3f[3]; + Vector3[] tv = new Vector3[3]; for (int m = 0; m < 3; ++m) { int v = tile.data.detailTris[t + m]; if (v < p.vertCount) { - tv[m] = new RcVec3f( + tv[m] = new Vector3( tile.data.verts[p.verts[v] * 3], tile.data.verts[p.verts[v] * 3 + 1], tile.data.verts[p.verts[v] * 3 + 2] ); } else { - tv[m] = new RcVec3f( + tv[m] = new Vector3( tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3], tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3 + 1], tile.data.detailVerts[(pd.vertBase + (v - p.vertCount)) * 3 + 2] @@ -420,7 +421,7 @@ public class RecastDebugDraw : DebugDraw End(); } - static float DistancePtLine2d(RcVec3f pt, RcVec3f p, RcVec3f q) + static float DistancePtLine2d(Vector3 pt, Vector3 p, Vector3 q) { float pqx = q.X - p.X; float pqz = q.Z - p.Z; @@ -522,7 +523,7 @@ public class RecastDebugDraw : DebugDraw { float alpha = 1f; - RcVec3f orig = cset.bmin; + Vector3 orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; @@ -533,7 +534,7 @@ public class RecastDebugDraw : DebugDraw for (int i = 0; i < cset.conts.Count; ++i) { RcContour cont = cset.conts[i]; - RcVec3f pos = GetContourCenter(cont, orig, cs, ch); + Vector3 pos = GetContourCenter(cont, orig, cs, ch); for (int j = 0; j < cont.nverts; ++j) { int v = j * 4; @@ -545,7 +546,7 @@ public class RecastDebugDraw : DebugDraw RcContour cont2 = FindContourFromSet(cset, (short)cont.verts[v + 3]); if (cont2 != null) { - RcVec3f pos2 = GetContourCenter(cont2, orig, cs, ch); + Vector3 pos2 = GetContourCenter(cont2, orig, cs, ch); AppendArc(pos.X, pos.Y, pos.Z, pos2.X, pos2.Y, pos2.Z, 0.25f, 0.6f, 0.6f, color); } } @@ -561,16 +562,16 @@ public class RecastDebugDraw : DebugDraw { RcContour cont = cset.conts[i]; int col = DuDarkenCol(DuIntToCol(cont.reg, a)); - RcVec3f pos = GetContourCenter(cont, orig, cs, ch); + Vector3 pos = GetContourCenter(cont, orig, cs, ch); Vertex(pos, col); } End(); } - private RcVec3f GetContourCenter(RcContour cont, RcVec3f orig, float cs, float ch) + private Vector3 GetContourCenter(RcContour cont, Vector3 orig, float cs, float ch) { - RcVec3f center = new RcVec3f(); + Vector3 center = new Vector3(); center.X = 0; center.Y = 0; center.Z = 0; @@ -612,7 +613,7 @@ public class RecastDebugDraw : DebugDraw public void DebugDrawRawContours(RcContourSet cset, float alpha) { - RcVec3f orig = cset.bmin; + Vector3 orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; @@ -688,7 +689,7 @@ public class RecastDebugDraw : DebugDraw public void DebugDrawContours(RcContourSet cset) { float alpha = 1f; - RcVec3f orig = cset.bmin; + Vector3 orig = cset.bmin; float cs = cset.cs; float ch = cset.ch; @@ -770,7 +771,7 @@ public class RecastDebugDraw : DebugDraw return; } - RcVec3f orig = hf.bmin; + Vector3 orig = hf.bmin; float cs = hf.cs; float ch = hf.ch; @@ -802,7 +803,7 @@ public class RecastDebugDraw : DebugDraw public void DebugDrawHeightfieldWalkable(RcHeightfield hf) { - RcVec3f orig = hf.bmin; + Vector3 orig = hf.bmin; float cs = hf.cs; float ch = hf.ch; @@ -935,7 +936,7 @@ public class RecastDebugDraw : DebugDraw int nvp = mesh.nvp; float cs = mesh.cs; float ch = mesh.ch; - RcVec3f orig = mesh.bmin; + Vector3 orig = mesh.bmin; Begin(DebugDrawPrimitives.TRIS); @@ -1348,11 +1349,11 @@ public class RecastDebugDraw : DebugDraw continue; // Create new links - var va = new RcVec3f( + var va = new Vector3( tile.data.verts[poly.verts[j] * 3], tile.data.verts[poly.verts[j] * 3 + 1], tile.data.verts[poly.verts[j] * 3 + 2] ); - var vb = new RcVec3f( + var vb = new Vector3( tile.data.verts[poly.verts[(j + 1) % nv] * 3], tile.data.verts[poly.verts[(j + 1) % nv] * 3 + 1], tile.data.verts[poly.verts[(j + 1) % nv] * 3 + 2] diff --git a/src/DotRecast.Recast.Demo/Messages/RaycastEvent.cs b/src/DotRecast.Recast.Demo/Messages/RaycastEvent.cs index da45ce3..6d953ec 100644 --- a/src/DotRecast.Recast.Demo/Messages/RaycastEvent.cs +++ b/src/DotRecast.Recast.Demo/Messages/RaycastEvent.cs @@ -1,9 +1,10 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Demo.Messages; public class RaycastEvent : IRecastDemoMessage { - public RcVec3f Start { get; init; } - public RcVec3f End { get; init; } + public Vector3 Start { get; init; } + public Vector3 End { get; init; } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/RecastDemo.cs b/src/DotRecast.Recast.Demo/RecastDemo.cs index c551aeb..c22bb0a 100644 --- a/src/DotRecast.Recast.Demo/RecastDemo.cs +++ b/src/DotRecast.Recast.Demo/RecastDemo.cs @@ -34,6 +34,7 @@ using Silk.NET.OpenGL.Extensions.ImGui; using Silk.NET.Windowing; using ImGuiNET; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.Extras.Unity.Astar; using DotRecast.Detour.Io; @@ -80,7 +81,7 @@ public class RecastDemo : IRecastDemoChannel private bool processHitTestShift; private int _modState; - private RcVec2f mousePos = new RcVec2f(); + private Vector2 mousePos = new Vector2(); private bool _mouseOverMenu; private bool pan; @@ -88,12 +89,12 @@ public class RecastDemo : IRecastDemoChannel private bool rotate; private bool movedDuringRotate; private float scrollZoom; - private RcVec2f origMousePos = new RcVec2f(); - private RcVec2f origCameraEulers = new RcVec2f(); - private RcVec3f origCameraPos = new RcVec3f(); + private Vector2 origMousePos = new Vector2(); + private Vector2 origCameraEulers = new Vector2(); + private Vector3 origCameraPos = new Vector3(); - private RcVec2f cameraEulers = new RcVec2f(45, -45); - private RcVec3f cameraPos = new RcVec3f(0, 0, 0); + private Vector2 cameraEulers = new Vector2(45, -45); + private Vector3 cameraPos = new Vector3(0, 0, 0); private float[] projectionMatrix = new float[16]; @@ -109,7 +110,7 @@ public class RecastDemo : IRecastDemoChannel private int[] viewport; private bool markerPositionSet; - private RcVec3f markerPosition = new RcVec3f(); + private Vector3 markerPosition = new Vector3(); private RcToolsetView toolset; private RcSettingsView settingsView; @@ -459,8 +460,8 @@ public class RecastDemo : IRecastDemoChannel if (_sample.GetInputGeom() != null) { var settings = _sample.GetSettings(); - RcVec3f bmin = _sample.GetInputGeom().GetMeshBoundsMin(); - RcVec3f bmax = _sample.GetInputGeom().GetMeshBoundsMax(); + Vector3 bmin = _sample.GetInputGeom().GetMeshBoundsMin(); + Vector3 bmax = _sample.GetInputGeom().GetMeshBoundsMax(); RcCommons.CalcGridSize(bmin, bmax, settings.cellSize, out var gw, out var gh); settingsView.SetVoxels(gw, gh); settingsView.SetTiles(tileNavMeshBuilder.GetTiles(_sample.GetInputGeom(), settings.cellSize, settings.tileSize)); @@ -518,8 +519,8 @@ public class RecastDemo : IRecastDemoChannel { processHitTest = false; - RcVec3f rayStart = new RcVec3f(); - RcVec3f rayEnd = new RcVec3f(); + Vector3 rayStart = new Vector3(); + Vector3 rayEnd = new Vector3(); GLU.GlhUnProjectf(mousePos.X, viewport[3] - 1 - mousePos.Y, 0.0f, modelviewMatrix, projectionMatrix, viewport, ref rayStart); GLU.GlhUnProjectf(mousePos.X, viewport[3] - 1 - mousePos.Y, 1.0f, modelviewMatrix, projectionMatrix, viewport, ref rayEnd); @@ -534,8 +535,8 @@ public class RecastDemo : IRecastDemoChannel if (_sample.IsChanged()) { bool hasBound = false; - RcVec3f bminN = RcVec3f.Zero; - RcVec3f bmaxN = RcVec3f.Zero; + Vector3 bminN = Vector3.Zero; + Vector3 bmaxN = Vector3.Zero; if (_sample.GetInputGeom() != null) { bminN = _sample.GetInputGeom().GetMeshBoundsMin(); @@ -555,17 +556,17 @@ public class RecastDemo : IRecastDemoChannel { if (!hasBound) { - bminN = new RcVec3f(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); - bmaxN = new RcVec3f(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); + bminN = new Vector3(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity); + bmaxN = new Vector3(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); } - bminN = new RcVec3f( + bminN = new Vector3( Math.Min(bminN.X, result.GetSolidHeightfield().bmin.X), Math.Min(bminN.Y, result.GetSolidHeightfield().bmin.Y), Math.Min(bminN.Z, result.GetSolidHeightfield().bmin.Z) ); - bmaxN = new RcVec3f( + bmaxN = new Vector3( Math.Max(bmaxN.X, result.GetSolidHeightfield().bmax.X), Math.Max(bmaxN.Y, result.GetSolidHeightfield().bmax.Y), Math.Max(bmaxN.Z, result.GetSolidHeightfield().bmax.Z) @@ -578,8 +579,8 @@ public class RecastDemo : IRecastDemoChannel if (hasBound) { - RcVec3f bmin = bminN; - RcVec3f bmax = bmaxN; + Vector3 bmin = bminN; + Vector3 bmax = bmaxN; camr = (float)(Math.Sqrt(RcMath.Sqr(bmax.X - bmin.X) + RcMath.Sqr(bmax.Y - bmin.Y) + RcMath.Sqr(bmax.Z - bmin.Z)) / 2); cameraPos.X = (bmax.X + bmin.X) / 2 + camr; @@ -797,9 +798,9 @@ public class RecastDemo : IRecastDemoChannel hit = RcPolyMeshRaycast.Raycast(_sample.GetRecastResults(), rayStart, rayEnd, out hitTime); } - RcVec3f rayDir = new RcVec3f(rayEnd.X - rayStart.X, rayEnd.Y - rayStart.Y, rayEnd.Z - rayStart.Z); - rayDir = RcVec3f.Normalize(rayDir); - + Vector3 rayDir = new Vector3(rayEnd.X - rayStart.X, rayEnd.Y - rayStart.Y, rayEnd.Z - rayStart.Z); + rayDir = Vector3.Normalize(rayDir); + ISampleTool raySampleTool = toolset.GetTool(); if (raySampleTool != null) @@ -820,7 +821,7 @@ public class RecastDemo : IRecastDemoChannel } else { - RcVec3f pos = new RcVec3f(); + Vector3 pos = new Vector3(); pos.X = rayStart.X + (rayEnd.X - rayStart.X) * hitTime; pos.Y = rayStart.Y + (rayEnd.Y - rayStart.Y) * hitTime; pos.Z = rayStart.Z + (rayEnd.Z - rayStart.Z) * hitTime; diff --git a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs index ea5eb5e..7bd46bd 100644 --- a/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ConvexVolumeSampleTool.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Toolset.Builder; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; @@ -155,7 +156,7 @@ public class ConvexVolumeSampleTool : ISampleTool // .. } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { var geom = _sample.GetInputGeom(); if (shift) @@ -178,7 +179,7 @@ public class ConvexVolumeSampleTool : ISampleTool // TODO Auto-generated method stub } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdAgentProfilingSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdAgentProfilingSampleTool.cs index 200bf94..b49f056 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdAgentProfilingSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdAgentProfilingSampleTool.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.Linq; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.Crowd; using DotRecast.Recast.Toolset.Builder; @@ -133,7 +134,7 @@ public class CrowdAgentProfilingSampleTool : ISampleTool foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { float radius = ag.option.radius; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; dd.DebugDrawCircle(pos.X, pos.Y, pos.Z, radius, DuRGBA(0, 0, 0, 32), 2.0f); } @@ -143,7 +144,7 @@ public class CrowdAgentProfilingSampleTool : ISampleTool float height = ag.option.height; float radius = ag.option.radius; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; int col = DuRGBA(220, 220, 220, 128); if (crowAgentData.type == RcCrowdAgentType.TRAVELLER) @@ -198,7 +199,7 @@ public class CrowdAgentProfilingSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { //throw new NotImplementedException(); } @@ -209,7 +210,7 @@ public class CrowdAgentProfilingSampleTool : ISampleTool _tool.Update(dt); } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { //throw new NotImplementedException(); } diff --git a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs index e33ec2c..16d8a2c 100644 --- a/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/CrowdSampleTool.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.Crowd; @@ -188,7 +189,7 @@ public class CrowdSampleTool : ISampleTool float gridy = -float.MaxValue; foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { - RcVec3f pos = ag.corridor.GetPos(); + Vector3 pos = ag.corridor.GetPos(); gridy = Math.Max(gridy, pos.Y); } @@ -220,10 +221,10 @@ public class CrowdSampleTool : ISampleTool foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { RcCrowdAgentTrail trail = agentTrails[ag.idx]; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; dd.Begin(LINES, 3.0f); - RcVec3f prev = new RcVec3f(); + Vector3 prev = new Vector3(); float preva = 1; prev = pos; for (int j = 0; j < RcCrowdAgentTrail.AGENT_MAX_TRAIL - 1; ++j) @@ -247,7 +248,7 @@ public class CrowdSampleTool : ISampleTool continue; float radius = ag.option.radius; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; if (_showCorners) { @@ -256,8 +257,8 @@ public class CrowdSampleTool : ISampleTool dd.Begin(LINES, 2.0f); for (int j = 0; j < ag.corners.Count; ++j) { - RcVec3f va = j == 0 ? pos : ag.corners[j - 1].pos; - RcVec3f vb = ag.corners[j].pos; + Vector3 va = j == 0 ? pos : ag.corners[j - 1].pos; + Vector3 vb = ag.corners[j].pos; dd.Vertex(va.X, va.Y + radius, va.Z, DuRGBA(128, 0, 0, 192)); dd.Vertex(vb.X, vb.Y + radius, vb.Z, DuRGBA(128, 0, 0, 192)); } @@ -265,7 +266,7 @@ public class CrowdSampleTool : ISampleTool if ((ag.corners[ag.corners.Count - 1].flags & DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0) { - RcVec3f v = ag.corners[ag.corners.Count - 1].pos; + Vector3 v = ag.corners[ag.corners.Count - 1].pos; dd.Vertex(v.X, v.Y, v.Z, DuRGBA(192, 0, 0, 192)); dd.Vertex(v.X, v.Y + radius * 2, v.Z, DuRGBA(192, 0, 0, 192)); } @@ -299,7 +300,7 @@ public class CrowdSampleTool : ISampleTool if (_showCollisionSegments) { - RcVec3f center = ag.boundary.GetCenter(); + Vector3 center = ag.boundary.GetCenter(); dd.DebugDrawCross(center.X, center.Y + radius, center.Z, 0.2f, DuRGBA(192, 0, 128, 255), 2.0f); dd.DebugDrawCircle(center.X, center.Y + radius, center.Z, ag.option.collisionQueryRange, DuRGBA(192, 0, 128, 128), 2.0f); @@ -307,9 +308,9 @@ public class CrowdSampleTool : ISampleTool for (int j = 0; j < ag.boundary.GetSegmentCount(); ++j) { int col = DuRGBA(192, 0, 128, 192); - RcVec3f[] s = ag.boundary.GetSegment(j); - RcVec3f s0 = s[0]; - RcVec3f s3 = s[1]; + Vector3[] s = ag.boundary.GetSegment(j); + Vector3 s0 = s[0]; + Vector3 s3 = s[1]; if (DtUtils.TriArea2D(pos, s0, s3) < 0.0f) col = DuDarkenCol(col); @@ -352,7 +353,7 @@ public class CrowdSampleTool : ISampleTool foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { float radius = ag.option.radius; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; int col = DuRGBA(0, 0, 0, 32); if (agentDebug.agent == ag) @@ -365,7 +366,7 @@ public class CrowdSampleTool : ISampleTool { float height = ag.option.height; float radius = ag.option.radius; - RcVec3f pos = ag.npos; + Vector3 pos = ag.npos; int col = DuRGBA(220, 220, 220, 128); if (ag.targetState == DtMoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING @@ -401,7 +402,7 @@ public class CrowdSampleTool : ISampleTool dd.Begin(QUADS); for (int j = 0; j < vod.GetSampleCount(); ++j) { - RcVec3f p = vod.GetSampleVelocity(j); + Vector3 p = vod.GetSampleVelocity(j); float sr = vod.GetSampleSize(j); float pen = vod.GetSamplePenalty(j); float pen2 = vod.GetSamplePreferredSidePenalty(j); @@ -422,9 +423,9 @@ public class CrowdSampleTool : ISampleTool { float radius = ag.option.radius; float height = ag.option.height; - RcVec3f pos = ag.npos; - RcVec3f vel = ag.vel; - RcVec3f dvel = ag.dvel; + Vector3 pos = ag.npos; + Vector3 vel = ag.vel; + Vector3 dvel = ag.dvel; int col = DuRGBA(220, 220, 220, 192); if (ag.targetState == DtMoveRequestState.DT_CROWDAGENT_TARGET_REQUESTING @@ -472,7 +473,7 @@ public class CrowdSampleTool : ISampleTool } } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { var crowd = _tool.GetCrowd(); if (crowd == null) @@ -515,7 +516,7 @@ public class CrowdSampleTool : ISampleTool if (nav != null && navquery != null) { IDtQueryFilter filter = new DtQueryDefaultFilter(); - RcVec3f halfExtents = crowd.GetQueryExtents(); + Vector3 halfExtents = crowd.GetQueryExtents(); navquery.FindNearestPoly(p, halfExtents, filter, out var refs, out var nearestPt, out var _); if (refs != 0) { @@ -536,7 +537,7 @@ public class CrowdSampleTool : ISampleTool } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs index 9121213..9a34746 100644 --- a/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/DynamicUpdateSampleTool.cs @@ -24,6 +24,7 @@ using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic; using DotRecast.Recast.Toolset; using DotRecast.Recast.Toolset.Tools; @@ -81,10 +82,10 @@ public class DynamicUpdateSampleTool : ISampleTool private bool sposSet; private bool eposSet; - private RcVec3f spos; - private RcVec3f epos; + private Vector3 spos; + private Vector3 epos; private bool raycastHit; - private RcVec3f raycastHitPos; + private Vector3 raycastHitPos; public DynamicUpdateSampleTool() { @@ -303,7 +304,7 @@ public class DynamicUpdateSampleTool : ISampleTool } dd.DepthMask(false); - if (raycastHitPos != RcVec3f.Zero) + if (raycastHitPos != Vector3.Zero) { int spathCol = raycastHit ? DuRGBA(128, 32, 16, 220) : DuRGBA(64, 128, 240, 220); dd.Begin(LINES, 2.0f); @@ -316,7 +317,7 @@ public class DynamicUpdateSampleTool : ISampleTool } } - private void DrawAgent(RecastDebugDraw dd, RcVec3f pos, int col) + private void DrawAgent(RecastDebugDraw dd, Vector3 pos, int col) { var settings = _sample.GetSettings(); float r = settings.agentRadius; @@ -354,7 +355,7 @@ public class DynamicUpdateSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { if (mode == RcDynamicUpdateToolMode.COLLIDERS) { @@ -390,7 +391,7 @@ public class DynamicUpdateSampleTool : ISampleTool } - public void HandleClickRay(RcVec3f start, RcVec3f dir, bool shift) + public void HandleClickRay(Vector3 start, Vector3 dir, bool shift) { if (mode == RcDynamicUpdateToolMode.COLLIDERS) { diff --git a/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs b/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs index 2b8cf87..766e9b1 100644 --- a/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs +++ b/src/DotRecast.Recast.Demo/Tools/GizmoRenderer.cs @@ -1,6 +1,7 @@ using System; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset.Gizmos; @@ -38,9 +39,9 @@ public static class GizmoRenderer public static int GetColorByNormal(float[] vertices, int v0, int v1, int v2) { - RcVec3f e0 = new RcVec3f(); - RcVec3f e1 = new RcVec3f(); - RcVec3f normal = new RcVec3f(); + Vector3 e0 = new Vector3(); + Vector3 e1 = new Vector3(); + Vector3 normal = new Vector3(); for (int j = 0; j < 3; ++j) { e0 = RcVecUtils.Subtract(vertices, v1, v0); @@ -50,7 +51,7 @@ public static class GizmoRenderer normal.X = e0.Y * e1.Z - e0.Z * e1.Y; normal.Y = e0.Z * e1.X - e0.X * e1.Z; normal.Z = e0.X * e1.Y - e0.Y * e1.X; - normal = RcVec3f.Normalize(normal); + normal = Vector3.Normalize(normal); float c = Math.Clamp(0.57735026f * (normal.X + normal.Y + normal.Z), -1, 1); int col = DebugDraw.DuLerpCol( DebugDraw.DuRGBA(32, 32, 0, 160), @@ -62,15 +63,15 @@ public static class GizmoRenderer public static void RenderBox(RecastDebugDraw debugDraw, RcBoxGizmo box) { - var trX = new RcVec3f(box.halfEdges[0].X, box.halfEdges[1].X, box.halfEdges[2].X); - var trY = new RcVec3f(box.halfEdges[0].Y, box.halfEdges[1].Y, box.halfEdges[2].Y); - var trZ = new RcVec3f(box.halfEdges[0].Z, box.halfEdges[1].Z, box.halfEdges[2].Z); + var trX = new Vector3(box.halfEdges[0].X, box.halfEdges[1].X, box.halfEdges[2].X); + var trY = new Vector3(box.halfEdges[0].Y, box.halfEdges[1].Y, box.halfEdges[2].Y); + var trZ = new Vector3(box.halfEdges[0].Z, box.halfEdges[1].Z, box.halfEdges[2].Z); float[] vertices = new float[8 * 3]; for (int i = 0; i < 8; i++) { - vertices[i * 3 + 0] = RcVec3f.Dot(RcBoxGizmo.VERTS[i], trX) + box.center.X; - vertices[i * 3 + 1] = RcVec3f.Dot(RcBoxGizmo.VERTS[i], trY) + box.center.Y; - vertices[i * 3 + 2] = RcVec3f.Dot(RcBoxGizmo.VERTS[i], trZ) + box.center.Z; + vertices[i * 3 + 0] = Vector3.Dot(RcBoxGizmo.VERTS[i], trX) + box.center.X; + vertices[i * 3 + 1] = Vector3.Dot(RcBoxGizmo.VERTS[i], trY) + box.center.Y; + vertices[i * 3 + 2] = Vector3.Dot(RcBoxGizmo.VERTS[i], trZ) + box.center.Z; } debugDraw.Begin(DebugDrawPrimitives.TRIS); diff --git a/src/DotRecast.Recast.Demo/Tools/ISampleTool.cs b/src/DotRecast.Recast.Demo/Tools/ISampleTool.cs index bd9490d..54a8d63 100644 --- a/src/DotRecast.Recast.Demo/Tools/ISampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ISampleTool.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; @@ -31,8 +32,8 @@ public interface ISampleTool IRcToolable GetTool(); void Layout(); - void HandleClick(RcVec3f s, RcVec3f p, bool shift); + void HandleClick(Vector3 s, Vector3 p, bool shift); void HandleRender(NavMeshRenderer renderer); void HandleUpdate(float dt); - void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift); + void HandleClickRay(Vector3 start, Vector3 direction, bool shift); } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs index 7a33b6b..3f134e4 100644 --- a/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/JumpLinkBuilderSampleTool.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Extras.Jumplink; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; @@ -302,7 +303,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool { GroundSample s = link.start.gsamples[i]; float u = i / (float)(link.start.gsamples.Length - 1); - RcVec3f spt = RcVec3f.Lerp(link.start.p, link.start.q, u); + Vector3 spt = Vector3.Lerp(link.start.p, link.start.q, u); int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255); float off = 0.1f; if (!s.validHeight) @@ -322,7 +323,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool { GroundSample s = link.start.gsamples[i]; float u = i / (float)(link.start.gsamples.Length - 1); - RcVec3f spt = RcVec3f.Lerp(link.start.p, link.start.q, u); + Vector3 spt = Vector3.Lerp(link.start.p, link.start.q, u); int col = DuRGBA(255, 255, 255, 255); float off = 0; if (s.validHeight) @@ -342,7 +343,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool { GroundSample s = end.gsamples[i]; float u = i / (float)(end.gsamples.Length - 1); - RcVec3f spt = RcVec3f.Lerp(end.p, end.q, u); + Vector3 spt = Vector3.Lerp(end.p, end.q, u); int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255); float off = 0.1f; if (!s.validHeight) @@ -361,7 +362,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool { GroundSample s = end.gsamples[i]; float u = i / (float)(end.gsamples.Length - 1); - RcVec3f spt = RcVec3f.Lerp(end.p, end.q, u); + Vector3 spt = Vector3.Lerp(end.p, end.q, u); int col = DuRGBA(255, 255, 255, 255); float off = 0; if (s.validHeight) @@ -399,12 +400,12 @@ public class JumpLinkBuilderSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { } - private void DrawTrajectory(RecastDebugDraw dd, JumpLink link, RcVec3f pa, RcVec3f pb, Trajectory tra, int cola) + private void DrawTrajectory(RecastDebugDraw dd, JumpLink link, Vector3 pa, Vector3 pb, Trajectory tra, int cola) { } @@ -413,7 +414,7 @@ public class JumpLinkBuilderSampleTool : ISampleTool } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs index 216f7f3..66bd8e2 100644 --- a/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/ObstacleSampleTool.cs @@ -1,5 +1,6 @@ using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache; using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Recast.Demo.Draw; @@ -66,8 +67,8 @@ public class ObstacleSampleTool : ISampleTool if (ob.state == DtObstacleState.DT_OBSTACLE_EMPTY) continue; - RcVec3f bmin = RcVec3f.Zero; - RcVec3f bmax = RcVec3f.Zero; + Vector3 bmin = Vector3.Zero; + Vector3 bmax = Vector3.Zero; tc.GetObstacleBounds(ob, ref bmin, ref bmax); int col = 0; @@ -98,7 +99,7 @@ public class ObstacleSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { if (shift) { @@ -118,7 +119,7 @@ public class ObstacleSampleTool : ISampleTool tc.Update(); } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs index feb38f9..16938b5 100644 --- a/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/OffMeshConnectionSampleTool.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; using DotRecast.Recast.Toolset.Geom; @@ -40,7 +41,7 @@ public class OffMeshConnectionSampleTool : ISampleTool private int _bidir; private bool _hasStartPt; - private RcVec3f _startPt; + private Vector3 _startPt; public OffMeshConnectionSampleTool() { @@ -88,7 +89,7 @@ public class OffMeshConnectionSampleTool : ISampleTool // .. } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { DemoInputGeomProvider geom = _sample.GetInputGeom(); if (geom == null) @@ -124,7 +125,7 @@ public class OffMeshConnectionSampleTool : ISampleTool // TODO Auto-generated method stub } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs index b9552dd..dd3c085 100644 --- a/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TestNavmeshSampleTool.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Recast.Toolset.Builder; using DotRecast.Recast.Demo.Draw; @@ -42,18 +43,18 @@ public class TestNavmeshSampleTool : ISampleTool // private bool m_sposSet; private long m_startRef; - private RcVec3f m_spos; + private Vector3 m_spos; private bool m_eposSet; private long m_endRef; - private RcVec3f m_epos; + private Vector3 m_epos; private readonly DtQueryDefaultFilter m_filter; - private readonly RcVec3f m_polyPickExt = new RcVec3f(2, 4, 2); + private readonly Vector3 m_polyPickExt = new Vector3(2, 4, 2); // for hit - private RcVec3f m_hitPos; - private RcVec3f m_hitNormal; + private Vector3 m_hitPos; + private Vector3 m_hitNormal; private bool m_hitResult; private float m_distanceToWall; @@ -61,12 +62,12 @@ public class TestNavmeshSampleTool : ISampleTool private List m_polys; private List m_parent; private float m_neighbourhoodRadius; - private RcVec3f[] m_queryPoly = new RcVec3f[4]; - private List m_smoothPath; + private Vector3[] m_queryPoly = new Vector3[4]; + private List m_smoothPath; private DtStatus m_pathFindStatus = DtStatus.DT_FAILURE; // for mode RANDOM_POINTS_IN_CIRCLE - private List _randomPoints = new(); + private List _randomPoints = new(); public TestNavmeshSampleTool() { @@ -383,12 +384,12 @@ public class TestNavmeshSampleTool : ISampleTool { dd.DebugDrawNavMeshPoly(m_navMesh, m_startRef, startCol); dd.DepthMask(false); - if (m_spos != RcVec3f.Zero) + if (m_spos != Vector3.Zero) { dd.DebugDrawCircle(m_spos.X, m_spos.Y + agentHeight / 2, m_spos.Z, m_distanceToWall, DuRGBA(64, 16, 0, 220), 2.0f); } - if (m_hitPos != RcVec3f.Zero) + if (m_hitPos != Vector3.Zero) { dd.Begin(LINES, 3.0f); dd.Vertex(m_hitPos.X, m_hitPos.Y + 0.02f, m_hitPos.Z, DuRGBA(0, 0, 0, 192)); @@ -409,8 +410,8 @@ public class TestNavmeshSampleTool : ISampleTool if (m_parent[i] != 0) { dd.DepthMask(false); - RcVec3f p0 = m_navMesh.GetPolyCenter(m_parent[i]); - RcVec3f p1 = m_navMesh.GetPolyCenter(m_polys[i]); + Vector3 p0 = m_navMesh.GetPolyCenter(m_parent[i]); + Vector3 p1 = m_navMesh.GetPolyCenter(m_polys[i]); dd.DebugDrawArc(p0.X, p0.Y, p0.Z, p1.X, p1.Y, p1.Z, 0.25f, 0.0f, 0.4f, DuRGBA(0, 0, 0, 128), 2.0f); dd.DepthMask(true); } @@ -440,8 +441,8 @@ public class TestNavmeshSampleTool : ISampleTool if (m_parent[i] != 0) { dd.DepthMask(false); - RcVec3f p0 = m_navMesh.GetPolyCenter(m_parent[i]); - RcVec3f p1 = m_navMesh.GetPolyCenter(m_polys[i]); + Vector3 p0 = m_navMesh.GetPolyCenter(m_parent[i]); + Vector3 p1 = m_navMesh.GetPolyCenter(m_polys[i]); dd.DebugDrawArc(p0.X, p0.Y, p0.Z, p1.X, p1.Y, p1.Z, 0.25f, 0.0f, 0.4f, DuRGBA(0, 0, 0, 128), 2.0f); dd.DepthMask(true); } @@ -479,8 +480,8 @@ public class TestNavmeshSampleTool : ISampleTool if (m_parent[i] != 0) { dd.DepthMask(false); - RcVec3f p0 = m_navMesh.GetPolyCenter(m_parent[i]); - RcVec3f p1 = m_navMesh.GetPolyCenter(m_polys[i]); + Vector3 p0 = m_navMesh.GetPolyCenter(m_parent[i]); + Vector3 p1 = m_navMesh.GetPolyCenter(m_polys[i]); dd.DebugDrawArc(p0.X, p0.Y, p0.Z, p1.X, p1.Y, p1.Z, 0.25f, 0.0f, 0.4f, DuRGBA(0, 0, 0, 128), 2.0f); dd.DepthMask(true); } @@ -507,11 +508,11 @@ public class TestNavmeshSampleTool : ISampleTool continue; } - RcVec3f delta = RcVec3f.Subtract(s3, s.vmin); - RcVec3f p0 = RcVecUtils.Mad(s.vmin, delta, 0.5f); - RcVec3f norm = new RcVec3f(delta.Z, 0, -delta.X); - norm = RcVec3f.Normalize(norm); - RcVec3f p1 = RcVecUtils.Mad(p0, norm, agentRadius * 0.5f); + Vector3 delta = Vector3.Subtract(s3, s.vmin); + Vector3 p0 = RcVecUtils.Mad(s.vmin, delta, 0.5f); + Vector3 norm = new Vector3(delta.Z, 0, -delta.X); + norm = Vector3.Normalize(norm); + Vector3 p1 = RcVecUtils.Mad(p0, norm, agentRadius * 0.5f); // Skip backfacing segments. if (segmentRefs[j] != 0) { @@ -555,7 +556,7 @@ public class TestNavmeshSampleTool : ISampleTool dd.DepthMask(false); dd.Begin(POINTS, 4.0f); int col = DuRGBA(64, 16, 0, 220); - foreach (RcVec3f point in _randomPoints) + foreach (Vector3 point in _randomPoints) { dd.Vertex(point.X, point.Y + 0.1f, point.Z, col); } @@ -575,7 +576,7 @@ public class TestNavmeshSampleTool : ISampleTool } } - private void DrawAgent(RecastDebugDraw dd, RcVec3f pos, int col) + private void DrawAgent(RecastDebugDraw dd, Vector3 pos, int col) { var settings = _sample.GetSettings(); float r = settings.agentRadius; @@ -613,7 +614,7 @@ public class TestNavmeshSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { if (shift) { @@ -717,7 +718,7 @@ public class TestNavmeshSampleTool : ISampleTool } } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs b/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs index 5b33b99..26ff4b8 100644 --- a/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs +++ b/src/DotRecast.Recast.Demo/Tools/TileSampleTool.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Demo.Draw; using DotRecast.Recast.Toolset; using DotRecast.Recast.Toolset.Builder; @@ -18,7 +19,7 @@ public class TileSampleTool : ISampleTool private readonly RcTileTool _tool; private bool _hitPosSet; - private RcVec3f _hitPos; + private Vector3 _hitPos; public TileSampleTool() { @@ -62,8 +63,8 @@ public class TileSampleTool : ISampleTool int tx = (int)((_hitPos.X - bmin.X) / ts); int ty = (int)((_hitPos.Z - bmin.Z) / ts); - RcVec3f lastBuiltTileBmin = RcVec3f.Zero; - RcVec3f lastBuiltTileBmax = RcVec3f.Zero; + Vector3 lastBuiltTileBmin = Vector3.Zero; + Vector3 lastBuiltTileBmax = Vector3.Zero; lastBuiltTileBmin.X = bmin.X + tx * ts; lastBuiltTileBmin.Y = bmin.Y; @@ -98,7 +99,7 @@ public class TileSampleTool : ISampleTool } - public void HandleClick(RcVec3f s, RcVec3f p, bool shift) + public void HandleClick(Vector3 s, Vector3 p, bool shift) { _hitPosSet = true; _hitPos = p; @@ -130,7 +131,7 @@ public class TileSampleTool : ISampleTool { } - public void HandleClickRay(RcVec3f start, RcVec3f direction, bool shift) + public void HandleClickRay(Vector3 start, Vector3 direction, bool shift) { } } \ No newline at end of file diff --git a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 50b3390..de50bf7 100644 --- a/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; namespace DotRecast.Recast.Toolset.Geom @@ -32,8 +33,8 @@ namespace DotRecast.Recast.Toolset.Geom public readonly float[] vertices; public readonly int[] faces; public readonly float[] normals; - private readonly RcVec3f bmin; - private readonly RcVec3f bmax; + private readonly Vector3 bmin; + private readonly Vector3 bmax; private readonly List _convexVolumes = new List(); private readonly List _offMeshConnections = new List(); @@ -73,12 +74,12 @@ namespace DotRecast.Recast.Toolset.Geom return _mesh; } - public RcVec3f GetMeshBoundsMin() + public Vector3 GetMeshBoundsMin() { return bmin; } - public RcVec3f GetMeshBoundsMax() + public Vector3 GetMeshBoundsMax() { return bmax; } @@ -122,7 +123,7 @@ namespace DotRecast.Recast.Toolset.Geom return _offMeshConnections; } - public void AddOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags) + public void AddOffMeshConnection(Vector3 start, Vector3 end, float radius, bool bidir, int area, int flags) { _offMeshConnections.Add(new RcOffMeshConnection(start, end, radius, bidir, area, flags)); } @@ -133,7 +134,7 @@ namespace DotRecast.Recast.Toolset.Geom _offMeshConnections.RemoveAll(filter); // TODO : 확인 필요 } - public bool RaycastMesh(RcVec3f src, RcVec3f dst, out float tmin) + public bool RaycastMesh(Vector3 src, Vector3 dst, out float tmin) { tmin = 1.0f; @@ -143,8 +144,8 @@ namespace DotRecast.Recast.Toolset.Geom return false; } - var p = new RcVec2f(); - var q = new RcVec2f(); + var p = new Vector2(); + var q = new Vector2(); p.X = src.X + (dst.X - src.X) * btmin; p.Y = src.Z + (dst.Z - src.Z) * btmin; q.X = src.X + (dst.X - src.X) * btmax; @@ -163,17 +164,17 @@ namespace DotRecast.Recast.Toolset.Geom int[] tris = chunk.tris; for (int j = 0; j < chunk.tris.Length; j += 3) { - RcVec3f v1 = new RcVec3f( + Vector3 v1 = new Vector3( vertices[tris[j] * 3], vertices[tris[j] * 3 + 1], vertices[tris[j] * 3 + 2] ); - RcVec3f v2 = new RcVec3f( + Vector3 v2 = new Vector3( vertices[tris[j + 1] * 3], vertices[tris[j + 1] * 3 + 1], vertices[tris[j + 1] * 3 + 2] ); - RcVec3f v3 = new RcVec3f( + Vector3 v3 = new Vector3( vertices[tris[j + 2] * 3], vertices[tris[j + 2] * 3 + 1], vertices[tris[j + 2] * 3 + 2] diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcBoxGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcBoxGizmo.cs index 924f24a..7beee37 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcBoxGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcBoxGizmo.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic.Colliders; namespace DotRecast.Recast.Toolset.Gizmos @@ -11,28 +12,28 @@ namespace DotRecast.Recast.Toolset.Gizmos 2, 6, 7, 2, 7, 3, 4, 0, 3, 4, 3, 7 }; - public static readonly RcVec3f[] VERTS = + public static readonly Vector3[] VERTS = { - new RcVec3f(-1f, -1f, -1f), - new RcVec3f(1f, -1f, -1f), - new RcVec3f(1f, -1f, 1f), - new RcVec3f(-1f, -1f, 1f), - new RcVec3f(-1f, 1f, -1f), - new RcVec3f(1f, 1f, -1f), - new RcVec3f(1f, 1f, 1f), - new RcVec3f(-1f, 1f, 1f), + new Vector3(-1f, -1f, -1f), + new Vector3(1f, -1f, -1f), + new Vector3(1f, -1f, 1f), + new Vector3(-1f, -1f, 1f), + new Vector3(-1f, 1f, -1f), + new Vector3(1f, 1f, -1f), + new Vector3(1f, 1f, 1f), + new Vector3(-1f, 1f, 1f), }; public readonly float[] vertices = new float[8 * 3]; - public readonly RcVec3f center; - public readonly RcVec3f[] halfEdges; + public readonly Vector3 center; + public readonly Vector3[] halfEdges; - public RcBoxGizmo(RcVec3f center, RcVec3f extent, RcVec3f forward, RcVec3f up) : + public RcBoxGizmo(Vector3 center, Vector3 extent, Vector3 forward, Vector3 up) : this(center, DtBoxCollider.GetHalfEdges(up, forward, extent)) { } - public RcBoxGizmo(RcVec3f center, RcVec3f[] halfEdges) + public RcBoxGizmo(Vector3 center, Vector3[] halfEdges) { this.center = center; this.halfEdges = halfEdges; diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs index 90a10a7..dee5905 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcCapsuleGizmo.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.Toolset.Gizmos.RcGizmoHelper; namespace DotRecast.Recast.Toolset.Gizmos @@ -11,30 +12,30 @@ namespace DotRecast.Recast.Toolset.Gizmos public readonly float[] center; public readonly float[] gradient; - public RcCapsuleGizmo(RcVec3f start, RcVec3f end, float radius) + public RcCapsuleGizmo(Vector3 start, Vector3 end, float radius) { center = new float[] { 0.5f * (start.X + end.X), 0.5f * (start.Y + end.Y), 0.5f * (start.Z + end.Z) }; - RcVec3f axis = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); - RcVec3f[] normals = new RcVec3f[3]; - normals[1] = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); - normals[1] = RcVec3f.Normalize(normals[1]); + Vector3 axis = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + Vector3[] normals = new Vector3[3]; + normals[1] = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + normals[1] = Vector3.Normalize(normals[1]); normals[0] = GetSideVector(axis); - normals[2] = RcVec3f.Zero; - normals[2] = RcVec3f.Cross(normals[0], normals[1]); - normals[2] = RcVec3f.Normalize(normals[2]); + normals[2] = Vector3.Zero; + normals[2] = Vector3.Cross(normals[0], normals[1]); + normals[2] = Vector3.Normalize(normals[2]); triangles = GenerateSphericalTriangles(); - var trX = new RcVec3f(normals[0].X, normals[1].X, normals[2].X); - var trY = new RcVec3f(normals[0].Y, normals[1].Y, normals[2].Y); - var trZ = new RcVec3f(normals[0].Z, normals[1].Z, normals[2].Z); + var trX = new Vector3(normals[0].X, normals[1].X, normals[2].X); + var trY = new Vector3(normals[0].Y, normals[1].Y, normals[2].Y); + var trZ = new Vector3(normals[0].Z, normals[1].Z, normals[2].Z); float[] spVertices = GenerateSphericalVertices(); float halfLength = 0.5f * axis.Length(); vertices = new float[spVertices.Length]; gradient = new float[spVertices.Length / 3]; - RcVec3f v = new RcVec3f(); + Vector3 v = new Vector3(); for (int i = 0; i < spVertices.Length; i += 3) { float offset = (i >= spVertices.Length / 2) ? -halfLength : halfLength; @@ -47,22 +48,22 @@ namespace DotRecast.Recast.Toolset.Gizmos v.X = vertices[i] - center[0]; v.Y = vertices[i + 1] - center[1]; v.Z = vertices[i + 2] - center[2]; - v = RcVec3f.Normalize(v); + v = Vector3.Normalize(v); gradient[i / 3] = Math.Clamp(0.57735026f * (v.X + v.Y + v.Z), -1, 1); } } - private RcVec3f GetSideVector(RcVec3f axis) + private Vector3 GetSideVector(Vector3 axis) { - var side = new RcVec3f(1, 0, 0); + var side = new Vector3(1, 0, 0); if (axis.X > 0.8) { - side = new RcVec3f(0, 0, 1); + side = new Vector3(0, 0, 1); } - var forward = RcVec3f.Cross(side, axis); - side = RcVec3f.Cross(axis, forward); - side = RcVec3f.Normalize(side); + var forward = Vector3.Cross(side, axis); + side = Vector3.Cross(axis, forward); + side = Vector3.Normalize(side); return side; } } diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs index 2183bbf..fecacee 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcCylinderGizmo.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.Toolset.Gizmos.RcGizmoHelper; @@ -9,31 +10,31 @@ namespace DotRecast.Recast.Toolset.Gizmos { public readonly float[] vertices; public readonly int[] triangles; - public readonly RcVec3f center; + public readonly Vector3 center; public readonly float[] gradient; - public RcCylinderGizmo(RcVec3f start, RcVec3f end, float radius) + public RcCylinderGizmo(Vector3 start, Vector3 end, float radius) { - center = new RcVec3f( + center = new Vector3( 0.5f * (start.X + end.X), 0.5f * (start.Y + end.Y), 0.5f * (start.Z + end.Z) ); - RcVec3f axis = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); - RcVec3f[] normals = new RcVec3f[3]; - normals[1] = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); - normals[1] = RcVec3f.Normalize(normals[1]); + Vector3 axis = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + Vector3[] normals = new Vector3[3]; + normals[1] = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + normals[1] = Vector3.Normalize(normals[1]); normals[0] = GetSideVector(axis); - normals[2] = RcVec3f.Zero; - normals[2] = RcVec3f.Cross(normals[0], normals[1]); - normals[2] = RcVec3f.Normalize(normals[2]); + normals[2] = Vector3.Zero; + normals[2] = Vector3.Cross(normals[0], normals[1]); + normals[2] = Vector3.Normalize(normals[2]); triangles = GenerateCylindricalTriangles(); - RcVec3f trX = new RcVec3f(normals[0].X, normals[1].X, normals[2].X); - RcVec3f trY = new RcVec3f(normals[0].Y, normals[1].Y, normals[2].Y); - RcVec3f trZ = new RcVec3f(normals[0].Z, normals[1].Z, normals[2].Z); + Vector3 trX = new Vector3(normals[0].X, normals[1].X, normals[2].X); + Vector3 trY = new Vector3(normals[0].Y, normals[1].Y, normals[2].Y); + Vector3 trZ = new Vector3(normals[0].Z, normals[1].Z, normals[2].Z); vertices = GenerateCylindricalVertices(); float halfLength = 0.5f * axis.Length(); gradient = new float[vertices.Length / 3]; - RcVec3f v = new RcVec3f(); + Vector3 v = new Vector3(); for (int i = 0; i < vertices.Length; i += 3) { float offset = (i >= vertices.Length / 2) ? -halfLength : halfLength; @@ -52,23 +53,23 @@ namespace DotRecast.Recast.Toolset.Gizmos v.X = vertices[i] - center.X; v.Y = vertices[i + 1] - center.Y; v.Z = vertices[i + 2] - center.Z; - v = RcVec3f.Normalize(v); + v = Vector3.Normalize(v); gradient[i / 3] = Math.Clamp(0.57735026f * (v.X + v.Y + v.Z), -1, 1); } } } - private RcVec3f GetSideVector(RcVec3f axis) + private Vector3 GetSideVector(Vector3 axis) { - RcVec3f side = new RcVec3f(1, 0, 0); + Vector3 side = new Vector3(1, 0, 0); if (axis.X > 0.8) { - side = new RcVec3f(0, 0, 1); + side = new Vector3(0, 0, 1); } - var forward = RcVec3f.Cross(side, axis); - side = RcVec3f.Cross(axis, forward); - side = RcVec3f.Normalize(side); + var forward = Vector3.Cross(side, axis); + side = Vector3.Cross(axis, forward); + side = Vector3.Normalize(side); return side; } } diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcGizmoFactory.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcGizmoFactory.cs index c1b86be..85d221c 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcGizmoFactory.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcGizmoFactory.cs @@ -1,25 +1,26 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Toolset.Gizmos { public static class RcGizmoFactory { - public static RcBoxGizmo Box(RcVec3f center, RcVec3f[] halfEdges) + public static RcBoxGizmo Box(Vector3 center, Vector3[] halfEdges) { return new RcBoxGizmo(center, halfEdges); } - public static RcSphereGizmo Sphere(RcVec3f center, float radius) + public static RcSphereGizmo Sphere(Vector3 center, float radius) { return new RcSphereGizmo(center, radius); } - public static RcCapsuleGizmo Capsule(RcVec3f start, RcVec3f end, float radius) + public static RcCapsuleGizmo Capsule(Vector3 start, Vector3 end, float radius) { return new RcCapsuleGizmo(start, end, radius); } - public static RcCylinderGizmo Cylinder(RcVec3f start, RcVec3f end, float radius) + public static RcCylinderGizmo Cylinder(Vector3 start, Vector3 end, float radius) { return new RcCylinderGizmo(start, end, radius); } diff --git a/src/DotRecast.Recast.Toolset/Gizmos/RcSphereGizmo.cs b/src/DotRecast.Recast.Toolset/Gizmos/RcSphereGizmo.cs index 06a93be..d853c7b 100644 --- a/src/DotRecast.Recast.Toolset/Gizmos/RcSphereGizmo.cs +++ b/src/DotRecast.Recast.Toolset/Gizmos/RcSphereGizmo.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.Toolset.Gizmos.RcGizmoHelper; @@ -9,9 +10,9 @@ namespace DotRecast.Recast.Toolset.Gizmos public readonly float[] vertices; public readonly int[] triangles; public readonly float radius; - public readonly RcVec3f center; + public readonly Vector3 center; - public RcSphereGizmo(RcVec3f center, float radius) + public RcSphereGizmo(Vector3 center, float radius) { this.center = center; this.radius = radius; diff --git a/src/DotRecast.Recast.Toolset/Tools/RcConvexVolumeTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcConvexVolumeTool.cs index 69974bf..1357bc5 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcConvexVolumeTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcConvexVolumeTool.cs @@ -2,18 +2,19 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; namespace DotRecast.Recast.Toolset.Tools { public class RcConvexVolumeTool : IRcToolable { - private readonly List _pts; + private readonly List _pts; private readonly List _hull; public RcConvexVolumeTool() { - _pts = new List(); + _pts = new List(); _hull = new List(); } @@ -22,7 +23,7 @@ namespace DotRecast.Recast.Toolset.Tools return "Convex Volumes"; } - public List GetShapePoint() + public List GetShapePoint() { return _pts; } @@ -38,16 +39,16 @@ namespace DotRecast.Recast.Toolset.Tools _hull.Clear(); } - public bool PlottingShape(RcVec3f p, out List pts, out List hull) + public bool PlottingShape(Vector3 p, out List pts, out List hull) { pts = null; hull = null; // Create // If clicked on that last pt, create the shape. - if (_pts.Count > 0 && RcVec3f.DistanceSquared(p, _pts[_pts.Count - 1]) < 0.2f * 0.2f) + if (_pts.Count > 0 && Vector3.DistanceSquared(p, _pts[_pts.Count - 1]) < 0.2f * 0.2f) { - pts = new List(_pts); + pts = new List(_pts); hull = new List(_hull); _pts.Clear(); @@ -74,7 +75,7 @@ namespace DotRecast.Recast.Toolset.Tools } - public RcConvexVolume RemoveByPos(IInputGeomProvider geom, RcVec3f pos) + public RcConvexVolume RemoveByPos(IInputGeomProvider geom, Vector3 pos) { // Delete int nearestIndex = -1; @@ -102,7 +103,7 @@ namespace DotRecast.Recast.Toolset.Tools geom.AddConvexVolume(volume); } - public static RcConvexVolume CreateConvexVolume(List pts, List hull, RcAreaModification areaType, float boxDescent, float boxHeight, float polyOffset) + public static RcConvexVolume CreateConvexVolume(List pts, List hull, RcAreaModification areaType, float boxDescent, float boxHeight, float polyOffset) { // if (hull.Count <= 2) diff --git a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentData.cs b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentData.cs index 96b6e22..df545a1 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentData.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentData.cs @@ -1,13 +1,14 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Toolset.Tools { public class RcCrowdAgentData { public readonly RcCrowdAgentType type; - public readonly RcVec3f home = new RcVec3f(); + public readonly Vector3 home = new Vector3(); - public RcCrowdAgentData(RcCrowdAgentType type, RcVec3f home) + public RcCrowdAgentData(RcCrowdAgentType type, Vector3 home) { this.type = type; this.home = home; diff --git a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs index d5e00b1..9f0b543 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.Crowd; using DotRecast.Recast.Toolset.Builder; @@ -74,14 +75,14 @@ namespace DotRecast.Recast.Toolset.Tools return ap; } - private DtStatus GetMobPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out RcVec3f randomPt) + private DtStatus GetMobPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out Vector3 randomPt) { return navquery.FindRandomPoint(filter, rnd, out var randomRef, out randomPt); } - private DtStatus GetVillagerPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out RcVec3f randomPt) + private DtStatus GetVillagerPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out Vector3 randomPt) { - randomPt = RcVec3f.Zero; + randomPt = Vector3.Zero; if (0 >= _polyPoints.Count) return DtStatus.DT_FAILURE; @@ -107,7 +108,7 @@ namespace DotRecast.Recast.Toolset.Tools bool valid = true; foreach (var zone in _polyPoints) { - if (RcVec3f.DistanceSquared(zone.pt, randomPt) < zoneSeparation) + if (Vector3.DistanceSquared(zone.pt, randomPt) < zoneSeparation) { valid = false; break; @@ -189,7 +190,7 @@ namespace DotRecast.Recast.Toolset.Tools } var status = DtStatus.DT_FAILURE; - var randomPt = RcVec3f.Zero; + var randomPt = Vector3.Zero; switch (type) { case RcCrowdAgentType.MOB: @@ -285,7 +286,7 @@ namespace DotRecast.Recast.Toolset.Tools List potentialTargets = new List(); foreach (var zone in _polyPoints) { - if (RcVec3f.DistanceSquared(zone.pt, ag.npos) > _cfg.zoneRadius * _cfg.zoneRadius) + if (Vector3.DistanceSquared(zone.pt, ag.npos) > _cfg.zoneRadius * _cfg.zoneRadius) { potentialTargets.Add(zone); } @@ -317,7 +318,7 @@ namespace DotRecast.Recast.Toolset.Tools return false; } - private DtCrowdAgent AddAgent(RcVec3f p, RcCrowdAgentType type, float agentRadius, float agentHeight, float agentMaxAcceleration, float agentMaxSpeed) + private DtCrowdAgent AddAgent(Vector3 p, RcCrowdAgentType type, float agentRadius, float agentHeight, float agentMaxAcceleration, float agentMaxSpeed) { DtCrowdAgentParams ap = GetAgentParams(agentRadius, agentHeight, agentMaxAcceleration, agentMaxSpeed); ap.userData = new RcCrowdAgentData(type, p); diff --git a/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs index 4bfbd5f..dcd27da 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.Crowd; using DotRecast.Recast.Toolset.Builder; @@ -16,7 +17,7 @@ namespace DotRecast.Recast.Toolset.Tools private long crowdUpdateTime; private readonly Dictionary _trails; private long _moveTargetRef; - private RcVec3f _moveTargetPos; + private Vector3 _moveTargetPos; public RcCrowdTool() { @@ -52,7 +53,7 @@ namespace DotRecast.Recast.Toolset.Tools return _moveTargetRef; } - public RcVec3f GetMoveTargetPos() + public Vector3 GetMoveTargetPos() { return _moveTargetPos; } @@ -170,7 +171,7 @@ namespace DotRecast.Recast.Toolset.Tools } } - public void AddAgent(RcVec3f p, float agentRadius, float agentHeight, float agentMaxAcceleration, float agentMaxSpeed) + public void AddAgent(Vector3 p, float agentRadius, float agentHeight, float agentMaxAcceleration, float agentMaxSpeed) { DtCrowdAgentParams ap = CreateAgentParams(agentRadius, agentHeight, agentMaxAcceleration, agentMaxSpeed); DtCrowdAgent ag = crowd.AddAgent(p, ap); @@ -212,15 +213,15 @@ namespace DotRecast.Recast.Toolset.Tools return ap; } - public DtCrowdAgent HitTestAgents(RcVec3f s, RcVec3f p) + public DtCrowdAgent HitTestAgents(Vector3 s, Vector3 p) { DtCrowdAgent isel = null; float tsel = float.MaxValue; foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { - RcVec3f bmin = new RcVec3f(); - RcVec3f bmax = new RcVec3f(); + Vector3 bmin = new Vector3(); + Vector3 bmax = new Vector3(); GetAgentBounds(ag, ref bmin, ref bmax); if (RcIntersections.IsectSegAABB(s, p, bmin, bmax, out var tmin, out var tmax)) { @@ -235,9 +236,9 @@ namespace DotRecast.Recast.Toolset.Tools return isel; } - private void GetAgentBounds(DtCrowdAgent ag, ref RcVec3f bmin, ref RcVec3f bmax) + private void GetAgentBounds(DtCrowdAgent ag, ref Vector3 bmin, ref Vector3 bmax) { - RcVec3f p = ag.npos; + Vector3 p = ag.npos; float r = ag.option.radius; float h = ag.option.height; bmin.X = p.X - r; @@ -248,7 +249,7 @@ namespace DotRecast.Recast.Toolset.Tools bmax.Z = p.Z + r; } - public void SetMoveTarget(RcVec3f p, bool adjust) + public void SetMoveTarget(Vector3 p, bool adjust) { if (crowd == null) return; @@ -256,21 +257,21 @@ namespace DotRecast.Recast.Toolset.Tools // Find nearest point on navmesh and set move request to that location. DtNavMeshQuery navquery = crowd.GetNavMeshQuery(); IDtQueryFilter filter = crowd.GetFilter(0); - RcVec3f halfExtents = crowd.GetQueryExtents(); + Vector3 halfExtents = crowd.GetQueryExtents(); if (adjust) { // Request velocity if (_agentDebug.agent != null) { - RcVec3f vel = CalcVel(_agentDebug.agent.npos, p, _agentDebug.agent.option.maxSpeed); + Vector3 vel = CalcVel(_agentDebug.agent.npos, p, _agentDebug.agent.option.maxSpeed); crowd.RequestMoveVelocity(_agentDebug.agent, vel); } else { foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { - RcVec3f vel = CalcVel(ag.npos, p, ag.option.maxSpeed); + Vector3 vel = CalcVel(ag.npos, p, ag.option.maxSpeed); crowd.RequestMoveVelocity(ag, vel); } } @@ -292,11 +293,11 @@ namespace DotRecast.Recast.Toolset.Tools } } - private RcVec3f CalcVel(RcVec3f pos, RcVec3f tgt, float speed) + private Vector3 CalcVel(Vector3 pos, Vector3 tgt, float speed) { - RcVec3f vel = RcVec3f.Subtract(tgt, pos); + Vector3 vel = Vector3.Subtract(tgt, pos); vel.Y = 0.0f; - vel = RcVec3f.Normalize(vel); + vel = Vector3.Normalize(vel); return vel.Scale(speed); } diff --git a/src/DotRecast.Recast.Toolset/Tools/RcDynamicUpdateTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcDynamicUpdateTool.cs index 6900279..4c8092c 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcDynamicUpdateTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcDynamicUpdateTool.cs @@ -4,6 +4,7 @@ using System.IO; using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic; using DotRecast.Detour.Dynamic.Colliders; using DotRecast.Detour.Dynamic.Io; @@ -47,7 +48,7 @@ namespace DotRecast.Recast.Toolset.Tools return dynaMesh; } - public void RemoveShape(RcVec3f start, RcVec3f dir) + public void RemoveShape(Vector3 start, Vector3 dir) { foreach (var e in colliderGizmos) { @@ -60,7 +61,7 @@ namespace DotRecast.Recast.Toolset.Tools } } - private bool Hit(RcVec3f point, RcVec3f dir, float[] bounds) + private bool Hit(Vector3 point, Vector3 dir, float[] bounds) { float cx = 0.5f * (bounds[0] + bounds[3]); float cy = 0.5f * (bounds[1] + bounds[4]); @@ -89,7 +90,7 @@ namespace DotRecast.Recast.Toolset.Tools } - public RcGizmo AddShape(RcDynamicColliderShape colliderShape, RcVec3f p) + public RcGizmo AddShape(RcDynamicColliderShape colliderShape, Vector3 p) { if (dynaMesh == null) { @@ -166,7 +167,7 @@ namespace DotRecast.Recast.Toolset.Tools } - public RcGizmo SphereCollider(RcVec3f p, float walkableClimb) + public RcGizmo SphereCollider(Vector3 p, float walkableClimb) { float radius = 1 + (float)random.NextDouble() * 10; var collider = new DtSphereCollider(p, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb); @@ -175,86 +176,86 @@ namespace DotRecast.Recast.Toolset.Tools return new RcGizmo(collider, gizmo); } - public RcGizmo CapsuleCollider(RcVec3f p, float walkableClimb) + public RcGizmo CapsuleCollider(Vector3 p, float walkableClimb) { float radius = 0.4f + (float)random.NextDouble() * 4f; - RcVec3f a = new RcVec3f( + Vector3 a = new Vector3( (1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble()) ); - a = RcVec3f.Normalize(a); + a = Vector3.Normalize(a); float len = 1f + (float)random.NextDouble() * 20f; a.X *= len; a.Y *= len; a.Z *= len; - RcVec3f start = new RcVec3f(p.X, p.Y, p.Z); - RcVec3f end = new RcVec3f(p.X + a.X, p.Y + a.Y, p.Z + a.Z); + Vector3 start = new Vector3(p.X, p.Y, p.Z); + Vector3 end = new Vector3(p.X + a.X, p.Y + a.Y, p.Z + a.Z); var collider = new DtCapsuleCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb); var gizmo = RcGizmoFactory.Capsule(start, end, radius); return new RcGizmo(collider, gizmo); } - public RcGizmo BoxCollider(RcVec3f p, float walkableClimb) + public RcGizmo BoxCollider(Vector3 p, float walkableClimb) { - RcVec3f extent = new RcVec3f( + Vector3 extent = new Vector3( 0.5f + (float)random.NextDouble() * 6f, 0.5f + (float)random.NextDouble() * 6f, 0.5f + (float)random.NextDouble() * 6f ); - RcVec3f forward = new RcVec3f((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); - RcVec3f up = new RcVec3f((1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble())); - RcVec3f[] halfEdges = Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(up, forward, extent); + Vector3 forward = new Vector3((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); + Vector3 up = new Vector3((1f - 2 * (float)random.NextDouble()), 0.01f + (float)random.NextDouble(), (1f - 2 * (float)random.NextDouble())); + Vector3[] halfEdges = Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(up, forward, extent); var collider = new DtBoxCollider(p, halfEdges, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb); var gizmo = RcGizmoFactory.Box(p, halfEdges); return new RcGizmo(collider, gizmo); } - public RcGizmo CylinderCollider(RcVec3f p, float walkableClimb) + public RcGizmo CylinderCollider(Vector3 p, float walkableClimb) { float radius = 0.7f + (float)random.NextDouble() * 4f; - RcVec3f a = new RcVec3f(1f - 2 * (float)random.NextDouble(), 0.01f + (float)random.NextDouble(), 1f - 2 * (float)random.NextDouble()); - a = RcVec3f.Normalize(a); + Vector3 a = new Vector3(1f - 2 * (float)random.NextDouble(), 0.01f + (float)random.NextDouble(), 1f - 2 * (float)random.NextDouble()); + a = Vector3.Normalize(a); float len = 2f + (float)random.NextDouble() * 20f; a.X *= len; a.Y *= len; a.Z *= len; - RcVec3f start = new RcVec3f(p.X, p.Y, p.Z); - RcVec3f end = new RcVec3f(p.X + a.X, p.Y + a.Y, p.Z + a.Z); + Vector3 start = new Vector3(p.X, p.Y, p.Z); + Vector3 end = new Vector3(p.X + a.X, p.Y + a.Y, p.Z + a.Z); var collider = new DtCylinderCollider(start, end, radius, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_WATER, walkableClimb); var gizmo = RcGizmoFactory.Cylinder(start, end, radius); return new RcGizmo(collider, gizmo); } - public RcGizmo CompositeCollider(RcVec3f p, float walkableClimb) + public RcGizmo CompositeCollider(Vector3 p, float walkableClimb) { - RcVec3f baseExtent = new RcVec3f(5, 3, 8); - RcVec3f baseCenter = new RcVec3f(p.X, p.Y + 3, p.Z); - RcVec3f baseUp = new RcVec3f(0, 1, 0); - RcVec3f forward = new RcVec3f((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); - forward = RcVec3f.Normalize(forward); + Vector3 baseExtent = new Vector3(5, 3, 8); + Vector3 baseCenter = new Vector3(p.X, p.Y + 3, p.Z); + Vector3 baseUp = new Vector3(0, 1, 0); + Vector3 forward = new Vector3((1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble())); + forward = Vector3.Normalize(forward); - RcVec3f side = RcVec3f.Cross(forward, baseUp); + Vector3 side = Vector3.Cross(forward, baseUp); DtBoxCollider @base = new DtBoxCollider(baseCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(baseUp, forward, baseExtent), SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb); - var roofUp = RcVec3f.Zero; - RcVec3f roofExtent = new RcVec3f(4.5f, 4.5f, 8f); + var roofUp = Vector3.Zero; + Vector3 roofExtent = new Vector3(4.5f, 4.5f, 8f); var rx = RcMatrix4x4f.CreateFromRotate(45, forward.X, forward.Y, forward.Z); roofUp = MulMatrixVector(ref roofUp, rx, baseUp); - RcVec3f roofCenter = new RcVec3f(p.X, p.Y + 6, p.Z); + Vector3 roofCenter = new Vector3(p.X, p.Y + 6, p.Z); DtBoxCollider roof = new DtBoxCollider(roofCenter, Detour.Dynamic.Colliders.DtBoxCollider.GetHalfEdges(roofUp, forward, roofExtent), SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb); - RcVec3f trunkStart = new RcVec3f( + Vector3 trunkStart = new Vector3( baseCenter.X - forward.X * 15 + side.X * 6, p.Y, baseCenter.Z - forward.Z * 15 + side.Z * 6 ); - RcVec3f trunkEnd = new RcVec3f(trunkStart.X, trunkStart.Y + 10, trunkStart.Z); + Vector3 trunkEnd = new Vector3(trunkStart.X, trunkStart.Y + 10, trunkStart.Z); DtCapsuleCollider trunk = new DtCapsuleCollider(trunkStart, trunkEnd, 0.5f, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, walkableClimb); - RcVec3f crownCenter = new RcVec3f( + Vector3 crownCenter = new Vector3( baseCenter.X - forward.X * 15 + side.X * 6, p.Y + 10, baseCenter.Z - forward.Z * 15 + side.Z * 6 ); @@ -269,17 +270,17 @@ namespace DotRecast.Recast.Toolset.Tools return new RcGizmo(collider, gizmo); } - public RcGizmo TrimeshBridge(RcVec3f p, float walkableClimb) + public RcGizmo TrimeshBridge(Vector3 p, float walkableClimb) { return TrimeshCollider(p, bridgeGeom, walkableClimb); } - public RcGizmo TrimeshHouse(RcVec3f p, float walkableClimb) + public RcGizmo TrimeshHouse(Vector3 p, float walkableClimb) { return TrimeshCollider(p, houseGeom, walkableClimb); } - public RcGizmo ConvexTrimesh(RcVec3f p, float walkableClimb) + public RcGizmo ConvexTrimesh(Vector3 p, float walkableClimb) { float[] verts = TransformVertices(p, convexGeom, 360); var collider = new DtConvexTrimeshCollider(verts, convexGeom.faces, @@ -288,7 +289,7 @@ namespace DotRecast.Recast.Toolset.Tools return new RcGizmo(collider, gizmo); } - private RcGizmo TrimeshCollider(RcVec3f p, DemoInputGeomProvider geom, float walkableClimb) + private RcGizmo TrimeshCollider(Vector3 p, DemoInputGeomProvider geom, float walkableClimb) { float[] verts = TransformVertices(p, geom, 0); var collider = new DtTrimeshCollider(verts, geom.faces, SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, @@ -298,14 +299,14 @@ namespace DotRecast.Recast.Toolset.Tools return new RcGizmo(collider, gizmo); } - private float[] TransformVertices(RcVec3f p, DemoInputGeomProvider geom, float ax) + private float[] TransformVertices(Vector3 p, DemoInputGeomProvider geom, float ax) { var rx = RcMatrix4x4f.CreateFromRotate((float)random.NextDouble() * ax, 1, 0, 0); var ry = RcMatrix4x4f.CreateFromRotate((float)random.NextDouble() * 360, 0, 1, 0); var m = RcMatrix4x4f.Mul(ref rx, ref ry); float[] verts = new float[geom.vertices.Length]; - RcVec3f v = new RcVec3f(); - RcVec3f vr = new RcVec3f(); + Vector3 v = new Vector3(); + Vector3 vr = new Vector3(); for (int i = 0; i < geom.vertices.Length; i += 3) { v.X = geom.vertices[i]; @@ -331,7 +332,7 @@ namespace DotRecast.Recast.Toolset.Tools return resultvector; } - private static RcVec3f MulMatrixVector(ref RcVec3f resultvector, RcMatrix4x4f matrix, RcVec3f pvector) + private static Vector3 MulMatrixVector(ref Vector3 resultvector, RcMatrix4x4f matrix, Vector3 pvector) { resultvector.X = matrix.M11 * pvector.X + matrix.M21 * pvector.Y + matrix.M31 * pvector.Z; resultvector.Y = matrix.M12 * pvector.X + matrix.M22 * pvector.Y + matrix.M32 * pvector.Z; @@ -355,14 +356,14 @@ namespace DotRecast.Recast.Toolset.Tools return true; } - public bool Raycast(RcVec3f spos, RcVec3f epos, out float hitPos, out RcVec3f raycastHitPos) + public bool Raycast(Vector3 spos, Vector3 epos, out float hitPos, out Vector3 raycastHitPos) { - RcVec3f sp = new RcVec3f(spos.X, spos.Y + 1.3f, spos.Z); - RcVec3f ep = new RcVec3f(epos.X, epos.Y + 1.3f, epos.Z); + Vector3 sp = new Vector3(spos.X, spos.Y + 1.3f, spos.Z); + Vector3 ep = new Vector3(epos.X, epos.Y + 1.3f, epos.Z); bool hasHit = dynaMesh.VoxelQuery().Raycast(sp, ep, out hitPos); raycastHitPos = hasHit - ? new RcVec3f(sp.X + hitPos * (ep.X - sp.X), sp.Y + hitPos * (ep.Y - sp.Y), sp.Z + hitPos * (ep.Z - sp.Z)) + ? new Vector3(sp.X + hitPos * (ep.X - sp.X), sp.Y + hitPos * (ep.Y - sp.Y), sp.Z + hitPos * (ep.Z - sp.Z)) : ep; return hasHit; diff --git a/src/DotRecast.Recast.Toolset/Tools/RcJumpLinkBuilderTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcJumpLinkBuilderTool.cs index 105ca24..38397a6 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcJumpLinkBuilderTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcJumpLinkBuilderTool.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Extras.Jumplink; using DotRecast.Recast.Geom; using DotRecast.Recast.Toolset.Builder; @@ -111,11 +112,11 @@ namespace DotRecast.Recast.Toolset.Tools { int area = SampleAreaModifications.SAMPLE_POLYAREA_TYPE_JUMP_AUTO; int flags = SampleAreaModifications.SAMPLE_POLYFLAGS_JUMP; - RcVec3f prev = new RcVec3f(); + Vector3 prev = new Vector3(); for (int i = 0; i < link.startSamples.Length; i++) { - RcVec3f p = link.startSamples[i].p; - RcVec3f q = link.endSamples[i].p; + Vector3 p = link.startSamples[i].p; + Vector3 q = link.endSamples[i].p; if (i == 0 || RcVecUtils.Dist2D(prev, p) > agentRadius) { geom.AddOffMeshConnection(p, q, agentRadius, false, area, flags); diff --git a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index 68e22e1..a480224 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -3,6 +3,7 @@ using System.Linq; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Detour.TileCache; using DotRecast.Detour.TileCache.Io.Compress; @@ -96,7 +97,7 @@ namespace DotRecast.Recast.Toolset.Tools } } - public void RemoveTempObstacle(RcVec3f sp, RcVec3f sq) + public void RemoveTempObstacle(Vector3 sp, Vector3 sq) { if (null == _tc) return; @@ -105,7 +106,7 @@ namespace DotRecast.Recast.Toolset.Tools _tc.RemoveObstacle(refs); } - public long AddTempObstacle(RcVec3f p) + public long AddTempObstacle(Vector3 p) { if (null == _tc) return 0; @@ -148,7 +149,7 @@ namespace DotRecast.Recast.Toolset.Tools return tc; } - public long HitTestObstacle(RcVec3f sp, RcVec3f sq) + public long HitTestObstacle(Vector3 sp, Vector3 sq) { float tmin = float.MaxValue; DtTileCacheObstacle obmin = null; @@ -159,8 +160,8 @@ namespace DotRecast.Recast.Toolset.Tools if (ob.state == DtObstacleState.DT_OBSTACLE_EMPTY) continue; - RcVec3f bmin = RcVec3f.Zero; - RcVec3f bmax = RcVec3f.Zero; + Vector3 bmin = Vector3.Zero; + Vector3 bmax = Vector3.Zero; _tc.GetObstacleBounds(ob, ref bmin, ref bmax); if (RcIntersections.IsectSegAABB(sp, sq, bmin, bmax, out var t0, out var t1)) diff --git a/src/DotRecast.Recast.Toolset/Tools/RcOffMeshConnectionTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcOffMeshConnectionTool.cs index 2d7a960..969d1e8 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcOffMeshConnectionTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcOffMeshConnectionTool.cs @@ -1,5 +1,6 @@ using System; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; using DotRecast.Recast.Toolset.Builder; @@ -16,7 +17,7 @@ namespace DotRecast.Recast.Toolset.Tools return "Off-Mesh Links"; } - public void Add(IInputGeomProvider geom, RcNavMeshBuildSettings settings, RcVec3f start, RcVec3f end, bool bidir) + public void Add(IInputGeomProvider geom, RcNavMeshBuildSettings settings, Vector3 start, Vector3 end, bool bidir) { if (null == geom) return; @@ -26,7 +27,7 @@ namespace DotRecast.Recast.Toolset.Tools geom.AddOffMeshConnection(start, end, settings.agentRadius, bidir, area, flags); } - public void Remove(IInputGeomProvider geom, RcNavMeshBuildSettings settings, RcVec3f p) + public void Remove(IInputGeomProvider geom, RcNavMeshBuildSettings settings, Vector3 p) { // Delete // Find nearest link end-point diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index b8dac40..f756c46 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; namespace DotRecast.Recast.Toolset.Tools @@ -21,8 +22,8 @@ namespace DotRecast.Recast.Toolset.Tools return "Test Navmesh"; } - public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPt, RcVec3f endPt, IDtQueryFilter filter, bool enableRaycast, - ref List polys, ref List smoothPath) + public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 startPt, Vector3 endPt, IDtQueryFilter filter, bool enableRaycast, + ref List polys, ref List smoothPath) { if (startRef == 0 || endRef == 0) { @@ -33,7 +34,7 @@ namespace DotRecast.Recast.Toolset.Tools } polys ??= new List(); - smoothPath ??= new List(); + smoothPath ??= new List(); polys.Clear(); smoothPath.Clear(); @@ -73,8 +74,8 @@ namespace DotRecast.Recast.Toolset.Tools : false; // Find movement delta. - RcVec3f delta = RcVec3f.Subtract(steerPos, iterPos); - float len = MathF.Sqrt(RcVec3f.Dot(delta, delta)); + Vector3 delta = Vector3.Subtract(steerPos, iterPos); + float len = MathF.Sqrt(Vector3.Dot(delta, delta)); // If the steer target is end of path or off-mesh link, do not move past the location. if ((endOfPath || offMeshConnection) && len < STEP_SIZE) { @@ -85,7 +86,7 @@ namespace DotRecast.Recast.Toolset.Tools len = STEP_SIZE / len; } - RcVec3f moveTgt = RcVecUtils.Mad(iterPos, delta, len); + Vector3 moveTgt = RcVecUtils.Mad(iterPos, delta, len); // Move navQuery.MoveAlongSurface(polys[0], iterPos, moveTgt, filter, out var result, ref visited); @@ -116,8 +117,8 @@ namespace DotRecast.Recast.Toolset.Tools else if (offMeshConnection && DtPathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached off-mesh connection. - RcVec3f startPos = RcVec3f.Zero; - RcVec3f endPos = RcVec3f.Zero; + Vector3 startPos = Vector3.Zero; + Vector3 endPos = Vector3.Zero; // Advance the path up to and over the off-mesh connection. long prevRef = 0; @@ -163,7 +164,7 @@ namespace DotRecast.Recast.Toolset.Tools return DtStatus.DT_SUCCESS; } - public DtStatus FindStraightPath(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPt, RcVec3f endPt, IDtQueryFilter filter, bool enableRaycast, + public DtStatus FindStraightPath(DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 startPt, Vector3 endPt, IDtQueryFilter filter, bool enableRaycast, ref List polys, ref List straightPath, int straightPathOptions) { if (startRef == 0 || endRef == 0) @@ -184,7 +185,7 @@ namespace DotRecast.Recast.Toolset.Tools return DtStatus.DT_FAILURE; // In case of partial path, make sure the end point is clamped to the last polygon. - var epos = new RcVec3f(endPt.X, endPt.Y, endPt.Z); + var epos = new Vector3(endPt.X, endPt.Y, endPt.Z); if (polys[polys.Count - 1] != endRef) { var result = navQuery.ClosestPointOnPoly(polys[polys.Count - 1], endPt, out var closest, out var _); @@ -199,7 +200,7 @@ namespace DotRecast.Recast.Toolset.Tools return DtStatus.DT_SUCCESS; } - public DtStatus InitSlicedFindPath(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, bool enableRaycast) + public DtStatus InitSlicedFindPath(DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, bool enableRaycast) { if (startRef == 0 || endRef == 0) { @@ -212,7 +213,7 @@ namespace DotRecast.Recast.Toolset.Tools ); } - public DtStatus UpdateSlicedFindPath(DtNavMeshQuery navQuery, int maxIter, long endRef, RcVec3f startPos, RcVec3f endPos, + public DtStatus UpdateSlicedFindPath(DtNavMeshQuery navQuery, int maxIter, long endRef, Vector3 startPos, Vector3 endPos, ref List path, ref List straightPath) { var status = navQuery.UpdateSlicedFindPath(maxIter, out _); @@ -228,7 +229,7 @@ namespace DotRecast.Recast.Toolset.Tools if (path != null) { // In case of partial path, make sure the end point is clamped to the last polygon. - RcVec3f epos = endPos; + Vector3 epos = endPos; if (path[path.Count - 1] != endRef) { var result = navQuery.ClosestPointOnPoly(path[path.Count - 1], endPos, out var closest, out var _); @@ -246,8 +247,8 @@ namespace DotRecast.Recast.Toolset.Tools } - public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, - ref List polys, ref List straightPath, ref RcVec3f hitPos, ref RcVec3f hitNormal, ref bool hitResult) + public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 startPos, Vector3 endPos, IDtQueryFilter filter, + ref List polys, ref List straightPath, ref Vector3 hitPos, ref Vector3 hitNormal, ref bool hitResult) { if (startRef == 0 || endRef == 0) { @@ -275,7 +276,7 @@ namespace DotRecast.Recast.Toolset.Tools else { // Hit - hitPos = RcVec3f.Lerp(startPos, endPos, rayHit.t); + hitPos = Vector3.Lerp(startPos, endPos, rayHit.t); hitNormal = rayHit.hitNormal; hitResult = true; } @@ -298,8 +299,8 @@ namespace DotRecast.Recast.Toolset.Tools return status; } - public DtStatus FindDistanceToWall(DtNavMeshQuery navQuery, long startRef, RcVec3f spos, float maxRadius, IDtQueryFilter filter, - ref float hitDist, ref RcVec3f hitPos, ref RcVec3f hitNormal) + public DtStatus FindDistanceToWall(DtNavMeshQuery navQuery, long startRef, Vector3 spos, float maxRadius, IDtQueryFilter filter, + ref float hitDist, ref Vector3 hitPos, ref Vector3 hitNormal) { if (0 == startRef) { @@ -320,7 +321,7 @@ namespace DotRecast.Recast.Toolset.Tools } - public DtStatus FindPolysAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, ref List resultRef, ref List resultParent) + public DtStatus FindPolysAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 spos, Vector3 epos, IDtQueryFilter filter, ref List resultRef, ref List resultParent) { if (startRef == 0 || endRef == 0) { @@ -344,7 +345,7 @@ namespace DotRecast.Recast.Toolset.Tools return status; } - public DtStatus FindLocalNeighbourhood(DtNavMeshQuery navQuery, long startRef, RcVec3f spos, float radius, IDtQueryFilter filter, + public DtStatus FindLocalNeighbourhood(DtNavMeshQuery navQuery, long startRef, Vector3 spos, float radius, IDtQueryFilter filter, ref List resultRef, ref List resultParent) { if (startRef == 0) @@ -365,8 +366,8 @@ namespace DotRecast.Recast.Toolset.Tools } - public DtStatus FindPolysAroundShape(DtNavMeshQuery navQuery, float agentHeight, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, - ref List resultRefs, ref List resultParents, ref RcVec3f[] queryPoly) + public DtStatus FindPolysAroundShape(DtNavMeshQuery navQuery, float agentHeight, long startRef, long endRef, Vector3 spos, Vector3 epos, IDtQueryFilter filter, + ref List resultRefs, ref List resultParents, ref Vector3[] queryPoly) { if (startRef == 0 || endRef == 0) { @@ -376,7 +377,7 @@ namespace DotRecast.Recast.Toolset.Tools float nx = (epos.Z - spos.Z) * 0.25f; float nz = -(epos.X - spos.X) * 0.25f; - var tempQueryPoly = new RcVec3f[4]; + var tempQueryPoly = new Vector3[4]; tempQueryPoly[0].X = spos.X + nx * 1.2f; tempQueryPoly[0].Y = spos.Y + agentHeight / 2; tempQueryPoly[0].Z = spos.Z + nz * 1.2f; @@ -407,8 +408,8 @@ namespace DotRecast.Recast.Toolset.Tools return status; } - public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f spos, RcVec3f epos, IDtQueryFilter filter, bool constrainByCircle, int count, - ref List points) + public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startRef, long endRef, Vector3 spos, Vector3 epos, IDtQueryFilter filter, bool constrainByCircle, int count, + ref List points) { if (startRef == 0 || endRef == 0) { @@ -426,7 +427,7 @@ namespace DotRecast.Recast.Toolset.Tools var frand = new RcRand(); int prevCnt = points.Count; - points = new List(); + points = new List(); while (0 < count && points.Count < prevCnt + count) { var status = navQuery.FindRandomPointAroundCircle(startRef, spos, dist, filter, frand, constraint, diff --git a/src/DotRecast.Recast.Toolset/Tools/RcTileTool.cs b/src/DotRecast.Recast.Toolset/Tools/RcTileTool.cs index 020b6ce..b7a43b5 100644 --- a/src/DotRecast.Recast.Toolset/Tools/RcTileTool.cs +++ b/src/DotRecast.Recast.Toolset/Tools/RcTileTool.cs @@ -2,6 +2,7 @@ using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour; using DotRecast.Recast.Geom; using DotRecast.Recast.Toolset.Builder; @@ -74,8 +75,8 @@ namespace DotRecast.Recast.Toolset.Tools return false; } - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); RcConfig cfg = new RcConfig( true, settings.tileSize, settings.tileSize, @@ -112,7 +113,7 @@ namespace DotRecast.Recast.Toolset.Tools return true; } - public bool BuildTile(IInputGeomProvider geom, RcNavMeshBuildSettings settings, DtNavMesh navMesh, RcVec3f pos, out long tileBuildTicks, out int tileTriCount, out int tileMemUsage) + public bool BuildTile(IInputGeomProvider geom, RcNavMeshBuildSettings settings, DtNavMesh navMesh, Vector3 pos, out long tileBuildTicks, out int tileTriCount, out int tileMemUsage) { tileBuildTicks = 0; tileTriCount = 0; @@ -123,8 +124,8 @@ namespace DotRecast.Recast.Toolset.Tools float ts = settings.tileSize * settings.cellSize; - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); int tx = (int)((pos.X - bmin.X) / ts); int ty = (int)((pos.Z - bmin.Z) / ts); @@ -132,7 +133,7 @@ namespace DotRecast.Recast.Toolset.Tools return BuildTile(geom, settings, navMesh, tx, ty, out tileBuildTicks, out tileTriCount, out tileMemUsage); } - public bool RemoveTile(IInputGeomProvider geom, RcNavMeshBuildSettings settings, DtNavMesh navMesh, RcVec3f pos) + public bool RemoveTile(IInputGeomProvider geom, RcNavMeshBuildSettings settings, DtNavMesh navMesh, Vector3 pos) { if (null == settings || null == geom || navMesh == null) return false; diff --git a/src/DotRecast.Recast/Geom/BoundsItem.cs b/src/DotRecast.Recast/Geom/BoundsItem.cs index d9e9f99..727f883 100644 --- a/src/DotRecast.Recast/Geom/BoundsItem.cs +++ b/src/DotRecast.Recast/Geom/BoundsItem.cs @@ -1,11 +1,12 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { public class BoundsItem { - public RcVec2f bmin; - public RcVec2f bmax; + public Vector2 bmin; + public Vector2 bmax; public int i; } } \ No newline at end of file diff --git a/src/DotRecast.Recast/Geom/IInputGeomProvider.cs b/src/DotRecast.Recast/Geom/IInputGeomProvider.cs index 32215bb..77ae02f 100644 --- a/src/DotRecast.Recast/Geom/IInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/IInputGeomProvider.cs @@ -21,15 +21,16 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { public interface IInputGeomProvider { RcTriMesh GetMesh(); - RcVec3f GetMeshBoundsMin(); + Vector3 GetMeshBoundsMin(); - RcVec3f GetMeshBoundsMax(); + Vector3 GetMeshBoundsMax(); IEnumerable Meshes(); @@ -39,7 +40,7 @@ namespace DotRecast.Recast.Geom // off mesh connections public List GetOffMeshConnections(); - public void AddOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags); + public void AddOffMeshConnection(Vector3 start, Vector3 end, float radius, bool bidir, int area, int flags); public void RemoveOffMeshConnections(Predicate filter); } diff --git a/src/DotRecast.Recast/Geom/RcChunkyTriMesh.cs b/src/DotRecast.Recast/Geom/RcChunkyTriMesh.cs index 361483a..fbf8431 100644 --- a/src/DotRecast.Recast/Geom/RcChunkyTriMesh.cs +++ b/src/DotRecast.Recast/Geom/RcChunkyTriMesh.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { @@ -30,7 +31,7 @@ namespace DotRecast.Recast.Geom private int ntris; private int maxTrisPerChunk; - private void CalcExtends(BoundsItem[] items, int imin, int imax, ref RcVec2f bmin, ref RcVec2f bmax) + private void CalcExtends(BoundsItem[] items, int imin, int imax, ref Vector2 bmin, ref Vector2 bmax) { bmin.X = items[imin].bmin.X; bmin.Y = items[imin].bmin.Y; @@ -185,7 +186,7 @@ namespace DotRecast.Recast.Geom } } - private bool CheckOverlapRect(float[] amin, float[] amax, RcVec2f bmin, RcVec2f bmax) + private bool CheckOverlapRect(float[] amin, float[] amax, Vector2 bmin, Vector2 bmax) { bool overlap = true; overlap = (amin[0] > bmax.X || amax[0] < bmin.X) ? false : overlap; @@ -222,7 +223,7 @@ namespace DotRecast.Recast.Geom return ids; } - public List GetChunksOverlappingSegment(RcVec2f p, RcVec2f q) + public List GetChunksOverlappingSegment(Vector2 p, Vector2 q) { // Traverse tree List ids = new List(); @@ -251,13 +252,13 @@ namespace DotRecast.Recast.Geom return ids; } - private bool CheckOverlapSegment(RcVec2f p, RcVec2f q, RcVec2f bmin, RcVec2f bmax) + private bool CheckOverlapSegment(Vector2 p, Vector2 q, Vector2 bmin, Vector2 bmax) { const float EPSILON = 1e-6f; float tmin = 0; float tmax = 1; - var d = new RcVec2f(); + var d = new Vector2(); d.X = q.X - p.X; d.Y = q.Y - p.Y; diff --git a/src/DotRecast.Recast/Geom/RcChunkyTriMeshNode.cs b/src/DotRecast.Recast/Geom/RcChunkyTriMeshNode.cs index 830c6c1..bf46f1a 100644 --- a/src/DotRecast.Recast/Geom/RcChunkyTriMeshNode.cs +++ b/src/DotRecast.Recast/Geom/RcChunkyTriMeshNode.cs @@ -1,11 +1,12 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { public class RcChunkyTriMeshNode { - public RcVec2f bmin; - public RcVec2f bmax; + public Vector2 bmin; + public Vector2 bmax; public int i; public int[] tris; } diff --git a/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs b/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs index 599c53a..0ad2a36 100644 --- a/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs +++ b/src/DotRecast.Recast/Geom/RcOffMeshConnection.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { @@ -33,7 +34,7 @@ namespace DotRecast.Recast.Geom public readonly int flags; public readonly int userId; - public RcOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags) + public RcOffMeshConnection(Vector3 start, Vector3 end, float radius, bool bidir, int area, int flags) { verts = new float[6]; verts[0] = start.X; diff --git a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs index ec08dd2..e7083c1 100644 --- a/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs +++ b/src/DotRecast.Recast/Geom/SimpleInputGeomProvider.cs @@ -23,6 +23,7 @@ using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast.Geom { @@ -31,8 +32,8 @@ namespace DotRecast.Recast.Geom public readonly float[] vertices; public readonly int[] faces; public readonly float[] normals; - private RcVec3f bmin; - private RcVec3f bmax; + private Vector3 bmin; + private Vector3 bmax; private readonly List volumes = new List(); private readonly RcTriMesh _mesh; @@ -93,12 +94,12 @@ namespace DotRecast.Recast.Geom return _mesh; } - public RcVec3f GetMeshBoundsMin() + public Vector3 GetMeshBoundsMin() { return bmin; } - public RcVec3f GetMeshBoundsMax() + public Vector3 GetMeshBoundsMax() { return bmax; } @@ -132,7 +133,7 @@ namespace DotRecast.Recast.Geom throw new NotImplementedException(); } - public void AddOffMeshConnection(RcVec3f start, RcVec3f end, float radius, bool bidir, int area, int flags) + public void AddOffMeshConnection(Vector3 start, Vector3 end, float radius, bool bidir, int area, int flags) { throw new NotImplementedException(); } @@ -150,8 +151,8 @@ namespace DotRecast.Recast.Geom int v1 = faces[i + 1] * 3; int v2 = faces[i + 2] * 3; - var e0 = new RcVec3f(); - var e1 = new RcVec3f(); + var e0 = new Vector3(); + var e1 = new Vector3(); e0.X = vertices[v1 + 0] - vertices[v0 + 0]; e0.Y = vertices[v1 + 1] - vertices[v0 + 1]; e0.Z = vertices[v1 + 2] - vertices[v0 + 2]; diff --git a/src/DotRecast.Recast/RcAreas.cs b/src/DotRecast.Recast/RcAreas.cs index 05d8e2c..ef38245 100644 --- a/src/DotRecast.Recast/RcAreas.cs +++ b/src/DotRecast.Recast/RcAreas.cs @@ -22,6 +22,7 @@ using System; using DotRecast.Core; using DotRecast.Core.Collections; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -457,8 +458,8 @@ namespace DotRecast.Recast int zStride = xSize; // For readability // Compute the bounding box of the polygon - RcVec3f bmin = RcVecUtils.Create(verts); - RcVec3f bmax = RcVecUtils.Create(verts); + Vector3 bmin = RcVecUtils.Create(verts); + Vector3 bmax = RcVecUtils.Create(verts); for (int i = 3; i < verts.Length; i += 3) { bmin = RcVecUtils.Min(bmin, verts, i); @@ -539,7 +540,7 @@ namespace DotRecast.Recast continue; } - RcVec3f point = new RcVec3f( + Vector3 point = new Vector3( compactHeightfield.bmin.X + (x + 0.5f) * compactHeightfield.cs, 0, compactHeightfield.bmin.Z + (z + 0.5f) * compactHeightfield.cs @@ -577,13 +578,13 @@ namespace DotRecast.Recast int zStride = xSize; // For readability // Compute the bounding box of the cylinder - RcVec3f cylinderBBMin = new RcVec3f( + Vector3 cylinderBBMin = new Vector3( position[0] - radius, position[1], position[2] - radius ); - RcVec3f cylinderBBMax = new RcVec3f( + Vector3 cylinderBBMax = new Vector3( position[0] + radius, position[1] + height, position[2] + radius @@ -679,7 +680,7 @@ namespace DotRecast.Recast } } - // public static bool PointInPoly(float[] verts, RcVec3f p) + // public static bool PointInPoly(float[] verts, Vector3 p) // { // bool c = false; // int i, j; @@ -703,13 +704,13 @@ namespace DotRecast.Recast /// @param[in] verts The polygon vertices /// @param[in] point The point to check /// @returns true if the point lies within the polygon, false otherwise. - public static bool PointInPoly(float[] verts, RcVec3f point) + public static bool PointInPoly(float[] verts, Vector3 point) { bool inPoly = false; for (int i = 0, j = verts.Length / 3 - 1; i < verts.Length / 3; j = i++) { - RcVec3f vi = new RcVec3f(verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]); - RcVec3f vj = new RcVec3f(verts[j * 3], verts[j * 3 + 1], verts[j * 3 + 2]); + Vector3 vi = new Vector3(verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]); + Vector3 vj = new Vector3(verts[j * 3], verts[j * 3 + 1], verts[j * 3 + 2]); if (vi.Z > point.Z == vj.Z > point.Z) { continue; @@ -753,17 +754,17 @@ namespace DotRecast.Recast int vertIndexB = vertIndex; int vertIndexC = (vertIndex + 1) % numVerts; - RcVec3f vertA = RcVecUtils.Create(verts, vertIndexA * 3); - RcVec3f vertB = RcVecUtils.Create(verts, vertIndexB * 3); - RcVec3f vertC = RcVecUtils.Create(verts, vertIndexC * 3); + Vector3 vertA = RcVecUtils.Create(verts, vertIndexA * 3); + Vector3 vertB = RcVecUtils.Create(verts, vertIndexB * 3); + Vector3 vertC = RcVecUtils.Create(verts, vertIndexC * 3); // From A to B on the x/z plane - RcVec3f prevSegmentDir = RcVec3f.Subtract(vertB, vertA); + Vector3 prevSegmentDir = Vector3.Subtract(vertB, vertA); prevSegmentDir.Y = 0; // Squash onto x/z plane prevSegmentDir = RcVecUtils.SafeNormalize(prevSegmentDir); // From B to C on the x/z plane - RcVec3f currSegmentDir = RcVec3f.Subtract(vertC, vertB); + Vector3 currSegmentDir = Vector3.Subtract(vertC, vertB); currSegmentDir.Y = 0; // Squash onto x/z plane currSegmentDir = RcVecUtils.SafeNormalize(currSegmentDir); diff --git a/src/DotRecast.Recast/RcBuilder.cs b/src/DotRecast.Recast/RcBuilder.cs index 202922c..1cc068b 100644 --- a/src/DotRecast.Recast/RcBuilder.cs +++ b/src/DotRecast.Recast/RcBuilder.cs @@ -24,6 +24,7 @@ using System.Threading; using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; namespace DotRecast.Recast @@ -47,8 +48,8 @@ namespace DotRecast.Recast public List BuildTiles(IInputGeomProvider geom, RcConfig cfg, TaskFactory taskFactory) { - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); List results = new List(); if (null != taskFactory) @@ -66,8 +67,8 @@ namespace DotRecast.Recast public Task BuildTilesAsync(IInputGeomProvider geom, RcConfig cfg, int threads, List results, TaskFactory taskFactory, CancellationToken cancellationToken) { - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); CalcTileCount(bmin, bmax, cfg.Cs, cfg.TileSizeX, cfg.TileSizeZ, out var tw, out var th); Task task; if (1 < threads) @@ -82,7 +83,7 @@ namespace DotRecast.Recast return task; } - private Task BuildSingleThreadAsync(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, + private Task BuildSingleThreadAsync(IInputGeomProvider geom, RcConfig cfg, Vector3 bmin, Vector3 bmax, int tw, int th, List results) { RcAtomicInteger counter = new RcAtomicInteger(0); @@ -97,7 +98,7 @@ namespace DotRecast.Recast return Task.CompletedTask; } - private Task BuildMultiThreadAsync(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, + private Task BuildMultiThreadAsync(IInputGeomProvider geom, RcConfig cfg, Vector3 bmin, Vector3 bmax, int tw, int th, List results, TaskFactory taskFactory, CancellationToken cancellationToken) { RcAtomicInteger counter = new RcAtomicInteger(0); @@ -147,7 +148,7 @@ namespace DotRecast.Recast return Task.WhenAll(tasks.ToArray()); } - public RcBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tx, + public RcBuilderResult BuildTile(IInputGeomProvider geom, RcConfig cfg, Vector3 bmin, Vector3 bmax, int tx, int ty, RcAtomicInteger counter, int total) { RcBuilderResult result = Build(geom, new RcBuilderConfig(cfg, bmin, bmax, tx, ty)); diff --git a/src/DotRecast.Recast/RcBuilderConfig.cs b/src/DotRecast.Recast/RcBuilderConfig.cs index f5bfb9e..a9bb6d1 100644 --- a/src/DotRecast.Recast/RcBuilderConfig.cs +++ b/src/DotRecast.Recast/RcBuilderConfig.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -36,16 +37,16 @@ namespace DotRecast.Recast public readonly int height; /** The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu] **/ - public readonly RcVec3f bmin = new RcVec3f(); + public readonly Vector3 bmin = new Vector3(); /** The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu] **/ - public readonly RcVec3f bmax = new RcVec3f(); + public readonly Vector3 bmax = new Vector3(); - public RcBuilderConfig(RcConfig cfg, RcVec3f bmin, RcVec3f bmax) : this(cfg, bmin, bmax, 0, 0) + public RcBuilderConfig(RcConfig cfg, Vector3 bmin, Vector3 bmax) : this(cfg, bmin, bmax, 0, 0) { } - public RcBuilderConfig(RcConfig cfg, RcVec3f bmin, RcVec3f bmax, int tileX, int tileZ) + public RcBuilderConfig(RcConfig cfg, Vector3 bmin, Vector3 bmax, int tileX, int tileZ) { this.tileX = tileX; this.tileZ = tileZ; diff --git a/src/DotRecast.Recast/RcCommons.cs b/src/DotRecast.Recast/RcCommons.cs index f35b4f0..0a4f575 100644 --- a/src/DotRecast.Recast/RcCommons.cs +++ b/src/DotRecast.Recast/RcCommons.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -98,14 +99,14 @@ namespace DotRecast.Recast // Calculate bounding box. } - public static void CalcGridSize(RcVec3f bmin, RcVec3f bmax, float cs, out int sizeX, out int sizeZ) + public static void CalcGridSize(Vector3 bmin, Vector3 bmax, float cs, out int sizeX, out int sizeZ) { sizeX = (int)((bmax.X - bmin.X) / cs + 0.5f); sizeZ = (int)((bmax.Z - bmin.Z) / cs + 0.5f); } - public static void CalcTileCount(RcVec3f bmin, RcVec3f bmax, float cs, int tileSizeX, int tileSizeZ, out int tw, out int td) + public static void CalcTileCount(Vector3 bmin, Vector3 bmax, float cs, int tileSizeX, int tileSizeZ, out int tw, out int td) { CalcGridSize(bmin, bmax, cs, out var gw, out var gd); tw = (gw + tileSizeX - 1) / tileSizeX; @@ -123,7 +124,7 @@ namespace DotRecast.Recast { int[] areas = new int[nt]; float walkableThr = MathF.Cos(walkableSlopeAngle / 180.0f * MathF.PI); - RcVec3f norm = new RcVec3f(); + Vector3 norm = new Vector3(); for (int i = 0; i < nt; ++i) { int tri = i * 3; @@ -136,12 +137,12 @@ namespace DotRecast.Recast return areas; } - public static void CalcTriNormal(float[] verts, int v0, int v1, int v2, ref RcVec3f norm) + public static void CalcTriNormal(float[] verts, int v0, int v1, int v2, ref Vector3 norm) { var e0 = RcVecUtils.Subtract(verts, v1 * 3, v0 * 3); var e1 = RcVecUtils.Subtract(verts, v2 * 3, v0 * 3); - norm = RcVec3f.Cross(e0, e1); - norm = RcVec3f.Normalize(norm); + norm = Vector3.Cross(e0, e1); + norm = Vector3.Normalize(norm); } @@ -157,7 +158,7 @@ namespace DotRecast.Recast { float walkableThr = MathF.Cos(walkableSlopeAngle / 180.0f * MathF.PI); - RcVec3f norm = new RcVec3f(); + Vector3 norm = new Vector3(); for (int i = 0; i < nt; ++i) { diff --git a/src/DotRecast.Recast/RcCompactHeightfield.cs b/src/DotRecast.Recast/RcCompactHeightfield.cs index 9148d24..0028bcf 100644 --- a/src/DotRecast.Recast/RcCompactHeightfield.cs +++ b/src/DotRecast.Recast/RcCompactHeightfield.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -50,10 +51,10 @@ namespace DotRecast.Recast public int maxRegions; /** The minimum bounds in world space. [(x, y, z)] */ - public RcVec3f bmin = new RcVec3f(); + public Vector3 bmin = new Vector3(); /** The maximum bounds in world space. [(x, y, z)] */ - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmax = new Vector3(); /** The size of each cell. (On the xz-plane.) */ public float cs; diff --git a/src/DotRecast.Recast/RcContourSet.cs b/src/DotRecast.Recast/RcContourSet.cs index ed0e6f1..6101890 100644 --- a/src/DotRecast.Recast/RcContourSet.cs +++ b/src/DotRecast.Recast/RcContourSet.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -30,10 +31,10 @@ namespace DotRecast.Recast public List conts = new List(); /** The minimum bounds in world space. [(x, y, z)] */ - public RcVec3f bmin = new RcVec3f(); + public Vector3 bmin = new Vector3(); /** The maximum bounds in world space. [(x, y, z)] */ - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmax = new Vector3(); /** The size of each cell. (On the xz-plane.) */ public float cs; diff --git a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs index ac0a2c4..af79e23 100644 --- a/src/DotRecast.Recast/RcFilledVolumeRasterization.cs +++ b/src/DotRecast.Recast/RcFilledVolumeRasterization.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.RcConstants; @@ -30,7 +31,7 @@ namespace DotRecast.Recast private const float EPSILON = 0.00001f; private static readonly int[] BOX_EDGES = new[] { 0, 1, 0, 2, 0, 4, 1, 3, 1, 5, 2, 3, 2, 6, 3, 7, 4, 5, 4, 6, 5, 7, 6, 7 }; - public static void RasterizeSphere(RcHeightfield hf, RcVec3f center, float radius, int area, int flagMergeThr, RcTelemetry ctx) + public static void RasterizeSphere(RcHeightfield hf, Vector3 center, float radius, int area, int flagMergeThr, RcTelemetry ctx) { using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_RASTERIZE_SPHERE); float[] bounds = @@ -42,7 +43,7 @@ namespace DotRecast.Recast rectangle => IntersectSphere(rectangle, center, radius * radius)); } - public static void RasterizeCapsule(RcHeightfield hf, RcVec3f start, RcVec3f end, float radius, int area, int flagMergeThr, RcTelemetry ctx) + public static void RasterizeCapsule(RcHeightfield hf, Vector3 start, Vector3 end, float radius, int area, int flagMergeThr, RcTelemetry ctx) { using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_RASTERIZE_CAPSULE); float[] bounds = @@ -51,12 +52,12 @@ namespace DotRecast.Recast Math.Min(start.Z, end.Z) - radius, Math.Max(start.X, end.X) + radius, Math.Max(start.Y, end.Y) + radius, Math.Max(start.Z, end.Z) + radius }; - RcVec3f axis = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + Vector3 axis = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); RasterizationFilledShape(hf, bounds, area, flagMergeThr, rectangle => IntersectCapsule(rectangle, start, end, axis, radius * radius)); } - public static void RasterizeCylinder(RcHeightfield hf, RcVec3f start, RcVec3f end, float radius, int area, int flagMergeThr, RcTelemetry ctx) + public static void RasterizeCylinder(RcHeightfield hf, Vector3 start, Vector3 end, float radius, int area, int flagMergeThr, RcTelemetry ctx) { using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_RASTERIZE_CYLINDER); float[] bounds = @@ -65,23 +66,23 @@ namespace DotRecast.Recast Math.Min(start.Z, end.Z) - radius, Math.Max(start.X, end.X) + radius, Math.Max(start.Y, end.Y) + radius, Math.Max(start.Z, end.Z) + radius }; - RcVec3f axis = new RcVec3f(end.X - start.X, end.Y - start.Y, end.Z - start.Z); + Vector3 axis = new Vector3(end.X - start.X, end.Y - start.Y, end.Z - start.Z); RasterizationFilledShape(hf, bounds, area, flagMergeThr, rectangle => IntersectCylinder(rectangle, start, end, axis, radius * radius)); } - public static void RasterizeBox(RcHeightfield hf, RcVec3f center, RcVec3f[] halfEdges, int area, int flagMergeThr, RcTelemetry ctx) + public static void RasterizeBox(RcHeightfield hf, Vector3 center, Vector3[] halfEdges, int area, int flagMergeThr, RcTelemetry ctx) { using var timer = ctx.ScopedTimer(RcTimerLabel.RC_TIMER_RASTERIZE_BOX); - RcVec3f[] normals = + Vector3[] normals = { - new RcVec3f(halfEdges[0].X, halfEdges[0].Y, halfEdges[0].Z), - new RcVec3f(halfEdges[1].X, halfEdges[1].Y, halfEdges[1].Z), - new RcVec3f(halfEdges[2].X, halfEdges[2].Y, halfEdges[2].Z), + new Vector3(halfEdges[0].X, halfEdges[0].Y, halfEdges[0].Z), + new Vector3(halfEdges[1].X, halfEdges[1].Y, halfEdges[1].Z), + new Vector3(halfEdges[2].X, halfEdges[2].Y, halfEdges[2].Z), }; - normals[0] = RcVec3f.Normalize(normals[0]); - normals[1] = RcVec3f.Normalize(normals[1]); - normals[2] = RcVec3f.Normalize(normals[2]); + normals[0] = Vector3.Normalize(normals[0]); + normals[1] = Vector3.Normalize(normals[1]); + normals[2] = Vector3.Normalize(normals[2]); float[] vertices = new float[8 * 3]; float[] bounds = new float[] @@ -230,7 +231,7 @@ namespace DotRecast.Recast } } - private static float[] IntersectSphere(float[] rectangle, RcVec3f center, float radiusSqr) + private static float[] IntersectSphere(float[] rectangle, Vector3 center, float radiusSqr) { float x = Math.Max(rectangle[0], Math.Min(center.X, rectangle[2])); float y = rectangle[4]; @@ -265,7 +266,7 @@ namespace DotRecast.Recast return new float[] { y + tmin, y + tmax }; } - private static float[] IntersectCapsule(float[] rectangle, RcVec3f start, RcVec3f end, RcVec3f axis, float radiusSqr) + private static float[] IntersectCapsule(float[] rectangle, Vector3 start, Vector3 end, Vector3 axis, float radiusSqr) { float[] s = MergeIntersections(IntersectSphere(rectangle, start, radiusSqr), IntersectSphere(rectangle, end, radiusSqr)); float axisLen2dSqr = axis.X * axis.X + axis.Z * axis.Z; @@ -277,14 +278,14 @@ namespace DotRecast.Recast return s; } - private static float[] IntersectCylinder(float[] rectangle, RcVec3f start, RcVec3f end, RcVec3f axis, float radiusSqr) + private static float[] IntersectCylinder(float[] rectangle, Vector3 start, Vector3 end, Vector3 axis, float radiusSqr) { float[] s = MergeIntersections( - RayCylinderIntersection(new RcVec3f( + RayCylinderIntersection(new Vector3( Math.Clamp(start.X, rectangle[0], rectangle[2]), rectangle[4], Math.Clamp(start.Z, rectangle[1], rectangle[3]) ), start, axis, radiusSqr), - RayCylinderIntersection(new RcVec3f( + RayCylinderIntersection(new Vector3( Math.Clamp(end.X, rectangle[0], rectangle[2]), rectangle[4], Math.Clamp(end.Z, rectangle[1], rectangle[3]) ), start, axis, radiusSqr)); @@ -296,16 +297,16 @@ namespace DotRecast.Recast if (axis.Y * axis.Y > EPSILON) { - RcVec3f[] rectangleOnStartPlane = new RcVec3f[4]; - RcVec3f[] rectangleOnEndPlane = new RcVec3f[4]; - float ds = RcVec3f.Dot(axis, start); - float de = RcVec3f.Dot(axis, end); + Vector3[] rectangleOnStartPlane = new Vector3[4]; + Vector3[] rectangleOnEndPlane = new Vector3[4]; + float ds = Vector3.Dot(axis, start); + float de = Vector3.Dot(axis, end); for (int i = 0; i < 4; i++) { float x = rectangle[(i + 1) & 2]; float z = rectangle[(i & 2) + 1]; - RcVec3f a = new RcVec3f(x, rectangle[4], z); - float dotAxisA = RcVec3f.Dot(axis, a); + Vector3 a = new Vector3(x, rectangle[4], z); + float dotAxisA = Vector3.Dot(axis, a); float t = (ds - dotAxisA) / axis.Y; rectangleOnStartPlane[i].X = x; rectangleOnStartPlane[i].Y = rectangle[4] + t; @@ -326,23 +327,23 @@ namespace DotRecast.Recast return s; } - private static float[] CylinderCapIntersection(RcVec3f start, float radiusSqr, float[] s, int i, RcVec3f[] rectangleOnPlane) + private static float[] CylinderCapIntersection(Vector3 start, float radiusSqr, float[] s, int i, Vector3[] rectangleOnPlane) { int j = (i + 1) % 4; // Ray against sphere intersection - var m = new RcVec3f( + var m = new Vector3( rectangleOnPlane[i].X - start.X, rectangleOnPlane[i].Y - start.Y, rectangleOnPlane[i].Z - start.Z ); - var d = new RcVec3f( + var d = new Vector3( rectangleOnPlane[j].X - rectangleOnPlane[i].X, rectangleOnPlane[j].Y - rectangleOnPlane[i].Y, rectangleOnPlane[j].Z - rectangleOnPlane[i].Z ); - float dl = RcVec3f.Dot(d, d); - float b = RcVec3f.Dot(m, d) / dl; - float c = (RcVec3f.Dot(m, m) - radiusSqr) / dl; + float dl = Vector3.Dot(d, d); + float b = Vector3.Dot(m, d) / dl; + float c = (Vector3.Dot(m, m) - radiusSqr) / dl; float discr = b * b - c; if (discr > EPSILON) { @@ -363,7 +364,7 @@ namespace DotRecast.Recast return s; } - private static float[] SlabsCylinderIntersection(float[] rectangle, RcVec3f start, RcVec3f end, RcVec3f axis, float radiusSqr, float[] s) + private static float[] SlabsCylinderIntersection(float[] rectangle, Vector3 start, Vector3 end, Vector3 axis, float radiusSqr, float[] s) { if (Math.Min(start.X, end.X) < rectangle[0]) { @@ -388,42 +389,42 @@ namespace DotRecast.Recast return s; } - private static float[] XSlabCylinderIntersection(float[] rectangle, RcVec3f start, RcVec3f axis, float radiusSqr, float x) + private static float[] XSlabCylinderIntersection(float[] rectangle, Vector3 start, Vector3 axis, float radiusSqr, float x) { return RayCylinderIntersection(XSlabRayIntersection(rectangle, start, axis, x), start, axis, radiusSqr); } - private static RcVec3f XSlabRayIntersection(float[] rectangle, RcVec3f start, RcVec3f direction, float x) + private static Vector3 XSlabRayIntersection(float[] rectangle, Vector3 start, Vector3 direction, float x) { // 2d intersection of plane and segment float t = (x - start.X) / direction.X; float z = Math.Clamp(start.Z + t * direction.Z, rectangle[1], rectangle[3]); - return new RcVec3f(x, rectangle[4], z); + return new Vector3(x, rectangle[4], z); } - private static float[] ZSlabCylinderIntersection(float[] rectangle, RcVec3f start, RcVec3f axis, float radiusSqr, float z) + private static float[] ZSlabCylinderIntersection(float[] rectangle, Vector3 start, Vector3 axis, float radiusSqr, float z) { return RayCylinderIntersection(ZSlabRayIntersection(rectangle, start, axis, z), start, axis, radiusSqr); } - private static RcVec3f ZSlabRayIntersection(float[] rectangle, RcVec3f start, RcVec3f direction, float z) + private static Vector3 ZSlabRayIntersection(float[] rectangle, Vector3 start, Vector3 direction, float z) { // 2d intersection of plane and segment float t = (z - start.Z) / direction.Z; float x = Math.Clamp(start.X + t * direction.X, rectangle[0], rectangle[2]); - return new RcVec3f(x, rectangle[4], z); + return new Vector3(x, rectangle[4], z); } // Based on Christer Ericsons's "Real-Time Collision Detection" - private static float[] RayCylinderIntersection(RcVec3f point, RcVec3f start, RcVec3f axis, float radiusSqr) + private static float[] RayCylinderIntersection(Vector3 point, Vector3 start, Vector3 axis, float radiusSqr) { - RcVec3f d = axis; - RcVec3f m = new RcVec3f(point.X - start.X, point.Y - start.Y, point.Z - start.Z); + Vector3 d = axis; + Vector3 m = new Vector3(point.X - start.X, point.Y - start.Y, point.Z - start.Z); // float[] n = { 0, 1, 0 }; - float md = RcVec3f.Dot(m, d); + float md = Vector3.Dot(m, d); // float nd = Dot(n, d); float nd = axis.Y; - float dd = RcVec3f.Dot(d, d); + float dd = Vector3.Dot(d, d); // float nn = Dot(n, n); float nn = 1; @@ -431,7 +432,7 @@ namespace DotRecast.Recast float mn = m.Y; // float a = dd * nn - nd * nd; float a = dd - nd * nd; - float k = RcVec3f.Dot(m, m) - radiusSqr; + float k = Vector3.Dot(m, m) - radiusSqr; float c = dd * k - md * md; if (MathF.Abs(a) < EPSILON) { @@ -516,7 +517,7 @@ namespace DotRecast.Recast } // check intersection with rays starting in rectangle vertices - var point = new RcVec3f(0, rectangle[1], 0); + var point = new Vector3(0, rectangle[1], 0); for (int i = 0; i < 4; i++) { point.X = ((i & 1) == 0) ? rectangle[0] : rectangle[2]; @@ -669,7 +670,7 @@ namespace DotRecast.Recast } // rectangle vertex - var point = new RcVec3f(0, rectangle[1], 0); + var point = new Vector3(0, rectangle[1], 0); for (int i = 0; i < 4; i++) { point.X = ((i & 1) == 0) ? rectangle[0] : rectangle[2]; @@ -726,7 +727,7 @@ namespace DotRecast.Recast return false; } - private static bool RayTriangleIntersection(RcVec3f point, int plane, float[][] planes, out float y) + private static bool RayTriangleIntersection(Vector3 point, int plane, float[][] planes, out float y) { y = 0.0f; float t = (planes[plane][3] - RcVecUtils.Dot(planes[plane], point)) / planes[plane][1]; @@ -773,7 +774,7 @@ namespace DotRecast.Recast return dx * dx + dy * dy + dz * dz; } - private static bool OverlapBounds(RcVec3f amin, RcVec3f amax, float[] bounds) + private static bool OverlapBounds(Vector3 amin, Vector3 amax, float[] bounds) { bool overlap = true; overlap = (amin.X > bounds[3] || amax.X < bounds[0]) ? false : overlap; diff --git a/src/DotRecast.Recast/RcHeightfield.cs b/src/DotRecast.Recast/RcHeightfield.cs index dd8b5fc..3b97e12 100644 --- a/src/DotRecast.Recast/RcHeightfield.cs +++ b/src/DotRecast.Recast/RcHeightfield.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -32,10 +33,10 @@ namespace DotRecast.Recast public readonly int height; /** The minimum bounds in world space. [(x, y, z)] */ - public readonly RcVec3f bmin; + public readonly Vector3 bmin; /** The maximum bounds in world space. [(x, y, z)] */ - public RcVec3f bmax; + public Vector3 bmax; /** The size of each cell. (On the xz-plane.) */ public readonly float cs; @@ -49,7 +50,7 @@ namespace DotRecast.Recast /** Border size in cell units */ public readonly int borderSize; - public RcHeightfield(int width, int height, RcVec3f bmin, RcVec3f bmax, float cs, float ch, int borderSize) + public RcHeightfield(int width, int height, Vector3 bmin, Vector3 bmax, float cs, float ch, int borderSize) { this.width = width; this.height = height; diff --git a/src/DotRecast.Recast/RcHeightfieldLayer.cs b/src/DotRecast.Recast/RcHeightfieldLayer.cs index 43b22d5..571dac0 100644 --- a/src/DotRecast.Recast/RcHeightfieldLayer.cs +++ b/src/DotRecast.Recast/RcHeightfieldLayer.cs @@ -1,4 +1,5 @@ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -6,10 +7,10 @@ namespace DotRecast.Recast /// @see rcHeightfieldLayerSet public class RcHeightfieldLayer { - public RcVec3f bmin = new RcVec3f(); + public Vector3 bmin = new Vector3(); /// < The minimum bounds in world space. [(x, y, z)] - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmax = new Vector3(); /// < The maximum bounds in world space. [(x, y, z)] public float cs; diff --git a/src/DotRecast.Recast/RcHeightfieldLayerSet.cs b/src/DotRecast.Recast/RcHeightfieldLayerSet.cs index 72f4347..96e46ac 100644 --- a/src/DotRecast.Recast/RcHeightfieldLayerSet.cs +++ b/src/DotRecast.Recast/RcHeightfieldLayerSet.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { diff --git a/src/DotRecast.Recast/RcLayers.cs b/src/DotRecast.Recast/RcLayers.cs index bffb989..d8b2dd0 100644 --- a/src/DotRecast.Recast/RcLayers.cs +++ b/src/DotRecast.Recast/RcLayers.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -412,8 +413,8 @@ namespace DotRecast.Recast int lh = h - borderSize * 2; // Build contracted bbox for layers. - RcVec3f bmin = chf.bmin; - RcVec3f bmax = chf.bmax; + Vector3 bmin = chf.bmin; + Vector3 bmax = chf.bmax; bmin.X += borderSize * chf.cs; bmin.Z += borderSize * chf.cs; bmax.X -= borderSize * chf.cs; diff --git a/src/DotRecast.Recast/RcMeshDetails.cs b/src/DotRecast.Recast/RcMeshDetails.cs index c1b183e..6c3f4b2 100644 --- a/src/DotRecast.Recast/RcMeshDetails.cs +++ b/src/DotRecast.Recast/RcMeshDetails.cs @@ -22,6 +22,7 @@ using System; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.RcConstants; namespace DotRecast.Recast @@ -45,7 +46,7 @@ namespace DotRecast.Recast return a[0] * b[0] + a[2] * b[2]; } - private static float Vdot2(RcVec3f a, RcVec3f b) + private static float Vdot2(Vector3 a, Vector3 b) { return a.X * b.X + a.Z * b.Z; } @@ -70,7 +71,7 @@ namespace DotRecast.Recast return dx * dx + dy * dy; } - private static float VdistSq2(float[] p, RcVec3f q) + private static float VdistSq2(float[] p, Vector3 q) { float dx = q.X - p[0]; float dy = q.Z - p[2]; @@ -78,7 +79,7 @@ namespace DotRecast.Recast } - private static float VdistSq2(RcVec3f p, RcVec3f q) + private static float VdistSq2(Vector3 p, Vector3 q) { float dx = q.X - p.X; float dy = q.Z - p.Z; @@ -91,12 +92,12 @@ namespace DotRecast.Recast return MathF.Sqrt(VdistSq2(p, q)); } - private static float Vdist2(RcVec3f p, RcVec3f q) + private static float Vdist2(Vector3 p, Vector3 q) { return MathF.Sqrt(VdistSq2(p, q)); } - private static float Vdist2(float[] p, RcVec3f q) + private static float Vdist2(float[] p, Vector3 q) { return MathF.Sqrt(VdistSq2(p, q)); } @@ -109,7 +110,7 @@ namespace DotRecast.Recast return dx * dx + dy * dy; } - private static float VdistSq2(RcVec3f p, float[] verts, int q) + private static float VdistSq2(Vector3 p, float[] verts, int q) { float dx = verts[q + 0] - p.X; float dy = verts[q + 2] - p.Z; @@ -122,7 +123,7 @@ namespace DotRecast.Recast return MathF.Sqrt(VdistSq2(p, verts, q)); } - private static float Vdist2(RcVec3f p, float[] verts, int q) + private static float Vdist2(Vector3 p, float[] verts, int q) { return MathF.Sqrt(VdistSq2(p, verts, q)); } @@ -146,7 +147,7 @@ namespace DotRecast.Recast return u1 * v2 - v1 * u2; } - private static float Vcross2(RcVec3f p1, RcVec3f p2, RcVec3f p3) + private static float Vcross2(Vector3 p1, Vector3 p2, Vector3 p3) { float u1 = p2.X - p1.X; float v1 = p2.Z - p1.Z; @@ -156,11 +157,11 @@ namespace DotRecast.Recast } - private static bool CircumCircle(float[] verts, int p1, int p2, int p3, ref RcVec3f c, RcAtomicFloat r) + private static bool CircumCircle(float[] verts, int p1, int p2, int p3, ref Vector3 c, RcAtomicFloat r) { const float EPS = 1e-6f; // Calculate the circle relative to p1, to avoid some precision issues. - var v1 = new RcVec3f(); + var v1 = new Vector3(); var v2 = RcVecUtils.Subtract(verts, p2, p1); var v3 = RcVecUtils.Subtract(verts, p3, p1); @@ -183,7 +184,7 @@ namespace DotRecast.Recast return false; } - private static float DistPtTri(RcVec3f p, float[] verts, int a, int b, int c) + private static float DistPtTri(Vector3 p, float[] verts, int a, int b, int c) { var v0 = RcVecUtils.Subtract(verts, c, a); var v1 = RcVecUtils.Subtract(verts, b, a); @@ -242,7 +243,7 @@ namespace DotRecast.Recast return dx * dx + dy * dy + dz * dz; } - private static float DistancePtSeg2d(RcVec3f verts, float[] poly, int p, int q) + private static float DistancePtSeg2d(Vector3 verts, float[] poly, int p, int q) { float pqx = poly[q + 0] - poly[p + 0]; float pqz = poly[q + 2] - poly[p + 2]; @@ -298,7 +299,7 @@ namespace DotRecast.Recast return dx * dx + dz * dz; } - private static float DistToTriMesh(RcVec3f p, float[] verts, int nverts, List tris, int ntris) + private static float DistToTriMesh(Vector3 p, float[] verts, int nverts, List tris, int ntris) { float dmin = float.MaxValue; for (int i = 0; i < ntris; ++i) @@ -321,7 +322,7 @@ namespace DotRecast.Recast return dmin; } - private static float DistToPoly(int nvert, float[] verts, RcVec3f p) + private static float DistToPoly(int nvert, float[] verts, Vector3 p) { float dmin = float.MaxValue; int i, j; @@ -533,7 +534,7 @@ namespace DotRecast.Recast // Find best point on left of edge. int pt = npts; - RcVec3f c = new RcVec3f(); + Vector3 c = new Vector3(); RcAtomicFloat r = new RcAtomicFloat(-1f); for (int u = 0; u < npts; ++u) { @@ -1001,8 +1002,8 @@ namespace DotRecast.Recast if (sampleDist > 0) { // Create sample locations in a grid. - RcVec3f bmin = RcVecUtils.Create(@in); - RcVec3f bmax = RcVecUtils.Create(@in); + Vector3 bmin = RcVecUtils.Create(@in); + Vector3 bmax = RcVecUtils.Create(@in); for (int i = 1; i < nin; ++i) { bmin = RcVecUtils.Min(bmin, @in, i * 3); @@ -1018,7 +1019,7 @@ namespace DotRecast.Recast { for (int x = x0; x < x1; ++x) { - RcVec3f pt = new RcVec3f(); + Vector3 pt = new Vector3(); pt.X = x * sampleDist; pt.Y = (bmax.Y + bmin.Y) * 0.5f; pt.Z = z * sampleDist; @@ -1047,7 +1048,7 @@ namespace DotRecast.Recast } // Find sample with most error. - RcVec3f bestpt = new RcVec3f(); + Vector3 bestpt = new Vector3(); float bestd = 0; int besti = -1; for (int i = 0; i < nsamples; ++i) @@ -1058,7 +1059,7 @@ namespace DotRecast.Recast continue; // skip added. } - RcVec3f pt = new RcVec3f(); + Vector3 pt = new Vector3(); // The sample location is jittered to get rid of some bad triangulations // which are cause by symmetrical data from the grid structure. pt.X = samples[s + 0] * sampleDist + GetJitterX(i) * cs * 0.1f; @@ -1441,7 +1442,7 @@ namespace DotRecast.Recast int nvp = mesh.nvp; float cs = mesh.cs; float ch = mesh.ch; - RcVec3f orig = mesh.bmin; + Vector3 orig = mesh.bmin; int borderSize = mesh.borderSize; int heightSearchRadius = (int)Math.Max(1, MathF.Ceiling(mesh.maxEdgeError)); diff --git a/src/DotRecast.Recast/RcMeshs.cs b/src/DotRecast.Recast/RcMeshs.cs index 40e1cf8..b34c672 100644 --- a/src/DotRecast.Recast/RcMeshs.cs +++ b/src/DotRecast.Recast/RcMeshs.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -1231,8 +1232,8 @@ namespace DotRecast.Recast int maxVertsPerMesh = 0; for (int i = 0; i < nmeshes; ++i) { - mesh.bmin = RcVec3f.Min(mesh.bmin, meshes[i].bmin); - mesh.bmax = RcVec3f.Max(mesh.bmax, meshes[i].bmax); + mesh.bmin = Vector3.Min(mesh.bmin, meshes[i].bmin); + mesh.bmax = Vector3.Max(mesh.bmax, meshes[i].bmax); maxVertsPerMesh = Math.Max(maxVertsPerMesh, meshes[i].nverts); maxVerts += meshes[i].nverts; maxPolys += meshes[i].npolys; diff --git a/src/DotRecast.Recast/RcPolyMesh.cs b/src/DotRecast.Recast/RcPolyMesh.cs index f5bbdf6..b6493a4 100644 --- a/src/DotRecast.Recast/RcPolyMesh.cs +++ b/src/DotRecast.Recast/RcPolyMesh.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { @@ -53,10 +54,10 @@ namespace DotRecast.Recast public int[] flags; /** The minimum bounds in world space. [(x, y, z)] */ - public RcVec3f bmin = new RcVec3f(); + public Vector3 bmin = new Vector3(); /** The maximum bounds in world space. [(x, y, z)] */ - public RcVec3f bmax = new RcVec3f(); + public Vector3 bmax = new Vector3(); /** The size of each cell. (On the xz-plane.) */ public float cs; diff --git a/src/DotRecast.Recast/RcPolyMeshRaycast.cs b/src/DotRecast.Recast/RcPolyMeshRaycast.cs index 78af411..2c405c1 100644 --- a/src/DotRecast.Recast/RcPolyMeshRaycast.cs +++ b/src/DotRecast.Recast/RcPolyMeshRaycast.cs @@ -20,12 +20,13 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; namespace DotRecast.Recast { public static class RcPolyMeshRaycast { - public static bool Raycast(IList results, RcVec3f src, RcVec3f dst, out float hitTime) + public static bool Raycast(IList results, Vector3 src, Vector3 dst, out float hitTime) { hitTime = 0.0f; foreach (RcBuilderResult result in results) @@ -42,7 +43,7 @@ namespace DotRecast.Recast return false; } - private static bool Raycast(RcPolyMesh poly, RcPolyMeshDetail meshDetail, RcVec3f sp, RcVec3f sq, out float hitTime) + private static bool Raycast(RcPolyMesh poly, RcPolyMeshDetail meshDetail, Vector3 sp, Vector3 sq, out float hitTime) { hitTime = 0; if (meshDetail != null) @@ -57,7 +58,7 @@ namespace DotRecast.Recast int tris = btris * 4; for (int j = 0; j < ntris; ++j) { - RcVec3f[] vs = new RcVec3f[3]; + Vector3[] vs = new Vector3[3]; for (int k = 0; k < 3; ++k) { vs[k].X = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3]; diff --git a/src/DotRecast.Recast/RcRasterizations.cs b/src/DotRecast.Recast/RcRasterizations.cs index 8c2a864..ec4cb8a 100644 --- a/src/DotRecast.Recast/RcRasterizations.cs +++ b/src/DotRecast.Recast/RcRasterizations.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using static DotRecast.Recast.RcConstants; namespace DotRecast.Recast @@ -49,7 +50,7 @@ namespace DotRecast.Recast return overlap; } - private static bool OverlapBounds(RcVec3f amin, RcVec3f amax, RcVec3f bmin, RcVec3f bmax) + private static bool OverlapBounds(Vector3 amin, Vector3 amax, Vector3 bmin, Vector3 bmax) { bool overlap = true; overlap = (amin.X > bmax.X || amax.X < bmin.X) ? false : overlap; @@ -230,15 +231,15 @@ namespace DotRecast.Recast /// @param[in] flagMergeThreshold The threshold in which area flags will be merged /// @returns true if the operation completes successfully. false if there was an error adding spans to the heightfield. private static void RasterizeTri(float[] verts, int v0, int v1, int v2, int area, RcHeightfield heightfield, - RcVec3f heightfieldBBMin, RcVec3f heightfieldBBMax, + Vector3 heightfieldBBMin, Vector3 heightfieldBBMax, float cellSize, float inverseCellSize, float inverseCellHeight, int flagMergeThreshold) { float by = heightfieldBBMax.Y - heightfieldBBMin.Y; // Calculate the bounding box of the triangle. - RcVec3f tmin = RcVecUtils.Create(verts, v0 * 3); - RcVec3f tmax = RcVecUtils.Create(verts, v0 * 3); + Vector3 tmin = RcVecUtils.Create(verts, v0 * 3); + Vector3 tmax = RcVecUtils.Create(verts, v0 * 3); tmin = RcVecUtils.Min(tmin, verts, v1 * 3); tmin = RcVecUtils.Min(tmin, verts, v2 * 3); tmax = RcVecUtils.Max(tmax, verts, v1 * 3); diff --git a/test/DotRecast.Core.Test/Vector3Tests.cs b/test/DotRecast.Core.Test/Vector3Tests.cs index 975a733..3bc6846 100644 --- a/test/DotRecast.Core.Test/Vector3Tests.cs +++ b/test/DotRecast.Core.Test/Vector3Tests.cs @@ -1,6 +1,7 @@ using System; using System.Numerics; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Core.Test; @@ -12,7 +13,7 @@ public class Vector3Tests public void TestVectorLength() { var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle()); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); Assert.That(v1.Length(), Is.EqualTo(v11.Length())); Assert.That(v1.LengthSquared(), Is.EqualTo(v11.LengthSquared())); @@ -28,9 +29,9 @@ public class Vector3Tests var v4 = v1 - v2; Assert.That(v3, Is.EqualTo(v4)); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var v33 = RcVec3f.Subtract(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var v33 = Vector3.Subtract(v11, v22); var v44 = v11 - v22; Assert.That(v33, Is.EqualTo(v44)); @@ -50,9 +51,9 @@ public class Vector3Tests var v4 = v1 + v2; Assert.That(v3, Is.EqualTo(v4)); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var v33 = RcVec3f.Add(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var v33 = Vector3.Add(v11, v22); var v44 = v11 + v22; Assert.That(v33, Is.EqualTo(v44)); @@ -68,8 +69,8 @@ public class Vector3Tests var v1 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle()); var v2 = Vector3.Normalize(v1); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = RcVec3f.Normalize(v11); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = Vector3.Normalize(v11); Assert.That(v2.X, Is.EqualTo(v22.X).Within(0.000001d)); Assert.That(v2.Y, Is.EqualTo(v22.Y).Within(0.000001d)); @@ -84,9 +85,9 @@ public class Vector3Tests var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle()); var v3 = Vector3.Cross(v1, v2); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var v33 = RcVec3f.Cross(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var v33 = Vector3.Cross(v11, v22); Assert.That(v3.X, Is.EqualTo(v33.X)); Assert.That(v3.Y, Is.EqualTo(v33.Y)); @@ -103,7 +104,7 @@ public class Vector3Tests v1.CopyTo(array1); v1.CopyTo(array2, 0); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); var array11 = new float[3]; var array22 = new float[3]; v11.CopyTo(array11); @@ -121,9 +122,9 @@ public class Vector3Tests var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle()); float d3 = Vector3.Dot(v1, v2); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var d33 = RcVec3f.Dot(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var d33 = Vector3.Dot(v11, v22); Assert.That(d3, Is.EqualTo(d33)); } @@ -137,10 +138,10 @@ public class Vector3Tests var d3 = Vector3.Distance(v1, v2); var d4 = Vector3.DistanceSquared(v1, v2); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var d33 = RcVec3f.Distance(v11, v22); - var d44 = RcVec3f.DistanceSquared(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var d33 = Vector3.Distance(v11, v22); + var d44 = Vector3.DistanceSquared(v11, v22); Assert.That(d3, Is.EqualTo(d33)); Assert.That(d4, Is.EqualTo(d44)); @@ -155,10 +156,10 @@ public class Vector3Tests var v3 = Vector3.Min(v1, v2); var v4 = Vector3.Max(v1, v2); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var v33 = RcVec3f.Min(v11, v22); - var v44 = RcVec3f.Max(v11, v22); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var v33 = Vector3.Min(v11, v22); + var v44 = Vector3.Max(v11, v22); Assert.That(v3.X, Is.EqualTo(v33.X)); Assert.That(v3.Y, Is.EqualTo(v33.Y)); @@ -179,9 +180,9 @@ public class Vector3Tests var v2 = new Vector3(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle()); var v3 = Vector3.Lerp(v1, v2, amt); - var v11 = new RcVec3f(v1.X, v1.Y, v1.Z); - var v22 = new RcVec3f(v2.X, v2.Y, v2.Z); - var v33 = RcVec3f.Lerp(v11, v22, amt); + var v11 = new Vector3(v1.X, v1.Y, v1.Z); + var v22 = new Vector3(v2.X, v2.Y, v2.Z); + var v33 = Vector3.Lerp(v11, v22, amt); Assert.That(v3.X, Is.EqualTo(v33.X)); Assert.That(v3.Y, Is.EqualTo(v33.Y)); diff --git a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs index ec93b91..c2f6c72 100644 --- a/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs +++ b/test/DotRecast.Detour.Crowd.Test/AbstractCrowdTest.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System; using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Crowd.Test; @@ -36,22 +37,22 @@ public class AbstractCrowdTest protected readonly long[] endRefs = { 281474976710721L, 281474976710767L, 281474976710758L, 281474976710731L, 281474976710772L }; - protected readonly RcVec3f[] startPoss = + protected readonly Vector3[] startPoss = { - new RcVec3f(22.60652f, 10.197294f, -45.918674f), - new RcVec3f(22.331268f, 10.197294f, -1.0401875f), - new RcVec3f(18.694363f, 15.803535f, -73.090416f), - new RcVec3f(0.7453353f, 10.197294f, -5.94005f), - new RcVec3f(-20.651257f, 5.904126f, -13.712508f), + new Vector3(22.60652f, 10.197294f, -45.918674f), + new Vector3(22.331268f, 10.197294f, -1.0401875f), + new Vector3(18.694363f, 15.803535f, -73.090416f), + new Vector3(0.7453353f, 10.197294f, -5.94005f), + new Vector3(-20.651257f, 5.904126f, -13.712508f), }; - protected readonly RcVec3f[] endPoss = + protected readonly Vector3[] endPoss = { - new RcVec3f(6.4576626f, 10.197294f, -18.33406f), - new RcVec3f(-5.8023443f, 0.19729415f, 3.008419f), - new RcVec3f(38.423977f, 10.197294f, -0.116066754f), - new RcVec3f(0.8635526f, 10.197294f, -10.31032f), - new RcVec3f(18.784092f, 10.197294f, 3.0543678f), + new Vector3(6.4576626f, 10.197294f, -18.33406f), + new Vector3(-5.8023443f, 0.19729415f, 3.008419f), + new Vector3(38.423977f, 10.197294f, -0.116066754f), + new Vector3(0.8635526f, 10.197294f, -10.31032f), + new Vector3(18.784092f, 10.197294f, 3.0543678f), }; protected DtMeshData nmd; @@ -110,14 +111,14 @@ public class AbstractCrowdTest return ap; } - protected void AddAgentGrid(int size, float distance, int updateFlags, int obstacleAvoidanceType, RcVec3f startPos) + protected void AddAgentGrid(int size, float distance, int updateFlags, int obstacleAvoidanceType, Vector3 startPos) { DtCrowdAgentParams ap = GetAgentParams(updateFlags, obstacleAvoidanceType); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { - RcVec3f pos = new RcVec3f(); + Vector3 pos = new Vector3(); pos.X = startPos.X + i * distance; pos.Y = startPos.Y; pos.Z = startPos.Z + j * distance; @@ -126,15 +127,15 @@ public class AbstractCrowdTest } } - protected void SetMoveTarget(RcVec3f pos, bool adjust) + protected void SetMoveTarget(Vector3 pos, bool adjust) { - RcVec3f ext = crowd.GetQueryExtents(); + Vector3 ext = crowd.GetQueryExtents(); IDtQueryFilter filter = crowd.GetFilter(0); if (adjust) { foreach (DtCrowdAgent ag in crowd.GetActiveAgents()) { - RcVec3f vel = CalcVel(ag.npos, pos, ag.option.maxSpeed); + Vector3 vel = CalcVel(ag.npos, pos, ag.option.maxSpeed); crowd.RequestMoveVelocity(ag, vel); } } @@ -148,11 +149,11 @@ public class AbstractCrowdTest } } - protected RcVec3f CalcVel(RcVec3f pos, RcVec3f tgt, float speed) + protected Vector3 CalcVel(Vector3 pos, Vector3 tgt, float speed) { - RcVec3f vel = RcVec3f.Subtract(tgt, pos); + Vector3 vel = Vector3.Subtract(tgt, pos); vel.Y = 0.0f; - vel = RcVec3f.Normalize(vel); + vel = Vector3.Normalize(vel); vel = vel.Scale(speed); return vel; } diff --git a/test/DotRecast.Detour.Crowd.Test/PathCorridorTest.cs b/test/DotRecast.Detour.Crowd.Test/PathCorridorTest.cs index c5ff52c..896578c 100644 --- a/test/DotRecast.Detour.Crowd.Test/PathCorridorTest.cs +++ b/test/DotRecast.Detour.Crowd.Test/PathCorridorTest.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using Moq; using NUnit.Framework; @@ -34,27 +35,27 @@ public class PathCorridorTest [SetUp] public void SetUp() { - corridor.Reset(0, new RcVec3f(10, 20, 30)); + corridor.Reset(0, new Vector3(10, 20, 30)); } [Test] public void ShouldKeepOriginalPathInFindCornersWhenNothingCanBePruned() { List straightPath = new(); - straightPath.Add(new DtStraightPath(new RcVec3f(11, 20, 30.00001f), 0, 0)); - straightPath.Add(new DtStraightPath(new RcVec3f(12, 20, 30.00002f), 0, 0)); - straightPath.Add(new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0)); - straightPath.Add(new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0)); + straightPath.Add(new DtStraightPath(new Vector3(11, 20, 30.00001f), 0, 0)); + straightPath.Add(new DtStraightPath(new Vector3(12, 20, 30.00002f), 0, 0)); + straightPath.Add(new DtStraightPath(new Vector3(11f, 21, 32f), 0, 0)); + straightPath.Add(new DtStraightPath(new Vector3(11f, 21, 32f), 0, 0)); var mockQuery = new Mock(It.IsAny()); mockQuery.Setup(q => q.FindStraightPath( - It.IsAny(), - It.IsAny(), + It.IsAny(), + It.IsAny(), It.IsAny>(), ref It.Ref>.IsAny, It.IsAny(), It.IsAny()) ) - .Callback((RcVec3f startPos, RcVec3f endPos, List path, + .Callback((Vector3 startPos, Vector3 endPos, List path, ref List refStraightPath, int maxStraightPath, int options) => { refStraightPath = straightPath; @@ -71,21 +72,21 @@ public class PathCorridorTest public void ShouldPrunePathInFindCorners() { List straightPath = new(); - straightPath.Add(new DtStraightPath(new RcVec3f(10, 20, 30.00001f), 0, 0)); // too close - straightPath.Add(new DtStraightPath(new RcVec3f(10, 20, 30.00002f), 0, 0)); // too close - straightPath.Add(new DtStraightPath(new RcVec3f(11f, 21, 32f), 0, 0)); - straightPath.Add(new DtStraightPath(new RcVec3f(12f, 22, 33f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh - straightPath.Add(new DtStraightPath(new RcVec3f(11f, 21, 32f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh + straightPath.Add(new DtStraightPath(new Vector3(10, 20, 30.00001f), 0, 0)); // too close + straightPath.Add(new DtStraightPath(new Vector3(10, 20, 30.00002f), 0, 0)); // too close + straightPath.Add(new DtStraightPath(new Vector3(11f, 21, 32f), 0, 0)); + straightPath.Add(new DtStraightPath(new Vector3(12f, 22, 33f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh + straightPath.Add(new DtStraightPath(new Vector3(11f, 21, 32f), DtStraightPathFlags.DT_STRAIGHTPATH_OFFMESH_CONNECTION, 0)); // offmesh var mockQuery = new Mock(It.IsAny()); mockQuery.Setup(q => q.FindStraightPath( - It.IsAny(), - It.IsAny(), + It.IsAny(), + It.IsAny(), It.IsAny>(), ref It.Ref>.IsAny, It.IsAny(), It.IsAny()) - ).Callback((RcVec3f startPos, RcVec3f endPos, List path, + ).Callback((Vector3 startPos, Vector3 endPos, List path, ref List refStraightPath, int maxStraightPath, int options) => { refStraightPath = straightPath; diff --git a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs index 9a68823..cab56c7 100644 --- a/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Crowd.Test/RecastTestMeshBuilder.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; using DotRecast.Recast.Geom; diff --git a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs index a889a83..e5c5fcd 100644 --- a/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/DynamicNavMeshTest.cs @@ -3,6 +3,7 @@ using System.IO; using System.Threading.Tasks; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic.Colliders; using DotRecast.Detour.Dynamic.Io; using DotRecast.Detour.Dynamic.Test.Io; @@ -13,10 +14,10 @@ namespace DotRecast.Detour.Dynamic.Test; [Parallelizable] public class DynamicNavMeshTest { - private static readonly RcVec3f START_POS = new RcVec3f(70.87453f, 0.0010070801f, 86.69021f); - private static readonly RcVec3f END_POS = new RcVec3f(-50.22061f, 0.0010070801f, -70.761444f); - private static readonly RcVec3f EXTENT = new RcVec3f(0.1f, 0.1f, 0.1f); - private static readonly RcVec3f SPHERE_POS = new RcVec3f(45.381645f, 0.0010070801f, 52.68981f); + private static readonly Vector3 START_POS = new Vector3(70.87453f, 0.0010070801f, 86.69021f); + private static readonly Vector3 END_POS = new Vector3(-50.22061f, 0.0010070801f, -70.761444f); + private static readonly Vector3 EXTENT = new Vector3(0.1f, 0.1f, 0.1f); + private static readonly Vector3 SPHERE_POS = new Vector3(45.381645f, 0.0010070801f, 52.68981f); [Test] diff --git a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs index 5e81f8f..3a26155 100644 --- a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderTest.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic.Io; using NUnit.Framework; @@ -50,8 +51,8 @@ public class VoxelFileReaderTest Assert.That(f.tiles[0].cellHeight, Is.EqualTo(0.001f)); Assert.That(f.tiles[0].width, Is.EqualTo(810)); Assert.That(f.tiles[0].depth, Is.EqualTo(810)); - Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new RcVec3f(-101.25f, 0f, -101.25f))); - Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new RcVec3f(101.25f, 5.0f, 101.25f))); + Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new Vector3(-101.25f, 0f, -101.25f))); + Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new Vector3(101.25f, 5.0f, 101.25f))); } [Test] @@ -77,7 +78,7 @@ public class VoxelFileReaderTest Assert.That(f.tiles[0].cellHeight, Is.EqualTo(0.001f)); Assert.That(f.tiles[0].width, Is.EqualTo(90)); Assert.That(f.tiles[0].depth, Is.EqualTo(90)); - Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new RcVec3f(-101.25f, 0f, -101.25f))); - Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new RcVec3f(-78.75f, 5.0f, -78.75f))); + Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new Vector3(-101.25f, 0f, -101.25f))); + Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new Vector3(-78.75f, 5.0f, -78.75f))); } } \ No newline at end of file diff --git a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs index 54a0640..181a118 100644 --- a/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/Io/VoxelFileReaderWriterTest.cs @@ -20,6 +20,7 @@ freely, subject to the following restrictions: using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic.Io; using NUnit.Framework; @@ -52,8 +53,8 @@ public class VoxelFileReaderWriterTest Assert.That(f.tiles[0].width, Is.EqualTo(810)); Assert.That(f.tiles[0].depth, Is.EqualTo(810)); Assert.That(f.tiles[0].spanData.Length, Is.EqualTo(9021024)); - Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new RcVec3f(-101.25f, 0f, -101.25f))); - Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new RcVec3f(101.25f, 5.0f, 101.25f))); + Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new Vector3(-101.25f, 0f, -101.25f))); + Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new Vector3(101.25f, 5.0f, 101.25f))); } [TestCase(false)] @@ -83,8 +84,8 @@ public class VoxelFileReaderWriterTest Assert.That(f.tiles[0].spanData.Length, Is.EqualTo(104952)); Assert.That(f.tiles[5].spanData.Length, Is.EqualTo(109080)); Assert.That(f.tiles[18].spanData.Length, Is.EqualTo(113400)); - Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new RcVec3f(-101.25f, 0f, -101.25f))); - Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new RcVec3f(-78.75f, 5.0f, -78.75f))); + Assert.That(f.tiles[0].boundsMin, Is.EqualTo(new Vector3(-101.25f, 0f, -101.25f))); + Assert.That(f.tiles[0].boundsMax, Is.EqualTo(new Vector3(-78.75f, 5.0f, -78.75f))); } private DtVoxelFile ReadWriteRead(BinaryReader bis, bool compression) diff --git a/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs b/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs index 577a754..ed34058 100644 --- a/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs +++ b/test/DotRecast.Detour.Dynamic.Test/VoxelQueryTest.cs @@ -23,6 +23,7 @@ using System.Threading.Tasks; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Dynamic.Io; using DotRecast.Detour.Dynamic.Test.Io; using DotRecast.Recast; @@ -36,7 +37,7 @@ public class VoxelQueryTest { private const int TILE_WIDTH = 100; private const int TILE_DEPTH = 90; - private static readonly RcVec3f ORIGIN = new RcVec3f(50, 10, 40); + private static readonly Vector3 ORIGIN = new Vector3(50, 10, 40); [Test] @@ -58,8 +59,8 @@ public class VoxelQueryTest }); DtVoxelQuery query = new DtVoxelQuery(ORIGIN, TILE_WIDTH, TILE_DEPTH, hfProvider.Object); - RcVec3f start = new RcVec3f(120, 10, 365); - RcVec3f end = new RcVec3f(320, 10, 57); + Vector3 start = new Vector3(120, 10, 365); + Vector3 end = new Vector3(320, 10, 57); // When query.Raycast(start, end, out var hit); @@ -74,8 +75,8 @@ public class VoxelQueryTest { DtDynamicNavMesh mesh = CreateDynaMesh(); DtVoxelQuery query = mesh.VoxelQuery(); - RcVec3f start = new RcVec3f(7.4f, 0.5f, -64.8f); - RcVec3f end = new RcVec3f(31.2f, 0.5f, -75.3f); + Vector3 start = new Vector3(7.4f, 0.5f, -64.8f); + Vector3 end = new Vector3(31.2f, 0.5f, -75.3f); bool isHit = query.Raycast(start, end, out var hit); Assert.That(isHit, Is.EqualTo(false)); } @@ -85,8 +86,8 @@ public class VoxelQueryTest { DtDynamicNavMesh mesh = CreateDynaMesh(); DtVoxelQuery query = mesh.VoxelQuery(); - RcVec3f start = new RcVec3f(32.3f, 0.5f, 47.9f); - RcVec3f end = new RcVec3f(-31.2f, 0.5f, -29.8f); + Vector3 start = new Vector3(32.3f, 0.5f, 47.9f); + Vector3 end = new Vector3(-31.2f, 0.5f, -29.8f); bool isHit = query.Raycast(start, end, out var hit); Assert.That(isHit, Is.EqualTo(true)); Assert.That(hit, Is.EqualTo(0.5263836f).Within(1e-7f)); diff --git a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs index 915e278..444b594 100644 --- a/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs +++ b/test/DotRecast.Detour.Extras.Test/Unity/Astar/UnityAStarPathfindingImporterTest.cs @@ -20,6 +20,7 @@ using System.IO; using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Extras.Unity.Astar; using DotRecast.Detour.Io; using NUnit.Framework; @@ -33,8 +34,8 @@ public class UnityAStarPathfindingImporterTest public void Test_v4_0_6() { DtNavMesh mesh = LoadNavMesh("graph.zip"); - RcVec3f startPos = new RcVec3f(8.200293f, 2.155071f, -26.176147f); - RcVec3f endPos = new RcVec3f(11.971109f, 0.000000f, 8.663261f); + Vector3 startPos = new Vector3(8.200293f, 2.155071f, -26.176147f); + Vector3 endPos = new Vector3(11.971109f, 0.000000f, 8.663261f); var path = new List(); var status = FindPath(mesh, startPos, endPos, ref path); Assert.That(status, Is.EqualTo(DtStatus.DT_SUCCESS)); @@ -46,8 +47,8 @@ public class UnityAStarPathfindingImporterTest public void Test_v4_1_16() { DtNavMesh mesh = LoadNavMesh("graph_v4_1_16.zip"); - RcVec3f startPos = new RcVec3f(22.93f, -2.37f, -5.11f); - RcVec3f endPos = new RcVec3f(16.81f, -2.37f, 25.52f); + Vector3 startPos = new Vector3(22.93f, -2.37f, -5.11f); + Vector3 endPos = new Vector3(16.81f, -2.37f, 25.52f); var path = new List(); var status = FindPath(mesh, startPos, endPos, ref path); Assert.That(status.Succeeded(), Is.True); @@ -59,7 +60,7 @@ public class UnityAStarPathfindingImporterTest public void TestBoundsTree() { DtNavMesh mesh = LoadNavMesh("test_boundstree.zip"); - RcVec3f position = new RcVec3f(387.52988f, 19.997f, 368.86282f); + Vector3 position = new Vector3(387.52988f, 19.997f, 368.86282f); mesh.CalcTileLoc(position, out var tileX, out var tileY); long tileRef = mesh.GetTileRefAt(tileX, tileY, 0); @@ -90,7 +91,7 @@ public class UnityAStarPathfindingImporterTest return meshes[0]; } - private DtStatus FindPath(DtNavMesh mesh, RcVec3f startPos, RcVec3f endPos, ref List path) + private DtStatus FindPath(DtNavMesh mesh, Vector3 startPos, Vector3 endPos, ref List path) { // Perform a simple pathfinding DtNavMeshQuery query = new DtNavMeshQuery(mesh); @@ -100,19 +101,19 @@ public class UnityAStarPathfindingImporterTest return query.FindPath(polys[0].refs, polys[1].refs, startPos, endPos, filter, ref path, DtFindPathOption.NoOption); } - private DtPolyPoint[] GetNearestPolys(DtNavMesh mesh, params RcVec3f[] positions) + private DtPolyPoint[] GetNearestPolys(DtNavMesh mesh, params Vector3[] positions) { DtNavMeshQuery query = new DtNavMeshQuery(mesh); IDtQueryFilter filter = new DtQueryDefaultFilter(); - RcVec3f extents = new RcVec3f(0.1f, 0.1f, 0.1f); + Vector3 extents = new Vector3(0.1f, 0.1f, 0.1f); var results = new DtPolyPoint[positions.Length]; for (int i = 0; i < results.Length; i++) { - RcVec3f position = positions[i]; + Vector3 position = positions[i]; var status = query.FindNearestPoly(position, extents, filter, out var nearestRef, out var nearestPt, out var _); Assert.That(status.Succeeded(), Is.True); - Assert.That(nearestPt, Is.Not.EqualTo(RcVec3f.Zero), "Nearest start position is null!"); + Assert.That(nearestPt, Is.Not.EqualTo(Vector3.Zero), "Nearest start position is null!"); results[i] = new DtPolyPoint(nearestRef, nearestPt); } diff --git a/test/DotRecast.Detour.Test/AbstractDetourTest.cs b/test/DotRecast.Detour.Test/AbstractDetourTest.cs index 259010a..52c855b 100644 --- a/test/DotRecast.Detour.Test/AbstractDetourTest.cs +++ b/test/DotRecast.Detour.Test/AbstractDetourTest.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -34,22 +35,22 @@ public abstract class AbstractDetourTest 281474976710721L, 281474976710767L, 281474976710758L, 281474976710731L, 281474976710772L }; - protected static readonly RcVec3f[] startPoss = + protected static readonly Vector3[] startPoss = { - new RcVec3f(22.60652f, 10.197294f, -45.918674f), - new RcVec3f(22.331268f, 10.197294f, -1.0401875f), - new RcVec3f(18.694363f, 15.803535f, -73.090416f), - new RcVec3f(0.7453353f, 10.197294f, -5.94005f), - new RcVec3f(-20.651257f, 5.904126f, -13.712508f) + new Vector3(22.60652f, 10.197294f, -45.918674f), + new Vector3(22.331268f, 10.197294f, -1.0401875f), + new Vector3(18.694363f, 15.803535f, -73.090416f), + new Vector3(0.7453353f, 10.197294f, -5.94005f), + new Vector3(-20.651257f, 5.904126f, -13.712508f) }; - protected static readonly RcVec3f[] endPoss = + protected static readonly Vector3[] endPoss = { - new RcVec3f(6.4576626f, 10.197294f, -18.33406f), - new RcVec3f(-5.8023443f, 0.19729415f, 3.008419f), - new RcVec3f(38.423977f, 10.197294f, -0.116066754f), - new RcVec3f(0.8635526f, 10.197294f, -10.31032f), - new RcVec3f(18.784092f, 10.197294f, 3.0543678f), + new Vector3(6.4576626f, 10.197294f, -18.33406f), + new Vector3(-5.8023443f, 0.19729415f, 3.008419f), + new Vector3(38.423977f, 10.197294f, -0.116066754f), + new Vector3(0.8635526f, 10.197294f, -10.31032f), + new Vector3(18.784092f, 10.197294f, 3.0543678f), }; protected DtNavMeshQuery query; diff --git a/test/DotRecast.Detour.Test/FindDistanceToWallTest.cs b/test/DotRecast.Detour.Test/FindDistanceToWallTest.cs index 081fff9..29c9e4b 100644 --- a/test/DotRecast.Detour.Test/FindDistanceToWallTest.cs +++ b/test/DotRecast.Detour.Test/FindDistanceToWallTest.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; @@ -27,22 +28,22 @@ public class FindDistanceToWallTest : AbstractDetourTest { private static readonly float[] DISTANCES_TO_WALL = { 0.597511f, 3.201085f, 0.603713f, 2.791475f, 2.815544f }; - private static readonly RcVec3f[] HIT_POSITION = + private static readonly Vector3[] HIT_POSITION = { - new RcVec3f(23.177608f, 10.197294f, -45.742954f), - new RcVec3f(22.331268f, 10.197294f, -4.241272f), - new RcVec3f(18.108675f, 15.743596f, -73.236839f), - new RcVec3f(1.984785f, 10.197294f, -8.441269f), - new RcVec3f(-22.315216f, 4.997294f, -11.441269f), + new Vector3(23.177608f, 10.197294f, -45.742954f), + new Vector3(22.331268f, 10.197294f, -4.241272f), + new Vector3(18.108675f, 15.743596f, -73.236839f), + new Vector3(1.984785f, 10.197294f, -8.441269f), + new Vector3(-22.315216f, 4.997294f, -11.441269f), }; - private static readonly RcVec3f[] HIT_NORMAL = + private static readonly Vector3[] HIT_NORMAL = { - new RcVec3f(-0.955779f, 0.0f, -0.29408592f), - new RcVec3f(0.0f, 0.0f, 1.0f), - new RcVec3f(0.97014254f, 0.0f, 0.24253564f), - new RcVec3f(-1.0f, 0.0f, 0.0f), - new RcVec3f(1.0f, 0.0f, 0.0f), + new Vector3(-0.955779f, 0.0f, -0.29408592f), + new Vector3(0.0f, 0.0f, 1.0f), + new Vector3(0.97014254f, 0.0f, 0.24253564f), + new Vector3(-1.0f, 0.0f, 0.0f), + new Vector3(1.0f, 0.0f, 0.0f), }; [Test] @@ -51,7 +52,7 @@ public class FindDistanceToWallTest : AbstractDetourTest IDtQueryFilter filter = new DtQueryDefaultFilter(); for (int i = 0; i < startRefs.Length; i++) { - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; query.FindDistanceToWall(startRefs[i], startPos, 3.5f, filter, out var hitDist, out var hitPos, out var hitNormal); Assert.That(hitDist, Is.EqualTo(DISTANCES_TO_WALL[i]).Within(0.001f)); diff --git a/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs b/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs index e637e17..7d3033b 100644 --- a/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs +++ b/test/DotRecast.Detour.Test/FindLocalNeighbourhoodTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -57,7 +58,7 @@ public class FindLocalNeighbourhoodTest : AbstractDetourTest IDtQueryFilter filter = new DtQueryDefaultFilter(); for (int i = 0; i < startRefs.Length; i++) { - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; var refs = new List(); var parentRefs = new List(); var status = query.FindLocalNeighbourhood(startRefs[i], startPos, 3.5f, filter, ref refs, ref parentRefs); diff --git a/test/DotRecast.Detour.Test/FindNearestPolyTest.cs b/test/DotRecast.Detour.Test/FindNearestPolyTest.cs index f9bb2a0..aeef583 100644 --- a/test/DotRecast.Detour.Test/FindNearestPolyTest.cs +++ b/test/DotRecast.Detour.Test/FindNearestPolyTest.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -26,23 +27,23 @@ public class FindNearestPolyTest : AbstractDetourTest { private static readonly long[] POLY_REFS = { 281474976710696L, 281474976710773L, 281474976710680L, 281474976710753L, 281474976710733L }; - private static readonly RcVec3f[] POLY_POS = + private static readonly Vector3[] POLY_POS = { - new RcVec3f(22.606520f, 10.197294f, -45.918674f), - new RcVec3f(22.331268f, 10.197294f, -1.040187f), - new RcVec3f(18.694363f, 15.803535f, -73.090416f), - new RcVec3f(0.745335f, 10.197294f, -5.940050f), - new RcVec3f(-20.651257f, 5.904126f, -13.712508f) + new Vector3(22.606520f, 10.197294f, -45.918674f), + new Vector3(22.331268f, 10.197294f, -1.040187f), + new Vector3(18.694363f, 15.803535f, -73.090416f), + new Vector3(0.745335f, 10.197294f, -5.940050f), + new Vector3(-20.651257f, 5.904126f, -13.712508f) }; [Test] public void TestFindNearestPoly() { IDtQueryFilter filter = new DtQueryDefaultFilter(); - RcVec3f extents = new RcVec3f(2, 4, 2); + Vector3 extents = new Vector3(2, 4, 2); for (int i = 0; i < startRefs.Length; i++) { - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; var status = query.FindNearestPoly(startPos, extents, filter, out var nearestRef, out var nearestPt, out var _); Assert.That(status.Succeeded(), Is.True); Assert.That(nearestRef, Is.EqualTo(POLY_REFS[i])); @@ -56,10 +57,10 @@ public class FindNearestPolyTest : AbstractDetourTest [Test] public void ShouldReturnStartPosWhenNoPolyIsValid() { - RcVec3f extents = new RcVec3f(2, 4, 2); + Vector3 extents = new Vector3(2, 4, 2); for (int i = 0; i < startRefs.Length; i++) { - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; var status = query.FindNearestPoly(startPos, extents, DtQueryEmptyFilter.Shared, out var nearestRef, out var nearestPt, out var _); Assert.That(status.Succeeded(), Is.True); Assert.That(nearestRef, Is.EqualTo(0L)); diff --git a/test/DotRecast.Detour.Test/FindPathTest.cs b/test/DotRecast.Detour.Test/FindPathTest.cs index 57d9ecb..16d6f79 100644 --- a/test/DotRecast.Detour.Test/FindPathTest.cs +++ b/test/DotRecast.Detour.Test/FindPathTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -74,59 +75,59 @@ public class FindPathTest : AbstractDetourTest { new[] { - new DtStraightPath(new RcVec3f(22.606520f, 10.197294f, -45.918674f), 1, 281474976710696L), - new DtStraightPath(new RcVec3f(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -29.741272f), 0, 281474976710727L), - new DtStraightPath(new RcVec3f(2.584784f, 10.197294f, -27.941273f), 0, 281474976710730L), - new DtStraightPath(new RcVec3f(6.457663f, 10.197294f, -18.334061f), 2, 0L) + new DtStraightPath(new Vector3(22.606520f, 10.197294f, -45.918674f), 1, 281474976710696L), + new DtStraightPath(new Vector3(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -29.741272f), 0, 281474976710727L), + new DtStraightPath(new Vector3(2.584784f, 10.197294f, -27.941273f), 0, 281474976710730L), + new DtStraightPath(new Vector3(6.457663f, 10.197294f, -18.334061f), 2, 0L) }, new[] { - new DtStraightPath(new RcVec3f(22.331268f, 10.197294f, -1.040187f), 1, 281474976710773L), - new DtStraightPath(new RcVec3f(9.784786f, 10.197294f, -2.141273f), 0, 281474976710755L), - new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710753L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710752L), - new DtStraightPath(new RcVec3f(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710724L), - new DtStraightPath(new RcVec3f(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710728L), - new DtStraightPath(new RcVec3f(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710738L), - new DtStraightPath(new RcVec3f(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710736L), - new DtStraightPath(new RcVec3f(-17.815216f, 5.197294f, -11.441269f), 0, 281474976710735L), - new DtStraightPath(new RcVec3f(-17.815216f, 5.197294f, -8.441269f), 0, 281474976710746L), - new DtStraightPath(new RcVec3f(-11.815216f, 0.197294f, 3.008419f), 2, 0L) + new DtStraightPath(new Vector3(22.331268f, 10.197294f, -1.040187f), 1, 281474976710773L), + new DtStraightPath(new Vector3(9.784786f, 10.197294f, -2.141273f), 0, 281474976710755L), + new DtStraightPath(new Vector3(7.984783f, 10.197294f, -2.441269f), 0, 281474976710753L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -8.441269f), 0, 281474976710752L), + new DtStraightPath(new Vector3(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710724L), + new DtStraightPath(new Vector3(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710728L), + new DtStraightPath(new Vector3(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710738L), + new DtStraightPath(new Vector3(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710736L), + new DtStraightPath(new Vector3(-17.815216f, 5.197294f, -11.441269f), 0, 281474976710735L), + new DtStraightPath(new Vector3(-17.815216f, 5.197294f, -8.441269f), 0, 281474976710746L), + new DtStraightPath(new Vector3(-11.815216f, 0.197294f, 3.008419f), 2, 0L) }, new[] { - new DtStraightPath(new RcVec3f(18.694363f, 15.803535f, -73.090416f), 1, 281474976710680L), - new DtStraightPath(new RcVec3f(17.584785f, 10.197294f, -49.841274f), 0, 281474976710697L), - new DtStraightPath(new RcVec3f(17.284786f, 10.197294f, -48.041275f), 0, 281474976710695L), - new DtStraightPath(new RcVec3f(16.084785f, 10.197294f, -45.341274f), 0, 281474976710694L), - new DtStraightPath(new RcVec3f(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L), - new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L), - new DtStraightPath(new RcVec3f(9.784786f, 10.197294f, -2.141273f), 0, 281474976710768L), - new DtStraightPath(new RcVec3f(38.423977f, 10.197294f, -0.116067f), 2, 0L) + new DtStraightPath(new Vector3(18.694363f, 15.803535f, -73.090416f), 1, 281474976710680L), + new DtStraightPath(new Vector3(17.584785f, 10.197294f, -49.841274f), 0, 281474976710697L), + new DtStraightPath(new Vector3(17.284786f, 10.197294f, -48.041275f), 0, 281474976710695L), + new DtStraightPath(new Vector3(16.084785f, 10.197294f, -45.341274f), 0, 281474976710694L), + new DtStraightPath(new Vector3(3.484785f, 10.197294f, -34.241272f), 0, 281474976710713L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -31.241272f), 0, 281474976710712L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L), + new DtStraightPath(new Vector3(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L), + new DtStraightPath(new Vector3(9.784786f, 10.197294f, -2.141273f), 0, 281474976710768L), + new DtStraightPath(new Vector3(38.423977f, 10.197294f, -0.116067f), 2, 0L) }, new[] { - new DtStraightPath(new RcVec3f(0.745335f, 10.197294f, -5.940050f), 1, 281474976710753L), - new DtStraightPath(new RcVec3f(0.863553f, 10.197294f, -10.310320f), 2, 0L) + new DtStraightPath(new Vector3(0.745335f, 10.197294f, -5.940050f), 1, 281474976710753L), + new DtStraightPath(new Vector3(0.863553f, 10.197294f, -10.310320f), 2, 0L) }, new[] { - new DtStraightPath(new RcVec3f(-20.651257f, 5.904126f, -13.712508f), 1, 281474976710733L), - new DtStraightPath(new RcVec3f(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710738L), - new DtStraightPath(new RcVec3f(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710728L), - new DtStraightPath(new RcVec3f(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710724L), - new DtStraightPath(new RcVec3f(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710729L), - new DtStraightPath(new RcVec3f(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L), - new DtStraightPath(new RcVec3f(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L), - new DtStraightPath(new RcVec3f(18.784092f, 10.197294f, 3.054368f), 2, 0L) + new DtStraightPath(new Vector3(-20.651257f, 5.904126f, -13.712508f), 1, 281474976710733L), + new DtStraightPath(new Vector3(-11.815216f, 9.997294f, -17.441269f), 0, 281474976710738L), + new DtStraightPath(new Vector3(-10.015216f, 10.197294f, -17.741272f), 0, 281474976710728L), + new DtStraightPath(new Vector3(-8.215216f, 10.197294f, -17.441269f), 0, 281474976710724L), + new DtStraightPath(new Vector3(-4.315216f, 10.197294f, -15.341270f), 0, 281474976710729L), + new DtStraightPath(new Vector3(1.984785f, 10.197294f, -8.441269f), 0, 281474976710753L), + new DtStraightPath(new Vector3(7.984783f, 10.197294f, -2.441269f), 0, 281474976710755L), + new DtStraightPath(new Vector3(18.784092f, 10.197294f, 3.054368f), 2, 0L) } }; @@ -139,8 +140,8 @@ public class FindPathTest : AbstractDetourTest { long startRef = startRefs[i]; long endRef = endRefs[i]; - RcVec3f startPos = startPoss[i]; - RcVec3f endPos = endPoss[i]; + Vector3 startPos = startPoss[i]; + Vector3 endPos = endPoss[i]; var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption); Assert.That(status, Is.EqualTo(STATUSES[i])); Assert.That(path.Count, Is.EqualTo(RESULTS[i].Length)); diff --git a/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs b/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs index 40fd7a0..5a9be52 100644 --- a/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs +++ b/test/DotRecast.Detour.Test/FindPolysAroundCircleTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -108,7 +109,7 @@ public class FindPolysAroundCircleTest : AbstractDetourTest for (int i = 0; i < startRefs.Length; i++) { long startRef = startRefs[i]; - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; var status = query.FindPolysAroundCircle(startRef, startPos, 7.5f, filter, ref refs, ref parentRefs, ref costs); Assert.That(status.Succeeded(), Is.True); diff --git a/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs b/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs index fedc1de..257177c 100644 --- a/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs +++ b/test/DotRecast.Detour.Test/FindPolysAroundShapeTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -136,7 +137,7 @@ public class FindPolysAroundShapeTest : AbstractDetourTest for (int i = 0; i < startRefs.Length; i++) { long startRef = startRefs[i]; - RcVec3f startPos = startPoss[i]; + Vector3 startPos = startPoss[i]; query.FindPolysAroundShape(startRef, GetQueryPoly(startPos, endPoss[i]), filter, ref refs, ref parentRefs, ref costs); Assert.That(refs.Count, Is.EqualTo(REFS[i].Length)); @@ -158,13 +159,13 @@ public class FindPolysAroundShapeTest : AbstractDetourTest } } - private RcVec3f[] GetQueryPoly(RcVec3f m_spos, RcVec3f m_epos) + private Vector3[] GetQueryPoly(Vector3 m_spos, Vector3 m_epos) { float nx = (m_epos.Z - m_spos.Z) * 0.25f; float nz = -(m_epos.X - m_spos.X) * 0.25f; float agentHeight = 2.0f; - RcVec3f[] m_queryPoly = new RcVec3f[4]; + Vector3[] m_queryPoly = new Vector3[4]; m_queryPoly[0].X = m_spos.X + nx * 1.2f; m_queryPoly[0].Y = m_spos.Y + agentHeight / 2; m_queryPoly[0].Z = m_spos.Z + nz * 1.2f; diff --git a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs index ed1aee5..8173d9a 100644 --- a/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs +++ b/test/DotRecast.Detour.Test/Io/MeshSetReaderWriterTest.cs @@ -20,6 +20,7 @@ using System.Collections.Generic; using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.Io; using DotRecast.Recast; using DotRecast.Recast.Geom; @@ -68,8 +69,8 @@ public class MeshSetReaderWriterTest header.numTiles = 0; DtNavMesh mesh = new DtNavMesh(header.option, 6); - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); RcCommons.CalcTileCount(bmin, bmax, m_cellSize, m_tileSize, m_tileSize, out var tw, out var th); for (int y = 0; y < th; ++y) { diff --git a/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs b/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs index ca1f396..17b79ee 100644 --- a/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs +++ b/test/DotRecast.Detour.Test/MoveAlongSurfaceTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -56,13 +57,13 @@ public class MoveAlongSurfaceTest : AbstractDetourTest } }; - private static readonly RcVec3f[] POSITION = + private static readonly Vector3[] POSITION = { - new RcVec3f(6.457663f, 10.197294f, -18.334061f), - new RcVec3f(-1.433933f, 10.197294f, -1.359993f), - new RcVec3f(12.184784f, 9.997294f, -18.941269f), - new RcVec3f(0.863553f, 10.197294f, -10.310320f), - new RcVec3f(18.784092f, 10.197294f, 3.054368f), + new Vector3(6.457663f, 10.197294f, -18.334061f), + new Vector3(-1.433933f, 10.197294f, -1.359993f), + new Vector3(12.184784f, 9.997294f, -18.941269f), + new Vector3(0.863553f, 10.197294f, -10.310320f), + new Vector3(18.784092f, 10.197294f, 3.054368f), }; [Test] @@ -73,8 +74,8 @@ public class MoveAlongSurfaceTest : AbstractDetourTest for (int i = 0; i < startRefs.Length; i++) { long startRef = startRefs[i]; - RcVec3f startPos = startPoss[i]; - RcVec3f endPos = endPoss[i]; + Vector3 startPos = startPoss[i]; + Vector3 endPos = endPoss[i]; var status = query.MoveAlongSurface(startRef, startPos, endPos, filter, out var result, ref visited); Assert.That(status.Succeeded(), Is.True); diff --git a/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs b/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs index 2c7f78b..5d3da15 100644 --- a/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs +++ b/test/DotRecast.Detour.Test/PolygonByCircleConstraintTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; namespace DotRecast.Detour.Test; @@ -31,7 +32,7 @@ public class PolygonByCircleConstraintTest public void ShouldHandlePolygonFullyInsideCircle() { float[] polygon = { -2, 0, 2, 2, 0, 2, 2, 0, -2, -2, 0, -2 }; - RcVec3f center = new RcVec3f(1, 0, 1); + Vector3 center = new Vector3(1, 0, 1); float[] constrained = _constraint.Apply(polygon, center, 6); Assert.That(constrained, Is.EqualTo(polygon)); @@ -42,7 +43,7 @@ public class PolygonByCircleConstraintTest { int expectedSize = 21; float[] polygon = { -2, 0, 2, 2, 0, 2, 2, 0, -2, -2, 0, -2 }; - RcVec3f center = new RcVec3f(2, 0, 0); + Vector3 center = new Vector3(2, 0, 0); float[] constrained = _constraint.Apply(polygon, center, 3); Assert.That(constrained.Length, Is.EqualTo(expectedSize)); @@ -54,7 +55,7 @@ public class PolygonByCircleConstraintTest { int expectedSize = 12 * 3; float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 }; - RcVec3f center = new RcVec3f(-1, 0, -1); + Vector3 center = new Vector3(-1, 0, -1); float[] constrained = _constraint.Apply(polygon, center, 2); Assert.That(constrained.Length, Is.EqualTo(expectedSize)); @@ -72,7 +73,7 @@ public class PolygonByCircleConstraintTest { int expectedSize = 9 * 3; float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 }; - RcVec3f center = new RcVec3f(-2, 0, -1); + Vector3 center = new Vector3(-2, 0, -1); float[] constrained = _constraint.Apply(polygon, center, 3); Assert.That(constrained.Length, Is.EqualTo(expectedSize)); @@ -84,7 +85,7 @@ public class PolygonByCircleConstraintTest { int expectedSize = 7 * 3; float[] polygon = { -4, 0, 0, -3, 0, 3, 2, 0, 3, 3, 0, -3, -2, 0, -4 }; - RcVec3f center = new RcVec3f(4, 0, 0); + Vector3 center = new Vector3(4, 0, 0); float[] constrained = _constraint.Apply(polygon, center, 4); Assert.That(constrained.Length, Is.EqualTo(expectedSize)); diff --git a/test/DotRecast.Detour.Test/RandomPointTest.cs b/test/DotRecast.Detour.Test/RandomPointTest.cs index 7905c54..93d11f4 100644 --- a/test/DotRecast.Detour.Test/RandomPointTest.cs +++ b/test/DotRecast.Detour.Test/RandomPointTest.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; diff --git a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs index 4d755a0..d79f480 100644 --- a/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs +++ b/test/DotRecast.Detour.Test/RecastTestMeshBuilder.cs @@ -17,6 +17,7 @@ freely, subject to the following restrictions: */ using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; using DotRecast.Recast.Geom; diff --git a/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs b/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs index 6baef44..79ab654 100644 --- a/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs +++ b/test/DotRecast.Detour.Test/TestTiledNavMeshBuilder.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast; using DotRecast.Recast.Geom; diff --git a/test/DotRecast.Detour.Test/TiledFindPathTest.cs b/test/DotRecast.Detour.Test/TiledFindPathTest.cs index 05ec6ff..7c18e31 100644 --- a/test/DotRecast.Detour.Test/TiledFindPathTest.cs +++ b/test/DotRecast.Detour.Test/TiledFindPathTest.cs @@ -18,6 +18,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core.Numerics; +using System.Numerics; using NUnit.Framework; @@ -43,8 +44,8 @@ public class TiledFindPathTest protected static readonly long[] START_REFS = { 281475015507969L }; protected static readonly long[] END_REFS = { 281474985099266L }; - protected static readonly RcVec3f[] START_POS = { new RcVec3f(39.447338f, 9.998177f, -0.784811f) }; - protected static readonly RcVec3f[] END_POS = { new RcVec3f(19.292645f, 11.611748f, -57.750366f) }; + protected static readonly Vector3[] START_POS = { new Vector3(39.447338f, 9.998177f, -0.784811f) }; + protected static readonly Vector3[] END_POS = { new Vector3(19.292645f, 11.611748f, -57.750366f) }; protected DtNavMeshQuery query; protected DtNavMesh navmesh; @@ -70,8 +71,8 @@ public class TiledFindPathTest { long startRef = START_REFS[i]; long endRef = END_REFS[i]; - RcVec3f startPos = START_POS[i]; - RcVec3f endPos = END_POS[i]; + Vector3 startPos = START_POS[i]; + Vector3 endPos = END_POS[i]; var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption); Assert.That(status, Is.EqualTo(STATUSES[i])); Assert.That(path.Count, Is.EqualTo(RESULTS[i].Length)); diff --git a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs index f8b8502..7705faa 100644 --- a/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TempObstaclesTest.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; using NUnit.Framework; @@ -47,7 +48,7 @@ public class TempObstaclesTest : AbstractTileCacheTest DtMeshTile tile = tiles[0]; Assert.That(tile.data.header.vertCount, Is.EqualTo(16)); Assert.That(tile.data.header.polyCount, Is.EqualTo(6)); - long o = tc.AddObstacle(new RcVec3f(-1.815208f, 9.998184f, -20.307983f), 1f, 2f); + long o = tc.AddObstacle(new Vector3(-1.815208f, 9.998184f, -20.307983f), 1f, 2f); bool upToDate = tc.Update(); Assert.That(upToDate, Is.True); tiles = tc.GetNavMesh().GetTilesAt(1, 4); @@ -82,8 +83,8 @@ public class TempObstaclesTest : AbstractTileCacheTest Assert.That(tile.data.header.vertCount, Is.EqualTo(16)); Assert.That(tile.data.header.polyCount, Is.EqualTo(6)); long o = tc.AddBoxObstacle( - new RcVec3f(-2.315208f, 9.998184f, -20.807983f), - new RcVec3f(-1.315208f, 11.998184f, -19.807983f) + new Vector3(-2.315208f, 9.998184f, -20.807983f), + new Vector3(-1.315208f, 11.998184f, -19.807983f) ); bool upToDate = tc.Update(); Assert.That(upToDate, Is.True); diff --git a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs index 3864ac2..83bf7ad 100644 --- a/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs +++ b/test/DotRecast.Detour.TileCache.Test/TestTileLayerBuilder.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.Linq; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Recast; using DotRecast.Recast.Geom; @@ -71,8 +72,8 @@ public class TestTileLayerBuilder : DtTileCacheLayerBuilder true, true, true, SampleAreaModifications.SAMPLE_AREAMOD_GROUND, true); - RcVec3f bmin = geom.GetMeshBoundsMin(); - RcVec3f bmax = geom.GetMeshBoundsMax(); + Vector3 bmin = geom.GetMeshBoundsMin(); + Vector3 bmax = geom.GetMeshBoundsMax(); RcCommons.CalcTileCount(bmin, bmax, CellSize, m_tileSize, m_tileSize, out tw, out th); } diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs index 68931d2..b75c416 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheFindPathTest.cs @@ -22,6 +22,7 @@ using System.Collections.Generic; using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Detour.TileCache.Io; using DotRecast.Detour.TileCache.Io.Compress; using DotRecast.Detour.TileCache.Test.Io; @@ -32,8 +33,8 @@ namespace DotRecast.Detour.TileCache.Test; [Parallelizable] public class TileCacheFindPathTest : AbstractTileCacheTest { - private readonly RcVec3f start = new RcVec3f(39.44734f, 9.998177f, -0.784811f); - private readonly RcVec3f end = new RcVec3f(19.292645f, 11.611748f, -57.750366f); + private readonly Vector3 start = new Vector3(39.44734f, 9.998177f, -0.784811f); + private readonly Vector3 end = new Vector3(19.292645f, 11.611748f, -57.750366f); private readonly DtNavMesh navmesh; private readonly DtNavMeshQuery query; @@ -50,7 +51,7 @@ public class TileCacheFindPathTest : AbstractTileCacheTest public void TestFindPath() { IDtQueryFilter filter = new DtQueryDefaultFilter(); - RcVec3f extents = new RcVec3f(2f, 4f, 2f); + Vector3 extents = new Vector3(2f, 4f, 2f); query.FindNearestPoly(start, extents, filter, out var startRef, out var startPos, out var _); query.FindNearestPoly(end, extents, filter, out var endRef, out var endPos, out var _); diff --git a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs index b3eaaaa..4127904 100644 --- a/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs +++ b/test/DotRecast.Detour.TileCache.Test/TileCacheNavigationTest.cs @@ -21,6 +21,7 @@ freely, subject to the following restrictions: using System.Collections.Generic; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; using NUnit.Framework; @@ -31,8 +32,8 @@ public class TileCacheNavigationTest : AbstractTileCacheTest { protected readonly long[] startRefs = { 281475006070787L }; protected readonly long[] endRefs = { 281474986147841L }; - protected readonly RcVec3f[] startPoss = { new RcVec3f(39.447338f, 9.998177f, -0.784811f) }; - protected readonly RcVec3f[] endPoss = { new RcVec3f(19.292645f, 11.611748f, -57.750366f) }; + protected readonly Vector3[] startPoss = { new Vector3(39.447338f, 9.998177f, -0.784811f) }; + protected readonly Vector3[] endPoss = { new Vector3(19.292645f, 11.611748f, -57.750366f) }; private readonly DtStatus[] statuses = { DtStatus.DT_SUCCESS }; private readonly long[][] results = @@ -88,8 +89,8 @@ public class TileCacheNavigationTest : AbstractTileCacheTest { long startRef = startRefs[i]; long endRef = endRefs[i]; - RcVec3f startPos = startPoss[i]; - RcVec3f endPos = endPoss[i]; + Vector3 startPos = startPoss[i]; + Vector3 endPos = endPoss[i]; var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.NoOption); Assert.That(status, Is.EqualTo(statuses[i])); Assert.That(path.Count, Is.EqualTo(results[i].Length)); @@ -109,8 +110,8 @@ public class TileCacheNavigationTest : AbstractTileCacheTest { long startRef = startRefs[i]; long endRef = endRefs[i]; - RcVec3f startPos = startPoss[i]; - RcVec3f endPos = endPoss[i]; + Vector3 startPos = startPoss[i]; + Vector3 endPos = endPoss[i]; var status = query.FindPath(startRef, endRef, startPos, endPos, filter, ref path, DtFindPathOption.ZeroScale); Assert.That(status, Is.EqualTo(statuses[i])); Assert.That(path.Count, Is.EqualTo(results[i].Length)); diff --git a/test/DotRecast.Recast.Test/RecastLayersTest.cs b/test/DotRecast.Recast.Test/RecastLayersTest.cs index b45b7dd..4b058a2 100644 --- a/test/DotRecast.Recast.Test/RecastLayersTest.cs +++ b/test/DotRecast.Recast.Test/RecastLayersTest.cs @@ -19,6 +19,7 @@ freely, subject to the following restrictions: using System; using System.IO; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; using NUnit.Framework; diff --git a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs index 000ce51..b1f2ea3 100644 --- a/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs +++ b/test/DotRecast.Recast.Test/RecastSoloMeshTest.cs @@ -20,6 +20,7 @@ using System; using System.IO; using DotRecast.Core; using DotRecast.Core.Numerics; +using System.Numerics; using DotRecast.Recast.Geom; using NUnit.Framework; @@ -99,8 +100,8 @@ public class RecastSoloMeshTest m_partitionType = partitionType; IInputGeomProvider geomProvider = SimpleInputGeomProvider.LoadFile(filename); long time = RcFrequency.Ticks; - RcVec3f bmin = geomProvider.GetMeshBoundsMin(); - RcVec3f bmax = geomProvider.GetMeshBoundsMax(); + Vector3 bmin = geomProvider.GetMeshBoundsMin(); + Vector3 bmax = geomProvider.GetMeshBoundsMax(); RcTelemetry m_ctx = new RcTelemetry(); // // Step 1. Initialize build config.