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

Position camera above, near, and looking at the scene.

This commit is contained in:
Aesylwinn 2016-03-18 14:02:24 -04:00
parent fcccacc0fa
commit 999869da24
4 changed files with 33 additions and 1 deletions

View File

@ -69,6 +69,14 @@ namespace CSVRender
mMouseScalar = value;
}
void CameraController::setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up)
{
osg::Vec3d eye = osg::Vec3d(bounds.xMax(), bounds.yMax(), bounds.zMax());
osg::Vec3d center = bounds.center();
getCamera()->setViewMatrixAsLookAt(eye, center, up);
}
void CameraController::setModified()
{
mModified = true;

View File

@ -3,6 +3,7 @@
#include <string>
#include <osg/BoundingBox>
#include <osg/ref_ptr>
#include <osg/Vec3d>
@ -41,6 +42,9 @@ namespace CSVRender
void setCamera(osg::Camera*);
void setMouseScalar(double value);
// moves the camera to an intelligent position
void setSceneBounds(const osg::BoundingBox& bounds, const osg::Vec3d& up);
virtual bool handleKeyEvent(QKeyEvent* event, bool pressed) = 0;
virtual bool handleMouseMoveEvent(std::string mode, int x, int y) = 0;

View File

@ -11,6 +11,8 @@
#include <osgViewer/CompositeViewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/LightModel>
#include <osg/BoundingBox>
#include <osg/ComputeBoundsVisitor>
#include <osgGA/TrackballManipulator>
#include <osgGA/FirstPersonManipulator>
@ -164,6 +166,7 @@ SceneWidget::SceneWidget(boost::shared_ptr<Resource::ResourceSystem> resourceSys
, mFreeCamControl(new FreeCameraController())
, mOrbitCamControl(new OrbitCameraController())
, mCurrentCamControl(mFreeCamControl.get())
, mCamPositionSet(false)
{
selectNavigationMode("free");
@ -306,7 +309,21 @@ void SceneWidget::keyReleaseEvent (QKeyEvent *event)
void SceneWidget::update(double dt)
{
mCurrentCamControl->update(dt);
if (mCamPositionSet)
{
mCurrentCamControl->update(dt);
}
else
{
osg::ComputeBoundsVisitor boundsVisitor;
osg::BoundingBox &boundingBox(boundsVisitor.getBoundingBox());
mRootNode->accept(boundsVisitor);
mCurrentCamControl->setSceneBounds(boundingBox, CameraController::WorldUp);
mCamPositionSet = true;
}
}
void SceneWidget::settingChanged (const CSMPrefs::Setting *setting)

View File

@ -120,6 +120,9 @@ namespace CSVRender
std::map<std::pair<Qt::MouseButton, bool>, std::string> mButtonMapping;
private:
bool mCamPositionSet;
public slots:
void update(double dt);