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


C++ Vec3r::cross方法代码示例

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


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

示例1: intersect

/*! Intersect the line with a triangle.
    \param [in] v0,v1,v2  Points definiting a triangle in CW orientation.
    \param [out] t  If hit, this returns the distance the hit is down the line.
    \param [in,out] norm If non-NULL, this is set to the normal at the point of
            intersection
    \returns True if there is an intersection.

    This algorithm is based on "Fast, Minimum Storage Ray/Triangle Instersection" by
    T. Moeller and B. Trumbore, with the addition of avoiding the computation of
    inv_det when no intersection happens.
 */
bool Line::intersect(const Pnt3r &v0, 
                     const Pnt3r &v1,
                     const Pnt3r &v2, 
                           Real  &t,
                           Vec3r *norm) const
{
    // Eps (1E-6f) didn't work with very small geometries!
    static const Real sEps = 1E-10f;

    // find vectors for two edges sharing v0.
    Vec3r edge1 = v1 - v0;
    Vec3r edge2 = v2 - v0;

    // begin calculating determinant - also used to calculate U parameter.
    Vec3r pvec = _dir.cross(edge2);

    // if determinant is near zero, ray lies in plane of triangle.
    Real det = edge1.dot(pvec);

    Vec3r qvec;

    if(det > sEps)
    {
        // calculate distance from v0 to ray origin.
        Vec3r tvec = _pos - v0;

        // calculate U parameter and test bounds.
        Real u = tvec.dot(pvec);

        if(u < 0.f || u > det)
        {
            return false;
        }

        // prepare to test V parameter.
        qvec = tvec.cross(edge1);

        // calculate V parameter and test bounds.
        Real v = _dir.dot(qvec);

        if(v < 0.f || u + v > det)
        {
            return false;
        }
    }
    else if(det < -sEps)
    {
        // calculate distance from v0 to ray origin.
        Vec3r tvec = _pos - v0;

        // calculate U parameter and test bounds.
        Real u = tvec.dot(pvec);

        if(u > 0.f || u < det)
        {
            return false;
        }

        // prepare to test V parameter.
        qvec = tvec.cross(edge1);

        // calculate V parameter and test bounds.
        Real v = _dir.dot(qvec);

        if(v > 0.f || u + v < det)
        {
            return false;
        }
    }
    else
    {
        return false;  // ray is parallel to the plane of the triangle.
    }

    Real inv_det = 1.0f / det;

    // calculate t, ray intersects triangle.
    t = edge2.dot(qvec) * inv_det;

    if(norm != NULL)
    {
        *norm = edge1.cross(edge2);
        norm->normalize();
    }

    return true;
}
开发者ID:Langkamp,项目名称:OpenSGDevMaster_Toolbox,代码行数:98,代码来源:OSGLine.cpp


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