コード例 #1
0
 //***************************************
 //      ContinueGesture
 //
 //      use:            Update min and max x and y values for
 //                      the current gesture being recorded
 //                      and add the new point to the list.
 //                      Called while player holds input down.
 private void ContinueGesture()
 {
     currentPoint.SetX(Input.mousePosition.x - startPoint.GetX());
     currentPoint.SetY(Input.mousePosition.y - startPoint.GetY());
     currentPointList.Add(new TwoDPoint(currentPoint.GetX(), currentPoint.GetY()));
     if (currentPoint.GetX() > currentGesture.GetMaxX())
     {
         currentGesture.SetMaxX(currentPoint.GetX());
     }
     if (currentPoint.GetX() < currentGesture.GetMinX())
     {
         currentGesture.SetMinX(currentPoint.GetX());
     }
     if (currentPoint.GetY() > currentGesture.GetMaxY())
     {
         currentGesture.SetMaxY(currentPoint.GetY());
     }
     if (currentPoint.GetY() < currentGesture.GetMinY())
     {
         currentGesture.SetMinY(currentPoint.GetY());
     }
     if (limitSamples && currentPointList.Count >= maxPointsAllowed)
     {
         gestureComplete = true;
         Debug.Log(message: "Gesture Complete!");
     }
 }
コード例 #2
0
    //***************************************
    //      Rescale
    //
    //      use:        scales recorded list of points to a square field
    //                  of a chosen size by multiplication of the factor
    //                  of the desired size it already is
    //                  Called on every gesture after recording
    private void Rescale(DrawnGesture gesture)
    {
        float scale  = 1f;
        float xrange = gesture.GetMaxX() - gesture.GetMinX();
        float yrange = gesture.GetMaxY() - gesture.GetMinY();

        if (xrange >= yrange)
        {
            scale = standardRatio / (gesture.GetMaxX() - gesture.GetMinX());
        }
        else
        {
            scale = standardRatio / (gesture.GetMaxY() - gesture.GetMinY());
        }
        if (scale != 1)
        {
            foreach (TwoDPoint point in currentPointList)
            {
                point.SetX(point.GetX() * scale);
                point.SetY(point.GetY() * scale);
            }
        }
    }