本文整理汇总了C++中Plane::GetSignedDistance方法的典型用法代码示例。如果您正苦于以下问题:C++ Plane::GetSignedDistance方法的具体用法?C++ Plane::GetSignedDistance怎么用?C++ Plane::GetSignedDistance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Plane
的用法示例。
在下文中一共展示了Plane::GetSignedDistance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PolygonSweptSphereIntersect
// Test between a polygon and a swept sphere with radius inRadius moving from inBegin to inBegin + inDelta
// If there is an intersection the intersection position is returned in outPoint and the center of the
// sphere is at inBegin + outFraction * inDelta when it collides
bool PolygonSweptSphereIntersect(const Plane &inPlane, const Vector2 *inVertices, int inNumVertices, const Vector3 &inBegin, const Vector3 &inDelta, float inRadius, Vector3 &outPoint, float &outFraction)
{
// Determine the range over which the sphere intersects the plane
float t1, t2;
if (!PlaneSweptSphereIntersect(inPlane, inBegin, inDelta, inRadius, t1, t2))
return false;
// The radius of the circle is defined as: radius^2 = (sphere radius)^2 - (distance plane to center)^2
// this can be written as: radius^2 = a * t^2 + b * t + c
float n_dot_d = inPlane.mNormal.Dot(inDelta);
float dist_to_b = inPlane.GetSignedDistance(inBegin);
float a = -n_dot_d * n_dot_d;
float b = -2.0f * n_dot_d * dist_to_b;
float c = inRadius * inRadius - dist_to_b * dist_to_b;
// Get basis
Vector3 u, v;
inPlane.GetBasisVectors(u, v);
// Get begin and delta in plane space
Vector2 begin = Plane::sConvertWorldToPlane(u, v, inBegin);
Vector2 delta = Plane::sConvertWorldToPlane(u, v, inDelta);
// Test if sphere intersects at t1
Vector2 p;
if (PolygonCircleIntersect(inVertices, inNumVertices, begin + delta * t1, a * t1 * t1 + b * t1 + c, p))
{
outFraction = t1;
outPoint = inPlane.ConvertPlaneToWorld(u, v, p);
return true;
}
// Test if sphere intersects with one of the edges or vertices
if (SweptCircleEdgeVertexIntersect(inVertices, inNumVertices, begin, delta, a, b, c, p, outFraction))
{
outPoint = inPlane.ConvertPlaneToWorld(u, v, p);
return true;
}
return false;
}
示例2: PlaneSweptSphereIntersect
// Test intersection between a plane inPlane and a swept sphere with radius inRadius moving from inBegin to inBegin + inDelta
// If there is an intersection the function returns true and the intersection range is from
// inBegin + outT1 * inDelta to inBegin + outT2 * inDelta
bool PlaneSweptSphereIntersect(const Plane &inPlane, const Vector3 &inBegin, const Vector3 &inDelta, float inRadius, float &outT1, float &outT2)
{
// If the center of the sphere moves like: center = inBegin + t * inDelta for t e [0, 1]
// then the sphere intersects the plane if: -R <= distance plane to center <= R
float n_dot_d = inPlane.mNormal.Dot(inDelta);
float dist_to_b = inPlane.GetSignedDistance(inBegin);
if (n_dot_d == 0.0f)
{
// The sphere is moving nearly parallel to the plane, check if the distance
// is smaller than the radius
if (Abs(dist_to_b) > inRadius)
return false;
// Intersection on the entire range
outT1 = 0.0f;
outT2 = 1.0f;
}
else
{
// Determine interval of intersection
outT1 = (inRadius - dist_to_b) / n_dot_d;
outT2 = (-inRadius - dist_to_b) / n_dot_d;
// Order the results
if (outT1 > outT2)
Swap(outT1, outT2);
// Early out if no hit possible
if (outT1 > 1.0f || outT2 < 0.0f)
return false;
// Clamp it to the range [0, 1], the range of the swept sphere
if (outT1 < 0.0f) outT1 = 0.0f;
if (outT2 > 1.0f) outT2 = 1.0f;
}
return true;
}