From 438b30d6f0a1d6726a80df7ef24e49fd5623c85a Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 6 Jan 2016 13:19:15 +0100 Subject: [PATCH] Move configureLight to a separate file --- apps/openmw/mwrender/animation.cpp | 3 ++- components/CMakeLists.txt | 3 ++- components/sceneutil/lightmanager.cpp | 24 -------------------- components/sceneutil/lightmanager.hpp | 4 ---- components/sceneutil/lightutil.cpp | 32 +++++++++++++++++++++++++++ components/sceneutil/lightutil.hpp | 19 ++++++++++++++++ 6 files changed, 55 insertions(+), 30 deletions(-) create mode 100644 components/sceneutil/lightutil.cpp create mode 100644 components/sceneutil/lightutil.hpp diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index c2fc82881..6300d28cf 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -30,8 +30,9 @@ #include #include #include -#include +#include #include +#include #include #include diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index af26fc998..089779eda 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -45,7 +45,8 @@ add_component_dir (resource ) add_component_dir (sceneutil - clone attach lightmanager visitor util statesetupdater controller skeleton riggeometry lightcontroller positionattitudetransform + clone attach visitor util statesetupdater controller skeleton riggeometry lightcontroller + lightmanager lightutil positionattitudetransform # not used yet #workqueue ) diff --git a/components/sceneutil/lightmanager.cpp b/components/sceneutil/lightmanager.cpp index 1706bb2b1..f9182c1d2 100644 --- a/components/sceneutil/lightmanager.cpp +++ b/components/sceneutil/lightmanager.cpp @@ -371,28 +371,4 @@ namespace SceneUtil traverse(node, nv); } - void configureLight(osg::Light *light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, - float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue) - { - bool quadratic = useQuadratic && (!outQuadInLin || isExterior); - - float quadraticAttenuation = 0; - float linearAttenuation = 0; - if (quadratic) - { - float r = radius * quadraticRadiusMult; - quadraticAttenuation = quadraticValue / std::pow(r, 2); - } - if (useLinear) - { - float r = radius * linearRadiusMult; - linearAttenuation = linearValue / r; - } - - light->setLinearAttenuation(linearAttenuation); - light->setQuadraticAttenuation(quadraticAttenuation); - light->setConstantAttenuation(0.f); - - } - } diff --git a/components/sceneutil/lightmanager.hpp b/components/sceneutil/lightmanager.hpp index 3e6d3251b..07b3b4a62 100644 --- a/components/sceneutil/lightmanager.hpp +++ b/components/sceneutil/lightmanager.hpp @@ -168,10 +168,6 @@ namespace SceneUtil LightManager::LightList mLightList; }; - /// @brief Configures a light's attenuation according to vanilla Morrowind attenuation settings. - void configureLight(osg::Light* light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, float quadraticValue, - float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue); - } #endif diff --git a/components/sceneutil/lightutil.cpp b/components/sceneutil/lightutil.cpp new file mode 100644 index 000000000..711a94ba8 --- /dev/null +++ b/components/sceneutil/lightutil.cpp @@ -0,0 +1,32 @@ +#include "lightutil.hpp" + +#include + +namespace SceneUtil +{ + + void configureLight(osg::Light *light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, + float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, float linearValue) + { + bool quadratic = useQuadratic && (!outQuadInLin || isExterior); + + float quadraticAttenuation = 0; + float linearAttenuation = 0; + if (quadratic) + { + float r = radius * quadraticRadiusMult; + quadraticAttenuation = quadraticValue / std::pow(r, 2); + } + if (useLinear) + { + float r = radius * linearRadiusMult; + linearAttenuation = linearValue / r; + } + + light->setLinearAttenuation(linearAttenuation); + light->setQuadraticAttenuation(quadraticAttenuation); + light->setConstantAttenuation(0.f); + + } + +} diff --git a/components/sceneutil/lightutil.hpp b/components/sceneutil/lightutil.hpp new file mode 100644 index 000000000..09d23d4a2 --- /dev/null +++ b/components/sceneutil/lightutil.hpp @@ -0,0 +1,19 @@ +#ifndef OPENMW_COMPONENTS_LIGHTUTIL_H +#define OPENMW_COMPONENTS_LIGHTUTIL_H + +namespace osg +{ + class Light; +} + +namespace SceneUtil +{ + + /// @brief Configures a light's attenuation according to vanilla Morrowind attenuation settings. + void configureLight(osg::Light* light, float radius, bool isExterior, bool outQuadInLin, bool useQuadratic, + float quadraticValue, float quadraticRadiusMult, bool useLinear, float linearRadiusMult, + float linearValue); + +} + +#endif