Game Development Reference
In-Depth Information
20. Touch handling is performed in the OnTouch() method:
void clFlowFlinger::OnTouch( bool KeyState )
{
int CurImg = ( int )ceilf( FValue / OneImageSize );
vec2 MousePt = Env_GetMouse();
double MouseTime = Env_GetMouseTime();
FPressed = KeyState;
if ( KeyState )
{
FClickPoint = FLastPoint = MousePt;
FClickedTime = FLastTime = MouseTime;
FInitVal = FValue;
FVelocity = 0;
}
else
{
21. If the touch point has moved less than 1 percent of the screen, or the gesture has
taken less than 10 milliseconds we consider it being a tap:
double Time = MouseTime - FClickedTime;
double c_TimeThreshold = 0.15;
float c_LenThreshold = 0.01f;
if ( ( FClickPoint - MousePt ).Length() <
c_LenThreshold
&& ( Time < c_TimeThreshold ) )
{
HandleSelection( MousePt.x, MousePt.y );
FVelocity = 0;
return;
}
22. Otherwise, if the gesture spans less than 300 milliseconds, we stop the motion:
float c_SpanThreshold = 0.3f;
float dT = (float)( MouseTime - FLastTime );
float dSx = MousePt.x - FLastPoint.x;
FVelocity = ( dT < c_SpanThreshold ) ?
-AccelCoeff * dSx / dT : 0;
}
}
 
Search WWH ::




Custom Search