refactor: new float[2] -> RcVec2f

This commit is contained in:
ikpil 2023-10-12 23:21:24 +09:00
parent fe305e6fd1
commit 61a21327e9
2 changed files with 16 additions and 16 deletions

View File

@ -148,12 +148,12 @@ namespace DotRecast.Recast.Toolset.Geom
return false; return false;
} }
float[] p = new float[2]; var p = new RcVec2f();
float[] q = new float[2]; var q = new RcVec2f();
p[0] = src.X + (dst.X - src.X) * btmin; p.X = src.X + (dst.X - src.X) * btmin;
p[1] = src.Z + (dst.Z - src.Z) * btmin; p.Y = src.Z + (dst.Z - src.Z) * btmin;
q[0] = src.X + (dst.X - src.X) * btmax; q.X = src.X + (dst.X - src.X) * btmax;
q[1] = src.Z + (dst.Z - src.Z) * btmax; q.Y = src.Z + (dst.Z - src.Z) * btmax;
List<RcChunkyTriMeshNode> chunks = _mesh.chunkyTriMesh.GetChunksOverlappingSegment(p, q); List<RcChunkyTriMeshNode> chunks = _mesh.chunkyTriMesh.GetChunksOverlappingSegment(p, q);
if (0 == chunks.Count) if (0 == chunks.Count)

View File

@ -222,7 +222,7 @@ namespace DotRecast.Recast.Geom
return ids; return ids;
} }
public List<RcChunkyTriMeshNode> GetChunksOverlappingSegment(float[] p, float[] q) public List<RcChunkyTriMeshNode> GetChunksOverlappingSegment(RcVec2f p, RcVec2f q)
{ {
// Traverse tree // Traverse tree
List<RcChunkyTriMeshNode> ids = new List<RcChunkyTriMeshNode>(); List<RcChunkyTriMeshNode> ids = new List<RcChunkyTriMeshNode>();
@ -251,30 +251,30 @@ namespace DotRecast.Recast.Geom
return ids; return ids;
} }
private bool CheckOverlapSegment(float[] p, float[] q, RcVec2f bmin, RcVec2f bmax) private bool CheckOverlapSegment(RcVec2f p, RcVec2f q, RcVec2f bmin, RcVec2f bmax)
{ {
const float EPSILON = 1e-6f; const float EPSILON = 1e-6f;
float tmin = 0; float tmin = 0;
float tmax = 1; float tmax = 1;
float[] d = new float[2]; var d = new RcVec2f();
d[0] = q[0] - p[0]; d.X = q.X - p.X;
d[1] = q[1] - p[1]; d.Y = q.Y - p.Y;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)
{ {
if (Math.Abs(d[i]) < EPSILON) if (Math.Abs(d.Get(i)) < EPSILON)
{ {
// Ray is parallel to slab. No hit if origin not within slab // Ray is parallel to slab. No hit if origin not within slab
if (p[i] < bmin.Get(i) || p[i] > bmax.Get(i)) if (p.Get(i) < bmin.Get(i) || p.Get(i) > bmax.Get(i))
return false; return false;
} }
else else
{ {
// Compute intersection t value of ray with near and far plane of slab // Compute intersection t value of ray with near and far plane of slab
float ood = 1.0f / d[i]; float ood = 1.0f / d.Get(i);
float t1 = (bmin.Get(i) - p[i]) * ood; float t1 = (bmin.Get(i) - p.Get(i)) * ood;
float t2 = (bmax.Get(i) - p[i]) * ood; float t2 = (bmax.Get(i) - p.Get(i)) * ood;
if (t1 > t2) if (t1 > t2)
{ {
(t1, t2) = (t2, t1); (t1, t2) = (t2, t1);