forked from bit/DotRecastNetSim
intergrate math funcitons
This commit is contained in:
parent
762e62b757
commit
553f236320
|
@ -1,93 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
||||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
|
||||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
*/
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace DotRecast.Core
|
|
||||||
{
|
|
||||||
public class DemoMath
|
|
||||||
{
|
|
||||||
public static float vDistSqr(float[] v1, float[] v2, int i)
|
|
||||||
{
|
|
||||||
float dx = v2[i] - v1[0];
|
|
||||||
float dy = v2[i + 1] - v1[1];
|
|
||||||
float dz = v2[i + 2] - v1[2];
|
|
||||||
return dx * dx + dy * dy + dz * dz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float[] vCross(float[] v1, float[] v2)
|
|
||||||
{
|
|
||||||
float[] dest = new float[3];
|
|
||||||
dest[0] = v1[1] * v2[2] - v1[2] * v2[1];
|
|
||||||
dest[1] = v1[2] * v2[0] - v1[0] * v2[2];
|
|
||||||
dest[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
|
||||||
return dest;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float vDot(float[] v1, float[] v2)
|
|
||||||
{
|
|
||||||
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float sqr(float f)
|
|
||||||
{
|
|
||||||
return f * f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float getPathLen(float[] path, int npath)
|
|
||||||
{
|
|
||||||
float totd = 0;
|
|
||||||
for (int i = 0; i < npath - 1; ++i)
|
|
||||||
{
|
|
||||||
totd += (float)Math.Sqrt(vDistSqr(path, i * 3, (i + 1) * 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
return totd;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float vDistSqr(float[] v, int i, int j)
|
|
||||||
{
|
|
||||||
float dx = v[i] - v[j];
|
|
||||||
float dy = v[i + 1] - v[j + 1];
|
|
||||||
float dz = v[i + 2] - v[j + 2];
|
|
||||||
return dx * dx + dy * dy + dz * dz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float step(float threshold, float v)
|
|
||||||
{
|
|
||||||
return v < threshold ? 0.0f : 1.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int clamp(int v, int min, int max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(v, max), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float clamp(float v, float min, float max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(v, max), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float lerp(float f, float g, float u)
|
|
||||||
{
|
|
||||||
return u * g + (1f - u) * f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,8 +5,8 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="System.Collections.Immutable" Version="7.0.0"/>
|
<PackageReference Include="System.Collections.Immutable" Version="7.0.0" />
|
||||||
<PackageReference Include="System.Text.Json" Version="7.0.2"/>
|
<PackageReference Include="System.Text.Json" Version="7.0.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -20,11 +20,79 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Core
|
||||||
{
|
{
|
||||||
public static class DetourCommon
|
public static class RecastMath
|
||||||
{
|
{
|
||||||
public const float EPS = 1e-4f;
|
public const float EPS = 1e-4f;
|
||||||
|
private static readonly float EQUAL_THRESHOLD = sqr(1.0f / 16384.0f);
|
||||||
|
|
||||||
|
public static float vDistSqr(float[] v1, float[] v2, int i)
|
||||||
|
{
|
||||||
|
float dx = v2[i] - v1[0];
|
||||||
|
float dy = v2[i + 1] - v1[1];
|
||||||
|
float dz = v2[i + 2] - v1[2];
|
||||||
|
return dx * dx + dy * dy + dz * dz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float[] vCross(float[] v1, float[] v2)
|
||||||
|
{
|
||||||
|
float[] dest = new float[3];
|
||||||
|
dest[0] = v1[1] * v2[2] - v1[2] * v2[1];
|
||||||
|
dest[1] = v1[2] * v2[0] - v1[0] * v2[2];
|
||||||
|
dest[2] = v1[0] * v2[1] - v1[1] * v2[0];
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float vDot(float[] v1, float[] v2)
|
||||||
|
{
|
||||||
|
return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float sqr(float f)
|
||||||
|
{
|
||||||
|
return f * f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float getPathLen(float[] path, int npath)
|
||||||
|
{
|
||||||
|
float totd = 0;
|
||||||
|
for (int i = 0; i < npath - 1; ++i)
|
||||||
|
{
|
||||||
|
totd += (float)Math.Sqrt(vDistSqr(path, i * 3, (i + 1) * 3));
|
||||||
|
}
|
||||||
|
|
||||||
|
return totd;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float vDistSqr(float[] v, int i, int j)
|
||||||
|
{
|
||||||
|
float dx = v[i] - v[j];
|
||||||
|
float dy = v[i + 1] - v[j + 1];
|
||||||
|
float dz = v[i + 2] - v[j + 2];
|
||||||
|
return dx * dx + dy * dy + dz * dz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float step(float threshold, float v)
|
||||||
|
{
|
||||||
|
return v < threshold ? 0.0f : 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float clamp(float v, float min, float max)
|
||||||
|
{
|
||||||
|
return Math.Max(Math.Min(v, max), min);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int clamp(int v, int min, int max)
|
||||||
|
{
|
||||||
|
return Math.Max(Math.Min(v, max), min);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float lerp(float f, float g, float u)
|
||||||
|
{
|
||||||
|
return u * g + (1f - u) * f;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s))
|
/// Performs a scaled vector addition. (@p v1 + (@p v2 * @p s))
|
||||||
/// @param[out] dest The result vector. [(x, y, z)]
|
/// @param[out] dest The result vector. [(x, y, z)]
|
||||||
|
@ -159,11 +227,6 @@ namespace DotRecast.Detour
|
||||||
return dx * dx + dy * dy + dz * dz;
|
return dx * dx + dy * dy + dz * dz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float sqr(float a)
|
|
||||||
{
|
|
||||||
return a * a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Derives the square of the scalar length of the vector. (len * len)
|
/// Derives the square of the scalar length of the vector. (len * len)
|
||||||
/// @param[in] v The vector. [(x, y, z)]
|
/// @param[in] v The vector. [(x, y, z)]
|
||||||
/// @return The square of the scalar length of the vector.
|
/// @return The square of the scalar length of the vector.
|
||||||
|
@ -185,15 +248,6 @@ namespace DotRecast.Detour
|
||||||
return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
|
return (float)Math.Sqrt(dx * dx + dy * dy + dz * dz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float clamp(float v, float min, float max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(v, max), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int clamp(int v, int min, int max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(v, max), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Derives the distance between the specified points on the xz-plane.
|
/// Derives the distance between the specified points on the xz-plane.
|
||||||
/// @param[in] v1 A point. [(x, y, z)]
|
/// @param[in] v1 A point. [(x, y, z)]
|
||||||
|
@ -236,7 +290,6 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly float EQUAL_THRESHOLD = sqr(1.0f / 16384.0f);
|
|
||||||
|
|
||||||
/// Performs a 'sloppy' colocation check of the specified points.
|
/// Performs a 'sloppy' colocation check of the specified points.
|
||||||
/// @param[in] p0 A point. [(x, y, z)]
|
/// @param[in] p0 A point. [(x, y, z)]
|
|
@ -18,12 +18,12 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Core
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Wrapper for 3-element pieces (3D vectors) of a bigger float array.
|
* Wrapper for 3-element pieces (3D vectors) of a bigger float array.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class VectorPtr
|
public class VectorPtr
|
||||||
{
|
{
|
||||||
private readonly float[] array;
|
private readonly float[] array;
|
|
@ -27,7 +27,7 @@ using DotRecast.Detour.Crowd.Tracking;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Members in this module implement local steering and dynamic avoidance features.
|
* Members in this module implement local steering and dynamic avoidance features.
|
||||||
|
|
|
@ -23,7 +23,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
/// Represents an agent managed by a #dtCrowd object.
|
/// Represents an agent managed by a #dtCrowd object.
|
||||||
/// @ingroup crowd
|
/// @ingroup crowd
|
||||||
|
|
|
@ -23,7 +23,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class LocalBoundary
|
public class LocalBoundary
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ using DotRecast.Detour.Crowd.Tracking;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class ObstacleAvoidanceQuery
|
public class ObstacleAvoidanceQuery
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a dynamic polygon corridor used to plan agent movement.
|
* Represents a dynamic polygon corridor used to plan agent movement.
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd
|
namespace DotRecast.Detour.Crowd
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class PathQueue
|
public class PathQueue
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd.Tracking
|
namespace DotRecast.Detour.Crowd.Tracking
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class ObstacleAvoidanceDebugData
|
public class ObstacleAvoidanceDebugData
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,7 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Dynamic
|
namespace DotRecast.Detour.Dynamic
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,7 @@ freely, subject to the following restrictions:
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras
|
namespace DotRecast.Detour.Extras
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras.Jumplink
|
namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras.Jumplink
|
namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras.Jumplink
|
namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Extras.Jumplink
|
namespace DotRecast.Detour.Extras.Jumplink
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io;
|
using DotRecast.Detour.TileCache.Io;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache
|
namespace DotRecast.Detour.TileCache
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,7 +24,7 @@ using System.IO;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io;
|
using DotRecast.Detour.TileCache.Io;
|
||||||
using DotRecast.Detour.TileCache.Io.Compress;
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache
|
namespace DotRecast.Detour.TileCache
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convex-convex intersection based on "Computational Geometry in C" by Joseph O'Rourke
|
* Convex-convex intersection based on "Computational Geometry in C" by Joseph O'Rourke
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <b>The Default Implementation</b>
|
* <b>The Default Implementation</b>
|
||||||
|
|
|
@ -15,10 +15,10 @@ freely, subject to the following restrictions:
|
||||||
misrepresented as being the original software.
|
misrepresented as being the original software.
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
*/
|
*/
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
|
||||||
|
|
||||||
public class DefaultQueryHeuristic : QueryHeuristic
|
public class DefaultQueryHeuristic : QueryHeuristic
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DotRecast.Core\DotRecast.Core.csproj"/>
|
<ProjectReference Include="..\DotRecast.Core\DotRecast.Core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -2,7 +2,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class FindNearestPolyQuery : PolyQuery
|
public class FindNearestPolyQuery : PolyQuery
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,7 +22,7 @@ using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Io
|
namespace DotRecast.Detour.Io
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
|
|
||||||
public class MeshSetReader
|
public class MeshSetReader
|
||||||
|
|
|
@ -18,10 +18,11 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
|
|
||||||
public class LegacyNavMeshQuery : NavMeshQuery
|
public class LegacyNavMeshQuery : NavMeshQuery
|
||||||
|
|
|
@ -25,7 +25,7 @@ using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class NavMesh
|
public class NavMesh
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,10 +20,11 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class NavMeshBuilder
|
public class NavMeshBuilder
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,10 +21,11 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
|
using DotRecast.Core;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static Node;
|
using static Node;
|
||||||
|
|
||||||
public class NavMeshQuery
|
public class NavMeshQuery
|
||||||
|
|
|
@ -20,7 +20,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public interface PolygonByCircleConstraint
|
public interface PolygonByCircleConstraint
|
||||||
{
|
{
|
||||||
|
|
|
@ -20,7 +20,7 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
namespace DotRecast.Detour
|
namespace DotRecast.Detour
|
||||||
{
|
{
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
//TODO: (PP) Add comments
|
//TODO: (PP) Add comments
|
||||||
public class StraightPathItem
|
public class StraightPathItem
|
||||||
|
|
|
@ -22,6 +22,7 @@ using System.Threading.Tasks;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour;
|
using DotRecast.Detour;
|
||||||
using DotRecast.Recast.Demo.Geom;
|
using DotRecast.Recast.Demo.Geom;
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Builder;
|
namespace DotRecast.Recast.Demo.Builder;
|
||||||
|
|
||||||
|
@ -99,7 +100,7 @@ public class TileNavMeshBuilder : AbstractNavMeshBuilder
|
||||||
int[] wh = Recast.calcGridSize(geom.getMeshBoundsMin(), geom.getMeshBoundsMax(), cellSize);
|
int[] wh = Recast.calcGridSize(geom.getMeshBoundsMin(), geom.getMeshBoundsMax(), cellSize);
|
||||||
int tw = (wh[0] + tileSize - 1) / tileSize;
|
int tw = (wh[0] + tileSize - 1) / tileSize;
|
||||||
int th = (wh[1] + tileSize - 1) / tileSize;
|
int th = (wh[1] + tileSize - 1) / tileSize;
|
||||||
int tileBits = Math.Min(DetourCommon.ilog2(DetourCommon.nextPow2(tw * th)), 14);
|
int tileBits = Math.Min(ilog2(nextPow2(tw * th)), 14);
|
||||||
return tileBits;
|
return tileBits;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Geom;
|
namespace DotRecast.Recast.Demo.Geom;
|
||||||
|
|
||||||
|
@ -33,11 +33,11 @@ public class Intersections
|
||||||
|
|
||||||
// Compute triangle normal. Can be precalculated or cached if
|
// Compute triangle normal. Can be precalculated or cached if
|
||||||
// intersecting multiple segments against the same triangle
|
// intersecting multiple segments against the same triangle
|
||||||
float[] norm = DemoMath.vCross(ab, ac);
|
float[] norm = RecastMath.vCross(ab, ac);
|
||||||
|
|
||||||
// Compute denominator d. If d <= 0, segment is parallel to or points
|
// Compute denominator d. If d <= 0, segment is parallel to or points
|
||||||
// away from triangle, so exit early
|
// away from triangle, so exit early
|
||||||
float d = DemoMath.vDot(qp, norm);
|
float d = RecastMath.vDot(qp, norm);
|
||||||
if (d <= 0.0f)
|
if (d <= 0.0f)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -47,7 +47,7 @@ public class Intersections
|
||||||
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
|
// intersects iff 0 <= t. Segment intersects iff 0 <= t <= 1. Delay
|
||||||
// dividing by d until intersection has been found to pierce triangle
|
// dividing by d until intersection has been found to pierce triangle
|
||||||
float[] ap = vSub(sp, a);
|
float[] ap = vSub(sp, a);
|
||||||
float t = DemoMath.vDot(ap, norm);
|
float t = RecastMath.vDot(ap, norm);
|
||||||
if (t < 0.0f)
|
if (t < 0.0f)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -59,14 +59,14 @@ public class Intersections
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute barycentric coordinate components and test if within bounds
|
// Compute barycentric coordinate components and test if within bounds
|
||||||
float[] e = DemoMath.vCross(qp, ap);
|
float[] e = RecastMath.vCross(qp, ap);
|
||||||
v = DemoMath.vDot(ac, e);
|
v = RecastMath.vDot(ac, e);
|
||||||
if (v < 0.0f || v > d)
|
if (v < 0.0f || v > d)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
w = -DemoMath.vDot(ab, e);
|
w = -RecastMath.vDot(ab, e);
|
||||||
if (w < 0.0f || v + w > d)
|
if (w < 0.0f || v + w > d)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -45,7 +45,7 @@ using DotRecast.Recast.Demo.Tools;
|
||||||
using DotRecast.Recast.Demo.UI;
|
using DotRecast.Recast.Demo.UI;
|
||||||
using Silk.NET.SDL;
|
using Silk.NET.SDL;
|
||||||
using Silk.NET.Windowing.Sdl;
|
using Silk.NET.Windowing.Sdl;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using Color = System.Drawing.Color;
|
using Color = System.Drawing.Color;
|
||||||
using Window = Silk.NET.Windowing.Window;
|
using Window = Silk.NET.Windowing.Window;
|
||||||
|
|
||||||
|
@ -457,13 +457,13 @@ public class RecastDemo
|
||||||
var tempMoveDown = keyboard.IsKeyPressed(Key.E) || keyboard.IsKeyPressed(Key.PageDown) ? 1.0f : -1f;
|
var tempMoveDown = keyboard.IsKeyPressed(Key.E) || keyboard.IsKeyPressed(Key.PageDown) ? 1.0f : -1f;
|
||||||
var tempMoveAccel = keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight) ? 1.0f : -1f;
|
var tempMoveAccel = keyboard.IsKeyPressed(Key.ShiftLeft) || keyboard.IsKeyPressed(Key.ShiftRight) ? 1.0f : -1f;
|
||||||
|
|
||||||
_moveFront = DemoMath.clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f);
|
_moveFront = RecastMath.clamp(_moveFront + tempMoveFront * dt * 4.0f, 0, 2.0f);
|
||||||
_moveLeft = DemoMath.clamp(_moveLeft + tempMoveLeft * dt * 4.0f, 0, 2.0f);
|
_moveLeft = RecastMath.clamp(_moveLeft + tempMoveLeft * dt * 4.0f, 0, 2.0f);
|
||||||
_moveBack = DemoMath.clamp(_moveBack + tempMoveBack * dt * 4.0f, 0, 2.0f);
|
_moveBack = RecastMath.clamp(_moveBack + tempMoveBack * dt * 4.0f, 0, 2.0f);
|
||||||
_moveRight = DemoMath.clamp(_moveRight + tempMoveRight * dt * 4.0f, 0, 2.0f);
|
_moveRight = RecastMath.clamp(_moveRight + tempMoveRight * dt * 4.0f, 0, 2.0f);
|
||||||
_moveUp = DemoMath.clamp(_moveUp + tempMoveUp * dt * 4.0f, 0, 2.0f);
|
_moveUp = RecastMath.clamp(_moveUp + tempMoveUp * dt * 4.0f, 0, 2.0f);
|
||||||
_moveDown = DemoMath.clamp(_moveDown + tempMoveDown * dt * 4.0f, 0, 2.0f);
|
_moveDown = RecastMath.clamp(_moveDown + tempMoveDown * dt * 4.0f, 0, 2.0f);
|
||||||
_moveAccel = DemoMath.clamp(_moveAccel + tempMoveAccel * dt * 4.0f, 0, 2.0f);
|
_moveAccel = RecastMath.clamp(_moveAccel + tempMoveAccel * dt * 4.0f, 0, 2.0f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ public class RecastDemo
|
||||||
if (bmin != null && bmax != null)
|
if (bmin != null && bmax != null)
|
||||||
{
|
{
|
||||||
camr = (float)(Math.Sqrt(
|
camr = (float)(Math.Sqrt(
|
||||||
DemoMath.sqr(bmax[0] - bmin[0]) + DemoMath.sqr(bmax[1] - bmin[1]) + DemoMath.sqr(bmax[2] - bmin[2]))
|
RecastMath.sqr(bmax[0] - bmin[0]) + RecastMath.sqr(bmax[1] - bmin[1]) + RecastMath.sqr(bmax[2] - bmin[2]))
|
||||||
/ 2);
|
/ 2);
|
||||||
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
cameraPos[0] = (bmax[0] + bmin[0]) / 2 + camr;
|
||||||
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
cameraPos[1] = (bmax[1] + bmin[1]) / 2 + camr;
|
||||||
|
|
|
@ -79,7 +79,7 @@ public class ConvexVolumeTool : Tool
|
||||||
// Create
|
// Create
|
||||||
|
|
||||||
// If clicked on that last pt, create the shape.
|
// If clicked on that last pt, create the shape.
|
||||||
if (pts.Count > 0 && DemoMath.vDistSqr(p,
|
if (pts.Count > 0 && RecastMath.vDistSqr(p,
|
||||||
new float[] { pts[pts.Count - 3], pts[pts.Count - 2], pts[pts.Count - 1] },
|
new float[] { pts[pts.Count - 3], pts[pts.Count - 2], pts[pts.Count - 1] },
|
||||||
0) < 0.2f * 0.2f)
|
0) < 0.2f * 0.2f)
|
||||||
{
|
{
|
||||||
|
|
|
@ -186,7 +186,7 @@ public class CrowdProfilingTool
|
||||||
bool valid = true;
|
bool valid = true;
|
||||||
foreach (FindRandomPointResult zone in zones)
|
foreach (FindRandomPointResult zone in zones)
|
||||||
{
|
{
|
||||||
if (DemoMath.vDistSqr(zone.getRandomPt(), result.result.getRandomPt(), 0) < zoneSeparation)
|
if (RecastMath.vDistSqr(zone.getRandomPt(), result.result.getRandomPt(), 0) < zoneSeparation)
|
||||||
{
|
{
|
||||||
valid = false;
|
valid = false;
|
||||||
break;
|
break;
|
||||||
|
@ -310,7 +310,7 @@ public class CrowdProfilingTool
|
||||||
List<FindRandomPointResult> potentialTargets = new();
|
List<FindRandomPointResult> potentialTargets = new();
|
||||||
foreach (FindRandomPointResult zone in zones)
|
foreach (FindRandomPointResult zone in zones)
|
||||||
{
|
{
|
||||||
if (DemoMath.vDistSqr(zone.getRandomPt(), ag.npos, 0) > zoneRadius * zoneRadius)
|
if (RecastMath.vDistSqr(zone.getRandomPt(), ag.npos, 0) > zoneRadius * zoneRadius)
|
||||||
{
|
{
|
||||||
potentialTargets.Add(zone);
|
potentialTargets.Add(zone);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ using DotRecast.Recast.Demo.Geom;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Tools;
|
namespace DotRecast.Recast.Demo.Tools;
|
||||||
|
|
||||||
|
@ -323,10 +324,10 @@ public class CrowdTool : Tool
|
||||||
|
|
||||||
private float[] calcVel(float[] pos, float[] tgt, float speed)
|
private float[] calcVel(float[] pos, float[] tgt, float speed)
|
||||||
{
|
{
|
||||||
float[] vel = DetourCommon.vSub(tgt, pos);
|
float[] vel = vSub(tgt, pos);
|
||||||
vel[1] = 0.0f;
|
vel[1] = 0.0f;
|
||||||
DetourCommon.vNormalize(vel);
|
vNormalize(vel);
|
||||||
return DetourCommon.vScale(vel, speed);
|
return vScale(vel, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void handleRender(NavMeshRenderer renderer)
|
public override void handleRender(NavMeshRenderer renderer)
|
||||||
|
@ -414,7 +415,7 @@ public class CrowdTool : Tool
|
||||||
dd.begin(LINES, 3.0f);
|
dd.begin(LINES, 3.0f);
|
||||||
float[] prev = new float[3];
|
float[] prev = new float[3];
|
||||||
float preva = 1;
|
float preva = 1;
|
||||||
DetourCommon.vCopy(prev, pos);
|
vCopy(prev, pos);
|
||||||
for (int j = 0; j < AGENT_MAX_TRAIL - 1; ++j)
|
for (int j = 0; j < AGENT_MAX_TRAIL - 1; ++j)
|
||||||
{
|
{
|
||||||
int idx = (trail.htrail + AGENT_MAX_TRAIL - j) % AGENT_MAX_TRAIL;
|
int idx = (trail.htrail + AGENT_MAX_TRAIL - j) % AGENT_MAX_TRAIL;
|
||||||
|
@ -423,7 +424,7 @@ public class CrowdTool : Tool
|
||||||
dd.vertex(prev[0], prev[1] + 0.1f, prev[2], duRGBA(0, 0, 0, (int)(128 * preva)));
|
dd.vertex(prev[0], prev[1] + 0.1f, prev[2], duRGBA(0, 0, 0, (int)(128 * preva)));
|
||||||
dd.vertex(trail.trail[v], trail.trail[v + 1] + 0.1f, trail.trail[v + 2], duRGBA(0, 0, 0, (int)(128 * a)));
|
dd.vertex(trail.trail[v], trail.trail[v + 1] + 0.1f, trail.trail[v + 2], duRGBA(0, 0, 0, (int)(128 * a)));
|
||||||
preva = a;
|
preva = a;
|
||||||
DetourCommon.vCopy(prev, trail.trail, v);
|
vCopy(prev, trail.trail, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
dd.end();
|
dd.end();
|
||||||
|
@ -500,7 +501,7 @@ public class CrowdTool : Tool
|
||||||
float[] s = ag.boundary.getSegment(j);
|
float[] s = ag.boundary.getSegment(j);
|
||||||
float[] s0 = new float[] { s[0], s[1], s[2] };
|
float[] s0 = new float[] { s[0], s[1], s[2] };
|
||||||
float[] s3 = new float[] { s[3], s[4], s[5] };
|
float[] s3 = new float[] { s[3], s[4], s[5] };
|
||||||
if (DetourCommon.triArea2D(pos, s0, s3) < 0.0f)
|
if (triArea2D(pos, s0, s3) < 0.0f)
|
||||||
col = duDarkenCol(col);
|
col = duDarkenCol(col);
|
||||||
|
|
||||||
dd.appendArrow(s[0], s[1] + 0.2f, s[2], s[3], s[4] + 0.2f, s[5], 0.0f, 0.3f, col);
|
dd.appendArrow(s[0], s[1] + 0.2f, s[2], s[3], s[4] + 0.2f, s[5], 0.0f, 0.3f, col);
|
||||||
|
|
|
@ -33,7 +33,7 @@ using ImGuiNET;
|
||||||
using Silk.NET.Windowing;
|
using Silk.NET.Windowing;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Tools;
|
namespace DotRecast.Recast.Demo.Tools;
|
||||||
|
|
||||||
|
@ -252,7 +252,7 @@ public class DynamicUpdateTool : Tool
|
||||||
float[] baseUp = new float[] { 0, 1, 0 };
|
float[] baseUp = new float[] { 0, 1, 0 };
|
||||||
float[] forward = new float[] { (1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()) };
|
float[] forward = new float[] { (1f - 2 * (float)random.NextDouble()), 0, (1f - 2 * (float)random.NextDouble()) };
|
||||||
vNormalize(forward);
|
vNormalize(forward);
|
||||||
float[] side = DemoMath.vCross(forward, baseUp);
|
float[] side = RecastMath.vCross(forward, baseUp);
|
||||||
BoxCollider @base = new BoxCollider(baseCenter, BoxCollider.getHalfEdges(baseUp, forward, baseExtent),
|
BoxCollider @base = new BoxCollider(baseCenter, BoxCollider.getHalfEdges(baseUp, forward, baseExtent),
|
||||||
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, dynaMesh.config.walkableClimb);
|
SampleAreaModifications.SAMPLE_POLYAREA_TYPE_ROAD, dynaMesh.config.walkableClimb);
|
||||||
float[] roofExtent = new float[] { 4.5f, 4.5f, 8f };
|
float[] roofExtent = new float[] { 4.5f, 4.5f, 8f };
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using static DotRecast.Recast.RecastVectors;
|
using static DotRecast.Recast.RecastVectors;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Tools.Gizmos;
|
namespace DotRecast.Recast.Demo.Tools.Gizmos;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using static DotRecast.Recast.RecastVectors;
|
using static DotRecast.Recast.RecastVectors;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Recast.Demo.Tools.Gizmos;
|
namespace DotRecast.Recast.Demo.Tools.Gizmos;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
using static DotRecast.Recast.Demo.Tools.Gizmos.GizmoHelper;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ using DotRecast.Recast.Demo.Builder;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using DotRecast.Recast.Demo.Geom;
|
using DotRecast.Recast.Demo.Geom;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
||||||
|
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class OffMeshConnectionTool : Tool
|
||||||
DemoOffMeshConnection nearestConnection = null;
|
DemoOffMeshConnection nearestConnection = null;
|
||||||
foreach (DemoOffMeshConnection offMeshCon in geom.getOffMeshConnections())
|
foreach (DemoOffMeshConnection offMeshCon in geom.getOffMeshConnections())
|
||||||
{
|
{
|
||||||
float d = Math.Min(DemoMath.vDistSqr(p, offMeshCon.verts, 0), DemoMath.vDistSqr(p, offMeshCon.verts, 3));
|
float d = Math.Min(RecastMath.vDistSqr(p, offMeshCon.verts, 0), RecastMath.vDistSqr(p, offMeshCon.verts, 3));
|
||||||
if (d < nearestDist && Math.Sqrt(d) < sample.getSettingsUI().getAgentRadius())
|
if (d < nearestDist && Math.Sqrt(d) < sample.getSettingsUI().getAgentRadius())
|
||||||
{
|
{
|
||||||
nearestDist = d;
|
nearestDist = d;
|
||||||
|
|
|
@ -6,7 +6,7 @@ using DotRecast.Detour;
|
||||||
using DotRecast.Recast.Demo.Builder;
|
using DotRecast.Recast.Demo.Builder;
|
||||||
using DotRecast.Recast.Demo.Draw;
|
using DotRecast.Recast.Demo.Draw;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
using static DotRecast.Recast.Demo.Draw.DebugDraw;
|
||||||
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
using static DotRecast.Recast.Demo.Draw.DebugDrawPrimitives;
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ public class TestNavmeshTool : Tool
|
||||||
|
|
||||||
// Find movement delta.
|
// Find movement delta.
|
||||||
float[] delta = vSub(steerTarget.steerPos, iterPos);
|
float[] delta = vSub(steerTarget.steerPos, iterPos);
|
||||||
float len = (float)Math.Sqrt(DemoMath.vDot(delta, delta));
|
float len = (float)Math.Sqrt(RecastMath.vDot(delta, delta));
|
||||||
// If the steer target is end of path or off-mesh link, do not move past the location.
|
// If the steer target is end of path or off-mesh link, do not move past the location.
|
||||||
if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
|
if ((endOfPath || offMeshConnection) && len < STEP_SIZE)
|
||||||
{
|
{
|
||||||
|
@ -882,8 +882,8 @@ public class TestNavmeshTool : Tool
|
||||||
float[] s = wallSegments.getSegmentVerts()[j];
|
float[] s = wallSegments.getSegmentVerts()[j];
|
||||||
float[] s3 = new float[] { s[3], s[4], s[5] };
|
float[] s3 = new float[] { s[3], s[4], s[5] };
|
||||||
// Skip too distant segments.
|
// Skip too distant segments.
|
||||||
Tuple<float, float> distSqr = DetourCommon.distancePtSegSqr2D(m_spos, s, 0, 3);
|
Tuple<float, float> distSqr = distancePtSegSqr2D(m_spos, s, 0, 3);
|
||||||
if (distSqr.Item1 > DemoMath.sqr(m_neighbourhoodRadius))
|
if (distSqr.Item1 > RecastMath.sqr(m_neighbourhoodRadius))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -903,7 +903,7 @@ public class TestNavmeshTool : Tool
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int col = duRGBA(192, 32, 16, 192);
|
int col = duRGBA(192, 32, 16, 192);
|
||||||
if (DetourCommon.triArea2D(m_spos, s, s3) < 0.0f)
|
if (triArea2D(m_spos, s, s3) < 0.0f)
|
||||||
{
|
{
|
||||||
col = duRGBA(96, 32, 16, 192);
|
col = duRGBA(96, 32, 16, 192);
|
||||||
}
|
}
|
||||||
|
@ -1026,7 +1026,7 @@ public class TestNavmeshTool : Tool
|
||||||
{
|
{
|
||||||
// In case of partial path, make sure the end point is clamped to the last polygon.
|
// In case of partial path, make sure the end point is clamped to the last polygon.
|
||||||
float[] epos = new float[3];
|
float[] epos = new float[3];
|
||||||
DetourCommon.vCopy(epos, m_epos);
|
vCopy(epos, m_epos);
|
||||||
if (m_polys[m_polys.Count - 1] != m_endRef)
|
if (m_polys[m_polys.Count - 1] != m_endRef)
|
||||||
{
|
{
|
||||||
Result<ClosestPointOnPolyResult> result = m_navQuery
|
Result<ClosestPointOnPolyResult> result = m_navQuery
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
public class RecastCommon
|
public static class RecastCommon
|
||||||
{
|
{
|
||||||
/// Gets neighbor connection data for the specified direction.
|
/// Gets neighbor connection data for the specified direction.
|
||||||
/// @param[in] s The span to check.
|
/// @param[in] s The span to check.
|
||||||
|
@ -75,10 +75,5 @@ namespace DotRecast.Recast
|
||||||
int con = s.con;
|
int con = s.con;
|
||||||
s.con = (con & ~(0x3f << shift)) | ((i & 0x3f) << shift);
|
s.con = (con & ~(0x3f << shift)) | ((i & 0x3f) << shift);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int clamp(int v, int min, int max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(max, v), min);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -18,11 +18,12 @@ freely, subject to the following restrictions:
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
using static DotRecast.Recast.RecastConstants;
|
||||||
|
using static DotRecast.Recast.RecastVectors;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
using static RecastConstants;
|
|
||||||
using static RecastVectors;
|
|
||||||
|
|
||||||
public class RecastCompact
|
public class RecastCompact
|
||||||
{
|
{
|
||||||
private const int MAX_LAYERS = RC_NOT_CONNECTED - 1;
|
private const int MAX_LAYERS = RC_NOT_CONNECTED - 1;
|
||||||
|
@ -92,8 +93,8 @@ namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
int bot = s.smax;
|
int bot = s.smax;
|
||||||
int top = s.next != null ? (int)s.next.smin : MAX_HEIGHT;
|
int top = s.next != null ? (int)s.next.smin : MAX_HEIGHT;
|
||||||
chf.spans[idx].y = RecastCommon.clamp(bot, 0, MAX_HEIGHT);
|
chf.spans[idx].y = clamp(bot, 0, MAX_HEIGHT);
|
||||||
chf.spans[idx].h = RecastCommon.clamp(top - bot, 0, MAX_HEIGHT);
|
chf.spans[idx].h = clamp(top - bot, 0, MAX_HEIGHT);
|
||||||
chf.areas[idx] = s.area;
|
chf.areas[idx] = s.area;
|
||||||
idx++;
|
idx++;
|
||||||
c.count++;
|
c.count++;
|
||||||
|
|
|
@ -19,12 +19,12 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
using static DotRecast.Recast.RecastConstants;
|
||||||
|
using static DotRecast.Recast.RecastVectors;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
using static RecastConstants;
|
|
||||||
using static RecastVectors;
|
|
||||||
using static RecastCommon;
|
|
||||||
|
|
||||||
public class RecastFilledVolumeRasterization
|
public class RecastFilledVolumeRasterization
|
||||||
{
|
{
|
||||||
private const float EPSILON = 0.00001f;
|
private const float EPSILON = 0.00001f;
|
||||||
|
@ -230,8 +230,8 @@ namespace DotRecast.Recast
|
||||||
int smax = (int)Math.Ceiling((h[1] - hf.bmin[1]) * ich);
|
int smax = (int)Math.Ceiling((h[1] - hf.bmin[1]) * ich);
|
||||||
if (smin != smax)
|
if (smin != smax)
|
||||||
{
|
{
|
||||||
int ismin = RecastCommon.clamp(smin, 0, SPAN_MAX_HEIGHT);
|
int ismin = clamp(smin, 0, SPAN_MAX_HEIGHT);
|
||||||
int ismax = RecastCommon.clamp(smax, ismin + 1, SPAN_MAX_HEIGHT);
|
int ismax = clamp(smax, ismin + 1, SPAN_MAX_HEIGHT);
|
||||||
RecastRasterization.addSpan(hf, x, z, ismin, ismax, area, flagMergeThr);
|
RecastRasterization.addSpan(hf, x, z, ismin, ismax, area, flagMergeThr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -786,11 +786,6 @@ namespace DotRecast.Recast
|
||||||
return dx * dx + dy * dy + dz * dz;
|
return dx * dx + dy * dy + dz * dz;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float clamp(float v, float min, float max)
|
|
||||||
{
|
|
||||||
return Math.Max(Math.Min(max, v), min);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool overlapBounds(float[] amin, float[] amax, float[] bounds)
|
private static bool overlapBounds(float[] amin, float[] amax, float[] bounds)
|
||||||
{
|
{
|
||||||
bool overlap = true;
|
bool overlap = true;
|
||||||
|
|
|
@ -21,11 +21,12 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
using static DotRecast.Recast.RecastCommon;
|
||||||
|
using static DotRecast.Recast.RecastConstants;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
using static RecastCommon;
|
|
||||||
using static RecastConstants;
|
|
||||||
|
|
||||||
public class RecastMeshDetail
|
public class RecastMeshDetail
|
||||||
{
|
{
|
||||||
|
@ -273,8 +274,8 @@ namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
int ix = (int)Math.Floor(fx * ics + 0.01f);
|
int ix = (int)Math.Floor(fx * ics + 0.01f);
|
||||||
int iz = (int)Math.Floor(fz * ics + 0.01f);
|
int iz = (int)Math.Floor(fz * ics + 0.01f);
|
||||||
ix = RecastCommon.clamp(ix - hp.xmin, 0, hp.width - 1);
|
ix = clamp(ix - hp.xmin, 0, hp.width - 1);
|
||||||
iz = RecastCommon.clamp(iz - hp.ymin, 0, hp.height - 1);
|
iz = clamp(iz - hp.ymin, 0, hp.height - 1);
|
||||||
int h = hp.data[ix + iz * hp.width];
|
int h = hp.data[ix + iz * hp.width];
|
||||||
if (h == RC_UNSET_HEIGHT)
|
if (h == RC_UNSET_HEIGHT)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,10 +19,11 @@ freely, subject to the following restrictions:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using static DotRecast.Core.RecastMath;
|
||||||
|
using static DotRecast.Recast.RecastConstants;
|
||||||
|
|
||||||
namespace DotRecast.Recast
|
namespace DotRecast.Recast
|
||||||
{
|
{
|
||||||
using static RecastConstants;
|
|
||||||
|
|
||||||
public class RecastRasterization
|
public class RecastRasterization
|
||||||
{
|
{
|
||||||
|
@ -269,8 +270,8 @@ namespace DotRecast.Recast
|
||||||
int w = hf.width;
|
int w = hf.width;
|
||||||
int h = hf.height;
|
int h = hf.height;
|
||||||
// use -1 rather than 0 to cut the polygon properly at the start of the tile
|
// use -1 rather than 0 to cut the polygon properly at the start of the tile
|
||||||
z0 = RecastCommon.clamp(z0, -1, h - 1);
|
z0 = clamp(z0, -1, h - 1);
|
||||||
z1 = RecastCommon.clamp(z1, 0, h - 1);
|
z1 = clamp(z1, 0, h - 1);
|
||||||
|
|
||||||
// Clip the triangle into all grid cells it touches.
|
// Clip the triangle into all grid cells it touches.
|
||||||
float[] buf = new float[7 * 3 * 4];
|
float[] buf = new float[7 * 3 * 4];
|
||||||
|
@ -320,8 +321,8 @@ namespace DotRecast.Recast
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
x0 = RecastCommon.clamp(x0, -1, w - 1);
|
x0 = clamp(x0, -1, w - 1);
|
||||||
x1 = RecastCommon.clamp(x1, 0, w - 1);
|
x1 = clamp(x1, 0, w - 1);
|
||||||
|
|
||||||
int nv, nv2 = nvRow;
|
int nv, nv2 = nvRow;
|
||||||
for (int x = x0; x <= x1; ++x)
|
for (int x = x0; x <= x1; ++x)
|
||||||
|
@ -366,8 +367,8 @@ namespace DotRecast.Recast
|
||||||
spanMax = by;
|
spanMax = by;
|
||||||
|
|
||||||
// Snap the span to the heightfield height grid.
|
// Snap the span to the heightfield height grid.
|
||||||
int spanMinCellIndex = RecastCommon.clamp((int)Math.Floor(spanMin * inverseCellHeight), 0, SPAN_MAX_HEIGHT);
|
int spanMinCellIndex = clamp((int)Math.Floor(spanMin * inverseCellHeight), 0, SPAN_MAX_HEIGHT);
|
||||||
int spanMaxCellIndex = RecastCommon.clamp((int)Math.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, SPAN_MAX_HEIGHT);
|
int spanMaxCellIndex = clamp((int)Math.Ceiling(spanMax * inverseCellHeight), spanMinCellIndex + 1, SPAN_MAX_HEIGHT);
|
||||||
|
|
||||||
addSpan(hf, x, z, spanMinCellIndex, spanMaxCellIndex, area, flagMergeThreshold);
|
addSpan(hf, x, z, spanMinCellIndex, spanMaxCellIndex, area, flagMergeThreshold);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ using NUnit.Framework;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Crowd.Test;
|
namespace DotRecast.Detour.Crowd.Test;
|
||||||
|
|
||||||
using static DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
public class AbstractCrowdTest
|
public class AbstractCrowdTest
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ using DotRecast.Detour.Io;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using DotRecast.Recast.Geom;
|
using DotRecast.Recast.Geom;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Test.Io;
|
namespace DotRecast.Detour.Test.Io;
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ freely, subject to the following restrictions:
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.Test;
|
namespace DotRecast.Detour.Test;
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ freely, subject to the following restrictions:
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Detour.TileCache.Io.Compress;
|
using DotRecast.Detour.TileCache.Io.Compress;
|
||||||
using DotRecast.Recast.Geom;
|
using DotRecast.Recast.Geom;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
using static DotRecast.Recast.RecastVectors;
|
using static DotRecast.Recast.RecastVectors;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache.Test;
|
namespace DotRecast.Detour.TileCache.Test;
|
||||||
|
|
|
@ -22,7 +22,7 @@ using System.Collections.Generic;
|
||||||
using DotRecast.Core;
|
using DotRecast.Core;
|
||||||
using DotRecast.Recast;
|
using DotRecast.Recast;
|
||||||
using DotRecast.Recast.Geom;
|
using DotRecast.Recast.Geom;
|
||||||
using static DotRecast.Detour.DetourCommon;
|
using static DotRecast.Core.RecastMath;
|
||||||
|
|
||||||
namespace DotRecast.Detour.TileCache.Test;
|
namespace DotRecast.Detour.TileCache.Test;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue