本文整理汇总了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;
}