Exemplo n.º 1
0
 public void HandleInput(TouchInputEvent inputEvent)
 {
     if (inputEvent.isPointerDownEvent)
     {
         m_pan.PointerDown(inputEvent);
         m_pinch.PointerDown(inputEvent);
         m_rotate.PointerDown(inputEvent);
         m_touch.PointerDown(inputEvent);
         m_tap.PointerDown(inputEvent);
     }
     else if (inputEvent.isPointerUpEvent)
     {
         m_pan.PointerUp(inputEvent);
         m_pinch.PointerUp(inputEvent);
         m_rotate.PointerUp(inputEvent);
         m_touch.PointerUp(inputEvent);
         m_tap.PointerUp(inputEvent);
     }
     else
     {
         m_pan.PointerMove(inputEvent);
         m_pinch.PointerMove(inputEvent);
         m_rotate.PointerMove(inputEvent);
         m_touch.PointerMove(inputEvent);
         m_tap.PointerMove(inputEvent);
     }
 }
Exemplo n.º 2
0
        public void PointerDown(TouchInputEvent touchEvent)
        {
            //Wrld_TTY("Rotate - down - primary %d\n", event.primaryActionIndex);
            if (touchEvent.primaryActionIndex > 1)
            {
                return;
            }

            float x = (m_handler.TranslateGlobalXToLocalX(touchEvent.pointerEvents[touchEvent.primaryActionIndex].x));
            float y = (m_handler.TranslateGlobalYToLocalY(touchEvent.pointerEvents[touchEvent.primaryActionIndex].y));

            lastPointer[touchEvent.primaryActionIndex] = new Vector2(x, y);

            if (!rotating)
            {
                int  numTouches = touchEvent.pointerEvents.Count;
                bool isRotating = UpdateRotation(touchEvent, numTouches, false);

                if (isRotating)
                {
                    //Wrld_TTY("ROTATE START\n");
                    AppInterface.RotateData rot;
                    rot      = PopulateRotateData(numTouches, m_totalRotation);
                    rotating = true;

                    m_handler.Event_TouchRotate_Start(rot);
                }
            }
        }
Exemplo n.º 3
0
        public void PointerUp(TouchInputEvent touchEvent)
        {
            TrackPointerUp();

            if (IsTapping())
            {
                ++m_tapUpCount;

                if (m_tapDownCount > m_tapUpCount)
                {
                    Reset();
                    return;
                }

                if (m_tapDownCount >= 2)
                {
                    if (WithinAnchorDeadzone(touchEvent))
                    {
                        DispatchDoubleTap();
                    }
                    else
                    {
                        // Two taps have occurred in the time window, but too far apart on screen, should be two single taps.

                        DispatchSingleTap();

                        m_tapAnchorX = touchEvent.pointerEvents[0].x;
                        m_tapAnchorY = touchEvent.pointerEvents[0].y;

                        DispatchSingleTap();
                    }
                }
            }
        }
Exemplo n.º 4
0
 public void PointerMove(TouchInputEvent touchEvent)
 {
     if (IsTapping() && !WithinAnchorDeadzone(touchEvent))
     {
         Reset();
     }
 }
Exemplo n.º 5
0
        public void PointerUp(TouchInputEvent touchEvent)
        {
            if (touchEvent.primaryActionIndex > 1)
            {
                return;
            }

            lastPointer[touchEvent.primaryActionIndex] = Vector2.zero;

            if (rotating)
            {
                int  numTouches = touchEvent.pointerEvents.Count;
                bool isRotating = UpdateRotation(touchEvent, numTouches, true);

                if (!isRotating)
                {
                    //Wrld_TTY("ROTATE STOP\n");
                    needNewBaseline = true;
                    AppInterface.RotateData rot = PopulateRotateData(numTouches, 0.0f);
                    rotating = false;
                    m_previousRotationDelta = 0.0f;
                    m_totalRotation         = 0.0f;
                    m_handler.Event_TouchRotate_End(rot);
                }
            }
        }
Exemplo n.º 6
0
 public void HandleInput(TouchInputEvent inputEvent)
 {
     if (inputEvent.isPointerDownEvent && !EventSystem.current.IsPointerOverGameObject())
     {
         m_pan.PointerDown(inputEvent);
         m_pinch.PointerDown(inputEvent);
         m_rotate.PointerDown(inputEvent);
         m_touch.PointerDown(inputEvent);
         m_tap.PointerDown(inputEvent);
     }
     else if (inputEvent.isPointerUpEvent && !EventSystem.current.IsPointerOverGameObject())
     {
         m_pan.PointerUp(inputEvent);
         m_pinch.PointerUp(inputEvent);
         m_rotate.PointerUp(inputEvent);
         m_touch.PointerUp(inputEvent);
         m_tap.PointerUp(inputEvent);
     }
     else
     {
         if (!EventSystem.current.IsPointerOverGameObject())
         {
             m_pan.PointerMove(inputEvent);
             m_pinch.PointerMove(inputEvent);
             m_rotate.PointerMove(inputEvent);
             m_touch.PointerMove(inputEvent);
             m_tap.PointerMove(inputEvent);
         }
     }
 }
Exemplo n.º 7
0
        public void PointerDown(TouchInputEvent touchEvent)
        {
            TrackPointerDown();

            if (m_tapDownCount == 0)
            {
                m_tapAnchorX = touchEvent.pointerEvents[0].x;
                m_tapAnchorY = touchEvent.pointerEvents[0].y;
            }

            ++m_tapDownCount;
            m_tapUnixTime = MillisecondsSinceEpoch();
        }
Exemplo n.º 8
0
 public void PointerMove(TouchInputEvent touchEvent)
 {
     if (pinching)
     {
         float pinchScale;
         int   numTouches = touchEvent.pointerEvents.Count;
         bool  isPinching = UpdatePinching(pinching, touchEvent, out pinchScale, numTouches, false);
         if (isPinching)
         {
             AppInterface.PinchData pinch;
             pinch.scale = pinchScale / majorScreenDimension;
             m_handler.Event_TouchPinch(pinch);
         }
     }
 }
Exemplo n.º 9
0
        private bool WithinAnchorDeadzone(TouchInputEvent touchEvent)
        {
            Debug.Assert(IsTapping());

            Vector2 tapLocation     = new Vector2(m_tapAnchorX, m_tapAnchorY);
            Vector2 currentLocation = new Vector2(touchEvent.pointerEvents[0].x, touchEvent.pointerEvents[0].y);

            if ((tapLocation - currentLocation).sqrMagnitude < TapDeadZonePixelsSq)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
 public void PointerUp(TouchInputEvent touchEvent)
 {
     if (pinching)
     {
         float pinchScale;
         int   numTouches = touchEvent.pointerEvents.Count;
         bool  isPinching = UpdatePinching(pinching, touchEvent, out pinchScale, numTouches, true);
         if (!isPinching)
         {
             //Wrld_TTY("PINCH STOP\n");
             AppInterface.PinchData pinch;
             pinching         = false;
             previousDistance = 0.0f;
             pinch.scale      = pinchScale;
             m_handler.Event_TouchPinch_End(pinch);
         }
     }
 }
Exemplo n.º 11
0
        public void PointerDown(TouchInputEvent touchEvent)
        {
            if (!pinching)
            {
                float pinchScale;
                int   numTouches = touchEvent.pointerEvents.Count;
                bool  isPinching = UpdatePinching(pinching, touchEvent, out pinchScale, numTouches, false);

                if (isPinching)
                {
                    //Wrld_TTY("PINCH START\n");
                    AppInterface.PinchData pinch;
                    pinching    = true;
                    pinch.scale = 0.0f;
                    m_handler.Event_TouchPinch_Start(pinch);
                }
            }
        }
Exemplo n.º 12
0
        public void PointerMove(TouchInputEvent touchEvent)
        {
            if (touchEvent.primaryActionIndex > 1)
            {
                return;
            }

            if (rotating)
            {
                int  numTouches = touchEvent.pointerEvents.Count;
                bool isRotating = UpdateRotation(touchEvent, numTouches, false);

                if (isRotating)
                {
                    AppInterface.RotateData rot = PopulateRotateData(numTouches, m_totalRotation);
                    m_handler.Event_TouchRotate(rot);
                }
            }
        }
Exemplo n.º 13
0
        public void PointerDown(TouchInputEvent touchEvent)
        {
            int   numTouches       = touchEvent.pointerEvents.Count;
            float x                = 0;
            float y                = 0;
            int   inputsToConsider = Math.Min(MaxPanInputs, numTouches);

            for (int i = 0; i < inputsToConsider; ++i)
            {
                int   pid  = touchEvent.pointerEvents[i].pointerIdentity;
                float newx = touchEvent.pointerEvents[i].x;
                float newy = touchEvent.pointerEvents[i].y;
                x          += newx;
                y          += newy;
                inputs[pid] = new Vector2(newx, newy);
            }

            if (!panning)
            {
                panAnchor.Set(x / inputsToConsider, y / inputsToConsider);
            }
        }
Exemplo n.º 14
0
        public void PointerUp(TouchInputEvent touchEvent)
        {
            int numTouches = touchEvent.pointerEvents.Count;

            if (panning && (numTouches == 1))
            {
                AppInterface.PanData pan;
                pan = PopulatePanData(0, Vector2.zero);
                m_handler.Event_TouchPan_End(pan);

                panning   = false;
                panCenter = Vector2.zero;
                panAnchor = Vector2.zero;
            }

            int pointerId = touchEvent.primaryActionIdentifier;

            if (pointerId < MaxPanInputs)
            {
                inputs[pointerId] = Vector2.zero;
            }
        }
Exemplo n.º 15
0
        private Vector2 GetTouchExtents(TouchInputEvent touchEvent)
        {
            Vector2 touchExtents = Vector2.zero;

            int numTouches       = touchEvent.pointerEvents.Count;
            int inputsToConsider = Math.Min(MaxPanInputs, numTouches);

            if (inputsToConsider > 1)
            {
                Vector2 boundsMin = inputs[0];
                Vector2 boundsMax = boundsMin;

                for (int i = 1; i < inputsToConsider; ++i)
                {
                    boundsMin = Vector2.Min(boundsMin, inputs[i]);
                    boundsMax = Vector2.Max(boundsMax, inputs[i]);
                }

                touchExtents = boundsMax - boundsMin;
            }

            return(touchExtents);
        }
Exemplo n.º 16
0
        private bool UpdatePinching(bool pinching, TouchInputEvent touchEvent, out float pinchScale, int numTouches, bool pointerUp)
        {
            float distance    = 0.0f;
            bool  nowPinching = false;

            pinchScale = 0.0f;

            if (numTouches == 2 && pointerUp)
            {
                return(false);
            }

            if (numTouches < 2)
            {
                distance = previousDistance;
            }
            else
            {
                float x1 = touchEvent.pointerEvents[0].x;
                float y1 = touchEvent.pointerEvents[0].y;
                float x2 = touchEvent.pointerEvents[1].x;
                float y2 = touchEvent.pointerEvents[1].y;

                Vector2 p1     = new Vector2(x1, y1);
                Vector2 p2     = new Vector2(x2, y2);
                Vector2 v2Dist = p1 - p2;
                distance    = v2Dist.magnitude;
                nowPinching = true;
            }

            float delta = (previousDistance - distance);

            pinchScale       = delta;
            previousDistance = distance;
            return(pinching || nowPinching);
        }
Exemplo n.º 17
0
        private bool UpdateRotation(TouchInputEvent touchEvent, int numTouches, bool pointerUp)
        {
            if (!rotating)
            {
                m_totalRotation = 0.0f;
            }

            if (numTouches == 2 && pointerUp)
            {
                //Eegeo_TTY("UpdateRotation - rotation ended as numTouches %d\n", numTouches);
                return(false);
            }

            if (numTouches > 1)
            {
                float x1 = (m_handler.TranslateGlobalXToLocalX(touchEvent.pointerEvents[0].x));
                float y1 = (m_handler.TranslateGlobalYToLocalY(touchEvent.pointerEvents[0].y));
                float x2 = (m_handler.TranslateGlobalXToLocalX(touchEvent.pointerEvents[1].x));
                float y2 = (m_handler.TranslateGlobalYToLocalY(touchEvent.pointerEvents[1].y));

                Vector2 p1 = new Vector2(Mathf.Floor(x1), Mathf.Floor(y1));
                Vector2 p2 = new Vector2(Mathf.Floor(x2), Mathf.Floor(y2));

                if (!rotating || needNewBaseline)
                {
                    m_baselineDirection     = (p2 - p1).normalized;
                    lastRotationRadians     = 0.0f;
                    m_previousRotationDelta = 0.0f;
                    needNewBaseline         = false;
                }

                float currentRotation = AngleBetween(m_baselineDirection, (p2 - p1));
                float rotationDelta   = currentRotation - lastRotationRadians;

                float deltaThresholdDifferentDirection = Mathf.Deg2Rad * 10.0f;

                if (m_previousRotationDelta * rotationDelta < 0.0f)
                {
                    // if rotation changed direction, throw away rotation deltas until we have surpassed a threshold
                    if (Math.Abs(rotationDelta) > deltaThresholdDifferentDirection)
                    {
                        m_previousRotationDelta = rotationDelta;
                        lastRotationRadians     = currentRotation;
                    }
                    rotationDelta = 0.0f;
                }
                else
                {
                    m_previousRotationDelta = rotationDelta;
                    lastRotationRadians     = currentRotation;
                }

                m_totalRotation += rotationDelta;

                lastPointer[0] = p1;
                lastPointer[1] = p2;
                return(true);
            }

            return(false);
        }
Exemplo n.º 18
0
        public void PointerMove(TouchInputEvent touchEvent)
        {
            int   numTouches       = touchEvent.pointerEvents.Count;
            float dx               = 0;
            float dy               = 0;
            float totalX           = 0;
            float totalY           = 0;
            int   inputsToConsider = Math.Min(MaxPanInputs, numTouches);
            bool  somethingPanned  = false;

            for (int i = 0; i < inputsToConsider; ++i)
            {
                int pid = touchEvent.pointerEvents[i].pointerIdentity;

                //Wrld_TTY("PanGesture::PointerMove %d -- %f\n", pid, inputs[pid].LengthSq());
                if (inputs[pid].sqrMagnitude > InputActivityTolerance)
                {
                    //Wrld_TTY("POINTER %d CONSIDERED\n", pid);

                    float x = touchEvent.pointerEvents[i].x;
                    float y = touchEvent.pointerEvents[i].y;
                    totalX     += x;
                    totalY     += y;
                    dx         += x - inputs[pid].x;
                    dy         += y - inputs[pid].y;
                    inputs[pid] = new Vector2(x, y);

                    //var delta = new Vector2(dx, dy);
                    //if(delta.LengthSq() > MIN_PAN_MAG_DELTA_SQUARED_TOLERANCE) {
                    somethingPanned = true;
                    //}
                }
            }

            if (inputsToConsider > 0)
            {
                if (!panning && somethingPanned)
                {
                    totalX /= inputsToConsider;
                    totalY /= inputsToConsider;
                    panning = true;
                    panCenter.Set(totalX, totalY);

                    AppInterface.PanData pan;
                    Vector2 touchExtents = GetTouchExtents(touchEvent);
                    pan = PopulatePanData(inputsToConsider, touchExtents);

                    //Wrld_TTY("PAN START\n");
                    m_handler.Event_TouchPan_Start(pan);
                }

                if (panning)
                {
                    dx /= inputsToConsider;
                    dy /= inputsToConsider;
                    float newX = panCenter.x + dx;
                    float newY = panCenter.y + dy;

                    panCenter.Set(newX, newY);

                    AppInterface.PanData pan;
                    Vector2 touchExtents = GetTouchExtents(touchEvent);
                    pan = PopulatePanData(inputsToConsider, touchExtents);

                    m_handler.Event_TouchPan(pan);
                }
            }
        }