void WorldPinsScaleController::UpdateWorldPin(WorldPinItemModel& worldPinItemModel, float deltaSeconds, const Eegeo::Camera::RenderCamera& renderCamera) { const bool showingInterior = m_interiorsController.ShowingInterior(); bool shouldHideInteirorPin = worldPinItemModel.IsInterior(); if( showingInterior == false) { shouldHideInteirorPin = shouldHideInteirorPin && !worldPinItemModel.GetInteriorData().showInExterior; } else { shouldHideInteirorPin = shouldHideInteirorPin && (worldPinItemModel.GetInteriorData().floor != m_interiorsController.GetCurrentFloorIndex()); } Eegeo::v2 screenLocation; GetScreenLocation(worldPinItemModel, screenLocation, renderCamera); const float ratioX = screenLocation.GetX() / renderCamera.GetViewportWidth(); const float ratioY = screenLocation.GetY() / renderCamera.GetViewportHeight(); const bool shouldHide = (ratioX < 0.1f) || (ratioX > 0.9f) || (ratioY < 0.15f) || (ratioY > 0.9f) || shouldHideInteirorPin; if(shouldHide) { worldPinItemModel.Hide(); } else { worldPinItemModel.Show(); } worldPinItemModel.Update(deltaSeconds); }
void WorldPinsScaleController::GetScreenLocation(const WorldPinItemModel& worldPinItemModel, Eegeo::v2& screenLocation, const Eegeo::Camera::RenderCamera& renderCamera) const { Eegeo::dv3 ecefLocation; m_worldPinsService.GetPinEcefAndScreenLocations(worldPinItemModel, ecefLocation, screenLocation); Eegeo::v3 cameraLocal = (ecefLocation - renderCamera.GetEcefLocation()).ToSingle(); Eegeo::v3 screenPos; renderCamera.Project(cameraLocal, screenPos); screenLocation.Set(screenPos.GetX(), screenPos.GetY()); }
float CompassModel::GetHeadingRadians() const { const Eegeo::Camera::RenderCamera renderCamera = m_cameraController.GetRenderCamera(); const Eegeo::m44& cameraModelMatrix = renderCamera.GetModelMatrix(); const Eegeo::v3& viewDirection = cameraModelMatrix.GetRow(2); Eegeo::v3 ecefUp = renderCamera.GetEcefLocation().ToSingle().Norm(); const float epsilon = 0.001f; Eegeo::v3 heading; if (Eegeo::Math::Abs(Eegeo::v3::Dot(viewDirection, ecefUp)) > (1.f - epsilon)) { const Eegeo::v3& viewUp = cameraModelMatrix.GetRow(1); heading = viewUp; } else { heading = viewDirection; } return Eegeo::Camera::CameraHelpers::GetAbsoluteBearingRadians(renderCamera.GetEcefLocation(), heading); }
void PoiRingView::AddIconSprite(const Eegeo::Camera::RenderCamera &renderCamera, const Eegeo::dv3& position, float scale) { m_iconRenderable.Reset(); m_iconRenderable.SetModelViewProjection(renderCamera.GetViewProjectionMatrix()); const float dimensionInMeters = scale; m_iconRenderable.AddSprite(renderCamera, position, Eegeo::v2(0, 0), Eegeo::v2(1, 1), Eegeo::Rendering::Colors::WHITE, Eegeo::v2(dimensionInMeters, dimensionInMeters)); }
bool PoiRingTouchController::HandleTouchMove(const AppInterface::TouchData &data, const Eegeo::Camera::RenderCamera &renderCamera, const Eegeo::dv3& nonFlattenedCameraPosition) { if (m_myPinCreationModel.GetCreationStage() != Ring) { return false; } if (m_isDragging) { float screenPixelX = data.point.GetX(); float screenPixelY = data.point.GetY(); Eegeo::dv3 rayDirection; Eegeo::Camera::CameraHelpers::GetScreenPickRay(renderCamera, screenPixelX, screenPixelY, rayDirection); Eegeo::dv3 rayOrigin = nonFlattenedCameraPosition; Eegeo::dv3 rayIntersectionPoint; double intersectionParam; float terrainHeight; float heightAboveTerrain; bool rayPick = PerformRayPick(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam, terrainHeight, heightAboveTerrain); if (rayPick) { const float currentCameraAltitiude = renderCamera.GetAltitude(); float offsetScale = 0.0f; if(currentCameraAltitiude != 0.0f && m_initialCameraAltitiude != 0.0f) { offsetScale = currentCameraAltitiude /m_initialCameraAltitiude; } Eegeo::Space::LatLong latLong = Eegeo::Space::LatLong::FromECEF(rayIntersectionPoint - (m_dragOffset * offsetScale)); m_myPinCreationModel.SetLatLong(latLong); m_myPinCreationModel.SetTerrainHeight(terrainHeight); m_myPinCreationModel.SetHeightAboveTerrain(heightAboveTerrain); } return true; } return false; }
bool PoiRingTouchController::TouchDownRaycast(const AppInterface::TouchData &data, const Eegeo::Camera::RenderCamera &renderCamera, const Eegeo::dv3 &rayOrigin) { float screenPixelX = data.point.GetX(); float screenPixelY = data.point.GetY(); Eegeo::dv3 rayDirection; Eegeo::Camera::CameraHelpers::GetScreenPickRay(renderCamera, screenPixelX, screenPixelY, rayDirection); Eegeo::dv3 rayIntersectionPoint; double intersectionParam; float terrainHeight; float heightAboveTerrain; bool rayPick = PerformRayPick(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam, terrainHeight, heightAboveTerrain); if (rayPick) { Eegeo::dv3 iconPosition; float iconSize; m_poiRingController.GetIconPositionAndSize(iconPosition, iconSize); Eegeo::dv3 spherePosition; float sphereRadius; m_poiRingController.GetSpherePositionAndRadius(spherePosition, sphereRadius); m_initialCameraAltitiude = renderCamera.GetAltitude(); bool hitIcon = Eegeo::Geometry::IntersectionTests::TestRaySphere(rayOrigin, rayDirection, iconPosition, iconSize/2.0f); if ((rayIntersectionPoint - spherePosition).Length() < sphereRadius || hitIcon) { m_dragOffset = rayIntersectionPoint - spherePosition; m_isDragging = true; return true; } } return false; }
ExampleApp::ExampleApp(Eegeo::EegeoWorld* pWorld, Eegeo::Camera::GlobeCamera::GlobeCameraInterestPointProvider& globeCameraInterestPointProvider, Examples::ExampleController& exampleController) : m_pGlobeCameraController(NULL) , m_pCameraTouchController(NULL) , m_globeCameraInterestPointProvider(globeCameraInterestPointProvider) , m_pWorld(pWorld) , m_exampleController(exampleController) { Eegeo_ASSERT(&m_globeCameraInterestPointProvider != NULL); Eegeo::EegeoWorld& eegeoWorld = *pWorld; Eegeo::Camera::GlobeCamera::GlobeCameraTouchControllerConfiguration touchControllerConfig = Eegeo::Camera::GlobeCamera::GlobeCameraTouchControllerConfiguration::CreateDefault(); // override default configuration to enable two-finger pan gesture to control additional camera pitch touchControllerConfig.tiltEnabled = true; m_pCameraTouchController = new Eegeo::Camera::GlobeCamera::GlobeCameraTouchController(touchControllerConfig); const bool useLowSpecSettings = false; Eegeo::Camera::GlobeCamera::GlobeCameraControllerConfiguration globeCameraControllerConfig = Eegeo::Camera::GlobeCamera::GlobeCameraControllerConfiguration::CreateDefault(useLowSpecSettings); m_pGlobeCameraController = new Eegeo::Camera::GlobeCamera::GlobeCameraController(eegeoWorld.GetTerrainHeightProvider(), eegeoWorld.GetEnvironmentFlatteningService(), eegeoWorld.GetResourceCeilingProvider(), *m_pCameraTouchController, globeCameraControllerConfig); Eegeo::Camera::RenderCamera* renderCamera = m_pGlobeCameraController->GetCamera(); const Eegeo::Rendering::RenderContext& renderContext = eegeoWorld.GetRenderContext(); renderCamera->SetViewport(0.f, 0.f, renderContext.GetScreenWidth(), renderContext.GetScreenHeight()); eegeoWorld.SetCamera(renderCamera); m_globeCameraInterestPointProvider.SetGlobeCamera(m_pGlobeCameraController); float interestPointLatitudeDegrees = 37.7858f; float interestPointLongitudeDegrees = -122.401f; float interestPointAltitudeMeters = 2.7; Eegeo::Space::LatLongAltitude location = Eegeo::Space::LatLongAltitude::FromDegrees(interestPointLatitudeDegrees, interestPointLongitudeDegrees, interestPointAltitudeMeters); float cameraControllerOrientationDegrees = 0.0f; float cameraControllerDistanceFromInterestPointMeters = 1781.0f; Eegeo::Space::EcefTangentBasis cameraInterestBasis; Eegeo::Camera::CameraHelpers::EcefTangentBasisFromPointAndHeading(location.ToECEF(), cameraControllerOrientationDegrees, cameraInterestBasis); m_pGlobeCameraController->SetView(cameraInterestBasis, cameraControllerDistanceFromInterestPointMeters); //register all generic examples m_exampleController.RegisterCameraExample<Examples::CameraSplineExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::CameraTransitionExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ControlCityThemeExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::DebugPrimitiveRenderingExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::DebugSphereExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::DynamicText3DExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::EnvironmentFlatteningExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::EnvironmentNotifierExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::FileIOExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::LoadModelExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ModifiedRenderingExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::NavigationGraphExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::Pick3DObjectExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::PinsExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::PinOverModelExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::PODAnimationExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::RenderToTextureExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ResourceSpatialQueryExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::RouteDrawingExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::RouteSimulationAnimationExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::RouteThicknessPolicyExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ScreenPickExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ScreenUnprojectExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::SingleCityExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::ToggleTrafficExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::TrafficCongestionExampleFactory>(*m_pGlobeCameraController); m_exampleController.RegisterCameraExample<Examples::WebRequestExampleFactory>(*m_pGlobeCameraController); }
void WorldPinsInFocusController::Update(float deltaSeconds, const Eegeo::dv3& ecefInterestPoint, const Eegeo::Camera::RenderCamera& renderCamera) { const IWorldPinsInFocusModel* pClosest = NULL; double minDistanceSq = std::numeric_limits<double>::max(); Eegeo::v2 closestScreenPinLocation; Eegeo::v2 screenInterestPoint = ProjectEcefToScreen(ecefInterestPoint, renderCamera); if(m_focusEnabled) { for(size_t i = 0; i < m_worldPinsRepository.GetItemCount(); ++i) { ExampleApp::WorldPins::SdkModel::WorldPinItemModel* worldPinItemModel = m_worldPinsRepository.GetItemAtIndex(i); if (!worldPinItemModel->IsFocusable()) { continue; } Eegeo::dv3 ecefPinLocation; Eegeo::v2 screenPinLocation; m_worldPinsService.GetPinEcefAndScreenLocations(*worldPinItemModel, ecefPinLocation, screenPinLocation); Eegeo::v3 cameraLocal = (ecefPinLocation - renderCamera.GetEcefLocation()).ToSingle(); Eegeo::v3 cameraSurfaceNormal = cameraLocal.Norm(); Eegeo::v3 upNormal = ecefPinLocation.Norm().ToSingle(); float dp = Eegeo::v3::Dot(cameraSurfaceNormal, upNormal); if(dp > 0.0f) { continue; } screenPinLocation = ProjectEcefToScreen(ecefPinLocation, renderCamera); double distanceToFocusSq = (screenInterestPoint - screenPinLocation).LengthSq(); if(distanceToFocusSq < minDistanceSq && worldPinItemModel->IsVisible()) { pClosest = &worldPinItemModel->GetInFocusModel(); minDistanceSq = distanceToFocusSq; closestScreenPinLocation = screenPinLocation; } } } if(m_pLastFocussedModel != pClosest) { m_pLastFocussedModel = pClosest; if(m_pLastFocussedModel != NULL) { m_messageBus.Publish(WorldPinGainedFocusMessage(WorldPinsInFocusModel(m_pLastFocussedModel->GetPinId(), m_pLastFocussedModel->GetTitle(), m_pLastFocussedModel->GetSubtitle(), m_pLastFocussedModel->GetVendor(), m_pLastFocussedModel->GetJsonData(), m_pLastFocussedModel->GetRatingsImage(), m_pLastFocussedModel->GetReviewCount()), closestScreenPinLocation)); } else { m_messageBus.Publish(WorldPinLostFocusMessage()); } } else { if(m_pLastFocussedModel != NULL) { m_messageBus.Publish(WorldPinInFocusChangedLocationMessage(closestScreenPinLocation)); } } }