Game Development Reference
In-Depth Information
25. To check whether the user is performing the pinch-zoom gesture, we call the
IsPinchZoomValid() function. We get the touch points and calculate the distance
between them. If we are already performing the pinch-zoom gesture, we update the
current points. Otherwise, we store the initial points and calculate the center:
static bool IsPinchZoomValid()
{
if (FMotionDataValid &&
FMotionData.GetNumTouchPoints() == 2 )
{
const sTouchPoint& Pt1 = FMotionData.GetTouchPoint(0);
const sTouchPoint& Pt2 = FMotionData.GetTouchPoint(1);
const LVector2& Pos1(FMotionData.GetTouchPointPos(0));
const LVector2& Pos2(FMotionData.GetTouchPointPos(1));
float NewDistance = (Pos1 - Pos2).Length();
if ( FPinchZoomValid )
{
FZoomFactor = NewDistance / FInitialDistance;
FCurrentPoint1 = Pt1;
FCurrentPoint2 = Pt2;
FCurrentCenter = ( Pos1 + Pos2 ) * 0.5f;
}
else
{
FInitialDistance = NewDistance;
FPinchZoomValid = true;
FZoomFactor = 1.0f;
FInitialPoint1 = Pt1;
FInitialPoint2 = Pt2;
FInitialCenter = ( Pos1 + Pos2 ) * 0.5f;
return false;
}
}
else
{
FPinchZoomValid = false;
FZoomFactor = 1.0f;
}
return FPinchZoomValid;
}
 
Search WWH ::




Custom Search