本文整理汇总了C++中vec::ToString方法的典型用法代码示例。如果您正苦于以下问题:C++ vec::ToString方法的具体用法?C++ vec::ToString怎么用?C++ vec::ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec
的用法示例。
在下文中一共展示了vec::ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OptimalEnclosingSphere
/** For reference, see http://realtimecollisiondetection.net/blog/?p=20 . */
Sphere Sphere::OptimalEnclosingSphere(const vec &a, const vec &b, const vec &c, const vec &d)
{
Sphere sphere;
float s,t,u;
const vec ab = b-a;
const vec ac = c-a;
const vec ad = d-a;
bool success = FitSphereThroughPoints(ab, ac, ad, s, t, u);
if (!success || s < 0.f || t < 0.f || u < 0.f || s+t+u > 1.f)
{
sphere = OptimalEnclosingSphere(a,b,c);
if (!sphere.Contains(d))
{
sphere = OptimalEnclosingSphere(a,b,d);
if (!sphere.Contains(c))
{
sphere = OptimalEnclosingSphere(a,c,d);
if (!sphere.Contains(b))
{
sphere = OptimalEnclosingSphere(b,c,d);
sphere.r = Max(sphere.r, a.Distance(sphere.pos) + 1e-3f); // For numerical stability, expand the radius of the sphere so it certainly contains the fourth point.
assume(sphere.Contains(a));
}
}
}
}
/* // Note: Trying to approach the problem like this, like was in the triangle case, is flawed:
if (s < 0.f)
sphere = OptimalEnclosingSphere(a, c, d);
else if (t < 0.f)
sphere = OptimalEnclosingSphere(a, b, d);
else if (u < 0.f)
sphere = OptimalEnclosingSphere(a, b, c);
else if (s + t + u > 1.f)
sphere = OptimalEnclosingSphere(b, c, d); */
else // The fitted sphere is inside the convex hull of the vertices (a,b,c,d), so it must be optimal.
{
const vec center = s*ab + t*ac + u*ad;
sphere.pos = a + center;
// Mathematically, the following would be correct, but it suffers from floating point inaccuracies,
// since it only tests distance against one point.
//sphere.r = center.Length();
// For robustness, take the radius to be the distance to the farthest point (though the distance are all
// equal).
sphere.r = Sqrt(Max(sphere.pos.DistanceSq(a), sphere.pos.DistanceSq(b), sphere.pos.DistanceSq(c), sphere.pos.DistanceSq(d)));
}
// Allow floating point inconsistency and expand the radius by a small epsilon so that the containment tests
// really contain the points (note that the points must be sufficiently near enough to the origin)
sphere.r += 2.f*sEpsilon; // We test against one epsilon, so expand using 2 epsilons.
#ifdef MATH_ASSERT_CORRECTNESS
if (!sphere.Contains(a, sEpsilon) || !sphere.Contains(b, sEpsilon) || !sphere.Contains(c, sEpsilon) || !sphere.Contains(d, sEpsilon))
{
LOGE("Pos: %s, r: %f", sphere.pos.ToString().c_str(), sphere.r);
LOGE("A: %s, dist: %f", a.ToString().c_str(), a.Distance(sphere.pos));
LOGE("B: %s, dist: %f", b.ToString().c_str(), b.Distance(sphere.pos));
LOGE("C: %s, dist: %f", c.ToString().c_str(), c.Distance(sphere.pos));
LOGE("D: %s, dist: %f", d.ToString().c_str(), d.Distance(sphere.pos));
mathassert(false);
}
#endif
return sphere;
}