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-04-23 08:13:10 +03:00
|
|
|
using DotRecast.Detour.QueryResults;
|
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-05-02 17:16:31 +03:00
|
|
|
private static readonly Vector3f[] HIT_POSITION =
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
2023-05-02 17:16:31 +03:00
|
|
|
Vector3f.Of(23.177608f, 10.197294f, -45.742954f),
|
|
|
|
Vector3f.Of(22.331268f, 10.197294f, -4.241272f),
|
|
|
|
Vector3f.Of(18.108675f, 15.743596f, -73.236839f),
|
|
|
|
Vector3f.Of(1.984785f, 10.197294f, -8.441269f),
|
|
|
|
Vector3f.Of(-22.315216f, 4.997294f, -11.441269f),
|
2023-03-14 08:02:43 +03:00
|
|
|
};
|
|
|
|
|
2023-05-02 17:16:31 +03:00
|
|
|
private static readonly Vector3f[] HIT_NORMAL =
|
2023-03-14 08:02:43 +03:00
|
|
|
{
|
2023-05-02 17:16:31 +03:00
|
|
|
Vector3f.Of(-0.955779f, 0.0f, -0.29408592f),
|
|
|
|
Vector3f.Of(0.0f, 0.0f, 1.0f),
|
|
|
|
Vector3f.Of(0.97014254f, 0.0f, 0.24253564f),
|
|
|
|
Vector3f.Of(-1.0f, 0.0f, 0.0f),
|
|
|
|
Vector3f.Of(1.0f, 0.0f, 0.0f),
|
2023-03-14 08:02:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void testFindDistanceToWall()
|
|
|
|
{
|
|
|
|
QueryFilter filter = new DefaultQueryFilter();
|
|
|
|
for (int i = 0; i < startRefs.Length; i++)
|
|
|
|
{
|
2023-03-29 18:59:00 +03:00
|
|
|
Vector3f startPos = startPoss[i];
|
2023-03-14 08:02:43 +03:00
|
|
|
Result<FindDistanceToWallResult> result = query.findDistanceToWall(startRefs[i], startPos, 3.5f, filter);
|
|
|
|
FindDistanceToWallResult hit = result.result;
|
|
|
|
Assert.That(hit.getDistance(), Is.EqualTo(DISTANCES_TO_WALL[i]).Within(0.001f));
|
2023-05-02 17:16:31 +03:00
|
|
|
|
|
|
|
Assert.That(hit.getPosition().x, Is.EqualTo(HIT_POSITION[i].x).Within(0.001f));
|
|
|
|
Assert.That(hit.getPosition().y, Is.EqualTo(HIT_POSITION[i].y).Within(0.001f));
|
|
|
|
Assert.That(hit.getPosition().z, Is.EqualTo(HIT_POSITION[i].z).Within(0.001f));
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-02 17:16:31 +03:00
|
|
|
Assert.That(hit.getNormal().x, Is.EqualTo(HIT_NORMAL[i].x).Within(0.001f));
|
|
|
|
Assert.That(hit.getNormal().y, Is.EqualTo(HIT_NORMAL[i].y).Within(0.001f));
|
|
|
|
Assert.That(hit.getNormal().z, Is.EqualTo(HIT_NORMAL[i].z).Within(0.001f));
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|