My program deals with multitouch. I am supposed to differentiate between my right hand and my left hand.
To save the x,y touch points in an array i have
public boolean onTouchEvent(MotionEvent event)
{
int pointerCount = event.getPointerCount();
if (pointerCount > MAX_TOUCHPOINTS)
{
pointerCount = MAX_TOUCHPOINTS;
}
xval = new int[pointerCount];
yval = new int[pointerCount];
for (int i = 0; i < pointerCount; i++)
{
xval[i]= (int) event.getX(i);
yval[i]= (int) event.getY(i);
}
Canvas c = getHolder().lockCanvas();
.....
.....
}
To determine left and right hand I have
private String DetermineTouch()
{
String message="" ;
int xcount1=0,ycount=0,xcount2=0;
int ylargest=yval[0];
int xlargest=xval[0];
int xlowest=xval[0];
// The thumb has the highest y
for(int i=0;i<yval.length;i++)
{
if(yval[i]> ylargest)
{
ylargest=yval[i];
ycount=i;
}
// if the thumb is of my left hand x is the largest among the points
for(int j=0;j<xval.length;j++)
{
if(xval[j]> xlargest)
{
xlargest=xval[j];
xcount1=j;
}
}
// X is the smallest if the thumb is of my right hand
for(int k=0;k<xval.length;k++)
{
if(xval[k]< xlowest)
{
xlowest=xval[k];
xcount2=k;
}
}
//determining left or right hand
if(xval[ycount]==xval[xcount1]){
message="left";
}
else if (xval[ycount]==xval[xcount2]){
message="right";
}
}
return message;
}
This works if I were to place my hand normally on the screen (All five fingers). But if I try to place my hand at any angle the program fails. ( Example inclining my hand more towards right or more towards left) Is there a better approach to detect between left and right hand?
Any help is appreciated