DotRecastNetSim/src/DotRecast.Detour.Crowd/Tracking/ObstacleAvoidanceDebugData.cs

143 lines
4.3 KiB
C#
Raw Normal View History

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-05-10 16:44:51 +03:00
using static DotRecast.Core.RcMath;
2023-03-16 19:48:49 +03:00
public class ObstacleAvoidanceDebugData
{
int m_nsamples;
int m_maxSamples;
float[] m_vel;
float[] m_ssize;
float[] m_pen;
float[] m_vpen;
float[] m_vcpen;
float[] m_spen;
float[] m_tpen;
public ObstacleAvoidanceDebugData(int maxSamples)
{
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-05-05 02:44:48 +03:00
arr[i] = 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-05-05 02:44:48 +03:00
public void AddSample(Vector3f 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-05-05 02:44:48 +03:00
public Vector3f GetSampleVelocity(int i)
2023-03-16 19:48:49 +03:00
{
2023-03-28 18:03:33 +03:00
Vector3f vel = new Vector3f();
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
}
}