add getCurrentSunLightDirection

This commit is contained in:
Sebastian Fieber 2025-07-23 23:48:54 +02:00
parent 6be96da6a4
commit d20a56517b
6 changed files with 21 additions and 7 deletions

View File

@ -487,6 +487,7 @@ namespace MWBase
// Allow NPCs to use torches?
virtual bool useTorches() const = 0;
virtual const osg::Vec4f& getSunLightPosition() const = 0;
virtual float getSunVisibility() const = 0;
virtual float getSunPercentage() const = 0;

View File

@ -117,12 +117,8 @@ namespace MWLua
weatherT["recordId"] = sol::readonly_property([](const MWWorld::Weather& w) { return w.mId.serializeText(); });
api["getCurrent"] = []() { return MWBase::Environment::get().getWorld()->getCurrentWeather(); };
api["getNext"] = []() -> sol::optional<const MWWorld::Weather&> {
auto next = MWBase::Environment::get().getWorld()->getNextWeather();
if (next != nullptr)
return *next;
return sol::nullopt;
};
api["getNext"]
= []() -> const MWWorld::Weather* { return MWBase::Environment::get().getWorld()->getNextWeather(); };
api["getTransition"] = []() { return MWBase::Environment::get().getWorld()->getWeatherTransition(); };
api["changeWeather"] = [](std::string_view regionId, const MWWorld::Weather& weather) {
@ -151,6 +147,12 @@ namespace MWLua
// Provide access to the store.
api["records"] = WeatherStore{};
api["getCurrentSunLightDirection"] = []() {
osg::Vec4f sunPos = MWBase::Environment::get().getWorld()->getSunLightPosition();
sunPos.normalize();
return sunPos;
};
api["getCurrentSunVisibility"] = []() { return MWBase::Environment::get().getWorld()->getSunVisibility(); };
api["getCurrentSunPercentage"] = []() { return MWBase::Environment::get().getWorld()->getSunPercentage(); };
api["getCurrentWindSpeed"] = []() { return MWBase::Environment::get().getWorld()->getWindSpeed(); };

View File

@ -139,6 +139,7 @@ namespace MWRender
int skyGetSecundaPhase() const;
void skySetMoonColour(bool red);
const osg::Vec4f& getSunLightPosition() const { return mSunLight->getPosition(); }
void setSunDirection(const osg::Vec3f& direction);
void setSunColour(const osg::Vec4f& diffuse, const osg::Vec4f& specular, float sunVis);
void setNight(bool isNight) { mNight = isNight; }

View File

@ -1,7 +1,6 @@
#include "worldimp.hpp"
#include <charconv>
#include <functional>
#include <vector>
#include <osg/ComputeBoundsVisitor>
@ -3154,6 +3153,11 @@ namespace MWWorld
}
}
const osg::Vec4f& World::getSunLightPosition() const
{
return mRendering->getSunLightPosition();
}
float World::getSunVisibility() const
{
return mWeatherManager->getSunVisibility();

View File

@ -579,6 +579,7 @@ namespace MWWorld
// Allow NPCs to use torches?
bool useTorches() const override;
const osg::Vec4f& getSunLightPosition() const override;
float getSunVisibility() const override;
float getSunPercentage() const override;

View File

@ -1235,6 +1235,11 @@
-- @param #string regionId
-- @param #WeatherData The weather to change to
---
-- Get the current direction of the light of the sun.
-- @function [parent=#Weather] getCurrentSunLightDirection
-- @return openmw.util#Vector4
---
-- Get the current sun visibility taking weather transition into account.
-- @function [parent=#Weather] getCurrentSunVisibility