私のプログラムはマルチタッチを扱います。右手と左手を区別することになっています。
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;
}
これは、画面上に通常どおり手を置いた場合 (5 本の指すべて) に機能します。しかし、任意の角度に手を置こうとすると、プログラムは失敗します。(私の手をより右に、またはより左に傾ける例) 左手と右手を検出するためのより良いアプローチはありますか?
どんな助けでも大歓迎です