1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 15:35:23 +00:00

Slight improvement to camera placement.

This commit is contained in:
Aesylwinn 2016-03-25 23:47:05 -04:00
parent bee8977e45
commit a0fb242bf8
3 changed files with 45 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include <QKeyEvent>
#include <osg/Camera>
#include <osg/Drawable>
#include <osg/Matrixd>
#include <osg/Quat>
@ -541,4 +542,31 @@ namespace CSVRender
getCamera()->setViewMatrixAsLookAt(mCenter + offset, mCenter, up);
}
CameraComputeBoundsVisitor::CameraComputeBoundsVisitor(unsigned int mask)
: mMask(mask)
{
}
unsigned int CameraComputeBoundsVisitor::getMask() const
{
return mMask;
}
void CameraComputeBoundsVisitor::setMask(unsigned int value)
{
mMask = value;
}
void CameraComputeBoundsVisitor::apply(osg::Drawable& drawable)
{
if (drawable.getNodeMask() & mMask)
ComputeBoundsVisitor::apply(drawable);
}
void CameraComputeBoundsVisitor::apply(osg::Transform& transform)
{
if (transform.getNodeMask() & mMask)
ComputeBoundsVisitor::apply(transform);
}
}

View File

@ -4,6 +4,7 @@
#include <string>
#include <osg/BoundingBox>
#include <osg/ComputeBoundsVisitor>
#include <osg/ref_ptr>
#include <osg/Vec3d>
@ -144,6 +145,21 @@ namespace CSVRender
double mOrbitSpeed;
double mOrbitSpeedMult;
};
class CameraComputeBoundsVisitor : public osg::ComputeBoundsVisitor
{
public:
CameraComputeBoundsVisitor(unsigned int mask);
unsigned int getMask() const;
void setMask(unsigned int mask);
void apply(osg::Drawable& drawable);
void apply(osg::Transform& transform);
private:
unsigned int mMask;
};
}
#endif

View File

@ -12,7 +12,6 @@
#include <osgViewer/ViewerEventHandlers>
#include <osg/LightModel>
#include <osg/BoundingBox>
#include <osg/ComputeBoundsVisitor>
#include <osgGA/TrackballManipulator>
#include <osgGA/FirstPersonManipulator>
@ -315,7 +314,7 @@ void SceneWidget::update(double dt)
}
else
{
osg::ComputeBoundsVisitor boundsVisitor;
CameraComputeBoundsVisitor boundsVisitor(Mask_Reference | Mask_Terrain);
osg::BoundingBox &boundingBox(boundsVisitor.getBoundingBox());
mRootNode->accept(boundsVisitor);