[개발/최익필] VLerp -> Vector3f.Lerp

This commit is contained in:
ikpil 2023-05-17 14:30:41 +09:00
parent 575d762c15
commit 63427dce0a
8 changed files with 44 additions and 42 deletions

View File

@ -125,14 +125,6 @@ namespace DotRecast.Core
);
}
public static Vector3f VLerp(Vector3f v1, Vector3f v2, float t)
{
return new Vector3f(
v1.x + (v2.x - v1.x) * t,
v1.y + (v2.y - v1.y) * t,
v1.z + (v2.z - v1.z) * t
);
}
public static Vector3f VAdd(Vector3f v1, Vector3f v2)
{

View File

@ -147,6 +147,18 @@ namespace DotRecast.Core
return hash;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Normalize()
{
float d = (float)(1.0f / Math.Sqrt(RcMath.Sqr(x) + RcMath.Sqr(y) + RcMath.Sqr(z)));
if (d != 0)
{
x *= d;
y *= d;
z *= d;
}
}
public static bool operator ==(Vector3f left, Vector3f right)
{
return left.Equals(right);
@ -174,15 +186,13 @@ namespace DotRecast.Core
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Normalize()
public static Vector3f Lerp(Vector3f v1, Vector3f v2, float t)
{
float d = (float)(1.0f / Math.Sqrt(RcMath.Sqr(x) + RcMath.Sqr(y) + RcMath.Sqr(z)));
if (d != 0)
{
x *= d;
y *= d;
z *= d;
}
return new Vector3f(
v1.x + (v2.x - v1.x) * t,
v1.y + (v2.y - v1.y) * t,
v1.z + (v2.z - v1.z) * t
);
}
}
}

View File

@ -1355,12 +1355,12 @@ namespace DotRecast.Detour.Crowd
if (anim.t < ta)
{
float u = Tween(anim.t, 0.0f, ta);
ag.npos = VLerp(anim.initPos, anim.startPos, u);
ag.npos = Vector3f.Lerp(anim.initPos, anim.startPos, u);
}
else
{
float u = Tween(anim.t, ta, tb);
ag.npos = VLerp(anim.startPos, anim.endPos, u);
ag.npos = Vector3f.Lerp(anim.startPos, anim.endPos, u);
}
// Update velocity.

View File

@ -32,7 +32,7 @@ namespace DotRecast.Detour.Extras.Jumplink
GroundSample s = new GroundSample();
seg.gsamples[i] = s;
Vector3f pt = VLerp(seg.p, seg.q, u);
Vector3f pt = Vector3f.Lerp(seg.p, seg.q, u);
Tuple<bool, float> height = heightFunc.Invoke(pt, seg.height);
s.p.x = pt.x;
s.p.y = height.Item2;

View File

@ -1226,7 +1226,7 @@ namespace DotRecast.Detour
}
}
return VLerp(pmin, pmax, tmin);
return Vector3f.Lerp(pmin, pmax, tmin);
}
public float? GetPolyHeight(MeshTile tile, Poly poly, Vector3f pos)
@ -1344,7 +1344,7 @@ namespace DotRecast.Detour
i = poly.verts[1] * 3;
var v1 = new Vector3f { x = tile.data.verts[i], y = tile.data.verts[i + 1], z = tile.data.verts[i + 2] };
Tuple<float, float> dt = DistancePtSegSqr2D(pos, v0, v1);
return new ClosestPointOnPolyResult(false, VLerp(v0, v1, dt.Item2));
return new ClosestPointOnPolyResult(false, Vector3f.Lerp(v0, v1, dt.Item2));
}
// Outside poly that is not an offmesh connection.

View File

@ -364,7 +364,7 @@ namespace DotRecast.Detour
// Cost
if (neighbourNode.flags == 0)
{
neighbourNode.pos = VLerp(va, vb, 0.5f);
neighbourNode.pos = Vector3f.Lerp(va, vb, 0.5f);
}
float total = bestNode.total + VDist(bestNode.pos, neighbourNode.pos);
@ -1505,7 +1505,7 @@ namespace DotRecast.Detour
if (null != interect)
{
float t = interect.Item2;
var pt = VLerp(left, right, t);
var pt = Vector3f.Lerp(left, right, t);
stat = AppendVertex(pt, 0, path[i + 1], straightPath, maxStraightPath);
if (!stat.IsInProgress())
{
@ -1826,7 +1826,7 @@ namespace DotRecast.Detour
bestPos = startPos;
// Search constraints
var searchPos = VLerp(startPos, endPos, 0.5f);
var searchPos = Vector3f.Lerp(startPos, endPos, 0.5f);
float searchRadSqr = Sqr(VDist(startPos, endPos) / 2.0f + 0.001f);
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
@ -2134,7 +2134,7 @@ namespace DotRecast.Detour
t = Clamp(interect.Item2, 0.1f, 0.9f);
}
Vector3f pt = VLerp(left, right, t);
Vector3f pt = Vector3f.Lerp(left, right, t);
return Results.Success(pt);
}
@ -2571,7 +2571,7 @@ namespace DotRecast.Detour
// Cost
if (neighbourNode.flags == 0)
{
neighbourNode.pos = VLerp(va, vb, 0.5f);
neighbourNode.pos = Vector3f.Lerp(va, vb, 0.5f);
}
float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef,
@ -2763,7 +2763,7 @@ namespace DotRecast.Detour
// Cost
if (neighbourNode.flags == 0)
{
neighbourNode.pos = VLerp(va, vb, 0.5f);
neighbourNode.pos = Vector3f.Lerp(va, vb, 0.5f);
}
float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef,

View File

@ -236,7 +236,7 @@ public class JumpLinkBuilderTool : Tool
{
GroundSample s = link.start.gsamples[i];
float u = i / (float)(link.start.gsamples.Length - 1);
Vector3f spt = VLerp(link.start.p, link.start.q, u);
Vector3f spt = Vector3f.Lerp(link.start.p, link.start.q, u);
int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255);
float off = 0.1f;
if (!s.validHeight)
@ -256,7 +256,7 @@ public class JumpLinkBuilderTool : Tool
{
GroundSample s = link.start.gsamples[i];
float u = i / (float)(link.start.gsamples.Length - 1);
Vector3f spt = VLerp(link.start.p, link.start.q, u);
Vector3f spt = Vector3f.Lerp(link.start.p, link.start.q, u);
int col = DuRGBA(255, 255, 255, 255);
float off = 0;
if (s.validHeight)
@ -276,7 +276,7 @@ public class JumpLinkBuilderTool : Tool
{
GroundSample s = end.gsamples[i];
float u = i / (float)(end.gsamples.Length - 1);
Vector3f spt = VLerp(end.p, end.q, u);
Vector3f spt = Vector3f.Lerp(end.p, end.q, u);
int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255);
float off = 0.1f;
if (!s.validHeight)
@ -295,7 +295,7 @@ public class JumpLinkBuilderTool : Tool
{
GroundSample s = end.gsamples[i];
float u = i / (float)(end.gsamples.Length - 1);
Vector3f spt = VLerp(end.p, end.q, u);
Vector3f spt = Vector3f.Lerp(end.p, end.q, u);
int col = DuRGBA(255, 255, 255, 255);
float off = 0;
if (s.validHeight)

View File

@ -380,7 +380,7 @@ public class TestNavmeshTool : Tool
else
{
// Hit
m_hitPos = VLerp(m_spos, m_epos, hit.result.t);
m_hitPos = Vector3f.Lerp(m_spos, m_epos, hit.result.t);
m_hitNormal = hit.result.hitNormal;
m_hitResult = true;
}