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


C++ Vec3f::length2方法代码示例

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


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

示例1: onCullBegin

// on cull begin
void LightNodeHandler::onCullBegin( osgUtil::CullVisitor * pCV, const osg::BoundingSphere * pSpherePtr /* = NULL */ )
{
    if(!_init)
        return;

    if(!m_pFatherRef)
        m_pFatherRef = GetScene()->getLights();

    // current stateset to work with
    const bool bReflPass = (pCV->getCullMask() == REFLECTION_MASK/*0x00010000UL*/);
    LightsPackStateSet & curStatePack = (bReflPass) ? m_lightsRefl : m_lightsMain;
    const std::vector<LightExternalInfo> & aCullVisibleLights = (bReflPass) ? m_pFatherRef->m_aReflVisibleLights : m_pFatherRef->m_aMainVisibleLights;
    const std::vector<LightProcessedInfo> & aCullProcessedLights = (bReflPass) ? m_pFatherRef->m_aReflProcessedLights : m_pFatherRef->m_aMainProcessedLights;
    // was state pushed last time?
    bool & bWasActive = (bReflPass) ? m_bReflWasActive : m_bMainWasActive;

    // calculate lights for specific geometry
    unsigned uLightsAdded = 0;
    for (unsigned i = 0; i < aCullVisibleLights.size() && uLightsAdded < nMaxLights; ++i)
    {
        const LightExternalInfo & lightData = aCullVisibleLights[i];

        // too big priority - continue
        if (lightData.uPriority > m_uMaxPriority)
            continue;

        const LightProcessedInfo & uniformData = aCullProcessedLights[i];

        // calculate whether light touches sphere
        if (pSpherePtr)
        {
            // test for spheres non-intersection
            const osg::Vec3f vVSLightPos(uniformData.lightVSPosAmbRatio.x(), uniformData.lightVSPosAmbRatio.y(), uniformData.lightVSPosAmbRatio.z());
            const float fRadSqrSum = cg::sqr(lightData.rDistAtt.hi() + pSpherePtr->radius());
            const osg::Vec3f vVecToCenter = pSpherePtr->center() - vVSLightPos;
            if (vVecToCenter.length2() >= fRadSqrSum)
                continue;

            // if cone - test for cone intersection
            if (!lightData.rConeAtt.empty() && vVecToCenter.length2() > pSpherePtr->radius2())
            {
                // get direction angle
                osg::Vec3f vVecToCenterDir = vVecToCenter;
                const float fVecLength = vVecToCenterDir.normalize();
                const float
                    fCenterAngle = acosf(vVecToCenterDir * osg::Vec3f(uniformData.lightVSDirSpecRatio.x(), uniformData.lightVSDirSpecRatio.y(), uniformData.lightVSDirSpecRatio.z())),
                    fSphereAngle = atan2f(pSpherePtr->radius(), fVecLength),
                    fMinDirAngle = std::max(fCenterAngle - fSphereAngle, 0.f);
                if (fMinDirAngle >= lightData.rConeAtt.hi())
                    continue;
            }
        }

#if LIGHTS_TURN_ON
        // okey, so we can add
        curStatePack.LightVSPosAmbRatio->setElement(uLightsAdded, uniformData.lightVSPosAmbRatio);
        curStatePack.LightVSDirSpecRatio->setElement(uLightsAdded, uniformData.lightVSDirSpecRatio);
        curStatePack.LightAttenuation->setElement(uLightsAdded, uniformData.lightAttenuation);
        curStatePack.LightDiffuse->setElement(uLightsAdded, uniformData.lightDiffuse);
#endif
        uLightsAdded++;
    }

    // so push stateset if needed
    m_bStatePushed = false;
    if (uLightsAdded > 0 || bWasActive)
    {
        curStatePack.LightsActiveNum->set(int(uLightsAdded));
        pCV->pushStateSet(curStatePack.pStateSet.get());
        bWasActive = (uLightsAdded > 0);
        m_bStatePushed = true;
    }

    // exit
    return;
}
开发者ID:wangfeilong321,项目名称:test_osg,代码行数:77,代码来源:Lights.cpp


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