Hi,

i'm currently investigating multi-touch support on >= 2.0 devices,
testing it on a motorola milestone. The multi-touch API seems to be
very well thought out and processing the respective MotionEvents is
really a piece of cake.

I want to use multi-touch as an optional input method for a small game
i'm developing. The requirement is to detect 2 fingers on screen with
their respective x/y coordinates. Fingers will be lifted and pressed
down randomly and rapidly (rapidly ~ 500ms intervals). As mentioned
earlier, getting the data is no problem at all, here's how i do it in
my test application:

@Override
        public boolean onTouch(View v, MotionEvent event)
        {
                int action = event.getAction();
            int ptrId = event.getPointerId(0);
            if(event.getPointerCount() > 1)
                ptrId = (action & MotionEvent.ACTION_POINTER_ID_MASK) >>
MotionEvent.ACTION_POINTER_ID_SHIFT;
            action = action & MotionEvent.ACTION_MASK;
            if(action < 7 && action > 4)
                action = action - 5;

                if( action == MotionEvent.ACTION_DOWN )
                {
                        for( int i = 0; i < event.getPointerCount(); i++ )
                        {
                                float x = event.getX(i);
                            float y = event.getY(i);

                                touchX[event.getPointerId(i)] = (int)x;
                                touchY[event.getPointerId(i)] = (int)y;
                        }

                        touched[ptrId] = true;
                }
                if( action == MotionEvent.ACTION_MOVE )
                {
                        for( int i = 0; i < event.getPointerCount(); i++ )
                        {
                                float x = event.getX(i);
                            float y = event.getY(i);

                                touchX[event.getPointerId(i)] = (int)x;
                                touchY[event.getPointerId(i)] = (int)y;
                        }
                }
                if( action == MotionEvent.ACTION_UP )
                {
                        touched[ptrId] = false;

                        if( event.getPointerCount() == 1 )
                                for( int i = 0; i < 10; i++ )
                                        touched[i] = false;
                }
                if( action == MotionEvent.ACTION_CANCEL )
                {
                        touched[ptrId] = false;
                        if( event.getPointerCount() == 1 )
                        for( int i = 0; i < 10; i++ )
                                touched[i] = false;
                }

                return true;
        }

touchX[], touchY[] and touch[] are fixed size arrays that store the
pointers coordinates and touch state. Later on i'm going to poll those
to react to player input.

Now, after some initial testing i noticed a problem when randomly
lifting and holding down 2 fingers in a random sequence. I arrived at
a small sequence that always let's me  reproduce the problem:

1) (in landscape mode) hold down finger 1 on the right side of the
screen
2) hold down finger 2 on the left side of the screen and leave both
fingers on the screen for a small amount of time
3) now lift finger 1 and let it go down on the screen again

What happens is that logcat get's filled with

01-30 13:06:45.702: INFO/InputDevice(1167): Dropping bad point #0:
newY=759 closestDy=420 maxDy=420

and the coordinates of the second finger are equal to the coordinate
of the other finger on a single axis.

I'm currently downloading the android source from git to maybe figure
out what's the problem but i'm afraid i'm not a kernel hacker enough
to arrive at a helpful conclusion.

Luke Hutchison posted on this list and on his web site (http://
lukehutch.wordpress.com/2010/01/06/my-multi-touch-code-ported-to-
eclair/) that he experienced similar results. The problem is also
reproduceable with his MTVisualizer application available in the
market as well as with all other multi touch games i could find on the
market. It seems that when the fingers are close on one axis the
hardware/driver/framework get's confused and sets one of the
coordinates of one of the fingers to the same value the coordinate of
the other finger has on this axis (Luke pointed that out in his posts,
i was hoping this would not be true for post G1 hardware). I wrote a
small sample application you can find at
http://code.google.com/p/android-gamedev/source/browse/trunk/src/com/badlogic/gamedev/samples/MultitouchSample.java
and prepared a video to show the problem:

http://www.youtube.com/watch?v=bvqX4EkpbNI

I'm not entirely sure wheter there's a bug in the code or wheter it is
hardware/driver related. I'd be very thankful for any comments on the
matter as the behaviour as shown in the video doesn't allow for multi-
touch controls of games as seen for example in iphone games as
minigore.

Thanks for reading,
Mario

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to