diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index be6534089..f4ba134d0 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -194,6 +194,8 @@ void CSMPrefs::State::declare() declareCategory ("Rendering"); declareDouble ("camera-fov", "Camera FOV", 90.).setPrecision(5).setRange(10.0, 160.0); + declareBool ("camera-ortho", "Orthographic projection for camera", false); + declareDouble ("camera-ortho-size", "Orthographic projection size parameter", 100.0).setPrecision(5).setRange(0.0, 1000.0); declareCategory ("Tooltips"); declareBool ("scene", "Show Tooltips in 3D scenes", true); diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 7d3ac3f1c..a151c638e 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -67,10 +67,7 @@ RenderWidget::RenderWidget(QWidget *parent, Qt::WindowFlags f) mView->getCamera()->setClearColor( osg::Vec4(0.2, 0.2, 0.6, 1.0) ); mView->getCamera()->setViewport( new osg::Viewport(0, 0, traits->width, traits->height) ); - mView->getCamera()->setProjectionMatrixAsPerspective( - CSMPrefs::get()["Rendering"]["camera-fov"].toDouble(), - static_cast(traits->width)/static_cast(traits->height), - 1.0f, 10000.0f); + updateCameraParameters(); SceneUtil::LightManager* lightMgr = new SceneUtil::LightManager; lightMgr->setStartLight(1); @@ -374,12 +371,34 @@ void SceneWidget::settingChanged (const CSMPrefs::Setting *setting) { mOrbitCamControl->setOrbitSpeedMultiplier(setting->toDouble()); } - else if (*setting=="Rendering/camera-fov") + else if (*setting=="Rendering/camera-fov" || + *setting=="Rendering/camera-ortho" || + *setting=="Rendering/camera-ortho-size") { + updateCameraParameters(); + } +} + +void RenderWidget::updateCameraParameters() +{ + const float near = 1.0; + const float far = 1000.0; + + if (CSMPrefs::get()["Rendering"]["camera-ortho"].isTrue()) + { + const float size = CSMPrefs::get()["Rendering"]["camera-ortho-size"].toDouble(); + const float half_w = size / 100.0 * static_cast(width()); + const float half_h = size / 100.0 * static_cast(height()); + + mView->getCamera()->setProjectionMatrixAsOrtho( + -half_w, half_w, -half_h, half_h, near, far); + } + else + { mView->getCamera()->setProjectionMatrixAsPerspective( - setting->toDouble(), + CSMPrefs::get()["Rendering"]["camera-fov"].toDouble(), static_cast(width())/static_cast(height()), - 1.0f, 10000.0f); + near, far); } } diff --git a/apps/opencs/view/render/scenewidget.hpp b/apps/opencs/view/render/scenewidget.hpp index cc3191c81..af7a6f1ec 100644 --- a/apps/opencs/view/render/scenewidget.hpp +++ b/apps/opencs/view/render/scenewidget.hpp @@ -64,6 +64,8 @@ namespace CSVRender osg::ref_ptr mView; osg::ref_ptr mRootNode; + void updateCameraParameters(); + QTimer mTimer; protected slots: