PDA

View Full Version : A problem about the non-uniform scaling.



akaiwall
04-13-2009, 01:45 AM
In the section 8.7.6 (OpenvG Specification 1.1) indicated that
if the user-to-surface tansformation includes non-uniform scaling, the geometry to be stroked must be transformed into surface coordinates prior to stroking. The paint transformation must also be set to the concatenation of the paint-to-user and user-to-surface transformations in order to allow correct painting of the stroked geometry. According to the sample code, i wrote my code as below, but had no effect to the line width.Why?



VGPath path;
VGubyte segments[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS};
VGfloat coords[] = {20.0f, 20.0f, 20.0f, 50.0f};
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
vgAppendPathData(path, 2, segments, coods);
vgSeti(VG_MATRIX_MODE, VG_MATRIX_STROKE_PAINT_TO_USER);
vgScale(5.0f, 5.0f);
vgDrawPath(path, VG_STROKE_PATH);

Xmas
04-14-2009, 03:49 AM
Why do you expect an effect on stroke width when the spec says the transformation happens prior to stroking?

akaiwall
04-14-2009, 09:11 PM
Why do you expect an effect on stroke width when the spec says the transformation happens prior to stroking?

hey, xmas, let me put it another way.

Previously, with GDI+ , when i am to stroke a path, i can simply scale the Pen to change only the line width of my stroked path
without affecting its coordinates nor shape. It seems in GDI+ , the linewidth scaling for stroking is seperated from the coordinates
scaling of path shaping.

Here with OpenVG, is there any way by which i can achieve the same effect as the aforementioned case.
I mean only scale the linewidth, keeping the shape and coordinates the same.

thanks ~~

Ivo Moravec
04-15-2009, 08:59 AM
Your code does not do any non-uniform scaling. It just draws a vertical line the normal way.

The VG 1.1 spec offers 2 different approaches to solve this problem:
1) If the desired transformations are uniform (i.e. the geometry stretches in all directions by the same amount), then simply figure out what the new line width should be (= linewidth / sqrt(absolute value of (sx*sy shx*shy))), and use that (vgSetf(VG_STROKE_LINE_WIDTH, modified_line_width)).
or
2) If there are non-uniform transformations (e.g. line width stretches by a factor of 5 but the line length only by a factor of 3), then use vgTransformPath() like in the example in section 8.7.6.

In your case, it seems like the first approach should do the trick, and simply adding a
vgSetf(VG_STROKE_LINE_WIDTH, 4.0f/5.0f);
before your draw call ought to work (4.0f = line width, 5.0f = sqrt(|(sx*sy shx*shy)|) = sqrt(|5*5 - 0*0|) [where sx,sy,shx,shy can be retrieved with vgGetMatrix()])