View | Details | Raw Unified | Return to bug 39762
Collapse All | Expand All

(-)xinput_calibrator.orig/src/calibrator.cpp (+52 lines)
Lines 144-149 Link Here
144
        return false;
144
        return false;
145
    }
145
    }
146
146
147
// Transformation matrix
148
// from http://support.fccps.cz/download/adv/frr/matrix_calibrator/matrix_calibrator.htm
149
150
    // get the average left/right X and upper/lower Y
151
    float x0x = ( clicked.x[UL] + clicked.x[LL] ) / 2.0 / width;
152
    float x0y = ( clicked.y[UL] + clicked.y[LL] ) / 2.0 / height;
153
    float x1x = ( clicked.x[UR] + clicked.x[LR] ) / 2.0 / width;
154
    float x1y = ( clicked.y[UR] + clicked.y[LR] ) / 2.0 / height;
155
    float y0x = ( clicked.x[UL] + clicked.x[UR] ) / 2.0 / width;
156
    float y0y = ( clicked.y[UL] + clicked.y[UR] ) / 2.0 / height;
157
    float y1x = ( clicked.x[LL] + clicked.x[LR] ) / 2.0 / width;
158
    float y1y = ( clicked.y[LL] + clicked.y[LR] ) / 2.0 / height;
159
//printf ("ZZ: %f %f    %f %f   %f %f    %f %f\n", x0x,x0y, x1x,x1y, y0x,y0y, y1x,y1y);
160
161
    //get the difference right-left X and lower-upper Y
162
    float dxx=x1x-x0x;
163
    float dxy=x1y-x0y;
164
    float dyx=y1x-y0x;
165
    float dyy=y1y-y0y;
166
//printf ("ZZ: Ds %f %f %f %f\n",dxx,dxy,dyx,dyy);
167
168
/* Calculation equations:
169
    1.	x0x * a + x0y * b + c = 1/8	(the left point equation)
170
    2.	x1x * a + x1y * b + c = 7/8	(the right point equation)
171
    3.	a / b = dxx / dxy		(tg alfa)
172
    Subtract 1. from 2.:
173
    4.	(x1x - x0x) * a + (x1y - x0y) * b = 6/8
174
    5.	dxx * a + dxy * b = 6/8
175
    Isolate (b) from 3.:
176
    6.	b = a * dxy / dxx
177
    Substitute (b) in 5.:
178
    7.	dxx * a + dxy * a * dxy / dxx = 6/8
179
    Isolate (a) from 7.:
180
    8.	a * (dxx + dxy^2 / dxx) = 6/8
181
    9.	a * (dxx^2 + dxy^2) / dxx = 6/8
182
    10.	a = 6/8 * dxx / (dxx^2 + dxy^2)	!RESULT!
183
    Analogically for (b):
184
    11.	b = 6/8 * dxy / (dxx^2 + dxy^2) !RESULT!
185
    We will get (c) substituting (a) and (b) in 1.
186
    For (d), (e) and (f) we use the same solution analogically.
187
*/
188
189
    //calculate the special sauce coefficients
190
    float a = 6.0/8 *  (dxx / (dxx*dxx + dxy*dxy));
191
    float b = 6.0/8 *  (dxy / (dxx*dxx + dxy*dxy));
192
    float c = 1.0/8 - a*x0x - b*x0y;
193
    float d = 6.0/8 *  (dyx / (dyx*dyx + dyy*dyy));
194
    float e = 6.0/8 *  (dyy / (dyx*dyx + dyy*dyy));
195
    float f = 1.0/8 - d*y0x - e*y0y;
196
197
    printf ("ZZ: TransformationMatrix %f %f %f %f %f %f 0 0 1\n", a, b, c, d, e, f);
198
147
    // new axis origin and scaling
199
    // new axis origin and scaling
148
    // based on old_axys: inversion/swapping is relative to the old axis
200
    // based on old_axys: inversion/swapping is relative to the old axis
149
    XYinfo new_axis(old_axys);
201
    XYinfo new_axis(old_axys);

Return to bug 39762