From: <hba...@us...> - 2008-08-19 14:31:05
|
Revision: 8678 http://plplot.svn.sourceforge.net/plplot/?rev=8678&view=rev Author: hbabcock Date: 2008-08-19 14:31:13 +0000 (Tue, 19 Aug 2008) Log Message: ----------- Added a stride term to the text transformation matrix so that it will properly scale text for pseudo 3D rendering. Modified Paths: -------------- trunk/drivers/aqt.c trunk/drivers/cairo.c trunk/drivers/pdf.c trunk/drivers/svg.c trunk/include/plplotP.h trunk/include/plstrm.h trunk/src/plcvt.c trunk/src/plot3d.c trunk/src/plsym.c trunk/src/plwind.c Modified: trunk/drivers/aqt.c =================================================================== --- trunk/drivers/aqt.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/drivers/aqt.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -508,7 +508,7 @@ void proc_str (PLStream *pls, EscText *args) { - PLFLT a1, ft_ht, angle, shear; + PLFLT a1, ft_ht, angle, shear, stride; PLINT clxmin, clxmax, clymin, clymax; int i, jst, ref; NSMutableAttributedString *str; @@ -532,7 +532,7 @@ ft_ht = 1.2 * pls->chrht * DPI/25.4; /* ft_ht in points. ht is in mm */ /* given transform, calculate rotation angle & shear angle */ - plRotationShear(args->xform, &angle, &shear); + plRotationShear(args->xform, &angle, &shear, &stride); angle *= 180.0/PI; shear *= -180.0/PI; Modified: trunk/drivers/cairo.c =================================================================== --- trunk/drivers/cairo.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/drivers/cairo.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -357,7 +357,7 @@ float fontSize; int textXExtent, textYExtent; char *textWithPangoMarkup; - PLFLT rotation, shear, cos_rot, sin_rot, cos_shear, sin_shear; + PLFLT rotation, shear, stride, cos_rot, sin_rot, cos_shear, sin_shear; cairo_matrix_t *cairoTransformMatrix; cairo_font_options_t *cairoFontOptions; PangoContext *context; @@ -419,7 +419,7 @@ /* Extract rotation angle and shear from the PLplot tranformation matrix. Compute sines and cosines of the angles as an optimization. */ - plRotationShear(args->xform, &rotation, &shear); + plRotationShear(args->xform, &rotation, &shear, &stride); rotation -= pls->diorot * 3.14159 / 2.0; cos_rot = cos(rotation); sin_rot = sin(rotation); @@ -428,8 +428,8 @@ /* Apply the transform matrix */ cairo_matrix_init(cairoTransformMatrix, - cos_rot, - -sin_rot, + cos_rot * stride, + -sin_rot * stride, cos_rot * sin_shear + sin_rot * cos_shear, -sin_rot * sin_shear + cos_rot * cos_shear, 0,0); Modified: trunk/drivers/pdf.c =================================================================== --- trunk/drivers/pdf.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/drivers/pdf.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -656,7 +656,7 @@ void process_string( PLStream* pls, EscText* args ) { pdfdev* dev = (pdfdev*)pls->dev; - PLFLT rotation, shear; + PLFLT rotation, shear, stride; HPDF_REAL cos_rot, sin_rot, cos_shear, sin_shear; /* Check that we got unicode, warning message and return if not */ @@ -680,7 +680,7 @@ dev->textBlue=(HPDF_REAL)(pls->curcolor.b/255.0); /* calculate transformation matrix (rotation and shear of text) */ - plRotationShear( args->xform, &rotation, &shear ); + plRotationShear( args->xform, &rotation, &shear, &stride); rotation -= pls->diorot * M_PI / 2.0; cos_rot = (HPDF_REAL)cos( rotation ); sin_rot = (HPDF_REAL)sin( rotation ); Modified: trunk/drivers/svg.c =================================================================== --- trunk/drivers/svg.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/drivers/svg.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -376,7 +376,7 @@ short lastOffset = 0; double ftHt; PLUNICODE fci; - PLFLT rotation, shear, cos_rot, sin_rot, sin_shear, cos_shear; + PLFLT rotation, shear, stride, cos_rot, sin_rot, sin_shear, cos_shear; PLFLT t[4]; /* PLFLT *t = args->xform; */ PLUNICODE *ucs4 = args->unicode_array; @@ -396,7 +396,7 @@ /* Calculate the tranformation matrix for SVG based on the transformation matrix provived by PLplot. */ - plRotationShear(args->xform, &rotation, &shear); + plRotationShear(args->xform, &rotation, &shear, &stride); /* N.B. Experimentally, I (AWI) have found the svg rotation angle is the negative of the libcairo rotation angle, and the svg shear angle is pi minus the libcairo shear angle. */ Modified: trunk/include/plplotP.h =================================================================== --- trunk/include/plplotP.h 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/include/plplotP.h 2008-08-19 14:31:13 UTC (rev 8678) @@ -861,10 +861,15 @@ PLFLT plP_w3wcy(PLFLT x, PLFLT y, PLFLT z); -/* Returns the rotation and shear angle from a plplot transformation matrix */ +/* 3-d coords to 2-d projection (z) */ +PLFLT +plP_w3wcz(PLFLT x, PLFLT y, PLFLT z); + +/* Returns the rotation and shear angle and stride from a plplot transformation matrix */ + void -plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear); +plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride); /* Driver calls */ Modified: trunk/include/plstrm.h =================================================================== --- trunk/include/plstrm.h 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/include/plstrm.h 2008-08-19 14:31:13 UTC (rev 8678) @@ -661,7 +661,7 @@ PLFLT base3x, base3y, basecx, basecy; PLFLT domxmi, domxma, domymi, domyma; PLFLT zzscl, ranmi, ranma; - PLFLT cxx, cxy, cyx, cyy, cyz; + PLFLT cxx, cxy, cyx, cyy, cyz, czx, czy, czz; /* Variables for keeping track of windows on a page. */ Modified: trunk/src/plcvt.c =================================================================== --- trunk/src/plcvt.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/src/plcvt.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -223,3 +223,14 @@ (y - plsc->basecy) * plsc->cyy + (z - plsc->ranmi) * plsc->cyz)); } + +/* 3-d coords to 2-d projection (z), if that makes any sense... */ +/* See c_plw3d for a mathematical explanation of the transformation. */ + +PLFLT +plP_w3wcz(PLFLT x, PLFLT y, PLFLT z) +{ + return ((PLFLT) ((x - plsc->basecx) * plsc->czx + + (y - plsc->basecy) * plsc->czy + + (z - plsc->ranmi) * plsc->czz)); +} Modified: trunk/src/plot3d.c =================================================================== --- trunk/src/plot3d.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/src/plot3d.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -2373,16 +2373,18 @@ * N.B. The plot transformation matrix is the product of the following * rotation and shear matrices: * - * [c(t) -s(t)] [1 s(p)] - * [s(t) c(t)] [0 c(p)] + * [c(t) -s(t)] [stride s(p)] + * [s(t) c(t)] [0 c(p)] * * Where t is the rotation angle and phi is the shear angle. \*--------------------------------------------------------------------------*/ void -plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear) +plRotationShear(PLFLT *xFormMatrix, PLFLT *rotation, PLFLT *shear, PLFLT *stride) { - *rotation = acos(xFormMatrix[0]); + *stride = sqrt(xFormMatrix[0] * xFormMatrix[0] + xFormMatrix[2] * xFormMatrix[2]); + + *rotation = acos(xFormMatrix[0] / *stride); if(xFormMatrix[2] < 0.0){ *rotation = -*rotation; } Modified: trunk/src/plsym.c =================================================================== --- trunk/src/plsym.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/src/plsym.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -1599,7 +1599,8 @@ PLFLT sx, PLFLT sy, PLFLT sz, PLFLT just, const char *text) { PLFLT xpc, ypc, xrefpc, yrefpc, xdpc, ydpc, xspc, yspc, ld, ls, cp, shift; - PLFLT theta, phi, xform[4]; + PLFLT x_o, y_o, z_o, x_dx, y_dy, z_dz; + PLFLT theta, phi, stride, xform[4]; /* check that the plotting environment is set up */ if (plsc->level < 3) { @@ -1639,6 +1640,20 @@ phi = 1.570796 - phi; } + /* Determine how to adjust the "stride" of the text to make it + appear that it is going into (or out of) the page. Basically + scale the x baseline of the text by the normalized length of + the d vector projected into the x-y plane. */ + x_o = plP_w3wcx(wx, wy, wz); + y_o = plP_w3wcy(wx, wy, wz); + z_o = plP_w3wcz(wx, wy, wz); + x_dx = x_o - plP_w3wcx(wx+dx, wy+dy, wz+dz); + y_dy = y_o - plP_w3wcy(wx+dx, wy+dy, wz+dz); + z_dz = z_o - plP_w3wcz(wx+dx, wy+dy, wz+dz); + + stride = sqrt(x_dx*x_dx + y_dy*y_dy); + stride = stride/sqrt(x_dx*x_dx + y_dy*y_dy + z_dz*z_dz); + /* compute the reference point */ xpc = plP_dcmmx(plP_pcdcx(xpc)); ypc = plP_dcmmy(plP_pcdcy(ypc)); @@ -1653,9 +1668,9 @@ yrefpc = plP_mmpcy(yrefpc); /* compute the transform */ - xform[0] = cos(theta); + xform[0] = cos(theta) * stride; xform[1] = cos(theta) * sin(phi) - sin(theta) * cos(phi); - xform[2] = sin(theta); + xform[2] = sin(theta) * stride; xform[3] = sin(theta) * sin(phi) + cos(theta) * cos(phi); plP_text(0, just, xform, xpc, ypc, xrefpc, yrefpc, text); Modified: trunk/src/plwind.c =================================================================== --- trunk/src/plwind.c 2008-08-19 13:16:23 UTC (rev 8677) +++ trunk/src/plwind.c 2008-08-19 14:31:13 UTC (rev 8678) @@ -229,4 +229,7 @@ plsc->cyx = cx * saz * salt; plsc->cyy = cy * caz * salt; plsc->cyz = zscale * calt; + plsc->czx = -cx * calt * saz; + plsc->czy = -cy * calt * caz; + plsc->czz = zscale * salt; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |