1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 17:53:53 +00:00
openmw/apps/opencs/view/render/scenewidget.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

565 lines
20 KiB
C++
Raw Normal View History

2013-11-02 01:48:30 +00:00
#include "scenewidget.hpp"
2020-06-25 19:46:07 +00:00
#include <chrono>
2022-10-19 17:02:00 +00:00
#include <exception>
2020-06-25 19:46:07 +00:00
#include <thread>
#include <QLayout>
2022-06-16 19:29:55 +00:00
#include <QMouseEvent>
#include <QSurfaceFormat>
2013-11-02 01:48:30 +00:00
2022-10-19 17:02:00 +00:00
#include <apps/opencs/model/prefs/category.hpp>
#include <apps/opencs/model/prefs/setting.hpp>
#include <apps/opencs/view/render/lightingbright.hpp>
#include <apps/opencs/view/render/lightingday.hpp>
#include <apps/opencs/view/render/lightingnight.hpp>
#include <extern/osgQt/CompositeOsgRenderer.hpp>
#include <extern/osgQt/osgQOpenGLWidget.hpp>
2022-10-19 17:02:00 +00:00
#include <osg/Array>
#include <osg/Camera>
#include <osg/DisplaySettings>
#include <osg/GL>
#include <osg/Geometry>
#include <osg/GraphicsContext>
2022-10-19 17:02:00 +00:00
#include <osg/Group>
2015-03-28 20:26:16 +00:00
#include <osg/LightModel>
#include <osg/Material>
2022-10-19 17:02:00 +00:00
#include <osg/Matrix>
#include <osg/PrimitiveSet>
#include <osg/StateAttribute>
#include <osg/StateSet>
#include <osg/Transform>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Vec4ub>
#include <osg/View>
#include <osg/Viewport>
#include <osgGA/EventQueue>
#include <osgGA/GUIEventAdapter>
#include <osgViewer/GraphicsWindow>
#include <osgViewer/View>
#include <osgViewer/ViewerBase>
#include <osgViewer/ViewerEventHandlers>
2018-11-13 19:07:01 +00:00
#include <components/debug/debuglog.hpp>
#include <components/resource/resourcesystem.hpp>
#include <components/resource/scenemanager.hpp>
#include <components/sceneutil/glextensions.hpp>
2016-01-06 14:00:58 +00:00
#include <components/sceneutil/lightmanager.hpp>
#include "../widget/scenetoolmode.hpp"
2014-03-23 14:14:26 +00:00
#include "../../model/prefs/shortcut.hpp"
2016-03-10 09:29:24 +00:00
#include "../../model/prefs/state.hpp"
2016-03-14 04:04:11 +00:00
#include "cameracontroller.hpp"
2014-03-23 14:14:26 +00:00
#include "lighting.hpp"
#include "mask.hpp"
namespace CSVRender
{
2013-11-02 01:48:30 +00:00
RenderWidget::RenderWidget(QWidget* parent, Qt::WindowFlags f)
: QWidget(parent, f)
2016-01-06 14:00:58 +00:00
, mRootNode(nullptr)
2022-09-22 18:26:05 +00:00
{
mView = new osgViewer::View;
updateCameraParameters(width() / static_cast<double>(height()));
mWidget = new osgQOpenGLWidget(this);
2022-09-22 18:26:05 +00:00
mRenderer = mWidget->getCompositeViewer();
osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> window
= new osgViewer::GraphicsWindowEmbedded(0, 0, width(), height());
mWidget->setGraphicsWindowEmbedded(window);
mRenderer->setRealizeOperation(new SceneUtil::GetGLExtensionsOperation());
int frameRateLimit = CSMPrefs::get()["Rendering"]["framerate-limit"].toInt();
mRenderer->setRunMaxFrameRate(frameRateLimit);
mRenderer->setUseConfigureAffinity(false);
2022-09-22 18:26:05 +00:00
QLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(mWidget);
setLayout(layout);
2022-09-22 18:26:05 +00:00
mView->getCamera()->setGraphicsContext(window);
2022-09-22 18:26:05 +00:00
osg::ref_ptr<SceneUtil::LightManager> lightMgr = new SceneUtil::LightManager;
2016-01-06 14:00:58 +00:00
lightMgr->setStartLight(1);
lightMgr->setLightingMask(Mask_Lighting);
mRootNode = std::move(lightMgr);
2022-09-22 18:26:05 +00:00
mView->getCamera()->setViewport(new osg::Viewport(0, 0, width(), height()));
2015-03-28 20:26:16 +00:00
mView->getCamera()->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
mView->getCamera()->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
osg::ref_ptr<osg::Material> defaultMat(new osg::Material);
defaultMat->setColorMode(osg::Material::OFF);
defaultMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 1, 1, 1));
defaultMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 1, 1, 1));
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
2017-02-01 14:49:20 +00:00
mView->getCamera()->getOrCreateStateSet()->setAttribute(defaultMat);
2022-09-22 18:26:05 +00:00
mView->setSceneData(mRootNode);
2022-09-22 18:26:05 +00:00
// Add ability to signal osg to show its statistics for debugging purposes
mView->addEventHandler(new osgViewer::StatsHandler);
2022-09-22 18:26:05 +00:00
mRenderer->addView(mView);
mRenderer->setDone(false);
2022-09-22 18:26:05 +00:00
}
RenderWidget::~RenderWidget()
2018-11-13 19:07:01 +00:00
{
2022-09-22 18:26:05 +00:00
try
{
mRenderer->removeView(mView);
2022-09-22 18:26:05 +00:00
}
2018-11-13 19:07:01 +00:00
catch (const std::exception& e)
2022-09-22 18:26:05 +00:00
{
2018-11-13 19:07:01 +00:00
Log(Debug::Error) << "Error in the destructor: " << e.what();
2022-09-22 18:26:05 +00:00
}
delete mWidget;
2018-11-13 19:07:01 +00:00
}
2022-09-22 18:26:05 +00:00
2018-11-13 19:07:01 +00:00
void RenderWidget::flagAsModified()
{
mView->requestRedraw();
}
void RenderWidget::setVisibilityMask(unsigned int mask)
2016-02-16 15:02:29 +00:00
{
mView->getCamera()->setCullMask(mask | Mask_ParticleSystem | Mask_Lighting);
}
osg::Camera* RenderWidget::getCamera()
2022-09-22 18:26:05 +00:00
{
return mView->getCamera();
2022-09-22 18:26:05 +00:00
}
void RenderWidget::toggleRenderStats()
2022-09-22 18:26:05 +00:00
{
osgViewer::GraphicsWindow* window
= static_cast<osgViewer::GraphicsWindow*>(mView->getCamera()->getGraphicsContext());
window->getEventQueue()->keyPress(osgGA::GUIEventAdapter::KEY_S);
window->getEventQueue()->keyRelease(osgGA::GUIEventAdapter::KEY_S);
2022-09-22 18:26:05 +00:00
}
2014-02-25 13:09:07 +00:00
2015-03-28 20:26:16 +00:00
// ---------------------------------------------------
SceneWidget::SceneWidget(std::shared_ptr<Resource::ResourceSystem> resourceSystem, QWidget* parent,
Qt::WindowFlags f, bool retrieveInput)
: RenderWidget(parent, f)
2023-07-29 07:44:39 +00:00
, mResourceSystem(std::move(resourceSystem))
2018-10-09 06:21:12 +00:00
, mLighting(nullptr)
, mHasDefaultAmbient(false)
, mIsExterior(true)
, mPrevMouseX(0)
, mPrevMouseY(0)
, mCamPositionSet(false)
2022-09-22 18:26:05 +00:00
{
mFreeCamControl = new FreeCameraController(this);
mOrbitCamControl = new OrbitCameraController(this);
mCurrentCamControl = mFreeCamControl;
mOrbitCamControl->setPickingMask(Mask_Reference | Mask_Terrain);
2016-03-10 09:29:24 +00:00
mOrbitCamControl->setConstRoll(CSMPrefs::get()["3D Scene Input"]["navi-orbit-const-roll"].isTrue());
2016-03-14 04:04:11 +00:00
// set up gradient view or configured clear color
QColor bgColour = CSMPrefs::get()["Rendering"]["scene-day-background-colour"].toColor();
if (CSMPrefs::get()["Rendering"]["scene-use-gradient"].isTrue())
2022-09-22 18:26:05 +00:00
{
QColor gradientColour = CSMPrefs::get()["Rendering"]["scene-day-gradient-colour"].toColor();
mGradientCamera = createGradientCamera(bgColour, gradientColour);
mView->getCamera()->setClearMask(0);
mView->getCamera()->addChild(mGradientCamera.get());
2022-09-22 18:26:05 +00:00
}
else
{
mView->getCamera()->setClearColor(osg::Vec4(bgColour.redF(), bgColour.greenF(), bgColour.blueF(), 1.0f));
}
// we handle lighting manually
mView->setLightingMode(osgViewer::View::NO_LIGHT);
setLighting(&mLightingDay);
mResourceSystem->getSceneManager()->setParticleSystemMask(Mask_ParticleSystem);
// Recieve mouse move event even if mouse button is not pressed
setMouseTracking(true);
setFocusPolicy(Qt::ClickFocus);
connect(&CSMPrefs::State::get(), &CSMPrefs::State::settingChanged, this, &SceneWidget::settingChanged);
// TODO update this outside of the constructor where virtual methods can be used
if (retrieveInput)
2022-09-22 18:26:05 +00:00
{
CSMPrefs::get()["3D Scene Input"].update();
CSMPrefs::get()["Tooltips"].update();
2022-09-22 18:26:05 +00:00
}
2023-04-06 04:04:21 +00:00
connect(mRenderer, &CompositeOsgRenderer::simulationUpdated, this, &SceneWidget::update);
// Shortcuts
CSMPrefs::Shortcut* focusToolbarShortcut = new CSMPrefs::Shortcut("scene-focus-toolbar", this);
2022-09-22 18:26:05 +00:00
connect(
focusToolbarShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this, &SceneWidget::focusToolbarRequest);
CSMPrefs::Shortcut* renderStatsShortcut = new CSMPrefs::Shortcut("scene-render-stats", this);
2022-09-22 18:26:05 +00:00
connect(
renderStatsShortcut, qOverload<>(&CSMPrefs::Shortcut::activated), this, &SceneWidget::toggleRenderStats);
2022-09-22 18:26:05 +00:00
}
SceneWidget::~SceneWidget()
2022-09-22 18:26:05 +00:00
{
// Since we're holding on to the resources past the existence of this graphics context, we'll need to manually
// release the created objects
mResourceSystem->releaseGLObjects(mView->getCamera()->getGraphicsContext()->getState());
2022-09-22 18:26:05 +00:00
}
2023-07-29 07:44:39 +00:00
osg::ref_ptr<osg::Geometry> SceneWidget::createGradientRectangle(QColor& bgColour, QColor& gradientColour)
2022-09-22 18:26:05 +00:00
{
osg::ref_ptr<osg::Geometry> geometry = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
vertices->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, -1.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, -1.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, -1.0f));
geometry->setVertexArray(vertices);
osg::ref_ptr<osg::DrawElementsUShort> primitives = new osg::DrawElementsUShort(osg::PrimitiveSet::TRIANGLES, 0);
// triangle 1
primitives->push_back(0);
primitives->push_back(1);
primitives->push_back(2);
// triangle 2
primitives->push_back(2);
primitives->push_back(1);
primitives->push_back(3);
geometry->addPrimitiveSet(primitives);
osg::ref_ptr<osg::Vec4ubArray> colours = new osg::Vec4ubArray;
colours->push_back(osg::Vec4ub(gradientColour.red(), gradientColour.green(), gradientColour.blue(), 1.0f));
colours->push_back(osg::Vec4ub(gradientColour.red(), gradientColour.green(), gradientColour.blue(), 1.0f));
colours->push_back(osg::Vec4ub(bgColour.red(), bgColour.green(), bgColour.blue(), 1.0f));
colours->push_back(osg::Vec4ub(bgColour.red(), bgColour.green(), bgColour.blue(), 1.0f));
geometry->setColorArray(colours, osg::Array::BIND_PER_VERTEX);
geometry->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geometry->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
return geometry;
2022-09-22 18:26:05 +00:00
}
2023-07-29 07:44:39 +00:00
osg::ref_ptr<osg::Camera> SceneWidget::createGradientCamera(QColor& bgColour, QColor& gradientColour)
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera();
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1.0f, 0, 1.0f));
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->setViewMatrix(osg::Matrix::identity());
camera->setClearMask(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
camera->setAllowEventFocus(false);
// draw subgraph before main camera view.
camera->setRenderOrder(osg::Camera::PRE_RENDER);
2015-03-28 20:26:16 +00:00
2020-11-13 07:39:47 +00:00
camera->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
osg::ref_ptr<osg::Geometry> gradientQuad = createGradientRectangle(bgColour, gradientColour);
2023-07-29 08:58:27 +00:00
camera->addChild(std::move(gradientQuad));
2015-03-28 20:26:16 +00:00
return camera;
}
2023-07-29 07:44:39 +00:00
void SceneWidget::updateGradientCamera(QColor& bgColour, QColor& gradientColour)
{
osg::ref_ptr<osg::Geometry> gradientRect = createGradientRectangle(bgColour, gradientColour);
// Replaces previous rectangle
mGradientCamera->setChild(0, gradientRect.get());
}
2022-09-22 18:26:05 +00:00
void SceneWidget::setLighting(Lighting* lighting)
{
if (mLighting)
mLighting->deactivate();
2022-09-22 18:26:05 +00:00
mLighting = lighting;
mLighting->activate(mRootNode, mIsExterior);
2022-09-22 18:26:05 +00:00
osg::Vec4f ambient = mLighting->getAmbientColour(mHasDefaultAmbient ? &mDefaultAmbient : nullptr);
setAmbient(ambient);
2022-09-22 18:26:05 +00:00
flagAsModified();
}
2022-09-22 18:26:05 +00:00
void SceneWidget::setAmbient(const osg::Vec4f& ambient)
{
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
osg::ref_ptr<osg::LightModel> lightmodel = new osg::LightModel;
lightmodel->setAmbientIntensity(ambient);
stateset->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateset->setMode(GL_LIGHT0, osg::StateAttribute::ON);
stateset->setAttributeAndModes(lightmodel, osg::StateAttribute::ON);
mRootNode->setStateSet(stateset);
}
void SceneWidget::selectLightingMode(const std::string& mode)
2022-09-22 18:26:05 +00:00
{
QColor backgroundColour;
QColor gradientColour;
if (mode == "day")
2022-09-22 18:26:05 +00:00
{
backgroundColour = CSMPrefs::get()["Rendering"]["scene-day-background-colour"].toColor();
gradientColour = CSMPrefs::get()["Rendering"]["scene-day-gradient-colour"].toColor();
setLighting(&mLightingDay);
2022-09-22 18:26:05 +00:00
}
else if (mode == "night")
2022-09-22 18:26:05 +00:00
{
backgroundColour = CSMPrefs::get()["Rendering"]["scene-night-background-colour"].toColor();
gradientColour = CSMPrefs::get()["Rendering"]["scene-night-gradient-colour"].toColor();
setLighting(&mLightingNight);
2022-09-22 18:26:05 +00:00
}
else if (mode == "bright")
2022-09-22 18:26:05 +00:00
{
backgroundColour = CSMPrefs::get()["Rendering"]["scene-bright-background-colour"].toColor();
gradientColour = CSMPrefs::get()["Rendering"]["scene-bright-gradient-colour"].toColor();
setLighting(&mLightingBright);
2022-09-22 18:26:05 +00:00
}
if (CSMPrefs::get()["Rendering"]["scene-use-gradient"].isTrue())
2022-09-22 18:26:05 +00:00
{
if (mGradientCamera.get() != nullptr)
{
// we can go ahead and update since this camera still exists
updateGradientCamera(backgroundColour, gradientColour);
2022-09-22 18:26:05 +00:00
if (!mView->getCamera()->containsNode(mGradientCamera.get()))
2022-09-22 18:26:05 +00:00
{
// need to re-attach the gradient camera
mView->getCamera()->setClearMask(0);
mView->getCamera()->addChild(mGradientCamera.get());
2022-09-22 18:26:05 +00:00
}
}
else
{
// need to create the gradient camera
mGradientCamera = createGradientCamera(backgroundColour, gradientColour);
mView->getCamera()->setClearMask(0);
mView->getCamera()->addChild(mGradientCamera.get());
}
}
else
{
// Fall back to using the clear color for the camera
mView->getCamera()->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
mView->getCamera()->setClearColor(
osg::Vec4(backgroundColour.redF(), backgroundColour.greenF(), backgroundColour.blueF(), 1.0f));
if (mGradientCamera.get() != nullptr && mView->getCamera()->containsNode(mGradientCamera.get()))
{
// Remove the child to prevent the gradient from rendering
mView->getCamera()->removeChild(mGradientCamera.get());
2022-09-22 18:26:05 +00:00
}
}
}
2016-03-14 04:04:11 +00:00
CSVWidget::SceneToolMode* SceneWidget::makeLightingSelector(CSVWidget::SceneToolbar* parent)
{
CSVWidget::SceneToolMode* tool = new CSVWidget::SceneToolMode(parent, "Lighting Mode");
2022-09-22 18:26:05 +00:00
/// \todo replace icons
tool->addButton(":scenetoolbar/day", "day",
2022-09-22 18:26:05 +00:00
"Day"
"<ul><li>Cell specific ambient in interiors</li>"
"<li>Low ambient in exteriors</li>"
"<li>Strong directional light source</li>"
"<li>This mode closely resembles day time in-game</li></ul>");
tool->addButton(":scenetoolbar/night", "night",
2022-09-22 18:26:05 +00:00
"Night"
"<ul><li>Cell specific ambient in interiors</li>"
"<li>Low ambient in exteriors</li>"
"<li>Weak directional light source</li>"
"<li>This mode closely resembles night time in-game</li></ul>");
tool->addButton(":scenetoolbar/bright", "bright",
2022-09-22 18:26:05 +00:00
"Bright"
"<ul><li>Maximum ambient</li>"
"<li>Strong directional light source</li></ul>");
2022-09-22 18:26:05 +00:00
connect(tool, &CSVWidget::SceneToolMode::modeChanged, this, &SceneWidget::selectLightingMode);
2022-09-22 18:26:05 +00:00
return tool;
2022-09-22 18:26:05 +00:00
}
void SceneWidget::setDefaultAmbient(const osg::Vec4f& colour)
{
mDefaultAmbient = colour;
mHasDefaultAmbient = true;
2016-03-10 09:29:24 +00:00
setAmbient(mLighting->getAmbientColour(&mDefaultAmbient));
}
2022-09-22 18:26:05 +00:00
void SceneWidget::setExterior(bool isExterior)
{
mIsExterior = isExterior;
}
2022-09-22 18:26:05 +00:00
void SceneWidget::mouseMoveEvent(QMouseEvent* event)
{
mCurrentCamControl->handleMouseMoveEvent(event->x() - mPrevMouseX, event->y() - mPrevMouseY);
2022-09-22 18:26:05 +00:00
2016-03-14 04:04:11 +00:00
mPrevMouseX = event->x();
mPrevMouseY = event->y();
}
2022-09-22 18:26:05 +00:00
void SceneWidget::wheelEvent(QWheelEvent* event)
{
mCurrentCamControl->handleMouseScrollEvent(event->angleDelta().y());
}
2022-09-22 18:26:05 +00:00
2017-12-08 17:18:27 +00:00
void SceneWidget::update(double dt)
2017-12-07 23:05:50 +00:00
{
if (mCamPositionSet)
2022-09-22 18:26:05 +00:00
{
2017-12-08 17:18:27 +00:00
mCurrentCamControl->update(dt);
2022-09-22 18:26:05 +00:00
}
else
{
2017-12-08 17:18:27 +00:00
mCurrentCamControl->setup(mRootNode, Mask_Reference | Mask_Terrain, CameraController::WorldUp);
mCamPositionSet = true;
2022-09-22 18:26:05 +00:00
}
2017-12-08 17:18:27 +00:00
}
2022-09-22 18:26:05 +00:00
2022-01-11 09:34:19 +00:00
void SceneWidget::settingChanged(const CSMPrefs::Setting* setting)
{
if (*setting == "3D Scene Input/p-navi-free-sensitivity")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setCameraSensitivity(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/p-navi-orbit-sensitivity")
2022-09-22 18:26:05 +00:00
{
mOrbitCamControl->setCameraSensitivity(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/p-navi-free-invert")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setInverted(setting->isTrue());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/p-navi-orbit-invert")
2022-09-22 18:26:05 +00:00
{
mOrbitCamControl->setInverted(setting->isTrue());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/s-navi-sensitivity")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setSecondaryMovementMultiplier(setting->toDouble());
mOrbitCamControl->setSecondaryMovementMultiplier(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-wheel-factor")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setWheelMovementMultiplier(setting->toDouble());
mOrbitCamControl->setWheelMovementMultiplier(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-free-lin-speed")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setLinearSpeed(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-free-rot-speed")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setRotationalSpeed(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-free-speed-mult")
2022-09-22 18:26:05 +00:00
{
mFreeCamControl->setSpeedMultiplier(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-orbit-rot-speed")
2022-09-22 18:26:05 +00:00
{
mOrbitCamControl->setOrbitSpeed(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-orbit-speed-mult")
2022-09-22 18:26:05 +00:00
{
mOrbitCamControl->setOrbitSpeedMultiplier(setting->toDouble());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "3D Scene Input/navi-orbit-const-roll")
2022-09-22 18:26:05 +00:00
{
mOrbitCamControl->setConstRoll(setting->isTrue());
2022-09-22 18:26:05 +00:00
}
else if (*setting == "Rendering/framerate-limit")
2022-09-22 18:26:05 +00:00
{
mRenderer->setRunMaxFrameRate(setting->toInt());
2022-09-22 18:26:05 +00:00
}
2017-12-08 17:18:27 +00:00
else if (*setting == "Rendering/camera-fov" || *setting == "Rendering/camera-ortho"
|| *setting == "Rendering/camera-ortho-size")
2022-09-22 18:26:05 +00:00
{
updateCameraParameters();
2022-09-22 18:26:05 +00:00
}
2022-01-11 09:34:19 +00:00
else if (*setting == "Rendering/scene-day-night-switch-nodes")
2022-09-22 18:26:05 +00:00
{
2022-01-11 09:34:19 +00:00
if (mLighting)
setLighting(mLighting);
2022-09-22 18:26:05 +00:00
}
2022-01-11 09:34:19 +00:00
}
2017-12-08 17:18:27 +00:00
void RenderWidget::updateCameraParameters(double overrideAspect)
{
const float nearDist = 1.0;
2017-12-08 21:06:03 +00:00
const float farDist = 1000.0;
2017-12-08 17:18:27 +00:00
if (CSMPrefs::get()["Rendering"]["camera-ortho"].isTrue())
{
const float size = CSMPrefs::get()["Rendering"]["camera-ortho-size"].toInt();
2017-12-07 23:05:50 +00:00
const float aspect = overrideAspect >= 0.0 ? overrideAspect : (width() / static_cast<double>(height()));
2017-12-08 21:06:03 +00:00
const float halfH = size * 10.0;
const float halfW = halfH * aspect;
2016-03-10 09:29:24 +00:00
mView->getCamera()->setProjectionMatrixAsOrtho(-halfW, halfW, -halfH, halfH, nearDist, farDist);
2022-09-22 18:26:05 +00:00
}
else
2016-03-14 04:04:11 +00:00
{
mView->getCamera()->setProjectionMatrixAsPerspective(CSMPrefs::get()["Rendering"]["camera-fov"].toInt(),
static_cast<double>(width()) / static_cast<double>(height()), nearDist, farDist);
2022-09-22 18:26:05 +00:00
}
2016-03-14 04:04:11 +00:00
}
2022-09-22 18:26:05 +00:00
void SceneWidget::selectNavigationMode(const std::string& mode)
2016-03-14 04:04:11 +00:00
{
if (mode == "1st")
2022-09-22 18:26:05 +00:00
{
2018-10-09 06:21:12 +00:00
mCurrentCamControl->setCamera(nullptr);
mCurrentCamControl = mFreeCamControl;
mFreeCamControl->setCamera(getCamera());
mFreeCamControl->fixUpAxis(CameraController::WorldUp);
2022-09-22 18:26:05 +00:00
}
else if (mode == "free")
2022-09-22 18:26:05 +00:00
{
2018-10-09 06:21:12 +00:00
mCurrentCamControl->setCamera(nullptr);
mCurrentCamControl = mFreeCamControl;
mFreeCamControl->setCamera(getCamera());
2016-03-14 04:04:11 +00:00
mFreeCamControl->unfixUpAxis();
2022-09-22 18:26:05 +00:00
}
else if (mode == "orbit")
2022-09-22 18:26:05 +00:00
{
2018-10-09 06:21:12 +00:00
mCurrentCamControl->setCamera(nullptr);
mCurrentCamControl = mOrbitCamControl;
mOrbitCamControl->setCamera(getCamera());
mOrbitCamControl->reset();
2022-09-22 18:26:05 +00:00
}
2016-03-14 04:04:11 +00:00
}
2013-11-02 01:48:30 +00:00
}