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


C++ Point3::nonZero方法代码示例

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


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

示例1: gridBounds

RayGridIterator::RayGridIterator
(Ray                    ray, 
 const Vector3int32&    numCells, 
 const Vector3&         cellSize,
 const Point3&          gridOrigin,
 const Point3int32&     gridOriginIndex) :
    m_numCells(numCells),
    m_enterDistance(0.0f),
    m_ray(ray), 
    m_cellSize(cellSize),
    m_insideGrid(true) {
    
    if (gridOrigin.nonZero()) {
        // Change to the grid's reference frame
        ray = Ray::fromOriginAndDirection(ray.origin() - gridOrigin, ray.direction());
    }

    //////////////////////////////////////////////////////////////////////
    // See if the ray begins inside the box
    const AABox gridBounds(Vector3::zero(), Vector3(numCells) * cellSize);

    bool startsOutside = false;
    bool inside = false;
    Point3 startLocation = ray.origin();

    const bool passesThroughGrid =
        CollisionDetection::rayAABox
        (ray, Vector3(1,1,1) / ray.direction(),
         gridBounds, gridBounds.center(),
         square(gridBounds.extent().length() * 0.5f),
         startLocation,
         inside);

    if (! inside) {
        if (passesThroughGrid) {
            // Back up slightly so that we immediately hit the
            // start location.  The precision here is tricky--if
            // the ray strikes at a very glancing angle, we need
            // to move a large distance along the ray to enter the
            // grid.  If the ray strikes head on, we only need to
            // move a small distance.
            m_enterDistance = (ray.origin() - startLocation).length() - 0.0001f;
            startLocation = ray.origin() + ray.direction() * m_enterDistance;
            startsOutside = true;
        } else {
            // The ray never hits the grid
            m_insideGrid = false;
        }
    }

    //////////////////////////////////////////////////////////////////////
    // Find the per-iteration variables
    for (int a = 0; a < 3; ++a) {
        m_index[a]  = floor(startLocation[a] / cellSize[a]);
        m_tDelta[a] = cellSize[a] / abs(ray.direction()[a]);

        m_step[a]   = sign(ray.direction()[a]);

        // Distance to the edge fo the cell along the ray direction
        float d = startLocation[a] - m_index[a] * cellSize[a];
        if (m_step[a] > 0) {
            // Measure from the other edge
            d = cellSize[a] - d;

            // Exit on the high side
            m_boundaryIndex[a] = m_numCells[a];
        } else {
            // Exit on the low side (or never)
            m_boundaryIndex[a] = -1;
        }
        debugAssert(d >= 0 && d <= cellSize[a]);

        if (ray.direction()[a] != 0) {
            m_exitDistance[a] = d / abs(ray.direction()[a]) + m_enterDistance;
        } else {
            // Ray is parallel to this partition axis.
            // Avoid dividing by zero, which could be NaN if d == 0
            m_exitDistance[a] = inf();
        }
    }

    if (gridOriginIndex.nonZero()) {
        // Offset the grid coordinates
        m_boundaryIndex += gridOriginIndex;
        m_index += gridOriginIndex;
    }


    if (startsOutside) {
        // Let the increment operator bring us into the first cell
        // so that the starting axis is initialized correctly.
        ++(*this);
    }
}
开发者ID:BuloZB,项目名称:StrawberryEMU,代码行数:94,代码来源:RayGridIterator.cpp


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