forked from bit/DotRecastNetSim
move RcMath.VDot2D -> Vector3f.Dot2D
This commit is contained in:
parent
0c37c9eedb
commit
0cdf8c67b4
|
@ -350,29 +350,6 @@ namespace DotRecast.Core
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v)
|
|
||||||
/// @param[in] u A vector [(x, y, z)]
|
|
||||||
/// @param[in] v A vector [(x, y, z)]
|
|
||||||
/// @return The dot product on the xz-plane.
|
|
||||||
///
|
|
||||||
/// The vectors are projected onto the xz-plane, so the y-values are
|
|
||||||
/// ignored.
|
|
||||||
public static float VDot2D(float[] u, float[] v)
|
|
||||||
{
|
|
||||||
return u[0] * v[0] + u[2] * v[2];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float VDot2D(Vector3f u, Vector3f v)
|
|
||||||
{
|
|
||||||
return u.x * v.x + u.z * v.z;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static float VDot2D(Vector3f u, float[] v, int vi)
|
|
||||||
{
|
|
||||||
return u.x * v[vi] + u.z * v[vi + 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Derives the xz-plane 2D perp product of the two vectors. (uz*vx - ux*vz)
|
/// Derives the xz-plane 2D perp product of the two vectors. (uz*vx - ux*vz)
|
||||||
/// @param[in] u The LHV vector [(x, y, z)]
|
/// @param[in] u The LHV vector [(x, y, z)]
|
||||||
/// @param[in] v The RHV vector [(x, y, z)]
|
/// @param[in] v The RHV vector [(x, y, z)]
|
||||||
|
@ -586,10 +563,10 @@ namespace DotRecast.Core
|
||||||
public static float[] ProjectPoly(Vector3f axis, float[] poly, int npoly)
|
public static float[] ProjectPoly(Vector3f axis, float[] poly, int npoly)
|
||||||
{
|
{
|
||||||
float rmin, rmax;
|
float rmin, rmax;
|
||||||
rmin = rmax = VDot2D(axis, poly, 0);
|
rmin = rmax = axis.Dot2D(poly, 0);
|
||||||
for (int i = 1; i < npoly; ++i)
|
for (int i = 1; i < npoly; ++i)
|
||||||
{
|
{
|
||||||
float d = VDot2D(axis, poly, i * 3);
|
float d = axis.Dot2D(poly, i * 3);
|
||||||
rmin = Math.Min(rmin, d);
|
rmin = Math.Min(rmin, d);
|
||||||
rmax = Math.Max(rmax, d);
|
rmax = Math.Max(rmax, d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,6 +104,25 @@ namespace DotRecast.Core
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Derives the dot product of two vectors on the xz-plane. (@p u . @p v)
|
||||||
|
/// @param[in] u A vector [(x, y, z)]
|
||||||
|
/// @param[in] v A vector [(x, y, z)]
|
||||||
|
/// @return The dot product on the xz-plane.
|
||||||
|
///
|
||||||
|
/// The vectors are projected onto the xz-plane, so the y-values are
|
||||||
|
/// ignored.
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public float Dot2D(Vector3f v)
|
||||||
|
{
|
||||||
|
return x * v.x + z * v.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public float Dot2D(float[] v, int vi)
|
||||||
|
{
|
||||||
|
return x * v[vi] + z * v[vi + 2];
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (!(obj is Vector3f))
|
if (!(obj is Vector3f))
|
||||||
|
|
|
@ -160,13 +160,13 @@ namespace DotRecast.Detour.Crowd
|
||||||
const float EPS = 0.0001f;
|
const float EPS = 0.0001f;
|
||||||
Vector3f s = c1.Subtract(c0);
|
Vector3f s = c1.Subtract(c0);
|
||||||
float r = r0 + r1;
|
float r = r0 + r1;
|
||||||
float c = VDot2D(s, s) - r * r;
|
float c = s.Dot2D(s) - r * r;
|
||||||
float a = VDot2D(v, v);
|
float a = v.Dot2D(v);
|
||||||
if (a < EPS)
|
if (a < EPS)
|
||||||
return new SweepCircleCircleResult(false, 0f, 0f); // not moving
|
return new SweepCircleCircleResult(false, 0f, 0f); // not moving
|
||||||
|
|
||||||
// Overlap, calc time to exit.
|
// Overlap, calc time to exit.
|
||||||
float b = VDot2D(v, s);
|
float b = v.Dot2D(s);
|
||||||
float d = b * b - a * c;
|
float d = b * b - a * c;
|
||||||
if (d < 0.0f)
|
if (d < 0.0f)
|
||||||
return new SweepCircleCircleResult(false, 0f, 0f); // no intersection.
|
return new SweepCircleCircleResult(false, 0f, 0f); // no intersection.
|
||||||
|
@ -234,7 +234,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
vab = vab.Subtract(cir.vel);
|
vab = vab.Subtract(cir.vel);
|
||||||
|
|
||||||
// Side
|
// Side
|
||||||
side += Clamp(Math.Min(VDot2D(cir.dp, vab) * 0.5f + 0.5f, VDot2D(cir.np, vab) * 2), 0.0f, 1.0f);
|
side += Clamp(Math.Min(cir.dp.Dot2D(vab) * 0.5f + 0.5f, cir.np.Dot2D(vab) * 2), 0.0f, 1.0f);
|
||||||
nside++;
|
nside++;
|
||||||
|
|
||||||
SweepCircleCircleResult sres = SweepCircleCircle(pos, rad, vab, cir.p, cir.rad);
|
SweepCircleCircleResult sres = SweepCircleCircle(pos, rad, vab, cir.p, cir.rad);
|
||||||
|
@ -274,7 +274,7 @@ namespace DotRecast.Detour.Crowd
|
||||||
snorm.x = -sdir.z;
|
snorm.x = -sdir.z;
|
||||||
snorm.z = sdir.x;
|
snorm.z = sdir.x;
|
||||||
// If the velocity is pointing towards the segment, no collision.
|
// If the velocity is pointing towards the segment, no collision.
|
||||||
if (VDot2D(snorm, vcand) < 0.0f)
|
if (snorm.Dot2D(vcand) < 0.0f)
|
||||||
continue;
|
continue;
|
||||||
// Else immediate collision.
|
// Else immediate collision.
|
||||||
htmin = 0.0f;
|
htmin = 0.0f;
|
||||||
|
|
|
@ -88,7 +88,7 @@ namespace DotRecast.Detour
|
||||||
/*-----Advance rules-----*/
|
/*-----Advance rules-----*/
|
||||||
|
|
||||||
/* Special case: A & B overlap and oppositely oriented. */
|
/* Special case: A & B overlap and oppositely oriented. */
|
||||||
if (code == Intersection.Overlap && VDot2D(A, B) < 0)
|
if (code == Intersection.Overlap && A.Dot2D(B) < 0)
|
||||||
{
|
{
|
||||||
ii = AddVertex(inters, ii, ip);
|
ii = AddVertex(inters, ii, ip);
|
||||||
ii = AddVertex(inters, ii, iq);
|
ii = AddVertex(inters, ii, iq);
|
||||||
|
|
Loading…
Reference in New Issue