XPT2046 ËÄÏßµç×èÆÁУ׼Ëã·¨
ËÄÏßµç×èÆÁµÄ´¥Ãþ°å×ø±êºÍÆÁ×ø±êÓÐÈçϹØϵ£º
X0 = xfac * X + xoff;
Y0 = yfac * Y + yoff;
£¨X1,Y1)ºÍ£¨X2,Y2£©ÊÇÓÃÓÚУ׼ʱÆÁÉÏÏÔʾµÄÁ½¸öµã£¬ÕâÁ½¸öµãµÄ×ø±ê±ØÐë²»Ò»Ñù£¬ÊÇÒÑÖªµÄ;
(x1,y1)ºÍ(x2,y2)ÊÇУ׼ʱ¶ÁÈ¡µÄ±»°´ÏµÄÁ½µãµÄ´¥Ãþ°å×ø±êÖµ;
ÓÐÈçÏ·½³Ì×飺
X1 = xfac * x1 + xoff; // 1
Y1 = yfac * y1 + yoff; // 2
X2 = xfac * x2 + xoff; // 3
Y2 = yfac * y2 + yoff; // 4
3 -1 µÃxfac = (X2 -X1)/(x2 -x1); //µÃµ½xÖá·½ÏòµÄ±ÈÀýÒò×Ó
3 + 1 µÃxoff = [(X2 + X1)-xfac(x2 + x1)]/2; //µÃµ½xÖá·½ÏòµÄÆ«ÒÆÁ¿
4 -2 µÃyfac = (Y2 -Y1)/(y2 -y1); //µÃµ½yÖá·½ÏòµÄ±ÈÀýÒò×Ó
4 + 2 µÃyoff = [(Y2 + Y1)-yfac(y2 + y1)]/2; //µÃµ½yÖá·½ÏòµÄÆ«ÒÆÁ¿
µÃµ½xfac£¬xoff£¬yfac£¬yoffÖµºó£¬¾Í¿ÉÒÔ¸ù¾Ý±ÈÀýÒò×ÓºÍÆ«ÒÆÁ¿Ëã³öʵ¼Ê×ø±ê¡£
//УÑé×ø±ê
//ˮƽÁ½¸öµãÖ®¼äµÄ¾àÀë±È½Ï
len1 = sqrt((touch_pos[1].xval-touch_pos[0].xval)*(touch_pos[1].xval-touch_pos[0].xval) \
+ (touch_pos[1].yval-touch_pos[0].yval)*(touch_pos[1].yval-touch_pos[0].yval));
len2 = sqrt((touch_pos[3].xval-touch_pos[2].xval)*(touch_pos[3].xval-touch_pos[2].xval) \
+ (touch_pos[3].yval-touch_pos[2].yval)*(touch_pos[3].yval-touch_pos[2].yval));
if(((len1/len2)<0.95)||((len1/len2)>1.05))
{
//µã»÷µÄµã²»·ûºÏÒªÇó
continue;
}
//´¹Ö±Á½¸öµãÖ®¼äµÄ¾àÀë±È½Ï
len1 = sqrt((touch_pos[2].xval-touch_pos[0].xval)*(touch_pos[2].xval-touch_pos[0].xval) \
+ (touch_pos[2].yval-touch_pos[0].yval)*(touch_pos[2].yval-touch_pos[0].yval));
len2 = sqrt((touch_pos[3].xval-touch_pos[1].xval)*(touch_pos[3].xval-touch_pos[1].xval) \
+ (touch_pos[3].yval-touch_pos[1].yval)*(touch_pos[3].yval-touch_pos[1].yval));
if(((len1/len2)<0.95)||((len1/len2)>1.05))
{
//µã»÷µÄµã²»·ûºÏÒªÇó
continue;
}
//¶Ô½ÇÏßÁ½¸öµãÖ®¼äµÄ¾àÀë±È½Ï
len1 = sqrt((touch_pos[3].xval-touch_pos[0].xval)*(touch_pos[3].xval-touch_pos[0].xval) \
+ (touch_pos[3].yval-touch_pos[0].yval)*(touch_pos[3].yval-touch_pos[0].yval));
len2 = sqrt((touch_pos[2].xval-touch_pos[1].xval)*(touch_pos[2].xval-touch_pos[1].xval) \
+ (touch_pos[2].yval-touch_pos[1].yval)*(touch_pos[2].yval-touch_pos[1].yval));
if(((len1/len2)<0.95)||((len1/len2)>1.05))
{
//µã»÷µÄµã²»·ûºÏÒªÇó
continue;
}
//¼ÆËãУ׼²ÎÊý
//¼ÆËãxÓ³Éä Xlcd = Kxtouch_x + Bx
gb_touch_xyval.xfac= (float)(lcd_pos[1][0]- lcd_pos[0][0])/ (touch_pos[1].xval- touch_pos[0].xval);
gb_touch_xyval.xoff= lcd_pos[0][0] - gb_touch_xyval.xfac*touch_pos[0].xval;
//¼ÆËãyÓ³Éä Ylcd = Kytouch_y + By
gb_touch_xyval.yfac = (float)( lcd_pos[2][1]- lcd_pos[0][1])/ (touch_pos[2].yval- touch_pos[0].yval);
gb_touch_xyval.yoff= lcd_pos[0][1] - gb_touch_xyval.yfac*touch_pos[0].yval;