mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-03-30 09:06:43 +00:00
static intersections
Signed-off-by: Bret Curtis <psi29a@gmail.com>
This commit is contained in:
parent
340d626589
commit
65cd2c77aa
3 changed files with 4 additions and 80 deletions
|
@ -124,23 +124,6 @@ void QuadTreeNode::traverseNodes(ViewData* vd, const osg::Vec3f& viewPoint, LodC
|
||||||
vd->add(this);
|
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)
|
void QuadTreeNode::setBoundingBox(const osg::BoundingBox &boundingBox)
|
||||||
{
|
{
|
||||||
mBoundingBox = boundingBox;
|
mBoundingBox = boundingBox;
|
||||||
|
|
|
@ -2,39 +2,12 @@
|
||||||
#define OPENMW_COMPONENTS_TERRAIN_QUADTREENODE_H
|
#define OPENMW_COMPONENTS_TERRAIN_QUADTREENODE_H
|
||||||
|
|
||||||
#include <osg/Group>
|
#include <osg/Group>
|
||||||
#include <osgUtil/LineSegmentIntersector>
|
|
||||||
|
|
||||||
#include "defs.hpp"
|
#include "defs.hpp"
|
||||||
|
|
||||||
namespace Terrain
|
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
|
enum ChildDirection
|
||||||
{
|
{
|
||||||
NW = 0,
|
NW = 0,
|
||||||
|
@ -105,9 +78,6 @@ namespace Terrain
|
||||||
/// Traverse nodes according to LOD selection.
|
/// Traverse nodes according to LOD selection.
|
||||||
void traverseNodes(ViewData* vd, const osg::Vec3f& viewPoint, LodCallback* lodCallback);
|
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:
|
private:
|
||||||
QuadTreeNode* mParent;
|
QuadTreeNode* mParent;
|
||||||
|
|
||||||
|
|
|
@ -418,44 +418,15 @@ void QuadTreeWorld::accept(osg::NodeVisitor &nv)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osg::Object * viewer = isCullVisitor ? static_cast<osgUtil::CullVisitor*>(&nv)->getCurrentCamera() : nullptr;
|
||||||
bool needsUpdate = true;
|
bool needsUpdate = true;
|
||||||
ViewData* vd = nullptr;
|
ViewData *vd = mViewDataMap->getViewData(viewer, nv.getViewPoint(), mActiveGrid, needsUpdate);
|
||||||
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.
|
|
||||||
}
|
|
||||||
|
|
||||||
if (needsUpdate)
|
if (needsUpdate)
|
||||||
{
|
{
|
||||||
vd->reset();
|
vd->reset();
|
||||||
if (isCullVisitor)
|
DefaultLodCallback lodCallback(mLodFactor, MIN_SIZE, mViewDistance, mActiveGrid);
|
||||||
{
|
mRootNode->traverseNodes(vd, nv.getViewPoint(), &lodCallback);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const float cellWorldSize = mStorage->getCellWorldSize();
|
const float cellWorldSize = mStorage->getCellWorldSize();
|
||||||
|
|
Loading…
Reference in a new issue