Hi everyone,
So I finally got an Android tablet and have started working on the android version of env3d (http://env3d.org). I found a very small bug in the AndroidInput’s MOVE delta calculation. Here is the relevant code:
[java]
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
touch = getNextFreeTouchEvent();
touch.set(Type.UP, event.getX(pointerIndex), this.getHeight() - event.getY(pointerIndex), 0, 0);
touch.setPointerId(pointerId);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure(pointerIndex));
processEvent(touch);
bWasHandled = true;
break;
case MotionEvent.ACTION_MOVE:
// Convert all pointers into events
for (int p = 0; p < event.getPointerCount(); p++) {
Vector2f lastPos = lastPositions.get§;
if (lastPos == null) {
lastPos = new Vector2f(event.getX§, this.getHeight() - event.getY§);
lastPositions.put(event.getPointerId§, lastPos);
}
touch = getNextFreeTouchEvent();
touch.set(Type.MOVE, event.getX§, this.getHeight() - event.getY§, event.getX§ - lastPos.x, this.getHeight() - event.getY§ - lastPos.y);
touch.setPointerId(event.getPointerId§);
touch.setTime(event.getEventTime());
touch.setPressure(event.getPressure§);
processEvent(touch);
lastPos.set(event.getX§, this.getHeight() - event.getY§);
}
bWasHandled = true;
break;
[/java]
The way the deltaX and deltaY are calculated is by first remembering the lastPos vector for the particular pointerID. This works great the first time but once the pointer is lifted, the lastPos vector remains in the lastPositions HashMap and the next time the screen is touched with the same pointerId, the lastPosition from the last touch event is retrieved and the incorrect deltaX and deltaY are calculated.
I think the solution is to remove the lastPos vector once the pointer is no longer valid, the following is my solution:
[patch]
This patch file was generated by NetBeans IDE
It uses platform neutral UTF-8 encoding and n newlines.
— Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -254,6 +254,10 @@
touch.setPressure(event.getPressure(pointerIndex));
processEvent(touch);
-
// user has pressed up, remove the lastPosition<br />
-
System.out.println("removing last position "+pointerIndex);<br />
-
lastPositions.remove(event.getPointerId(pointerIndex));<br />
+
bWasHandled = true;
break;
case MotionEvent.ACTION_MOVE:
[/patch]
Please review and commit if approved.
Thanks!