rename a function, update a test
This commit is contained in:
parent
8030c3458a
commit
6b95a04a09
@ -6,17 +6,17 @@ class ShapeCast : public Test
|
|||||||
public:
|
public:
|
||||||
ShapeCast()
|
ShapeCast()
|
||||||
{
|
{
|
||||||
m_xfA.SetIdentity();
|
m_shapeA.m_hull = &b3BoxHull_identity;
|
||||||
|
m_shapeA.m_radius = 0.0f;
|
||||||
|
|
||||||
|
m_shapeB.m_hull = &b3BoxHull_identity;
|
||||||
|
m_shapeB.m_radius = 0.0f;
|
||||||
|
|
||||||
m_xfA.position.Set(-5.0f, 0.0f, 0.0f);
|
m_xfA.position.Set(-5.0f, 0.0f, 0.0f);
|
||||||
m_xfA.rotation.SetIdentity();
|
m_xfA.rotation.SetIdentity();
|
||||||
m_shapeA.m_centers[0].Set(0.0f, -2.0f, 0.0f);
|
|
||||||
m_shapeA.m_centers[1].Set(0.0f, 2.0f, 0.0f);
|
|
||||||
m_shapeA.m_radius = 1.0f;
|
|
||||||
|
|
||||||
m_xfB.SetIdentity();
|
m_xfB.position.Set(10.0f, 0.0f, 0.0f);
|
||||||
m_xfB.position.Set(5.0f, 0.0f, 0.0f);
|
|
||||||
m_xfB.rotation.SetIdentity();
|
m_xfB.rotation.SetIdentity();
|
||||||
m_shapeB.m_hull = &b3BoxHull_identity;
|
|
||||||
|
|
||||||
m_proxyA.Set(&m_shapeA, 0);
|
m_proxyA.Set(&m_shapeA, 0);
|
||||||
m_proxyB.Set(&m_shapeB, 0);
|
m_proxyB.Set(&m_shapeB, 0);
|
||||||
@ -33,18 +33,21 @@ public:
|
|||||||
m_world.DrawShape(m_xfA, &m_shapeA);
|
m_world.DrawShape(m_xfA, &m_shapeA);
|
||||||
m_world.DrawShape(m_xfB, &m_shapeB);
|
m_world.DrawShape(m_xfB, &m_shapeB);
|
||||||
|
|
||||||
b3Vec3 translationB = -20.0f * b3Vec3_x;
|
g_draw->DrawSolidShape(&m_shapeA, b3Color_white, m_xfA);
|
||||||
|
g_draw->DrawSolidShape(&m_shapeB, b3Color_white, m_xfB);
|
||||||
|
|
||||||
|
b3Vec3 translationB = -100.0f * b3Vec3_x;
|
||||||
g_draw->DrawSegment(m_xfB.position, m_xfB.position + translationB, b3Color_white);
|
g_draw->DrawSegment(m_xfB.position, m_xfB.position + translationB, b3Color_white);
|
||||||
|
|
||||||
b3GJKRayCastOutput out;
|
b3GJKShapeCastOutput out;
|
||||||
bool hit = b3GJKRayCast(&out, m_xfA, m_proxyA, m_xfB, m_proxyB, translationB);
|
bool hit = b3GJKShapeCast(&out, m_xfA, m_proxyA, m_xfB, m_proxyB, translationB);
|
||||||
|
|
||||||
g_draw->DrawString(b3Color_white, "Iterations = %d", out.iterations);
|
g_draw->DrawString(b3Color_white, "Iterations = %d", out.iterations);
|
||||||
|
|
||||||
if (hit)
|
if (hit)
|
||||||
{
|
{
|
||||||
g_draw->DrawPoint(out.point, 4.0f, b3Color(0.0f, 1.0f, 0.0f));
|
g_draw->DrawPoint(out.point, 4.0f, b3Color_green);
|
||||||
g_draw->DrawSegment(out.point, out.point + out.normal, b3Color(0.0f, 1.0f, 0.0f));
|
g_draw->DrawSegment(out.point, out.point + out.normal, b3Color_green);
|
||||||
|
|
||||||
b3Transform xfB;
|
b3Transform xfB;
|
||||||
xfB.rotation = m_xfB.rotation;
|
xfB.rotation = m_xfB.rotation;
|
||||||
@ -106,7 +109,7 @@ public:
|
|||||||
return new ShapeCast();
|
return new ShapeCast();
|
||||||
}
|
}
|
||||||
|
|
||||||
b3CapsuleShape m_shapeA;
|
b3HullShape m_shapeA;
|
||||||
b3Transform m_xfA;
|
b3Transform m_xfA;
|
||||||
b3ShapeGJKProxy m_proxyA;
|
b3ShapeGJKProxy m_proxyA;
|
||||||
|
|
||||||
|
@ -114,8 +114,8 @@ b3GJKOutput b3GJK(const b3Transform& xf1, const b3GJKProxy& proxy1,
|
|||||||
const b3Transform& xf2, const b3GJKProxy& proxy2,
|
const b3Transform& xf2, const b3GJKProxy& proxy2,
|
||||||
bool applyRadius, b3SimplexCache* cache);
|
bool applyRadius, b3SimplexCache* cache);
|
||||||
|
|
||||||
// The output of the GJK-based ray cast algorithm.
|
// The output of the GJK-based shape cast algorithm.
|
||||||
struct b3GJKRayCastOutput
|
struct b3GJKShapeCastOutput
|
||||||
{
|
{
|
||||||
float32 t; // time of impact
|
float32 t; // time of impact
|
||||||
b3Vec3 point; // contact point at t
|
b3Vec3 point; // contact point at t
|
||||||
@ -124,7 +124,7 @@ struct b3GJKRayCastOutput
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Find the time of impact between two proxies given the relative target translation vector.
|
// Find the time of impact between two proxies given the relative target translation vector.
|
||||||
bool b3GJKRayCast(b3GJKRayCastOutput* output,
|
bool b3GJKShapeCast(b3GJKShapeCastOutput* output,
|
||||||
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
||||||
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2);
|
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2);
|
||||||
|
|
||||||
|
@ -854,7 +854,7 @@ b3GJKOutput b3GJK(const b3Transform& xf1, const b3GJKProxy& proxy1,
|
|||||||
|
|
||||||
// Brian Mirtich
|
// Brian Mirtich
|
||||||
// "Conservative Advancement"
|
// "Conservative Advancement"
|
||||||
bool b3GJKRayCast(b3GJKRayCastOutput* output,
|
bool b3GJKShapeCast(b3GJKShapeCastOutput* output,
|
||||||
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
||||||
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2)
|
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2)
|
||||||
{
|
{
|
||||||
@ -960,7 +960,7 @@ bool b3GJKRayCast(b3GJKRayCastOutput* output,
|
|||||||
// Gino van der Bergen
|
// Gino van der Bergen
|
||||||
// "Smooth Mesh Contacts with GJK"
|
// "Smooth Mesh Contacts with GJK"
|
||||||
// Game Physics Pearls 2010, page 99
|
// Game Physics Pearls 2010, page 99
|
||||||
bool b3GJKShapeCast(b3GJKRayCastOutput* output,
|
bool b3GJKShapeCastCSO(b3GJKShapeCastOutput* output,
|
||||||
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
const b3Transform& xf1, const b3GJKProxy& proxy1,
|
||||||
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2)
|
const b3Transform& xf2, const b3GJKProxy& proxy2, const b3Vec3& translation2)
|
||||||
{
|
{
|
||||||
@ -1032,14 +1032,6 @@ bool b3GJKShapeCast(b3GJKRayCastOutput* output,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy simplex so we can identify duplicates.
|
|
||||||
saveCount = simplex.m_count;
|
|
||||||
for (u32 i = 0; i < saveCount; ++i)
|
|
||||||
{
|
|
||||||
save1[i] = vertices[i].index1;
|
|
||||||
save2[i] = vertices[i].index2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unite p - s to simplex
|
// Unite p - s to simplex
|
||||||
b3Vec3 s = t * r;
|
b3Vec3 s = t * r;
|
||||||
|
|
||||||
@ -1075,6 +1067,14 @@ bool b3GJKShapeCast(b3GJKRayCastOutput* output,
|
|||||||
maxTolerance = b3Max(maxTolerance, b3LengthSquared(vertices[i].point));
|
maxTolerance = b3Max(maxTolerance, b3LengthSquared(vertices[i].point));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy simplex so we can identify duplicates.
|
||||||
|
saveCount = simplex.m_count;
|
||||||
|
for (u32 i = 0; i < saveCount; ++i)
|
||||||
|
{
|
||||||
|
save1[i] = vertices[i].index1;
|
||||||
|
save2[i] = vertices[i].index2;
|
||||||
|
}
|
||||||
|
|
||||||
// Sub-solve
|
// Sub-solve
|
||||||
const b3Vec3 origin = b3Vec3_zero;
|
const b3Vec3 origin = b3Vec3_zero;
|
||||||
|
|
||||||
@ -1098,9 +1098,7 @@ bool b3GJKShapeCast(b3GJKRayCastOutput* output,
|
|||||||
|
|
||||||
if (simplex.m_count == 4)
|
if (simplex.m_count == 4)
|
||||||
{
|
{
|
||||||
// Overlap
|
break;
|
||||||
output->iterations = iter;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v = simplex.GetClosestPoint();
|
v = simplex.GetClosestPoint();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user