1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 12:35:46 +00:00

Add the view frustum to the debug HUD (in the most annoying way possible)

This commit is contained in:
AnyOldName3 2018-05-05 00:08:00 +01:00
parent 6d29375d5e
commit 4547151863
2 changed files with 39 additions and 0 deletions

View File

@ -762,11 +762,43 @@ void MWShadowTechnique::disableShadows()
void SceneUtil::MWShadowTechnique::enableDebugHUD() void SceneUtil::MWShadowTechnique::enableDebugHUD()
{ {
_debugHud = new DebugHUD(getShadowedScene()->getShadowSettings()->getNumShadowMapsPerLight()); _debugHud = new DebugHUD(getShadowedScene()->getShadowSettings()->getNumShadowMapsPerLight());
_frustumGeometry = new osg::Geometry();
_frustumGeometry->setCullingActive(false);
osg::ref_ptr<osg::DrawElementsUByte> frustumDrawElements = new osg::DrawElementsUByte(osg::PrimitiveSet::LINE_STRIP);
_frustumGeometry->addPrimitiveSet(frustumDrawElements);
frustumDrawElements->push_back(0);
frustumDrawElements->push_back(1);
frustumDrawElements->push_back(2);
frustumDrawElements->push_back(3);
frustumDrawElements->push_back(0);
frustumDrawElements->push_back(4);
frustumDrawElements->push_back(5);
frustumDrawElements->push_back(6);
frustumDrawElements->push_back(7);
frustumDrawElements->push_back(4);
frustumDrawElements = new osg::DrawElementsUByte(osg::PrimitiveSet::LINES);
_frustumGeometry->addPrimitiveSet(frustumDrawElements);
frustumDrawElements->push_back(1);
frustumDrawElements->push_back(5);
frustumDrawElements->push_back(2);
frustumDrawElements->push_back(6);
frustumDrawElements->push_back(3);
frustumDrawElements->push_back(7);
// Ensure this doesn't contribute to bounds calculation.
_frustumGeometry->setComputeBoundingBoxCallback(new osg::Drawable::ComputeBoundingBoxCallback());
_frustumGeometry->setComputeBoundingSphereCallback(new osg::Node::ComputeBoundingSphereCallback());
getShadowedScene()->addChild(_frustumGeometry);
} }
void SceneUtil::MWShadowTechnique::disableDebugHUD() void SceneUtil::MWShadowTechnique::disableDebugHUD()
{ {
_debugHud = nullptr; _debugHud = nullptr;
getShadowedScene()->removeChild(_frustumGeometry);
_frustumGeometry = nullptr;
} }
void SceneUtil::MWShadowTechnique::setSplitPointUniformLogarithmicRatio(double ratio) void SceneUtil::MWShadowTechnique::setSplitPointUniformLogarithmicRatio(double ratio)
@ -887,6 +919,11 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv)
//OSG_NOTICE<<"maxZFar "<<maxZFar<<std::endl; //OSG_NOTICE<<"maxZFar "<<maxZFar<<std::endl;
Frustum frustum(&cv, minZNear, maxZFar); Frustum frustum(&cv, minZNear, maxZFar);
if (_frustumGeometry)
{
osg::ref_ptr<osg::Vec3dArray> frustumCorners = new osg::Vec3dArray(8, &frustum.corners[0]);
_frustumGeometry->setVertexArray(frustumCorners);
}
double reducedNear, reducedFar; double reducedNear, reducedFar;
if (cv.getComputeNearFarMode() != osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR) if (cv.getComputeNearFarMode() != osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR)

View File

@ -260,6 +260,8 @@ namespace SceneUtil {
}; };
osg::ref_ptr<DebugHUD> _debugHud; osg::ref_ptr<DebugHUD> _debugHud;
osg::ref_ptr<osg::Geometry> _frustumGeometry;
}; };
} }