2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
recast4j Copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2023-03-29 18:59:00 +03:00
|
|
|
using DotRecast.Core;
|
2023-06-23 01:54:28 +03:00
|
|
|
|
2023-03-14 08:02:43 +03:00
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
namespace DotRecast.Detour.Test;
|
|
|
|
|
2023-04-25 17:22:44 +03:00
|
|
|
[Parallelizable]
|
2023-03-14 08:02:43 +03:00
|
|
|
public class FindDistanceToWallTest : AbstractDetourTest
|
|
|
|
{
|
|
|
|
private static readonly float[] DISTANCES_TO_WALL = { 0.597511f, 3.201085f, 0.603713f, 2.791475f, 2.815544f };
|
|
|
|
|
2023-06-03 15:47:26 +03:00
|
|
|
private static readonly RcVec3f[] HIT_POSITION =
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
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),
|
2023-03-14 08:02:43 +03:00
|
|
|
};
|
|
|
|
|
2023-06-03 15:47:26 +03:00
|
|
|
private static readonly RcVec3f[] HIT_NORMAL =
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
2023-10-12 17:52:32 +03:00
|
|
|
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),
|
2023-03-14 08:02:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
[Test]
|
2023-05-05 02:44:48 +03:00
|
|
|
public void TestFindDistanceToWall()
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
2023-06-08 15:38:02 +03:00
|
|
|
IDtQueryFilter filter = new DtQueryDefaultFilter();
|
2023-03-14 08:02:43 +03:00
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f startPos = startPoss[i];
|
2023-06-18 11:29:36 +03:00
|
|
|
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));
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-10-12 17:04:29 +03:00
|
|
|
Assert.That(hitPos.X, Is.EqualTo(HIT_POSITION[i].X).Within(0.001f));
|
|
|
|
Assert.That(hitPos.Y, Is.EqualTo(HIT_POSITION[i].Y).Within(0.001f));
|
|
|
|
Assert.That(hitPos.Z, Is.EqualTo(HIT_POSITION[i].Z).Within(0.001f));
|
2023-06-18 11:29:36 +03:00
|
|
|
|
2023-10-12 17:04:29 +03:00
|
|
|
Assert.That(hitNormal.X, Is.EqualTo(HIT_NORMAL[i].X).Within(0.001f));
|
|
|
|
Assert.That(hitNormal.Y, Is.EqualTo(HIT_NORMAL[i].Y).Within(0.001f));
|
|
|
|
Assert.That(hitNormal.Z, Is.EqualTo(HIT_NORMAL[i].Z).Within(0.001f));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|