From 882245b9354189df0005837330f3e78427831468 Mon Sep 17 00:00:00 2001 From: Cody Glassman Date: Mon, 9 May 2022 19:40:48 +0000 Subject: [PATCH] Lua Bindings: Add view distance bindings to camera --- apps/openmw/mwlua/camerabindings.cpp | 7 +++++++ apps/openmw/mwrender/renderingmanager.cpp | 21 +++++++++++++-------- apps/openmw/mwrender/renderingmanager.hpp | 5 ++++- files/lua_api/openmw/camera.lua | 13 +++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwlua/camerabindings.cpp b/apps/openmw/mwlua/camerabindings.cpp index 4e865374cf..345564ef0c 100644 --- a/apps/openmw/mwlua/camerabindings.cpp +++ b/apps/openmw/mwlua/camerabindings.cpp @@ -92,6 +92,13 @@ namespace MWLua api["getFieldOfView"] = [renderingManager]() { return osg::DegreesToRadians(renderingManager->getFieldOfView()); }; api["setFieldOfView"] = [renderingManager](float v) { renderingManager->setFieldOfView(osg::RadiansToDegrees(v)); }; + api["getBaseViewDistance"] = []() + { + return std::max(0.f, Settings::Manager::getFloat("viewing distance", "Camera")); + }; + api["getViewDistance"] = [renderingManager]() { return renderingManager->getViewDistance(); }; + api["setViewDistance"] = [renderingManager](float d) { renderingManager->setViewDistance(d, true); }; + api["getViewTransform"] = [camera]() { return LuaUtil::TransformM{camera->getViewMatrix()}; }; api["viewportToWorldVector"] = [camera, renderingManager](osg::Vec2f pos) -> osg::Vec3f diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 52b647add3..24e37a93ea 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -363,7 +363,7 @@ namespace MWRender || reverseZ || Stereo::getMultiview(); resourceSystem->getSceneManager()->setForceShaders(forceShaders); - + // FIXME: calling dummy method because terrain needs to know whether lighting is clamped resourceSystem->getSceneManager()->setClampLighting(Settings::Manager::getBool("clamp lighting", "Shaders")); resourceSystem->getSceneManager()->setAutoUseNormalMaps(Settings::Manager::getBool("auto use object normal maps", "Shaders")); @@ -511,7 +511,7 @@ namespace MWRender // water goes after terrain for correct waterculling order mWater.reset(new Water(sceneRoot->getParent(0), sceneRoot, mResourceSystem, mViewer->getIncrementalCompileOperation(), resourcePath)); - + mCamera.reset(new Camera(mViewer->getCamera())); mScreenshotManager.reset(new ScreenshotManager(viewer, mRootNode, sceneRoot, mResourceSystem, mWater.get())); @@ -1293,10 +1293,7 @@ namespace MWRender } else if (it->first == "Camera" && it->second == "viewing distance") { - mViewDistance = Settings::Manager::getFloat("viewing distance", "Camera"); - if(!Settings::Manager::getBool("use distant fog", "Fog")) - mStateUpdater->setFogEnd(mViewDistance); - updateProjection = true; + setViewDistance(Settings::Manager::getFloat("viewing distance", "Camera")); } else if (it->first == "General" && (it->second == "texture filter" || it->second == "texture mipmap" || @@ -1346,9 +1343,17 @@ namespace MWRender } } - float RenderingManager::getNearClipDistance() const + void RenderingManager::setViewDistance(float distance, bool delay) { - return mNearClip; + mViewDistance = distance; + + if (delay) + { + mUpdateProjectionMatrix = true; + return; + } + + updateProjectionMatrix(); } float RenderingManager::getTerrainHeightAt(const osg::Vec3f &pos) diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index fe3b33b20e..5b5c28b198 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -206,7 +206,10 @@ namespace MWRender void processChangedSettings(const Settings::CategorySettingVector& settings); - float getNearClipDistance() const; + float getNearClipDistance() const { return mNearClip; } + float getViewDistance() const { return mViewDistance; } + + void setViewDistance(float distance, bool delay = false); float getTerrainHeightAt(const osg::Vec3f& pos); diff --git a/files/lua_api/openmw/camera.lua b/files/lua_api/openmw/camera.lua index f744dcbc5c..f699663c49 100644 --- a/files/lua_api/openmw/camera.lua +++ b/files/lua_api/openmw/camera.lua @@ -186,6 +186,19 @@ -- @function [parent=#camera] setFieldOfView -- @param #number fov Field of view vertical angle in radians +--- Return base view distance. +-- @function [parent=#camera] getBaseViewDistance +-- @return #number + +--- Return current view distance. +-- @function [parent=#camera] getViewDistance +-- @return #number + +--- Set view distance. +--- Takes effect on the next frame. +-- @function [parent=#camera] setViewDistance +-- @param #number distance View distance in game units + --- Get world to local transform for the camera. -- @function [parent=#camera] getViewTransform -- @return openmw.util#Transform