forked from bit/DotRecastNetSim
remove nullable RcVec3f
This commit is contained in:
parent
ee5d3fd8c7
commit
e22c31052c
|
@ -3157,8 +3157,10 @@ namespace DotRecast.Detour
|
||||||
m_openList.Push(startNode);
|
m_openList.Push(startNode);
|
||||||
|
|
||||||
float radiusSqr = Sqr(maxRadius);
|
float radiusSqr = Sqr(maxRadius);
|
||||||
RcVec3f? bestvj = null;
|
|
||||||
RcVec3f? bestvi = null;
|
var hasBestV = false;
|
||||||
|
var bestvj = RcVec3f.Zero;
|
||||||
|
var bestvi = RcVec3f.Zero;
|
||||||
|
|
||||||
var status = DtStatus.DT_SUCCSESS;
|
var status = DtStatus.DT_SUCCSESS;
|
||||||
while (!m_openList.IsEmpty())
|
while (!m_openList.IsEmpty())
|
||||||
|
@ -3238,6 +3240,7 @@ namespace DotRecast.Detour
|
||||||
hitPos.x = bestTile.data.verts[vj + 0] + (bestTile.data.verts[vi + 0] - bestTile.data.verts[vj + 0]) * tseg;
|
hitPos.x = bestTile.data.verts[vj + 0] + (bestTile.data.verts[vi + 0] - bestTile.data.verts[vj + 0]) * tseg;
|
||||||
hitPos.y = bestTile.data.verts[vj + 1] + (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg;
|
hitPos.y = bestTile.data.verts[vj + 1] + (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg;
|
||||||
hitPos.z = bestTile.data.verts[vj + 2] + (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg;
|
hitPos.z = bestTile.data.verts[vj + 2] + (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg;
|
||||||
|
hasBestV = true;
|
||||||
bestvj = RcVec3f.Of(bestTile.data.verts, vj);
|
bestvj = RcVec3f.Of(bestTile.data.verts, vj);
|
||||||
bestvi = RcVec3f.Of(bestTile.data.verts, vi);
|
bestvi = RcVec3f.Of(bestTile.data.verts, vi);
|
||||||
}
|
}
|
||||||
|
@ -3322,9 +3325,9 @@ namespace DotRecast.Detour
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calc hit normal.
|
// Calc hit normal.
|
||||||
if (bestvi != null && bestvj != null)
|
if (hasBestV)
|
||||||
{
|
{
|
||||||
var tangent = bestvi.Value.Subtract(bestvj.Value);
|
var tangent = bestvi.Subtract(bestvj);
|
||||||
hitNormal.x = tangent.z;
|
hitNormal.x = tangent.z;
|
||||||
hitNormal.y = 0;
|
hitNormal.y = 0;
|
||||||
hitNormal.z = -tangent.x;
|
hitNormal.z = -tangent.x;
|
||||||
|
|
|
@ -517,18 +517,21 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
|
|
||||||
if (_sample.IsChanged())
|
if (_sample.IsChanged())
|
||||||
{
|
{
|
||||||
RcVec3f? bminN = null;
|
bool hasBound = false;
|
||||||
RcVec3f? bmaxN = null;
|
RcVec3f bminN = RcVec3f.Zero;
|
||||||
|
RcVec3f bmaxN = RcVec3f.Zero;
|
||||||
if (_sample.GetInputGeom() != null)
|
if (_sample.GetInputGeom() != null)
|
||||||
{
|
{
|
||||||
bminN = _sample.GetInputGeom().GetMeshBoundsMin();
|
bminN = _sample.GetInputGeom().GetMeshBoundsMin();
|
||||||
bmaxN = _sample.GetInputGeom().GetMeshBoundsMax();
|
bmaxN = _sample.GetInputGeom().GetMeshBoundsMax();
|
||||||
|
hasBound = true;
|
||||||
}
|
}
|
||||||
else if (_sample.GetNavMesh() != null)
|
else if (_sample.GetNavMesh() != null)
|
||||||
{
|
{
|
||||||
RcVec3f[] bounds = NavMeshUtils.GetNavMeshBounds(_sample.GetNavMesh());
|
RcVec3f[] bounds = NavMeshUtils.GetNavMeshBounds(_sample.GetNavMesh());
|
||||||
bminN = bounds[0];
|
bminN = bounds[0];
|
||||||
bmaxN = bounds[1];
|
bmaxN = bounds[1];
|
||||||
|
hasBound = true;
|
||||||
}
|
}
|
||||||
else if (0 < _sample.GetRecastResults().Count)
|
else if (0 < _sample.GetRecastResults().Count)
|
||||||
{
|
{
|
||||||
|
@ -536,31 +539,33 @@ public class RecastDemo : IRecastDemoChannel
|
||||||
{
|
{
|
||||||
if (result.GetSolidHeightfield() != null)
|
if (result.GetSolidHeightfield() != null)
|
||||||
{
|
{
|
||||||
if (bminN == null)
|
if (!hasBound)
|
||||||
{
|
{
|
||||||
bminN = RcVec3f.Of(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
|
bminN = RcVec3f.Of(float.PositiveInfinity, float.PositiveInfinity, float.PositiveInfinity);
|
||||||
bmaxN = RcVec3f.Of(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
|
bmaxN = RcVec3f.Of(float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
bminN = RcVec3f.Of(
|
bminN = RcVec3f.Of(
|
||||||
Math.Min(bminN.Value.x, result.GetSolidHeightfield().bmin.x),
|
Math.Min(bminN.x, result.GetSolidHeightfield().bmin.x),
|
||||||
Math.Min(bminN.Value.y, result.GetSolidHeightfield().bmin.y),
|
Math.Min(bminN.y, result.GetSolidHeightfield().bmin.y),
|
||||||
Math.Min(bminN.Value.z, result.GetSolidHeightfield().bmin.z)
|
Math.Min(bminN.z, result.GetSolidHeightfield().bmin.z)
|
||||||
);
|
);
|
||||||
|
|
||||||
bmaxN = RcVec3f.Of(
|
bmaxN = RcVec3f.Of(
|
||||||
Math.Max(bmaxN.Value.x, result.GetSolidHeightfield().bmax.x),
|
Math.Max(bmaxN.x, result.GetSolidHeightfield().bmax.x),
|
||||||
Math.Max(bmaxN.Value.y, result.GetSolidHeightfield().bmax.y),
|
Math.Max(bmaxN.y, result.GetSolidHeightfield().bmax.y),
|
||||||
Math.Max(bmaxN.Value.z, result.GetSolidHeightfield().bmax.z)
|
Math.Max(bmaxN.z, result.GetSolidHeightfield().bmax.z)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
hasBound = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bminN != null && bmaxN != null)
|
if (hasBound)
|
||||||
{
|
{
|
||||||
RcVec3f bmin = bminN.Value;
|
RcVec3f bmin = bminN;
|
||||||
RcVec3f bmax = bmaxN.Value;
|
RcVec3f bmax = bmaxN;
|
||||||
|
|
||||||
camr = (float)(Math.Sqrt(
|
camr = (float)(Math.Sqrt(
|
||||||
Sqr(bmax.x - bmin.x) + Sqr(bmax.y - bmin.y) + Sqr(bmax.z - bmin.z))
|
Sqr(bmax.x - bmin.x) + Sqr(bmax.y - bmin.y) + Sqr(bmax.z - bmin.z))
|
||||||
|
|
|
@ -102,23 +102,24 @@ public class CrowdProfilingTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RcVec3f? pos = null;
|
var status = DtStatus.DT_FAILURE;
|
||||||
|
var randomPt = RcVec3f.Zero;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case CrowdAgentType.MOB:
|
case CrowdAgentType.MOB:
|
||||||
pos = GetMobPosition(navquery, filter);
|
status = GetMobPosition(navquery, filter, out randomPt);
|
||||||
break;
|
break;
|
||||||
case CrowdAgentType.VILLAGER:
|
case CrowdAgentType.VILLAGER:
|
||||||
pos = GetVillagerPosition(navquery, filter);
|
status = GetVillagerPosition(navquery, filter, out randomPt);
|
||||||
break;
|
break;
|
||||||
case CrowdAgentType.TRAVELLER:
|
case CrowdAgentType.TRAVELLER:
|
||||||
pos = GetVillagerPosition(navquery, filter);
|
status = GetVillagerPosition(navquery, filter, out randomPt);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pos != null)
|
if (status.Succeeded())
|
||||||
{
|
{
|
||||||
AddAgent(pos.Value, type);
|
AddAgent(randomPt, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,31 +143,21 @@ public class CrowdProfilingTool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcVec3f? GetMobPosition(DtNavMeshQuery navquery, IDtQueryFilter filter)
|
private DtStatus GetMobPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out RcVec3f randomPt)
|
||||||
{
|
{
|
||||||
var status = navquery.FindRandomPoint(filter, rnd, out var randomRef, out var randomPt);
|
return navquery.FindRandomPoint(filter, rnd, out var randomRef, out randomPt);
|
||||||
if (status.Succeeded())
|
|
||||||
{
|
|
||||||
return randomPt;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private RcVec3f? GetVillagerPosition(DtNavMeshQuery navquery, IDtQueryFilter filter)
|
private DtStatus GetVillagerPosition(DtNavMeshQuery navquery, IDtQueryFilter filter, out RcVec3f randomPt)
|
||||||
{
|
{
|
||||||
if (0 < _polyPoints.Count)
|
randomPt = RcVec3f.Zero;
|
||||||
{
|
|
||||||
int zone = (int)(rnd.Next() * _polyPoints.Count);
|
|
||||||
var status = navquery.FindRandomPointWithinCircle(_polyPoints[zone].refs, _polyPoints[zone].pt, zoneRadius, filter, rnd,
|
|
||||||
out var randomRef, out var randomPt);
|
|
||||||
if (status.Succeeded())
|
|
||||||
{
|
|
||||||
return randomPt;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
if (0 >= _polyPoints.Count)
|
||||||
|
return DtStatus.DT_FAILURE;
|
||||||
|
|
||||||
|
int zone = (int)(rnd.Next() * _polyPoints.Count);
|
||||||
|
return navquery.FindRandomPointWithinCircle(_polyPoints[zone].refs, _polyPoints[zone].pt, zoneRadius, filter, rnd,
|
||||||
|
out var randomRef, out randomPt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateZones()
|
private void CreateZones()
|
||||||
|
|
Loading…
Reference in New Issue