refactor DtTileCacheObstacle class

This commit is contained in:
ikpil 2024-06-21 00:07:58 +09:00
parent 35ef64d9b4
commit 267e15fd4c
5 changed files with 64 additions and 39 deletions

View File

@ -0,0 +1,10 @@
using DotRecast.Core.Numerics;
namespace DotRecast.Detour.TileCache
{
public class DtObstacleBox
{
public RcVec3f bmin;
public RcVec3f bmax;
}
}

View File

@ -0,0 +1,11 @@
using DotRecast.Core.Numerics;
namespace DotRecast.Detour.TileCache
{
public class DtObstacleCylinder
{
public RcVec3f pos;
public float radius;
public float height;
}
}

View File

@ -0,0 +1,11 @@
using DotRecast.Core.Numerics;
namespace DotRecast.Detour.TileCache
{
public class DtObstacleOrientedBox
{
public RcVec3f center;
public RcVec3f extents;
public readonly float[] rotAux = new float[2]; // { Cos(0.5f*angle)*Sin(-0.5f*angle); Cos(0.5f*angle)*Cos(0.5f*angle) - 0.5 }
}
}

View File

@ -350,9 +350,9 @@ namespace DotRecast.Detour.TileCache
DtTileCacheObstacle ob = AllocObstacle(); DtTileCacheObstacle ob = AllocObstacle();
ob.type = DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER; ob.type = DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER;
ob.pos = pos; ob.cylinder.pos = pos;
ob.radius = radius; ob.cylinder.radius = radius;
ob.height = height; ob.cylinder.height = height;
return AddObstacleRequest(ob).refs; return AddObstacleRequest(ob).refs;
} }
@ -363,8 +363,8 @@ namespace DotRecast.Detour.TileCache
DtTileCacheObstacle ob = AllocObstacle(); DtTileCacheObstacle ob = AllocObstacle();
ob.type = DtTileCacheObstacleType.DT_OBSTACLE_BOX; ob.type = DtTileCacheObstacleType.DT_OBSTACLE_BOX;
ob.bmin = bmin; ob.box.bmin = bmin;
ob.bmax = bmax; ob.box.bmax = bmax;
return AddObstacleRequest(ob).refs; return AddObstacleRequest(ob).refs;
} }
@ -374,12 +374,12 @@ namespace DotRecast.Detour.TileCache
{ {
DtTileCacheObstacle ob = AllocObstacle(); DtTileCacheObstacle ob = AllocObstacle();
ob.type = DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX; ob.type = DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX;
ob.center = center; ob.orientedBox.center = center;
ob.extents = extents; ob.orientedBox.extents = extents;
float coshalf = MathF.Cos(0.5f * yRadians); float coshalf = MathF.Cos(0.5f * yRadians);
float sinhalf = MathF.Sin(-0.5f * yRadians); float sinhalf = MathF.Sin(-0.5f * yRadians);
ob.rotAux[0] = coshalf * sinhalf; ob.orientedBox.rotAux[0] = coshalf * sinhalf;
ob.rotAux[1] = coshalf * coshalf - 0.5f; ob.orientedBox.rotAux[1] = coshalf * coshalf - 0.5f;
return AddObstacleRequest(ob).refs; return AddObstacleRequest(ob).refs;
} }
@ -614,15 +614,15 @@ namespace DotRecast.Detour.TileCache
{ {
if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER) if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER)
{ {
DtTileCacheBuilder.MarkCylinderArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.pos, ob.radius, ob.height, 0); DtTileCacheBuilder.MarkCylinderArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.cylinder.pos, ob.cylinder.radius, ob.cylinder.height, 0);
} }
else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_BOX) else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_BOX)
{ {
DtTileCacheBuilder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.bmin, ob.bmax, 0); DtTileCacheBuilder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.box.bmin, ob.box.bmax, 0);
} }
else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX) else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX)
{ {
DtTileCacheBuilder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.center, ob.extents, ob.rotAux, 0); DtTileCacheBuilder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.orientedBox.center, ob.orientedBox.extents, ob.orientedBox.rotAux, 0);
} }
} }
} }
@ -694,27 +694,27 @@ namespace DotRecast.Detour.TileCache
{ {
if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER) if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_CYLINDER)
{ {
bmin.X = ob.pos.X - ob.radius; bmin.X = ob.cylinder.pos.X - ob.cylinder.radius;
bmin.Y = ob.pos.Y; bmin.Y = ob.cylinder.pos.Y;
bmin.Z = ob.pos.Z - ob.radius; bmin.Z = ob.cylinder.pos.Z - ob.cylinder.radius;
bmax.X = ob.pos.X + ob.radius; bmax.X = ob.cylinder.pos.X + ob.cylinder.radius;
bmax.Y = ob.pos.Y + ob.height; bmax.Y = ob.cylinder.pos.Y + ob.cylinder.height;
bmax.Z = ob.pos.Z + ob.radius; bmax.Z = ob.cylinder.pos.Z + ob.cylinder.radius;
} }
else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_BOX) else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_BOX)
{ {
bmin = ob.bmin; bmin = ob.box.bmin;
bmax = ob.bmax; bmax = ob.box.bmax;
} }
else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX) else if (ob.type == DtTileCacheObstacleType.DT_OBSTACLE_ORIENTED_BOX)
{ {
float maxr = 1.41f * Math.Max(ob.extents.X, ob.extents.Z); float maxr = 1.41f * Math.Max(ob.orientedBox.extents.X, ob.orientedBox.extents.Z);
bmin.X = ob.center.X - maxr; bmin.X = ob.orientedBox.center.X - maxr;
bmax.X = ob.center.X + maxr; bmax.X = ob.orientedBox.center.X + maxr;
bmin.Y = ob.center.Y - ob.extents.Y; bmin.Y = ob.orientedBox.center.Y - ob.orientedBox.extents.Y;
bmax.Y = ob.center.Y + ob.extents.Y; bmax.Y = ob.orientedBox.center.Y + ob.orientedBox.extents.Y;
bmin.Z = ob.center.Z - maxr; bmin.Z = ob.orientedBox.center.Z - maxr;
bmax.Z = ob.center.Z + maxr; bmax.Z = ob.orientedBox.center.Z + maxr;
} }
} }

View File

@ -19,24 +19,17 @@ freely, subject to the following restrictions:
*/ */
using System.Collections.Generic; using System.Collections.Generic;
using DotRecast.Core.Numerics;
namespace DotRecast.Detour.TileCache namespace DotRecast.Detour.TileCache
{ {
public class DtTileCacheObstacle public class DtTileCacheObstacle
{ {
public readonly int index; public readonly int index;
public RcVec3f pos = new RcVec3f();
public float radius; public DtObstacleCylinder cylinder = new DtObstacleCylinder();
public float height; public DtObstacleBox box = new DtObstacleBox();
public DtObstacleOrientedBox orientedBox = new DtObstacleOrientedBox();
public RcVec3f bmin = new RcVec3f();
public RcVec3f bmax = new RcVec3f();
public RcVec3f center = new RcVec3f();
public RcVec3f extents = new RcVec3f();
public readonly float[] rotAux = new float[2]; // { Cos(0.5f*angle)*Sin(-0.5f*angle); Cos(0.5f*angle)*Cos(0.5f*angle) - 0.5 }
public List<long> touched = new List<long>(); public List<long> touched = new List<long>();
public readonly List<long> pending = new List<long>(); public readonly List<long> pending = new List<long>();
public int salt; public int salt;