forked from bit/DotRecastNetSim
refactor: vector3
This commit is contained in:
parent
21b3cd6caa
commit
2e7a75624c
|
@ -50,13 +50,13 @@ namespace DotRecast.Core.Numerics
|
|||
}
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public RcVec3f(ReadOnlySpan<float> values)
|
||||
{
|
||||
X = values[0];
|
||||
Y = values[1];
|
||||
Z = values[2];
|
||||
}
|
||||
// [MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
// public RcVec3f(ReadOnlySpan<float> values)
|
||||
// {
|
||||
// X = values[0];
|
||||
// Y = values[1];
|
||||
// Z = values[2];
|
||||
// }
|
||||
|
||||
public float this[int index]
|
||||
{
|
||||
|
|
|
@ -6,6 +6,18 @@ namespace DotRecast.Core.Numerics
|
|||
public static class RcVecUtils
|
||||
{
|
||||
public const float EPSILON = 1e-6f;
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static RcVec3f Create(float[] values)
|
||||
{
|
||||
return Create(values, 0);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static RcVec3f Create(float[] values, int n)
|
||||
{
|
||||
return new RcVec3f(values[n + 0], values[n + 1], values[n + 2]);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static float Get(this RcVec2f v, int i)
|
||||
|
|
|
@ -412,7 +412,7 @@ namespace DotRecast.Detour.Crowd
|
|||
else if (n == 0)
|
||||
{
|
||||
// The first polyref is bad, use current safe values.
|
||||
m_pos = new RcVec3f(safePos);
|
||||
m_pos = RcVecUtils.Create(safePos);
|
||||
m_path.Clear();
|
||||
m_path.Add(safeRef);
|
||||
}
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace DotRecast.Detour.Extras
|
|||
BVItem it = new BVItem();
|
||||
items[i] = it;
|
||||
it.i = i;
|
||||
RcVec3f bmin = new RcVec3f(data.verts.AsSpan(data.polys[i].verts[0] * 3));
|
||||
RcVec3f bmax = new RcVec3f(data.verts.AsSpan(data.polys[i].verts[0] * 3));
|
||||
RcVec3f bmin = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3);
|
||||
RcVec3f bmax = RcVecUtils.Create(data.verts, data.polys[i].verts[0] * 3);
|
||||
for (int j = 1; j < data.polys[i].vertCount; j++)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, data.verts, data.polys[i].verts[j] * 3);
|
||||
|
|
|
@ -56,7 +56,7 @@ namespace DotRecast.Detour.Extras.Unity.Astar
|
|||
connection.rad = 0.1f;
|
||||
connection.side = startTile == endTile
|
||||
? 0xFF
|
||||
: DtNavMeshBuilder.ClassifyOffMeshPoint(new RcVec3f(connection.pos.AsSpan(3)), startTile.header.bmin, startTile.header.bmax);
|
||||
: DtNavMeshBuilder.ClassifyOffMeshPoint(RcVecUtils.Create(connection.pos, 3), startTile.header.bmin, startTile.header.bmax);
|
||||
connection.userId = (int)l.linkID;
|
||||
if (startTile.offMeshCons == null)
|
||||
{
|
||||
|
|
|
@ -53,10 +53,10 @@ namespace DotRecast.Detour
|
|||
|
||||
do
|
||||
{
|
||||
a = new RcVec3f(p.AsSpan(3 * (ai % n)));
|
||||
b = new RcVec3f(q.AsSpan(3 * (bi % m)));
|
||||
a1 = new RcVec3f(p.AsSpan(3 * ((ai + n - 1) % n))); // prev a
|
||||
b1 = new RcVec3f(q.AsSpan(3 * ((bi + m - 1) % m))); // prev b
|
||||
a = RcVecUtils.Create(p, 3 * (ai % n));
|
||||
b = RcVecUtils.Create(q, 3 * (bi % m));
|
||||
a1 = RcVecUtils.Create(p, 3 * ((ai + n - 1) % n)); // prev a
|
||||
b1 = RcVecUtils.Create(q, 3 * ((bi + m - 1) % m)); // prev b
|
||||
|
||||
RcVec3f A = RcVec3f.Subtract(a, a1);
|
||||
RcVec3f B = RcVec3f.Subtract(b, b1);
|
||||
|
|
|
@ -401,8 +401,8 @@ namespace DotRecast.Detour
|
|||
|
||||
// Calc polygon bounds.
|
||||
int v = p.verts[0] * 3;
|
||||
bmin = new RcVec3f(tile.data.verts.AsSpan(v));
|
||||
bmax = new RcVec3f(tile.data.verts.AsSpan(v));
|
||||
bmin = RcVecUtils.Create(tile.data.verts, v);
|
||||
bmax = RcVecUtils.Create(tile.data.verts, v);
|
||||
for (int j = 1; j < p.vertCount; ++j)
|
||||
{
|
||||
v = p.verts[j] * 3;
|
||||
|
@ -1569,8 +1569,8 @@ namespace DotRecast.Detour
|
|||
}
|
||||
}
|
||||
|
||||
startPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx0] * 3));
|
||||
endPos = new RcVec3f(tile.data.verts.AsSpan(poly.verts[idx1] * 3));
|
||||
startPos = RcVecUtils.Create(tile.data.verts, poly.verts[idx0] * 3);
|
||||
endPos = RcVecUtils.Create(tile.data.verts, poly.verts[idx1] * 3);
|
||||
|
||||
return DtStatus.DT_SUCCSESS;
|
||||
}
|
||||
|
|
|
@ -158,8 +158,8 @@ namespace DotRecast.Detour
|
|||
int vb = option.detailMeshes[i * 4 + 0];
|
||||
int ndv = option.detailMeshes[i * 4 + 1];
|
||||
int dv = vb * 3;
|
||||
var bmin = new RcVec3f(option.detailVerts.AsSpan(dv));
|
||||
var bmax = new RcVec3f(option.detailVerts.AsSpan(dv));
|
||||
var bmin = RcVecUtils.Create(option.detailVerts, dv);
|
||||
var bmax = RcVecUtils.Create(option.detailVerts, dv);
|
||||
for (int j = 1; j < ndv; j++)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, option.detailVerts, dv + j * 3);
|
||||
|
@ -315,8 +315,8 @@ namespace DotRecast.Detour
|
|||
|
||||
for (int i = 0; i < option.offMeshConCount; ++i)
|
||||
{
|
||||
var p0 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 0) * 3));
|
||||
var p1 = new RcVec3f(option.offMeshConVerts.AsSpan((i * 2 + 1) * 3));
|
||||
var p0 = RcVecUtils.Create(option.offMeshConVerts, (i * 2 + 0) * 3);
|
||||
var p1 = RcVecUtils.Create(option.offMeshConVerts, (i * 2 + 1) * 3);
|
||||
|
||||
offMeshConClass[i * 2 + 0] = ClassifyOffMeshPoint(p0, bmin, bmax);
|
||||
offMeshConClass[i * 2 + 1] = ClassifyOffMeshPoint(p1, bmin, bmax);
|
||||
|
|
|
@ -641,8 +641,8 @@ namespace DotRecast.Detour
|
|||
|
||||
// Calc polygon bounds.
|
||||
int v = p.verts[0] * 3;
|
||||
bmin = new RcVec3f(tile.data.verts.AsSpan(v));
|
||||
bmax = new RcVec3f(tile.data.verts.AsSpan(v));
|
||||
bmin = RcVecUtils.Create(tile.data.verts, v);
|
||||
bmax = RcVecUtils.Create(tile.data.verts, v);
|
||||
for (int j = 1; j < p.vertCount; ++j)
|
||||
{
|
||||
v = p.verts[j] * 3;
|
||||
|
@ -2202,7 +2202,7 @@ namespace DotRecast.Detour
|
|||
int nv = 0;
|
||||
for (int i = 0; i < poly.vertCount; ++i)
|
||||
{
|
||||
verts[nv] = new RcVec3f(tile.data.verts.AsSpan(poly.verts[i] * 3));
|
||||
verts[nv] = RcVecUtils.Create(tile.data.verts, poly.verts[i] * 3);
|
||||
nv++;
|
||||
}
|
||||
|
||||
|
@ -3031,8 +3031,8 @@ namespace DotRecast.Detour
|
|||
int ivj = poly.verts[j] * 3;
|
||||
int ivi = poly.verts[i] * 3;
|
||||
var seg = new RcSegmentVert();
|
||||
seg.vmin = new RcVec3f(tile.data.verts.AsSpan(ivj));
|
||||
seg.vmax = new RcVec3f(tile.data.verts.AsSpan(ivi));
|
||||
seg.vmin = RcVecUtils.Create(tile.data.verts, ivj);
|
||||
seg.vmax = RcVecUtils.Create(tile.data.verts, ivi);
|
||||
// Array.Copy(tile.data.verts, ivj, seg, 0, 3);
|
||||
// Array.Copy(tile.data.verts, ivi, seg, 3, 3);
|
||||
segmentVerts.Add(seg);
|
||||
|
@ -3212,8 +3212,8 @@ namespace DotRecast.Detour
|
|||
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;
|
||||
hasBestV = true;
|
||||
bestvj = new RcVec3f(bestTile.data.verts.AsSpan(vj));
|
||||
bestvi = new RcVec3f(bestTile.data.verts.AsSpan(vi));
|
||||
bestvj = RcVecUtils.Create(bestTile.data.verts, vj);
|
||||
bestvi = RcVecUtils.Create(bestTile.data.verts, vi);
|
||||
}
|
||||
|
||||
for (int i = bestTile.polyLinks[bestPoly.index]; i != DtNavMesh.DT_NULL_LINK; i = bestTile.links[i].next)
|
||||
|
|
|
@ -309,8 +309,8 @@ namespace DotRecast.Detour
|
|||
|
||||
public static float DistancePtSegSqr2D(RcVec3f pt, float[] verts, int p, int q, out float t)
|
||||
{
|
||||
var vp = new RcVec3f(verts.AsSpan(p));
|
||||
var vq = new RcVec3f(verts.AsSpan(q));
|
||||
var vp = RcVecUtils.Create(verts, p);
|
||||
var vq = RcVecUtils.Create(verts, q);
|
||||
return DistancePtSegSqr2D(pt, vp, vq, out t);
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ public class CrowdSampleTool : ISampleTool
|
|||
dd.Vertex(prev.X, prev.Y + 0.1f, prev.Z, DuRGBA(0, 0, 0, (int)(128 * preva)));
|
||||
dd.Vertex(trail.trail[v], trail.trail[v + 1] + 0.1f, trail.trail[v + 2], DuRGBA(0, 0, 0, (int)(128 * a)));
|
||||
preva = a;
|
||||
prev = new RcVec3f(trail.trail.AsSpan(v));
|
||||
prev = RcVecUtils.Create(trail.trail, v);
|
||||
}
|
||||
|
||||
dd.End();
|
||||
|
|
|
@ -57,8 +57,8 @@ namespace DotRecast.Recast.Toolset.Geom
|
|||
this.faces = faces;
|
||||
normals = new float[faces.Length];
|
||||
CalculateNormals();
|
||||
bmin = new RcVec3f(vertices);
|
||||
bmax = new RcVec3f(vertices);
|
||||
bmin = RcVecUtils.Create(vertices);
|
||||
bmax = RcVecUtils.Create(vertices);
|
||||
for (int i = 1; i < vertices.Length / 3; i++)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, vertices, i * 3);
|
||||
|
|
|
@ -77,8 +77,8 @@ namespace DotRecast.Recast.Geom
|
|||
this.faces = faces;
|
||||
normals = new float[faces.Length];
|
||||
CalculateNormals();
|
||||
bmin = new RcVec3f(vertices);
|
||||
bmax = new RcVec3f(vertices);
|
||||
bmin = RcVecUtils.Create(vertices);
|
||||
bmax = RcVecUtils.Create(vertices);
|
||||
for (int i = 1; i < vertices.Length / 3; i++)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, vertices, i * 3);
|
||||
|
|
|
@ -457,8 +457,8 @@ namespace DotRecast.Recast
|
|||
int zStride = xSize; // For readability
|
||||
|
||||
// Compute the bounding box of the polygon
|
||||
RcVec3f bmin = new RcVec3f(verts);
|
||||
RcVec3f bmax = new RcVec3f(verts);
|
||||
RcVec3f bmin = RcVecUtils.Create(verts);
|
||||
RcVec3f bmax = RcVecUtils.Create(verts);
|
||||
for (int i = 3; i < verts.Length; i += 3)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, verts, i);
|
||||
|
@ -753,9 +753,9 @@ namespace DotRecast.Recast
|
|||
int vertIndexB = vertIndex;
|
||||
int vertIndexC = (vertIndex + 1) % numVerts;
|
||||
|
||||
RcVec3f vertA = new RcVec3f(verts.AsSpan(vertIndexA * 3));
|
||||
RcVec3f vertB = new RcVec3f(verts.AsSpan(vertIndexB * 3));
|
||||
RcVec3f vertC = new RcVec3f(verts.AsSpan(vertIndexC * 3));
|
||||
RcVec3f vertA = RcVecUtils.Create(verts, vertIndexA * 3);
|
||||
RcVec3f vertB = RcVecUtils.Create(verts, vertIndexB * 3);
|
||||
RcVec3f vertC = RcVecUtils.Create(verts, vertIndexC * 3);
|
||||
|
||||
// From A to B on the x/z plane
|
||||
RcVec3f prevSegmentDir = RcVec3f.Subtract(vertB, vertA);
|
||||
|
|
|
@ -178,7 +178,7 @@ namespace DotRecast.Recast
|
|||
return true;
|
||||
}
|
||||
|
||||
c = new RcVec3f(verts.AsSpan(p1));
|
||||
c = RcVecUtils.Create(verts, p1);
|
||||
r.Exchange(0f);
|
||||
return false;
|
||||
}
|
||||
|
@ -1000,8 +1000,8 @@ namespace DotRecast.Recast
|
|||
if (sampleDist > 0)
|
||||
{
|
||||
// Create sample locations in a grid.
|
||||
RcVec3f bmin = new RcVec3f(@in);
|
||||
RcVec3f bmax = new RcVec3f(@in);
|
||||
RcVec3f bmin = RcVecUtils.Create(@in);
|
||||
RcVec3f bmax = RcVecUtils.Create(@in);
|
||||
for (int i = 1; i < nin; ++i)
|
||||
{
|
||||
bmin = RcVecUtils.Min(bmin, @in, i * 3);
|
||||
|
|
|
@ -237,8 +237,8 @@ namespace DotRecast.Recast
|
|||
float by = heightfieldBBMax.Y - heightfieldBBMin.Y;
|
||||
|
||||
// Calculate the bounding box of the triangle.
|
||||
RcVec3f tmin = new RcVec3f(verts.AsSpan(v0 * 3));
|
||||
RcVec3f tmax = new RcVec3f(verts.AsSpan(v0 * 3));
|
||||
RcVec3f tmin = RcVecUtils.Create(verts, v0 * 3);
|
||||
RcVec3f tmax = RcVecUtils.Create(verts, v0 * 3);
|
||||
tmin = RcVecUtils.Min(tmin, verts, v1 * 3);
|
||||
tmin = RcVecUtils.Min(tmin, verts, v2 * 3);
|
||||
tmax = RcVecUtils.Max(tmax, verts, v1 * 3);
|
||||
|
|
Loading…
Reference in New Issue