6 #include "IPinObserver.h"
7 #include "PinRepository.h"
8 #include "TerrainHeightProvider.h"
9 #include "IPinViewFactory.h"
10 #include "PinViewRenderer.h"
39 : m_pinRepository(pinRepository)
40 , m_terrainHeightProvider(terrainHeightProvider)
41 , m_viewFactory(viewFactory)
42 , m_viewRenderer(viewRenderer)
51 for(TViewsByModel::iterator it = m_viewsByModel.begin(); it != m_viewsByModel.end(); ++it)
57 m_viewsByModel.clear();
66 UpdateTerrainHeights();
68 m_viewRenderer.
Update(renderCamera);
76 Eegeo_ASSERT(!HasViewForModel(pin),
"Attempt to add duplicate model to PinController.");
80 m_pinsNeedingHeightLookup.push_back(&pin);
81 m_viewsByModel[&pin] = pView;
90 Eegeo_ASSERT(HasViewForModel(pin),
"Attempt to remove unknown model from PinController.");
91 PinView* pView = GetViewForModel(pin);
93 m_pinsNeedingHeightLookup.erase(std::remove(m_pinsNeedingHeightLookup.begin(), m_pinsNeedingHeightLookup.end(), &pin), m_pinsNeedingHeightLookup.end());
94 m_viewsByModel.erase(&pin);
106 const PinView* pView = GetViewForModel(pin);
107 Eegeo_ASSERT(pView != NULL,
"Can't find screen bounds for a pin model that doesn't have a corresponding view.");
119 outIntersectingPins.clear();
121 std::vector<PinView*> intersectingViews;
124 for(std::vector<PinView*>::const_iterator it = intersectingViews.begin(); it != intersectingViews.end(); ++it)
127 outIntersectingPins.push_back(&(pView->
GetPin()));
131 return (outIntersectingPins.size() > 0);
141 const PinView* pView = GetViewForModel(pin);
142 Eegeo_ASSERT(pView != NULL,
"Can't get scale for a pin model that doesn't have a corresponding view.");
152 PinView* pView = GetViewForModel(pin);
153 Eegeo_ASSERT(pView != NULL,
"Can't set scale for a pin model that doesn't have a corresponding view.");
158 virtual void UpdateViews()
160 for(TViewsByModel::iterator it = m_viewsByModel.begin(); it != m_viewsByModel.end(); ++it)
162 const Pin* pPin = it->first;
174 PinRepository& m_pinRepository;
175 Resources::Terrain::Heights::TerrainHeightProvider& m_terrainHeightProvider;
176 IPinViewFactory& m_viewFactory;
177 PinViewRenderer& m_viewRenderer;
179 typedef std::map<Pin*, PinView*> TViewsByModel;
181 std::vector<Pin*> m_pinsNeedingHeightLookup;
183 TViewsByModel m_viewsByModel;
185 PinView* GetViewForModel(
const Pin& pin)
const
187 TViewsByModel::const_iterator foundPin = m_viewsByModel.find(const_cast<Pin*>(&pin));
189 if(foundPin != m_viewsByModel.end())
191 return foundPin->second;
197 bool HasViewForModel(
const Pin& pin)
const
199 return (GetViewForModel(pin) != NULL);
202 void UpdateTerrainHeights()
204 const int maxPinsToUpdatePerFrame = 30;
205 const int numberOfPinsNeedingLookup =
static_cast<int>(m_pinsNeedingHeightLookup.size());
206 int pinsToUpdateThisFrame = std::min(numberOfPinsNeedingLookup, maxPinsToUpdatePerFrame);
208 while (pinsToUpdateThisFrame--)
210 Pin* pPin = m_pinsNeedingHeightLookup.back();
213 int queryTerminationLevel;
215 if(m_terrainHeightProvider.TryGetHeight(pPin->GetEcefGeoidLocation(),
217 pPin->TerrainHeightLevel(),
218 pPin->TerrainHeight(),
219 queryTerminationLevel,
222 pPin->SetTerrainHeight(terrainHeight, queryTerminationLevel);
225 m_pinsNeedingHeightLookup.pop_back();
229 if (m_pinsNeedingHeightLookup.empty() && numOfPinsInRepo > 0)
231 RepopulatePinLookupVector();
235 void RepopulatePinLookupVector()
237 for (
int pinIndex = 0; pinIndex < m_pinRepository.
GetNumOfPins(); ++pinIndex)
240 m_pinsNeedingHeightLookup.push_back(pPin);