forked from bit/DotRecastNetSim
[개발/최익필] VLerp -> Vector3f.Lerp
This commit is contained in:
parent
575d762c15
commit
63427dce0a
|
@ -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)
|
public static Vector3f VAdd(Vector3f v1, Vector3f v2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -147,6 +147,18 @@ namespace DotRecast.Core
|
||||||
return hash;
|
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)
|
public static bool operator ==(Vector3f left, Vector3f right)
|
||||||
{
|
{
|
||||||
return left.Equals(right);
|
return left.Equals(right);
|
||||||
|
@ -174,15 +186,13 @@ namespace DotRecast.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[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)));
|
return new Vector3f(
|
||||||
if (d != 0)
|
v1.x + (v2.x - v1.x) * t,
|
||||||
{
|
v1.y + (v2.y - v1.y) * t,
|
||||||
x *= d;
|
v1.z + (v2.z - v1.z) * t
|
||||||
y *= d;
|
);
|
||||||
z *= d;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1355,12 +1355,12 @@ namespace DotRecast.Detour.Crowd
|
||||||
if (anim.t < ta)
|
if (anim.t < ta)
|
||||||
{
|
{
|
||||||
float u = Tween(anim.t, 0.0f, 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
|
else
|
||||||
{
|
{
|
||||||
float u = Tween(anim.t, ta, tb);
|
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.
|
// Update velocity.
|
||||||
|
|
|
@ -32,7 +32,7 @@ namespace DotRecast.Detour.Extras.Jumplink
|
||||||
|
|
||||||
GroundSample s = new GroundSample();
|
GroundSample s = new GroundSample();
|
||||||
seg.gsamples[i] = s;
|
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);
|
Tuple<bool, float> height = heightFunc.Invoke(pt, seg.height);
|
||||||
s.p.x = pt.x;
|
s.p.x = pt.x;
|
||||||
s.p.y = height.Item2;
|
s.p.y = height.Item2;
|
||||||
|
|
|
@ -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)
|
public float? GetPolyHeight(MeshTile tile, Poly poly, Vector3f pos)
|
||||||
|
@ -1344,7 +1344,7 @@ namespace DotRecast.Detour
|
||||||
i = poly.verts[1] * 3;
|
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] };
|
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);
|
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.
|
// Outside poly that is not an offmesh connection.
|
||||||
|
|
|
@ -364,7 +364,7 @@ namespace DotRecast.Detour
|
||||||
// Cost
|
// Cost
|
||||||
if (neighbourNode.flags == 0)
|
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);
|
float total = bestNode.total + VDist(bestNode.pos, neighbourNode.pos);
|
||||||
|
@ -1505,7 +1505,7 @@ namespace DotRecast.Detour
|
||||||
if (null != interect)
|
if (null != interect)
|
||||||
{
|
{
|
||||||
float t = interect.Item2;
|
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);
|
stat = AppendVertex(pt, 0, path[i + 1], straightPath, maxStraightPath);
|
||||||
if (!stat.IsInProgress())
|
if (!stat.IsInProgress())
|
||||||
{
|
{
|
||||||
|
@ -1826,7 +1826,7 @@ namespace DotRecast.Detour
|
||||||
bestPos = startPos;
|
bestPos = startPos;
|
||||||
|
|
||||||
// Search constraints
|
// 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 searchRadSqr = Sqr(VDist(startPos, endPos) / 2.0f + 0.001f);
|
||||||
|
|
||||||
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
float[] verts = new float[m_nav.GetMaxVertsPerPoly() * 3];
|
||||||
|
@ -2134,7 +2134,7 @@ namespace DotRecast.Detour
|
||||||
t = Clamp(interect.Item2, 0.1f, 0.9f);
|
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);
|
return Results.Success(pt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2571,7 +2571,7 @@ namespace DotRecast.Detour
|
||||||
// Cost
|
// Cost
|
||||||
if (neighbourNode.flags == 0)
|
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,
|
float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef,
|
||||||
|
@ -2763,7 +2763,7 @@ namespace DotRecast.Detour
|
||||||
// Cost
|
// Cost
|
||||||
if (neighbourNode.flags == 0)
|
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,
|
float cost = filter.GetCost(bestNode.pos, neighbourNode.pos, parentRef, parentTile, parentPoly, bestRef,
|
||||||
|
|
|
@ -236,7 +236,7 @@ public class JumpLinkBuilderTool : Tool
|
||||||
{
|
{
|
||||||
GroundSample s = link.start.gsamples[i];
|
GroundSample s = link.start.gsamples[i];
|
||||||
float u = i / (float)(link.start.gsamples.Length - 1);
|
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);
|
int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255);
|
||||||
float off = 0.1f;
|
float off = 0.1f;
|
||||||
if (!s.validHeight)
|
if (!s.validHeight)
|
||||||
|
@ -256,7 +256,7 @@ public class JumpLinkBuilderTool : Tool
|
||||||
{
|
{
|
||||||
GroundSample s = link.start.gsamples[i];
|
GroundSample s = link.start.gsamples[i];
|
||||||
float u = i / (float)(link.start.gsamples.Length - 1);
|
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);
|
int col = DuRGBA(255, 255, 255, 255);
|
||||||
float off = 0;
|
float off = 0;
|
||||||
if (s.validHeight)
|
if (s.validHeight)
|
||||||
|
@ -276,7 +276,7 @@ public class JumpLinkBuilderTool : Tool
|
||||||
{
|
{
|
||||||
GroundSample s = end.gsamples[i];
|
GroundSample s = end.gsamples[i];
|
||||||
float u = i / (float)(end.gsamples.Length - 1);
|
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);
|
int col = DuRGBA(48, 16, 16, 255); // DuRGBA(255,(s->flags & 4)?255:0,0,255);
|
||||||
float off = 0.1f;
|
float off = 0.1f;
|
||||||
if (!s.validHeight)
|
if (!s.validHeight)
|
||||||
|
@ -295,7 +295,7 @@ public class JumpLinkBuilderTool : Tool
|
||||||
{
|
{
|
||||||
GroundSample s = end.gsamples[i];
|
GroundSample s = end.gsamples[i];
|
||||||
float u = i / (float)(end.gsamples.Length - 1);
|
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);
|
int col = DuRGBA(255, 255, 255, 255);
|
||||||
float off = 0;
|
float off = 0;
|
||||||
if (s.validHeight)
|
if (s.validHeight)
|
||||||
|
|
|
@ -380,7 +380,7 @@ public class TestNavmeshTool : Tool
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Hit
|
// 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_hitNormal = hit.result.hitNormal;
|
||||||
m_hitResult = true;
|
m_hitResult = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue