Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | Related Pages | Examples

fgl::FGInputDevice Class Reference

#include <base.h>

List of all members.


Detailed Description

Interface for user touchscreen + calibration framework.


Public Member Functions

virtual bool Attach (void)=0
virtual int GetInputEvent (int &type, int &key, int &x, int &y, int &button)=0
virtual void Scale (int &x, int &y)
void Calibration (void)

Protected Member Functions

void init (int xmax, int ymax)
void save_values (void)
void load_values ()
int setCalibrationMatrix (POINT *display, POINT *screen, MATRIX *matrix)
int getDisplayPoint (POINT *display, POINT *screen, MATRIX *matrix)
void DoPoint (POINT *display, POINT *screen)

Protected Attributes

bool working
POINT imaginary [3]
POINT real [3]
MATRIX matrix


Member Function Documentation

int fgl::FGInputDevice::getDisplayPoint POINT *  displayPtr,
POINT *  screenPtr,
MATRIX *  matrixPtr
[protected]
 

Function: getDisplayPoint()

Description: Given a valid set of calibration factors and a point value reported by the touch screen, this function calculates and returns the true (or closest to true) display point below the spot where the touch screen was touched.

Argument(s): displayPtr (output) - Pointer to the calculated (true) display point. screenPtr (input) - Pointer to the reported touch screen point. matrixPtr (input) - Pointer to calibration factors matrix previously calculated from a call to setCalibrationMatrix()

The function simply solves for Xd and Yd by implementing the computations required by the translation matrix.

/- -\ /- -\ /- -\ | | | | | | | Xs | | Xd | | A B C | | | | | = | | * | Ys | | Yd | | D E F | | | | | | | | 1 | \- -/ \- -/ | | \- -/

It must be kept brief to avoid consuming CPU cycles.

Return: OK - the display point was correctly calculated and its value is in the output argument. NOT_OK - an error was detected and the function failed to return a valid point.

NOTE! NOTE! NOTE!

setCalibrationMatrix() and getDisplayPoint() will do fine for you as they are, provided that your digitizer resolution does not exceed 10 bits (1024 values). Higher resolutions may cause the integer operations to overflow and return incorrect values. If you wish to use these functions with digitizer resolutions of 12 bits (4096 values) you will either have to a) use 64-bit signed integer variables and math, or b) judiciously modify the operations to scale results by a factor of 2 or even 4.

int fgl::FGInputDevice::setCalibrationMatrix POINT *  displayPtr,
POINT *  screenPtr,
MATRIX *  matrixPtr
[protected]
 

Function: setCalibrationMatrix()

Description: Calling this function with valid input data in the display and screen input arguments causes the calibration factors between the screen and display points to be calculated, and the output argument - matrixPtr - to be populated.

This function needs to be called only when new calibration factors are desired.

Argument(s): displayPtr (input) - Pointer to an array of three sample, reference points. screenPtr (input) - Pointer to the array of touch screen points corresponding to the reference display points. matrixPtr (output) - Pointer to the calibration matrix computed for the set of points being provided.

From the article text, recall that the matrix coefficients are resolved to be the following:

Divider = (Xs0 - Xs2)*(Ys1 - Ys2) - (Xs1 - Xs2)*(Ys0 - Ys2)

(Xd0 - Xd2)*(Ys1 - Ys2) - (Xd1 - Xd2)*(Ys0 - Ys2) A = --------------------------------------------------- Divider

(Xs0 - Xs2)*(Xd1 - Xd2) - (Xd0 - Xd2)*(Xs1 - Xs2) B = --------------------------------------------------- Divider

Ys0*(Xs2*Xd1 - Xs1*Xd2) + Ys1*(Xs0*Xd2 - Xs2*Xd0) + Ys2*(Xs1*Xd0 - Xs0*Xd1) C = --------------------------------------------------- Divider

(Yd0 - Yd2)*(Ys1 - Ys2) - (Yd1 - Yd2)*(Ys0 - Ys2) D = --------------------------------------------------- Divider

(Xs0 - Xs2)*(Yd1 - Yd2) - (Yd0 - Yd2)*(Xs1 - Xs2) E = --------------------------------------------------- Divider

Ys0*(Xs2*Yd1 - Xs1*Yd2) + Ys1*(Xs0*Yd2 - Xs2*Yd0) + Ys2*(Xs1*Yd0 - Xs0*Yd1) F = --------------------------------------------------- Divider

Return: OK - the calibration matrix was correctly calculated and its value is in the output argument. NOT_OK - an error was detected and the function failed to return a valid set of matrix values. The only time this sample code returns NOT_OK is when Divider == 0

NOTE! NOTE! NOTE!

setCalibrationMatrix() and getDisplayPoint() will do fine for you as they are, provided that your digitizer resolution does not exceed 10 bits (1024 values). Higher resolutions may cause the integer operations to overflow and return incorrect values. If you wish to use these functions with digitizer resolutions of 12 bits (4096 values) you will either have to a) use 64-bit signed integer variables and math, or b) judiciously modify the operations to scale results by a factor of 2 or even 4.


Generated on Wed Feb 9 11:31:38 2005 for OpenGUI by  doxygen 1.4.0