38 SkyManager::SkyManager() : m_caelum_system(nullptr), m_last_clock(0.0)
41 m_caelum_system =
new Caelum::CaelumSystem(
44 Caelum::CaelumSystem::CAELUM_COMPONENTS_DEFAULT
54 SkyManager::~SkyManager()
57 m_caelum_system->shutdown(
false);
58 m_caelum_system =
nullptr;
61 void SkyManager::NotifySkyCameraChanged(Ogre::Camera* cam)
64 m_caelum_system->notifyCameraChanged(cam);
67 void SkyManager::DetectSkyUpdate()
74 Caelum::LongReal c = m_caelum_system->getUniversalClock()->getJulianDay();
76 if (c - m_last_clock > 0.001f)
86 void SkyManager::LoadCaelumScript(std::string script,
int fogStart,
int fogEnd)
91 Caelum::CaelumPlugin::getSingleton().loadCaelumSystemFromScript(m_caelum_system, script);
94 #ifdef CAELUM_VERSION_SEC
96 if (fogStart != -1 && fogEnd != -1 && fogStart < fogEnd)
101 m_caelum_system->setManageSceneFog(Ogre::FOG_LINEAR);
102 m_caelum_system->setManageSceneFogStart(fogStart);
103 m_caelum_system->setManageSceneFogEnd(fogEnd);
107 if (fogStart != -1 && fogEnd != -1)
109 LOG(
"CaelumFogStart must be smaller then CaelumFogEnd. Ignoring boundaries.");
111 else if (fogStart != -1 || fogEnd != -1)
113 LOG(
"You always need to define both boundaries (CaelumFogStart AND CaelumFogEnd). Ignoring boundaries.");
117 m_caelum_system->setManageSceneFog(Ogre::FOG_LINEAR);
118 m_caelum_system->setManageSceneFogStart(farclip * 0.7);
119 m_caelum_system->setManageSceneFogEnd(farclip * 0.9);
124 m_caelum_system->setManageSceneFog(Ogre::FOG_NONE);
127 #error please use a recent Caelum version, see http://www.rigsofrods.org/wiki/pages/Compiling_3rd_party_libraries#Caelum
128 #endif // CAELUM_VERSION
130 if (m_caelum_system->getMoon())
132 m_caelum_system->getMoon()->setAutoDisable(
true);
134 m_caelum_system->getMoon()->setForceDisable(
true);
135 m_caelum_system->getMoon()->getMainLight()->setCastShadows(
false);
138 m_caelum_system->setEnsureSingleShadowSource(
true);
139 m_caelum_system->setEnsureSingleLightSource(
true);
142 m_caelum_system->updateSubcomponents(0.1);
144 catch (Ogre::Exception& e)
146 RoR::LogFormat(
"[RoR] Exception while loading sky script: %s", e.getFullDescription().c_str());
148 Ogre::Vector3 lightsrc = m_caelum_system->getSun()->getMainLight()->getDirection();
149 m_caelum_system->getSun()->getMainLight()->setDirection(lightsrc.normalisedCopy());
152 void SkyManager::SetSkyTimeFactor(
float factor)
154 m_caelum_system->getUniversalClock()->setTimeScale(factor);
157 Ogre::Light* SkyManager::GetSkyMainLight()
159 if (m_caelum_system && m_caelum_system->getSun())
161 return m_caelum_system->getSun()->getMainLight();
166 float SkyManager::GetSkyTimeFactor()
168 return m_caelum_system->getUniversalClock()->getTimeScale();
171 std::string SkyManager::GetPrettyTime()
176 Caelum::LongReal second;
177 Caelum::Astronomy::getGregorianDateTimeFromJulianDay(m_caelum_system->getJulianDay()
178 , ignore, ignore, ignore, hour, minute, second);
181 snprintf(buf, 100,
"%02d:%02d:%02d", hour, minute,
static_cast<int>(second));