6 #include "ICityThemeStateObservable.h"
12 #include "WeatherOverlayMaterial2.h"
13 #include "WeatherOverlayController.h"
14 #include "PackedRenderable.h"
15 #include "EnvironmentMaterialRepository.h"
16 #include "VectorMath.h"
17 #include "IInterestPointProvider.h"
18 #include "GlobalShadowing.h"
19 #include "HttpAsyncTextureLoader.h"
20 #include "ICityThemeStateObserver.h"
21 #include "SceneElementRepository.h"
22 #include "EnvironmentStateTextures.h"
23 #include "GlobalLighting.h"
24 #include "GlobalFogging.h"
25 #include "EarthConstants.h"
26 #include "CityThemeState.h"
27 #include "SpaceHelpers.h"
52 : m_materialRepository(materialRepository)
53 , m_fromTextures(NULL)
55 , m_transportRenderables(transportRenderables)
56 , m_terrainRenderables(terrainRenderables)
57 , m_buildingRenderables(buildingsRenderables)
58 , m_globalLighting(globalLighting)
59 , m_globalFogging(globalFogging)
60 , m_globalShadowing(globalShadowing)
61 , m_vertexBindingPool(vertexBindingPool)
62 , m_asyncTextureLoader(asyncTextureLoader)
63 , m_weatherOverlayController(weatherOverlayController)
64 , m_weatherOverlayMaterial(weatherOverlayMaterial)
70 m_fromTextures = NULL;
76 m_fromTextures = &stateTextures;
78 m_toTextures = &stateTextures;
83 NotifyObservers(state);
88 m_toState = targetState;
89 m_toTextures = &targetStateTextures;
97 typedef std::vector<Rendering::Scene::SceneElement<Rendering::Renderables::PackedRenderable>*> TSceneElementPtrVec;
98 TSceneElementPtrVec allSceneElements;
99 sceneElements.GetSceneElements(allSceneElements);
101 for (TSceneElementPtrVec::iterator iter = allSceneElements.begin(); iter != allSceneElements.end(); ++iter)
104 const std::string& materialName = renderable.GetMaterial()->GetName();
106 renderable.SetMaterial(material, m_vertexBindingPool);
110 void SetTransition(
float t,
const dv3& ecefInterestPoint)
112 m44 interpolatedLightColours;
113 m44::Lerp(interpolatedLightColours, m_fromState.Lighting, m_toState.Lighting, t);
114 m_globalLighting.SetLightColourMatrix(interpolatedLightColours);
115 m_materialRepository.SetTransitionParam(t);
116 m_globalLighting.SetNightLightmapColour(v3::Lerp(m_fromState.LightMapColor, m_toState.LightMapColor, t));
117 m_globalLighting.SetNightGlowLightmapIntensity(Math::Lerp(m_fromState.LightMapIntensity, m_toState.LightMapIntensity, t));
118 m_globalLighting.SetAlternativeAmbientColour(v3::Lerp(m_fromState.AlternativeAmbientLight, m_toState.AlternativeAmbientLight, t));
120 float fogDensity = Math::Lerp(m_fromState.FogIntensity, m_toState.FogIntensity, t);
121 m_globalFogging.SetFogDensity(fogDensity);
123 v3 fogColor = v3::Lerp(m_fromState.FogColor, m_toState.FogColor, t);
124 m_globalFogging.SetFogColour(
v4(fogColor.GetX(), fogColor.GetY(), fogColor.GetZ(), 1.f));
128 v3 shadowColor = v3::Lerp(m_fromState.ShadowColor, m_toState.ShadowColor, t);
129 m_globalShadowing.SetShadowColor(shadowColor);
132 float fromIntensity = m_fromState.OverlayIntensity;
133 float toIntensity = m_toState.OverlayIntensity;
135 m_weatherOverlayController.SetIntensity(Math::Lerp(fromIntensity, toIntensity,t));
143 m_observers.push_back(&themeStateObserver);
148 TObservers::iterator toRemove = std::find(m_observers.begin(), m_observers.end(), &themeStateObserver);
149 if(toRemove != m_observers.end())
151 m_observers.erase(toRemove);
158 m_materialRepository.SetCurrentRepository(m_fromState, m_fromTextures, m_toState, m_toTextures);
159 m_asyncTextureLoader.UpdatePlaceholderEnvironmentTexture(m_toTextures->GetAsyncPlaceholderEnvironmentTexture());
160 UpdateMaterialsOnRenderables(m_buildingRenderables);
161 UpdateMaterialsOnRenderables(m_transportRenderables);
162 UpdateMaterialsOnRenderables(m_terrainRenderables);
165 void SetWeatherOverlay()
167 m_weatherOverlayMaterial.SetTextureId(m_toTextures->GetOverlayEffect());
168 m_weatherOverlayController.SetWeatherLayersParameters(m_toTextures->GetOverlayEffect() != 0,
169 m_toState.OverlayLayerOneOffset,
170 m_toState.OverlayLayerOneVelocity,
171 m_toState.OverlayLayerOneAlpha,
172 m_toState.OverlayLayerOneScale,
173 m_toState.OverlayLayerTwoOffset,
174 m_toState.OverlayLayerTwoVelocity,
175 m_toState.OverlayLayerTwoAlpha,
176 m_toState.OverlayLayerTwoScale);
181 for(TObservers::const_iterator it = m_observers.begin(); it != m_observers.end(); ++it)
183 (*it)->OnThemeStateChanged(state);
210 typedef std::vector<ICityThemeStateObserver*> TObservers;
211 TObservers m_observers;