当前位置: 首页>>代码示例>>C++>>正文


C++ Triangle::PlaneCCW方法代码示例

本文整理汇总了C++中Triangle::PlaneCCW方法的典型用法代码示例。如果您正苦于以下问题:C++ Triangle::PlaneCCW方法的具体用法?C++ Triangle::PlaneCCW怎么用?C++ Triangle::PlaneCCW使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Triangle的用法示例。


在下文中一共展示了Triangle::PlaneCCW方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Intersects

/** The Triangle-Triangle test implementation is based on pseudo-code from Tomas Möller's
	"A Fast Triangle-Triangle Intersection Test": http://jgt.akpeters.com/papers/Moller97/.
	See also Christer Ericson's Real-Time Collision Detection, p. 172. */
bool Triangle::Intersects(const Triangle &t2, LineSegment *outLine) const
{
    // Is the triangle t2 completely on one side of the plane of this triangle?
    Plane p1 = this->PlaneCCW();
    float t2da = p1.SignedDistance(t2.a);
    float t2db = p1.SignedDistance(t2.b);
    float t2dc = p1.SignedDistance(t2.c);
    if (t2da*t2db > 0.f && t2da*t2dc > 0.f)
        return false;
    // Is this triangle completely on one side of the plane of the triangle t2?
    Plane p2 = t2.PlaneCCW();
    float t1da = p2.SignedDistance(this->a);
    float t1db = p2.SignedDistance(this->b);
    float t1dc = p2.SignedDistance(this->c);
    if (t1da*t1db > 0.f && t1da*t1dc > 0.f)
        return false;

    // Find the intersection line of the two planes.
    Line l;
    bool success = p1.Intersects(p2, &l);
    assume(success); // We already determined the two triangles have intersecting planes, so this should always succeed.
    if (!success)
        return false;

    // Find the two line segments of both triangles which straddle the intersection line.
    LineSegment l1a, l1b;
    LineSegment l2a, l2b;
    FindIntersectingLineSegments(*this, t1da, t1db, t1dc, l1a, l1b);
    FindIntersectingLineSegments(t2, t2da, t2db, t2dc, l2a, l2b);

    // Find the projection intervals on the intersection line.
    float d1a, d1b, d2a, d2b;
    l.Distance(l1a, &d1a);
    l.Distance(l1b, &d1b);
    l.Distance(l2a, &d2a);
    l.Distance(l2b, &d2b);
    if (d1a > d1b)
        Swap(d1a, d1b);
    if (d2a > d2b)
        Swap(d2a, d2b);
    float rStart = Max(d1a, d2a);
    float rEnd = Min(d1b, d2b);
    if (rStart <= rEnd)
    {
        if (outLine)
            *outLine = LineSegment(l.GetPoint(rStart), l.GetPoint(rEnd));
        return true;
    }
    return false;
}
开发者ID:katik,项目名称:naali,代码行数:53,代码来源:Triangle.cpp


注:本文中的Triangle::PlaneCCW方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。