My code :
int _lastX= -1;
int _lastY= -1;
protected boolean touchEvent(TouchEvent message)
{
// Retrieve the new x and y touch positions
int x = message.getX(1);
int y = message.getY(1);
boolean isGesture= false;
int eventCode = message.getEvent();
if(eventCode == TouchEvent.DOWN)
{
// If this event is followed by a move event we'll need
// to know the starting point.
_lastX = x;
_lastY = y;
}
if(eventCode == TouchEvent.GESTURE)
{
TouchGesture ges= message.getGesture();
int gesEventCode= ges.getEvent();
if(gesEventCode == TouchGesture.PINCH_END || gesEventCode == TouchGesture.PINCH_UPDATE){
isGesture= true;
float pinchM= ges.getPinchMagnitude();
//-Zoom out.
if( pinchM< 0 ){_renderer.zoom-= pinchM/2.0f;}
//-Zoom in.
if(pinchM> 0 ){_renderer.zoom+= pinchM/2.0f;}
}
}
if(!isGesture){
if(eventCode == TouchEvent.MOVE)
{
_renderer.isAlt= true;
// Move Point calculation
int XmoveSize= x -_lastX;
int YmoveSize= y - _lastY;
if(XmoveSize< 0){_renderer.rotateLX();}
if(XmoveSize> 0){_renderer.rotateRX();}
if(YmoveSize< 0){_renderer.rotateDZ();}
if(YmoveSize> 0){_renderer.rotateUZ();}
_lastX = x;
_lastY = y;
}
}
if(eventCode == TouchEvent.UP){
_renderer.isAlt= false;
// We have lost contact with the screen, reset the last x and y
_lastX = -1;
_lastY = -1;
}
return true;
}
________________________________________________________
Hello,
I took the above code from the touchScreen blackberry sample project and modified a bit to accept pinch gesture.
Now I get one issue with it, the method getPinchmagnitude() always return a positive value so, how to be able to know if this was a pinch out or a pinch in event.
Any answer will help.
Thank.