Re: Unsymmetrical rotation

Carlos López González <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CAF52pzJ8yWmLhPu8R8ySw4c94PTZX-PvJM=TsJb3KyTzkGK_7Q@mail.gmail.com>
Hi Blagoj,
I don't think it is a bug I think that you need to do one extra step:
If alpha is the angle (ccw), origin is the rotation center (in device
units) and w,h are the final image dimensions you have to do this:

cairo_translate(cr, origin.x, origin.y);
cairo_rotate(cr, -1.0*angle);
cairo_translate(cr, -origin.x, -origin.y);
cairo_set_source_surface(cr, source, x, y);

where x and y are the result of the minimum x and minimum y of the
clockwise rotated corners
of the source surface top_left(0,0), top_right(w, 0), bottom_left(0,
h) and  bottom_right(w, h).
This rotation has to be performed at origin of course.

In your case it worked fine when offsets are zero but when offset is
not zero you have to undo the
rotation of the offset first before apply it.

See one example code here:
https://github.com/synfig/synfig/blob/genete_new_cairo_core_2/synfig-core/src/modules/lyr_std/rotate.cpp#L428
Notice that in the sample code there is one extra scale operation from
user units to device units.

I hope it helped.
Carlos



2013/3/4 Blagoj Kupev <[email protected]>

> Hello,
> Does anyone else have any other idea? Can this be a bug in cairo?
> Best regards,
> Blagoj
>
>
> On Sun, Mar 3, 2013 at 9:59 PM, Blagoj Kupev <[email protected]> wrote:
>
>> Hello,
>> Already tried, and does not work... as i can understand the documentation
>> the functions cairo_translate and cairo_rotate only modify the current
>> transformation matrix and then the transformation is applied when the
>> function cairo_set_source_surface is called. Then as i understand,
>> cairo_set_source_surface is doing additional matrix transformation with the
>> x and y offsets prior the matrix is executed.
>>
>> It seems that:
>>
>>    cairo_translate (cr, x_origin, y_origin);
>>    cairo_rotate (cr, (2*3.14*angle/360));
>>    cairo_set_source_surface(cr, surf1, x, y);
>>
>> Is the same as:
>>
>>    cairo_translate (cr, x_origin, y_origin);
>>    cairo_rotate (cr, (2*3.14*angle/360));
>>    cairo_translate (cr, x, y);
>>    cairo_set_source_surface(cr, surf1, 0, 0);
>>
>> Thanks,
>> Blagoj
>>
>> On Sun, Mar 3, 2013 at 9:37 PM, Bill Spitzak <[email protected]> wrote:
>>
>>> On 03/03/2013 06:33 AM, Blagoj Kupev wrote:
>>>
>>>     cairo_translate (cr, x_origin, y_origin);
>>>>    cairo_rotate (cr, (2*3.14*angle/360));
>>>>
>>>>    cairo_set_source_surface(cr, surf1, -x_origin+x_offset, -y_origin);
>>>>    cairo_paint(cr);
>>>>
>>>
>>> I think this will work:
>>>
>>>
>>>     cairo_translate (cr, x_origin, y_origin);
>>>     cairo_rotate (cr, (2*3.14*angle/360));
>>>     cairo_translate (cr, x_offset, 0);
>>>     cairo_set_source_surface(cr, surf1, -x_origin, -y_origin);
>>>
>>> --
>>> cairo mailing list
>>> [email protected]
>>> http://lists.cairographics.**org/mailman/listinfo/cairo<http://lists.cairographics.org/mailman/listinfo/cairo>
>>>
>>
>>
>
> --
> cairo mailing list
> [email protected]
> http://lists.cairographics.org/mailman/listinfo/cairo
>



-- 
Carlos
http://synfig.org

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.