Advertisement
Guest User

Untitled

a guest
Jan 8th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.56 KB | None | 0 0
  1. typedef struct Point
  2. {
  3.     unsigned int x;
  4.     unsigned int y;
  5. } POINT;
  6.  
  7. typedef struct Matrix
  8. {
  9.     long An;
  10.     long Bn;
  11.     long Cn;
  12.     long Dn;
  13.     long En;
  14.     long Fn;
  15.     long Divider;
  16. } MATRIX;
  17.  
  18. lcdPtr is the pointer to POINT variable with this content:    POINT displaySample[3] = {{80,48},{400,432},{720,240}}
  19. touchPtr is the pointer to POINT variable with the touch screen analog readings
  20. matrixPtr is the pointer to the matrix, where the final calculated matrix will be saved
  21.  
  22. int calibrationMatrix( POINT *lcdPtr, POINT *touchPtr, MATRIX *matrixPtr)
  23. {
  24.  
  25.     int  retValue = 1 ;
  26.    
  27.     matrixPtr->Divider = ((touchPtr[0].x - touchPtr[2].x) * (touchPtr[1].y - touchPtr[2].y)) -
  28.                          ((touchPtr[1].x - touchPtr[2].x) * (touchPtr[0].y - touchPtr[2].y)) ;
  29.  
  30.     if( matrixPtr->Divider == 0 )
  31.     {
  32.         retValue = 0 ;
  33.     }
  34.     else
  35.     {
  36.         matrixPtr->An = ((lcdPtr[0].x - lcdPtr[2].x) * (touchPtr[1].y - touchPtr[2].y)) -
  37.                         ((lcdPtr[1].x - lcdPtr[2].x) * (touchPtr[0].y - touchPtr[2].y)) ;
  38.  
  39.         matrixPtr->Bn = ((touchPtr[0].x - touchPtr[2].x) * (lcdPtr[1].x - lcdPtr[2].x)) -
  40.                         ((lcdPtr[0].x - lcdPtr[2].x) * (touchPtr[1].x - touchPtr[2].x)) ;
  41.  
  42.         matrixPtr->Cn = ((touchPtr[2].x * lcdPtr[1].x) - (touchPtr[1].x * lcdPtr[2].x)) * touchPtr[0].y +
  43.                         ((touchPtr[0].x * lcdPtr[2].x) - (touchPtr[2].x * lcdPtr[0].x)) * touchPtr[1].y +
  44.                         ((touchPtr[1].x * lcdPtr[0].x) - (touchPtr[0].x * lcdPtr[1].x)) * touchPtr[2].y ;
  45.  
  46.         matrixPtr->Dn = ((lcdPtr[0].y - lcdPtr[2].y) * (touchPtr[1].y - touchPtr[2].y)) -
  47.                         ((lcdPtr[1].y - lcdPtr[2].y) * (touchPtr[0].y - touchPtr[2].y)) ;
  48.    
  49.         matrixPtr->En = ((touchPtr[0].x - touchPtr[2].x) * (lcdPtr[1].y - lcdPtr[2].y)) -
  50.                         ((lcdPtr[0].y - lcdPtr[2].y) * (touchPtr[1].x - touchPtr[2].x)) ;
  51.  
  52.         matrixPtr->Fn = ((touchPtr[2].x * lcdPtr[1].y) - (touchPtr[1].x * lcdPtr[2].y)) * touchPtr[0].y +
  53.                         ((touchPtr[0].x * lcdPtr[2].y) - (touchPtr[2].x * lcdPtr[0].y)) * touchPtr[1].y +
  54.                         ((touchPtr[1].x * lcdPtr[0].y) - (touchPtr[0].x * lcdPtr[1].y)) * touchPtr[2].y ;
  55.     }
  56.  
  57.     return( retValue ) ;
  58.  
  59. }
  60.  
  61. When I want to calculate the screen pos from an analog reading I use this code:
  62.     long xAnalogReading, yAnalogReading;
  63.     x = ((matrix.An * xAnalogReading) + (matrix.Bn * yAnalogReading) + matrix.Cn) / matrix.Divider;
  64.     y = ((matrix.Dn * xAnalogReading) + (matrix.En * yAnalogReading) + matrix.Fn) / matrix.Divider;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement