<commit_before>// Copyright eeGeo Ltd (2012-2014), All Rights Reserved

#include "PoiRingTouchController.h"
#include "CameraHelpers.h"
#include "RenderCamera.h"
#include "IMyPinCreationModel.h"
#include "GlobeCameraController.h"

namespace ExampleApp
{
    namespace MyPinCreation
    {
        namespace PoiRing
        {
            PoiRingTouchController::PoiRingTouchController(IMyPinCreationModel& myPinCreationModel,
                                                           Eegeo::Resources::Terrain::Collision::IRayPicker& rayPicker)
            : m_myPinCreationModel(myPinCreationModel)
            , m_rayPicker(rayPicker)
            , m_isDragging(false)
            {
                
            }
            
            bool PoiRingTouchController::HandleTouchDown(const AppInterface::TouchData& data, const Eegeo::Camera::RenderCamera& renderCamera, Eegeo::Camera::GlobeCamera::GlobeCameraController& globeCameraController)
            {
                if (m_myPinCreationModel.GetCreationStage() != Ring)
                {
                    return false;
                }
                
                float screenPixelX = data.point.GetX();
                float screenPixelY = data.point.GetY();
                
                Eegeo::dv3 rayDirection;
                Eegeo::Camera::CameraHelpers::GetScreenPickRay(renderCamera, screenPixelX, screenPixelY, rayDirection);
                
                Eegeo::dv3 rayOrigin = globeCameraController.ComputeNonFlattenedCameraPosition();
                Eegeo::dv3 rayIntersectionPoint;
                double intersectionParam;
                bool rayPick = m_rayPicker.TryGetRayIntersection(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam);
                
                if (rayPick)
                {
                    const Eegeo::dv3& currentPosition = m_myPinCreationModel.GetPosition();
                    const float touchRadius = 170.f;
                    
                    if ((rayIntersectionPoint - currentPosition).Length() < touchRadius)
                    {
                        m_isDragging = true;
                        return true;
                    }
                }
                
                return false;
            }
            
            bool PoiRingTouchController::HandleTouchUp(const AppInterface::TouchData& data)
            {
                if (m_myPinCreationModel.GetCreationStage() != Ring)
                {
                    return false;
                }
                
                m_isDragging = false;
                return true;
            }
            
            bool PoiRingTouchController::HandleTouchMove(const AppInterface::TouchData &data, const Eegeo::Camera::RenderCamera &renderCamera, Eegeo::Camera::GlobeCamera::GlobeCameraController& globeCameraController)
            {
                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 = globeCameraController.ComputeNonFlattenedCameraPosition();
                    Eegeo::dv3 rayIntersectionPoint;
                    double intersectionParam;
                    bool rayPick = m_rayPicker.TryGetRayIntersection(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam);
                    
                    if (rayPick)
                    {
                        m_myPinCreationModel.SetPosition(rayIntersectionPoint);
                    }
                    
                    return true;
                }
                
                return false;
            }
            
            bool PoiRingTouchController::IsDragging() const
            {
                return m_isDragging;
            }
        }
    }<commit_msg>Fix for MPLY-5157. Camera control should be restored when leaving the Ring mode. Buddy: Ian<commit_after>// Copyright eeGeo Ltd (2012-2014), All Rights Reserved

#include "PoiRingTouchController.h"
#include "CameraHelpers.h"
#include "RenderCamera.h"
#include "IMyPinCreationModel.h"
#include "GlobeCameraController.h"

namespace ExampleApp
{
    namespace MyPinCreation
    {
        namespace PoiRing
        {
            PoiRingTouchController::PoiRingTouchController(IMyPinCreationModel& myPinCreationModel,
                                                           Eegeo::Resources::Terrain::Collision::IRayPicker& rayPicker)
            : m_myPinCreationModel(myPinCreationModel)
            , m_rayPicker(rayPicker)
            , m_isDragging(false)
            {
                
            }
            
            bool PoiRingTouchController::HandleTouchDown(const AppInterface::TouchData& data, const Eegeo::Camera::RenderCamera& renderCamera, Eegeo::Camera::GlobeCamera::GlobeCameraController& globeCameraController)
            {
                if (m_myPinCreationModel.GetCreationStage() != Ring)
                {
                    return false;
                }
                
                float screenPixelX = data.point.GetX();
                float screenPixelY = data.point.GetY();
                
                Eegeo::dv3 rayDirection;
                Eegeo::Camera::CameraHelpers::GetScreenPickRay(renderCamera, screenPixelX, screenPixelY, rayDirection);
                
                Eegeo::dv3 rayOrigin = globeCameraController.ComputeNonFlattenedCameraPosition();
                Eegeo::dv3 rayIntersectionPoint;
                double intersectionParam;
                bool rayPick = m_rayPicker.TryGetRayIntersection(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam);
                
                if (rayPick)
                {
                    const Eegeo::dv3& currentPosition = m_myPinCreationModel.GetPosition();
                    const float touchRadius = 170.f;
                    
                    if ((rayIntersectionPoint - currentPosition).Length() < touchRadius)
                    {
                        m_isDragging = true;
                        return true;
                    }
                }
                
                return false;
            }
            
            bool PoiRingTouchController::HandleTouchUp(const AppInterface::TouchData& data)
            {
                m_isDragging = false;
                
                if (m_myPinCreationModel.GetCreationStage() != Ring)
                {
                    return false;
                }
                
                return true;
            }
            
            bool PoiRingTouchController::HandleTouchMove(const AppInterface::TouchData &data, const Eegeo::Camera::RenderCamera &renderCamera, Eegeo::Camera::GlobeCamera::GlobeCameraController& globeCameraController)
            {
                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 = globeCameraController.ComputeNonFlattenedCameraPosition();
                    Eegeo::dv3 rayIntersectionPoint;
                    double intersectionParam;
                    bool rayPick = m_rayPicker.TryGetRayIntersection(rayOrigin, rayDirection, rayIntersectionPoint, intersectionParam);
                    
                    if (rayPick)
                    {
                        m_myPinCreationModel.SetPosition(rayIntersectionPoint);
                    }
                    
                    return true;
                }
                
                return false;
            }
            
            bool PoiRingTouchController::IsDragging() const
            {
                return m_isDragging && m_myPinCreationModel.GetCreationStage() == Ring;
            }
        }
    }
{'fraction_non_alphanumeric': 0.06909811232812864, 'fraction_numerical': 0.004660918200885575, 'mean_word_length': 1.390807799442897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1456655', 'n_tokens_mistral': 2085, 'n_tokens_neox': 1932, 'n_words': 328}