AutoCAD users with a digitizing tablet can calibrate the tablet by using the TABLET command. With the acedTablet() function, applications can manage calibrations by setting them directly and by saving calibration settings for future use. The function takes two arguments, list and result, each of which is a result-buffer list. The first result buffer in the first list is an integer code that must be 0 to retrieve the current calibration (in result), or 1 to set the calibration according to the remaining buffers in list. Calibrations are expressed as four 3D points (in addition to the code). The first three of these points—row1, row2, and row3—are the three rows of the tablet's transformation matrix. The fourth point is a vector, direction, that is normal to the plane of the tablet's surface (expressed in WCS).
The following code sequence retrieves the current tablet calibration, and saves it in calibr2. In this example, the user has used the TABLET command to calibrate the matrix, and Tablet mode is on.
struct resbuf *calibr1, *calibr2; struct resbuf varbuf, rb; // Retrieve the current calibration. calibr1 = acutBuildList(RTSHORT, 0, RTNONE); if (acedTablet(calibr1, &calibr2) != RTNORM) { acdbFail("Calibration not obtainable\n"); return BAD; }
The code returned in the result argument, calibr2 in the example, is automatically set to 1. To reset the calibration to the values retrieved by the preceding example, you could use the following code:
if (acedTablet(calibr2, &calibr1) != RTNORM) { acdbFail("Couldn't reset calibration\n"); return BAD; } rb.restype = RTSHORT; rb.resval.rint = 1; acedSetVar("TABMODE", &rb); acedGetVar("TABMODE" &varbuf); if (varbuf.resval.rint == 0) { acdbFail("Couldn't set TABMODE\n"); return BAD; }
In this example, calibr1 now contains the result of the calibration. Because this is presumably identical to calibr2 (which was initialized by acedTablet()), you don't necessarily need this result. When you set a calibration, you can specify a NULL result, which causes acedTablet() to set the calibration “silently.”
if (acedTablet(calibr2, NULL) != RTNORM) { . . . }
The transformation matrix passed as row1, row2, and row3 is a 3x3 transformation matrix meant to transform a 2D point. The 2D point is expressed as a column vector in homogeneous coordinates (by appending 1.0 as the third element), so the transformation looks like this:
The calculation of a point is similar to the 3D case. AutoCAD transforms the point by using the following formulas:
To turn the resulting vector back into a 2D point, the first two components are divided by the third, the scale factor , yielding the point .
For a projective transformation, which is the most general case, acedTablet() does the full calculation. But for affine and orthogonal transformations, and are both 0, so would be 1.0. The calculation of and the division are omitted; the resulting 2D point is simply .
An affine transformation is a special, uniform case of a projective trans-formation. An orthogonal transformation is a special case of an affine transformation: not only are and 0, but and .