emarsh
Posts: 7
Joined: Wed Feb 03, 2016 2:45 am

Unable to rotate path

Sat Feb 13, 2016 5:28 pm

Hi,

I'm an experienced software guy but a Pi noob. My goal is to use the Pi to drive a UI and from what I can see OpenVG is my best option. So of course that means I need to learn OpenVG. The downside to OpenVG is that it doesn't seem to have a huge following, or at least Google searches don't bring up too many examples and discussions.

I've started with some example code which I'm tweaking one item at a time to teach myself how to program OpenVG. At this point I seem to be stuck trying to rotate paths. I can rotate the entire display by using something like

Code: Select all

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    VGPath path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
    vguEllipse(path, x, y, w, h);
    setfill(fill);
    setstroke(stroke, sw);
    vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH);
    vgTranslate(width/2, height/2);
    vgRotate(h);
    vgTranslate(-width/2, -height/2);
    vgDestroyPath(path);
but when I change

Code: Select all

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
to

Code: Select all

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_FILL_PAINT_TO_USER | VG_MATRIX_STROKE_PAINT_TO_USER);
nothing rotates. It's probably just a dumb programmer mistake - these things usually are - but if that's the case I'm not seeing it.

Can anyone get me pointed in the right direction?

User avatar
Paeryn
Posts: 2014
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Unable to rotate path

Sat Feb 13, 2016 7:54 pm

You can only set the matrix mode to one matrix. That chooses which matrix will be affected by the other routines. If you want to change two matricies then you need to do them separately. OpenVG should have flagged an error when you tried setting two at once. Edit: it won't flag an error as they are integers not bit masks, or-ing them together will result in VG_MATRIX_STROKE_PAINT_TO_USER.

Also, VG_MATRIX_FILL_PAINT_TO_USER and VG_MATRIX_STROKE_PAINT_TO_USER are for transforming the paint's coordinates on the path, not how the path's coordinates transform onto the surface. If you are using solid colour paints then you won't see a difference as there's nothing to transform.

If your paths are all defined in local space then yes, you need to do the transforms each time to place then in the correct position in screen. You can avoid the "undoing" transforms between drawing paths by either using vgGetMatrix() before the path's transforms to save the current matrix and undoing it by putting it back with vgLoadMatrix(). Or if the pre path transform matrix is the default identity matrix you don't need to save it first as it can be set back to that with just vgLoadIdentity().

I'm slightly confused by your code only showing doing the transforms after drawing the path, I assume there are others earlier or more drawing after.
She who travels light — forgot something.

emarsh
Posts: 7
Joined: Wed Feb 03, 2016 2:45 am

Re: Unable to rotate path

Sat Feb 13, 2016 9:48 pm

I see - thanks. So what's the trick to rotating path objects independently of one another?

User avatar
Paeryn
Posts: 2014
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Unable to rotate path

Sat Feb 13, 2016 10:03 pm

You do it the way you are. The matricies are global and affect all subsequent drawing. You need to do the transforms before each draw. Once a transform is set it affects all drawing after it so if you want to reset it either use vgLoadIdentity() to set the transform matrix back to the default, or if you have a global transform set before the individual path transforms then save and restore the matrix.

Code: Select all

VGfloat savedMatrix[9];
vgGetMatrix(savedMatrix); // save the current matrix
vgTranslate(10, 10); // transform for 1st path
vgDrawPath(path1, VG_FILL_PATH); // draw 1st path
vgLoadMatrix(savedMatrix); // restore old matrix
vgTranslate(50, 50); // transform for 2nd path
vgDrawPath(path2, VG_FILL_PATH);
If you know the matrix you are saving is the default then you don't need the vgGetMatrix(savedMatrix) and can use vgLoadIdentity() instead of vgLoadMatrix(savedMatrix)
She who travels light — forgot something.

emarsh
Posts: 7
Joined: Wed Feb 03, 2016 2:45 am

Re: Unable to rotate path

Sat Feb 13, 2016 10:17 pm

Got it! Thanks for the help. Hopefully now I'm on the right track.

User avatar
Paeryn
Posts: 2014
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: Unable to rotate path

Sat Feb 13, 2016 10:38 pm

No worries. It's a shame OpenVG never got much documentation. The best info is from the specs document and the reference implementation, both available from khronos.org, but it doesn't go out of it's way to explain things. It helps if you already know how OpenGL works since that's what the API is based on.
She who travels light — forgot something.

Return to “OpenVG”

Who is online

Users browsing this forum: No registered users and 2 guests