remove VectorPtr

This commit is contained in:
ikpil 2023-05-13 12:46:18 +09:00
parent e13dc0ac70
commit 12b5cc9ea8
7 changed files with 40 additions and 101 deletions

View File

@ -155,15 +155,6 @@ namespace DotRecast.Core
}
public static Vector3f VSub(VectorPtr v1, VectorPtr v2)
{
Vector3f dest = new Vector3f();
dest.x = v1.Get(0) - v2.Get(0);
dest.y = v1.Get(1) - v2.Get(1);
dest.z = v1.Get(2) - v2.Get(2);
return dest;
}
public static Vector3f VSub(Vector3f v1, Vector3f v2)
{
Vector3f dest = new Vector3f();
@ -173,16 +164,6 @@ namespace DotRecast.Core
return dest;
}
public static Vector3f VSub(Vector3f v1, VectorPtr v2)
{
Vector3f dest = new Vector3f();
dest.x = v1.x - v2.Get(0);
dest.y = v1.y - v2.Get(1);
dest.z = v1.z - v2.Get(2);
return dest;
}
public static Vector3f VSub(Vector3f v1, float[] v2)
{
Vector3f dest = new Vector3f();
@ -821,8 +802,9 @@ namespace DotRecast.Core
var p0v = p0;
for (int i = 0, j = nverts - 1; i < nverts; j = i++)
{
VectorPtr vpj = new VectorPtr(verts, j * 3);
var edge = VSub(new VectorPtr(verts, i * 3), vpj);
Vector3f vpj = Vector3f.Of(verts, j * 3);
Vector3f vpi = Vector3f.Of(verts, i * 3);
var edge = VSub(vpi, vpj);
var diff = VSub(p0v, vpj);
float n = VPerp2D(edge, diff);
float d = VPerp2D(dir, edge);

View File

@ -31,7 +31,12 @@ namespace DotRecast.Core
public static Vector3f Of(float[] f)
{
return new Vector3f(f);
return Of(f, 0);
}
public static Vector3f Of(float[] f, int idx)
{
return Of(f[idx + 0], f[idx + 1], f[idx + 2]);
}
public static Vector3f Of(float x, float y, float z)
@ -95,7 +100,7 @@ namespace DotRecast.Core
return Equals((Vector3f)obj);
}
public bool Equals(Vector3f other)
{
return x.Equals(other.x) &&

View File

@ -1,48 +0,0 @@
/*
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
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.
*/
namespace DotRecast.Core
{
/**
* Wrapper for 3-element pieces (3D vectors) of a bigger float array.
*
*/
public class VectorPtr
{
private readonly float[] array;
private readonly int index;
public VectorPtr(float[] array) :
this(array, 0)
{
}
public VectorPtr(float[] array, int index)
{
this.array = array;
this.index = index;
}
public float Get(int offset)
{
return array[index + offset];
}
}
}

View File

@ -48,14 +48,13 @@ namespace DotRecast.Detour.Extras.Unity.Astar
connection.poly = poly;
connection.pos = new float[]
{
l.clamped1.x, l.clamped1.y, l.clamped1.z,
l.clamped1.x, l.clamped1.y, l.clamped1.z,
l.clamped2.x, l.clamped2.y, l.clamped2.z
};
connection.rad = 0.1f;
connection.side = startTile == endTile
? 0xFF
: NavMeshBuilder.ClassifyOffMeshPoint(new VectorPtr(connection.pos, 3),
startTile.header.bmin, startTile.header.bmax);
: NavMeshBuilder.ClassifyOffMeshPoint(Vector3f.Of(connection.pos, 3), startTile.header.bmin, startTile.header.bmax);
connection.userId = (int)l.linkID;
if (startTile.offMeshCons == null)
{
@ -73,4 +72,4 @@ namespace DotRecast.Detour.Extras.Unity.Astar
}
}
}
}
}

View File

@ -667,9 +667,10 @@ namespace DotRecast.Detour
m_openList.Push(startNode);
float radiusSqr = Sqr(maxRadius);
Vector3f hitPos = new Vector3f();
VectorPtr bestvj = null;
VectorPtr bestvi = null;
Vector3f hitPos = Vector3f.Zero;
Vector3f? bestvj = null;
Vector3f? bestvi = null;
while (!m_openList.IsEmpty())
{
Node bestNode = m_openList.Pop();
@ -752,11 +753,11 @@ namespace DotRecast.Detour
// Calculate hit pos.
hitPos.x = bestTile.data.verts[vj] + (bestTile.data.verts[vi] - bestTile.data.verts[vj]) * tseg;
hitPos.y = bestTile.data.verts[vj + 1]
+ (bestTile.data.verts[vi + 1] - bestTile.data.verts[vj + 1]) * tseg;
+ (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;
bestvj = new VectorPtr(bestTile.data.verts, vj);
bestvi = new VectorPtr(bestTile.data.verts, vi);
+ (bestTile.data.verts[vi + 2] - bestTile.data.verts[vj + 2]) * tseg;
bestvj = Vector3f.Of(bestTile.data.verts, vj);
bestvi = Vector3f.Of(bestTile.data.verts, vi);
}
for (int i = bestTile.polyLinks[bestPoly.index]; i != NavMesh.DT_NULL_LINK; i = bestTile.links[i].next)
@ -843,7 +844,7 @@ namespace DotRecast.Detour
Vector3f hitNormal = new Vector3f();
if (bestvi != null && bestvj != null)
{
var tangent = VSub(bestvi, bestvj);
var tangent = VSub(bestvi.Value, bestvj.Value);
hitNormal.x = tangent.z;
hitNormal.y = 0;
hitNormal.z = -tangent.x;

View File

@ -223,13 +223,13 @@ namespace DotRecast.Detour
const int XM = 1 << 2;
const int ZM = 1 << 3;
public static int ClassifyOffMeshPoint(VectorPtr pt, Vector3f bmin, Vector3f bmax)
public static int ClassifyOffMeshPoint(Vector3f pt, Vector3f bmin, Vector3f bmax)
{
int outcode = 0;
outcode |= (pt.Get(0) >= bmax.x) ? XP : 0;
outcode |= (pt.Get(2) >= bmax.z) ? ZP : 0;
outcode |= (pt.Get(0) < bmin.x) ? XM : 0;
outcode |= (pt.Get(2) < bmin.z) ? ZM : 0;
outcode |= (pt.x >= bmax.x) ? XP : 0;
outcode |= (pt.z >= bmax.z) ? ZP : 0;
outcode |= (pt.x < bmin.x) ? XM : 0;
outcode |= (pt.z < bmin.z) ? ZM : 0;
switch (outcode)
{
@ -319,8 +319,8 @@ namespace DotRecast.Detour
for (int i = 0; i < option.offMeshConCount; ++i)
{
VectorPtr p0 = new VectorPtr(option.offMeshConVerts, (i * 2 + 0) * 3);
VectorPtr p1 = new VectorPtr(option.offMeshConVerts, (i * 2 + 1) * 3);
var p0 = Vector3f.Of(option.offMeshConVerts, (i * 2 + 0) * 3);
var p1 = Vector3f.Of(option.offMeshConVerts, (i * 2 + 1) * 3);
offMeshConClass[i * 2 + 0] = ClassifyOffMeshPoint(p0, bmin, bmax);
offMeshConClass[i * 2 + 1] = ClassifyOffMeshPoint(p1, bmin, bmax);
@ -329,7 +329,7 @@ namespace DotRecast.Detour
// potentially touching the mesh.
if (offMeshConClass[i * 2 + 0] == 0xff)
{
if (p0.Get(1) < bmin.y || p0.Get(1) > bmax.y)
if (p0.y < bmin.y || p0.y > bmax.y)
offMeshConClass[i * 2 + 0] = 0;
}

View File

@ -2375,12 +2375,12 @@ namespace DotRecast.Detour
// and correct the height (since the raycast moves in 2d)
lastPos = curPos;
curPos = VMad(startPos, dir, hit.t);
VectorPtr e1 = new VectorPtr(verts, iresult.segMax * 3);
VectorPtr e2 = new VectorPtr(verts, ((iresult.segMax + 1) % nv) * 3);
Vector3f eDir = VSub(e2, e1);
Vector3f diff = VSub(curPos, e1);
var e1 = Vector3f.Of(verts, iresult.segMax * 3);
var e2 = Vector3f.Of(verts, ((iresult.segMax + 1) % nv) * 3);
var eDir = VSub(e2, e1);
var diff = VSub(curPos, e1);
float s = Sqr(eDir.x) > Sqr(eDir.z) ? diff.x / eDir.x : diff.z / eDir.z;
curPos.y = e1.Get(1) + eDir.y * s;
curPos.y = e1.y + eDir.y * s;
hit.pathCost += filter.GetCost(lastPos, curPos, prevRef, prevTile, prevPoly, curRef, tile, poly,
nextRef, nextTile, nextPoly);
@ -3193,8 +3193,8 @@ namespace DotRecast.Detour
float radiusSqr = Sqr(maxRadius);
Vector3f hitPos = new Vector3f();
VectorPtr bestvj = null;
VectorPtr bestvi = null;
Vector3f? bestvj = null;
Vector3f? bestvi = null;
while (!m_openList.IsEmpty())
{
Node bestNode = m_openList.Pop();
@ -3280,8 +3280,8 @@ namespace DotRecast.Detour
+ (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;
bestvj = new VectorPtr(bestTile.data.verts, vj);
bestvi = new VectorPtr(bestTile.data.verts, vi);
bestvj = Vector3f.Of(bestTile.data.verts, vj);
bestvi = Vector3f.Of(bestTile.data.verts, vi);
}
for (int i = bestTile.polyLinks[bestPoly.index]; i != NavMesh.DT_NULL_LINK; i = bestTile.links[i].next)
@ -3368,7 +3368,7 @@ namespace DotRecast.Detour
Vector3f hitNormal = new Vector3f();
if (bestvi != null && bestvj != null)
{
var tangent = VSub(bestvi, bestvj);
var tangent = VSub(bestvi.Value, bestvj.Value);
hitNormal.x = tangent.z;
hitNormal.y = 0;
hitNormal.z = -tangent.x;