static intersections

Signed-off-by: Bret Curtis <psi29a@gmail.com>
pull/2911/head
bzzt lost a hitlab login 5 years ago committed by Bret Curtis
parent 340d626589
commit 65cd2c77aa

@ -124,23 +124,6 @@ void QuadTreeNode::traverseNodes(ViewData* vd, const osg::Vec3f& viewPoint, LodC
vd->add(this);
}
void QuadTreeNode::intersect(ViewData* vd, TerrainLineIntersector& intersector)
{
if (!hasValidBounds())
return;
if (!intersector.intersectAndClip(getBoundingBox()))
return;
if (getNumChildren() == 0)
vd->add(this);
else
{
for (unsigned int i=0; i<getNumChildren(); ++i)
getChild(i)->intersect(vd, intersector);
}
}
void QuadTreeNode::setBoundingBox(const osg::BoundingBox &boundingBox)
{
mBoundingBox = boundingBox;

@ -2,39 +2,12 @@
#define OPENMW_COMPONENTS_TERRAIN_QUADTREENODE_H
#include <osg/Group>
#include <osgUtil/LineSegmentIntersector>
#include "defs.hpp"
namespace Terrain
{
class TerrainLineIntersector : public osgUtil::LineSegmentIntersector
{
public:
TerrainLineIntersector(osgUtil::LineSegmentIntersector* intersector, osg::Matrix& matrix) :
osgUtil::LineSegmentIntersector(intersector->getStart() * matrix, intersector->getEnd() * matrix)
{
setPrecisionHint(intersector->getPrecisionHint());
_intersectionLimit = intersector->getIntersectionLimit();
_parent = intersector;
}
TerrainLineIntersector(osgUtil::LineSegmentIntersector* intersector) :
osgUtil::LineSegmentIntersector(intersector->getStart(), intersector->getEnd())
{
setPrecisionHint(intersector->getPrecisionHint());
_intersectionLimit = intersector->getIntersectionLimit();
_parent = intersector;
}
bool intersectAndClip(const osg::BoundingBox& bbInput)
{
osg::Vec3d s(_start), e(_end);
return osgUtil::LineSegmentIntersector::intersectAndClip(s, e, bbInput);
}
};
enum ChildDirection
{
NW = 0,
@ -105,9 +78,6 @@ namespace Terrain
/// Traverse nodes according to LOD selection.
void traverseNodes(ViewData* vd, const osg::Vec3f& viewPoint, LodCallback* lodCallback);
/// Adds all leaf nodes which intersect the line from start to end
void intersect(ViewData* vd, TerrainLineIntersector& intersector);
private:
QuadTreeNode* mParent;

@ -418,44 +418,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
return;
}
osg::Object * viewer = isCullVisitor ? static_cast<osgUtil::CullVisitor*>(&nv)->getCurrentCamera() : nullptr;
bool needsUpdate = true;
ViewData* vd = nullptr;
if (isCullVisitor)
vd = mViewDataMap->getViewData(static_cast<osgUtil::CullVisitor*>(&nv)->getCurrentCamera(), nv.getViewPoint(), mActiveGrid, needsUpdate);
else
{
static ViewData sIntersectionViewData;
vd = &sIntersectionViewData;
vd->clear(); // we can't reuse intersection views in the next frame because they only contain what is touched by the intersection ray.
}
ViewData *vd = mViewDataMap->getViewData(viewer, nv.getViewPoint(), mActiveGrid, needsUpdate);
if (needsUpdate)
{
vd->reset();
if (isCullVisitor)
{
DefaultLodCallback lodCallback(mLodFactor, MIN_SIZE, mViewDistance, mActiveGrid);
mRootNode->traverseNodes(vd, nv.getViewPoint(), &lodCallback);
}
else
{
osgUtil::IntersectionVisitor* iv = static_cast<osgUtil::IntersectionVisitor*>(&nv);
osgUtil::LineSegmentIntersector* lineIntersector = dynamic_cast<osgUtil::LineSegmentIntersector*>(iv->getIntersector());
if (!lineIntersector)
throw std::runtime_error("Cannot update QuadTreeWorld: node visitor is not LineSegmentIntersector");
if (lineIntersector->getCoordinateFrame() == osgUtil::Intersector::CoordinateFrame::MODEL && iv->getModelMatrix() == 0)
{
TerrainLineIntersector terrainIntersector(lineIntersector);
mRootNode->intersect(vd, terrainIntersector);
}
else
{
osg::Matrix matrix(lineIntersector->getTransformation(*iv, lineIntersector->getCoordinateFrame()));
TerrainLineIntersector terrainIntersector(lineIntersector, matrix);
mRootNode->intersect(vd, terrainIntersector);
}
}
DefaultLodCallback lodCallback(mLodFactor, MIN_SIZE, mViewDistance, mActiveGrid);
mRootNode->traverseNodes(vd, nv.getViewPoint(), &lodCallback);
}
const float cellWorldSize = mStorage->getCellWorldSize();

Loading…
Cancel
Save