--- xinput_calibrator.orig/src/calibrator.cpp 2021-01-21 05:52:42.096387477 +0300 +++ xinput_calibrator/src/calibrator.cpp 2021-01-21 11:11:20.368336089 +0300 @@ -144,6 +144,58 @@ return false; } +// Transformation matrix +// from http://support.fccps.cz/download/adv/frr/matrix_calibrator/matrix_calibrator.htm + + // get the average left/right X and upper/lower Y + float x0x = ( clicked.x[UL] + clicked.x[LL] ) / 2.0 / width; + float x0y = ( clicked.y[UL] + clicked.y[LL] ) / 2.0 / height; + float x1x = ( clicked.x[UR] + clicked.x[LR] ) / 2.0 / width; + float x1y = ( clicked.y[UR] + clicked.y[LR] ) / 2.0 / height; + float y0x = ( clicked.x[UL] + clicked.x[UR] ) / 2.0 / width; + float y0y = ( clicked.y[UL] + clicked.y[UR] ) / 2.0 / height; + float y1x = ( clicked.x[LL] + clicked.x[LR] ) / 2.0 / width; + float y1y = ( clicked.y[LL] + clicked.y[LR] ) / 2.0 / height; +//printf ("ZZ: %f %f %f %f %f %f %f %f\n", x0x,x0y, x1x,x1y, y0x,y0y, y1x,y1y); + + //get the difference right-left X and lower-upper Y + float dxx=x1x-x0x; + float dxy=x1y-x0y; + float dyx=y1x-y0x; + float dyy=y1y-y0y; +//printf ("ZZ: Ds %f %f %f %f\n",dxx,dxy,dyx,dyy); + +/* Calculation equations: + 1. x0x * a + x0y * b + c = 1/8 (the left point equation) + 2. x1x * a + x1y * b + c = 7/8 (the right point equation) + 3. a / b = dxx / dxy (tg alfa) + Subtract 1. from 2.: + 4. (x1x - x0x) * a + (x1y - x0y) * b = 6/8 + 5. dxx * a + dxy * b = 6/8 + Isolate (b) from 3.: + 6. b = a * dxy / dxx + Substitute (b) in 5.: + 7. dxx * a + dxy * a * dxy / dxx = 6/8 + Isolate (a) from 7.: + 8. a * (dxx + dxy^2 / dxx) = 6/8 + 9. a * (dxx^2 + dxy^2) / dxx = 6/8 + 10. a = 6/8 * dxx / (dxx^2 + dxy^2) !RESULT! + Analogically for (b): + 11. b = 6/8 * dxy / (dxx^2 + dxy^2) !RESULT! + We will get (c) substituting (a) and (b) in 1. + For (d), (e) and (f) we use the same solution analogically. +*/ + + //calculate the special sauce coefficients + float a = 6.0/8 * (dxx / (dxx*dxx + dxy*dxy)); + float b = 6.0/8 * (dxy / (dxx*dxx + dxy*dxy)); + float c = 1.0/8 - a*x0x - b*x0y; + float d = 6.0/8 * (dyx / (dyx*dyx + dyy*dyy)); + float e = 6.0/8 * (dyy / (dyx*dyx + dyy*dyy)); + float f = 1.0/8 - d*y0x - e*y0y; + + printf ("ZZ: TransformationMatrix %f %f %f %f %f %f 0 0 1\n", a, b, c, d, e, f); + // new axis origin and scaling // based on old_axys: inversion/swapping is relative to the old axis XYinfo new_axis(old_axys);