我的程序处理多点触控。我应该区分我的右手和左手。
要将 x,y 接触点保存在我有的数组中
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();
.....
.....
}
为了确定左手和右手,我有
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;
}
如果我将手正常放在屏幕上(所有五个手指),这将起作用。但是,如果我尝试将手放在任何角度,程序就会失败。(例如让我的手更向右或更向左倾斜)有没有更好的方法来检测左右手之间的关系?
任何帮助表示赞赏