2023-03-14 08:02:43 +03:00
|
|
|
/*
|
|
|
|
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
|
|
|
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
2023-03-15 17:00:29 +03:00
|
|
|
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
2023-03-14 08:02:43 +03:00
|
|
|
|
|
|
|
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;
|
2023-03-28 19:52:26 +03:00
|
|
|
using DotRecast.Core;
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-03-16 19:09:10 +03:00
|
|
|
namespace DotRecast.Detour.Crowd.Tracking
|
|
|
|
{
|
2023-09-23 01:30:47 +03:00
|
|
|
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public class DtObstacleAvoidanceDebugData
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-05-10 18:10:35 +03:00
|
|
|
private int m_nsamples;
|
|
|
|
private int m_maxSamples;
|
|
|
|
private float[] m_vel;
|
|
|
|
private float[] m_ssize;
|
|
|
|
private float[] m_pen;
|
|
|
|
private float[] m_vpen;
|
|
|
|
private float[] m_vcpen;
|
|
|
|
private float[] m_spen;
|
|
|
|
private float[] m_tpen;
|
2023-03-16 19:48:49 +03:00
|
|
|
|
2023-06-08 15:38:02 +03:00
|
|
|
public DtObstacleAvoidanceDebugData(int maxSamples)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
m_maxSamples = maxSamples;
|
|
|
|
m_vel = new float[3 * m_maxSamples];
|
|
|
|
m_pen = new float[m_maxSamples];
|
|
|
|
m_ssize = new float[m_maxSamples];
|
|
|
|
m_vpen = new float[m_maxSamples];
|
|
|
|
m_vcpen = new float[m_maxSamples];
|
|
|
|
m_spen = new float[m_maxSamples];
|
|
|
|
m_tpen = new float[m_maxSamples];
|
|
|
|
}
|
2023-03-16 19:09:10 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public void Reset()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
m_nsamples = 0;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
void NormalizeArray(float[] arr, int n)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
// Normalize penaly range.
|
|
|
|
float minPen = float.MaxValue;
|
|
|
|
float maxPen = -float.MaxValue;
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
|
|
{
|
|
|
|
minPen = Math.Min(minPen, arr[i]);
|
|
|
|
maxPen = Math.Max(maxPen, arr[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
float penRange = maxPen - minPen;
|
|
|
|
float s = penRange > 0.001f ? (1.0f / penRange) : 1;
|
|
|
|
for (int i = 0; i < n; ++i)
|
2023-09-23 01:30:47 +03:00
|
|
|
arr[i] = RcMath.Clamp((arr[i] - minPen) * s, 0.0f, 1.0f);
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public void NormalizeSamples()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-05-05 02:44:48 +03:00
|
|
|
NormalizeArray(m_pen, m_nsamples);
|
|
|
|
NormalizeArray(m_vpen, m_nsamples);
|
|
|
|
NormalizeArray(m_vcpen, m_nsamples);
|
|
|
|
NormalizeArray(m_spen, m_nsamples);
|
|
|
|
NormalizeArray(m_tpen, m_nsamples);
|
2023-03-16 19:48:49 +03:00
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-03 15:47:26 +03:00
|
|
|
public void AddSample(RcVec3f vel, float ssize, float pen, float vpen, float vcpen, float spen, float tpen)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
if (m_nsamples >= m_maxSamples)
|
|
|
|
return;
|
2023-04-29 07:06:21 +03:00
|
|
|
m_vel[m_nsamples * 3] = vel.x;
|
|
|
|
m_vel[m_nsamples * 3 + 1] = vel.y;
|
|
|
|
m_vel[m_nsamples * 3 + 2] = vel.z;
|
2023-03-16 19:48:49 +03:00
|
|
|
m_ssize[m_nsamples] = ssize;
|
|
|
|
m_pen[m_nsamples] = pen;
|
|
|
|
m_vpen[m_nsamples] = vpen;
|
|
|
|
m_vcpen[m_nsamples] = vcpen;
|
|
|
|
m_spen[m_nsamples] = spen;
|
|
|
|
m_tpen[m_nsamples] = tpen;
|
|
|
|
m_nsamples++;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public int GetSampleCount()
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_nsamples;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-06-03 15:47:26 +03:00
|
|
|
public RcVec3f GetSampleVelocity(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
2023-06-03 15:47:26 +03:00
|
|
|
RcVec3f vel = new RcVec3f();
|
2023-04-29 07:06:21 +03:00
|
|
|
vel.x = m_vel[i * 3];
|
|
|
|
vel.y = m_vel[i * 3 + 1];
|
|
|
|
vel.z = m_vel[i * 3 + 2];
|
2023-03-16 19:48:49 +03:00
|
|
|
return vel;
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSampleSize(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_ssize[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSamplePenalty(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_pen[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSampleDesiredVelocityPenalty(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_vpen[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSampleCurrentVelocityPenalty(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_vcpen[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSamplePreferredSidePenalty(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_spen[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
|
2023-05-05 02:44:48 +03:00
|
|
|
public float GetSampleCollisionTimePenalty(int i)
|
2023-03-16 19:48:49 +03:00
|
|
|
{
|
|
|
|
return m_tpen[i];
|
|
|
|
}
|
2023-03-14 08:02:43 +03:00
|
|
|
}
|
|
|
|
}
|