A generic touchscreen calibration program for X.Org
Revisión | 9e15947b55f6847013d28aa0fea79dda432acecd (tree) |
---|---|
Tiempo | 2012-06-27 04:59:28 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
calib calculation: calculate average of clicks first
@@ -27,6 +27,7 @@ | ||
27 | 27 | #include <iostream> |
28 | 28 | #include <fstream> |
29 | 29 | #include <cstring> |
30 | +#include <cmath> | |
30 | 31 | |
31 | 32 | #include "calibrator.hh" |
32 | 33 |
@@ -153,14 +154,20 @@ bool Calibrator::finish(int width, int height) | ||
153 | 154 | std::swap(clicked.y[LL], clicked.y[UR]); |
154 | 155 | } |
155 | 156 | |
157 | + // calculate average of clicks | |
158 | + new_axis.x.min = round( (clicked.x[UL] + clicked.x[LL])/2.0 ); | |
159 | + new_axis.x.max = round( (clicked.x[UR] + clicked.x[LR])/2.0 ); | |
160 | + new_axis.y.min = round( (clicked.y[UL] + clicked.y[UR])/2.0 ); | |
161 | + new_axis.y.max = round( (clicked.y[LL] + clicked.y[LR])/2.0 ); | |
162 | + | |
156 | 163 | // Compute min/max coordinates. |
157 | 164 | // These are scaled using the values of old_axys |
158 | 165 | const float scale_x = (old_axys.x.max - old_axys.x.min)/(float)width; |
159 | - new_axis.x.min = ((clicked.x[UL] + clicked.x[LL]) * scale_x/2) + old_axys.x.min; | |
160 | - new_axis.x.max = ((clicked.x[UR] + clicked.x[LR]) * scale_x/2) + old_axys.x.min; | |
166 | + new_axis.x.min = (new_axis.x.min * scale_x) + old_axys.x.min; | |
167 | + new_axis.x.max = (new_axis.x.max * scale_x) + old_axys.x.min; | |
161 | 168 | const float scale_y = (old_axys.y.max - old_axys.y.min)/(float)height; |
162 | - new_axis.y.min = ((clicked.y[UL] + clicked.y[UR]) * scale_y/2) + old_axys.y.min; | |
163 | - new_axis.y.max = ((clicked.y[LL] + clicked.y[LR]) * scale_y/2) + old_axys.y.min; | |
169 | + new_axis.y.min = (new_axis.y.min * scale_y) + old_axys.y.min; | |
170 | + new_axis.y.max = (new_axis.y.max * scale_y) + old_axys.y.min; | |
164 | 171 | |
165 | 172 | // Add/subtract the offset that comes from not having the points in the |
166 | 173 | // corners (using the same coordinate system they are currently in) |