c - Understanding cairo_rotate -
i trying understand cairo_rotate
function.
consider following code. have expected cross drawn, horizontal line (before rotation) drawn. mistake?
cairo_move_to(cr,0,height/2.); cairo_line_to(cr,width,height/2.); cairo_stroke(cr); //horizontal line cairo_rotate(cr,90.*(m_pi/180.)); cairo_move_to(cr,0,height/2.); cairo_line_to(cr,width,height/2.); cairo_stroke(cr); //this line isn't painted
you rotating around origin, @ top-left corner of image. rotate around center of image, must translate well:
cairo_move_to(cr,0,height/2.); cairo_line_to(cr,width,height/2.); cairo_stroke(cr); cairo_translate(cr,width/2,height/2); // translate origin center cairo_rotate(cr,90.*(m_pi/180.)); cairo_translate(cr,-width/2,-height/2); // translate origin cairo_move_to(cr,0,height/2.); cairo_line_to(cr,width,height/2.); cairo_stroke(cr);
depending on application, might make sense draw relative center:
int half_w = width/2; int half_h = height/2; cairo_translate(cr, half_w, half_h); cairo_move_to(cr, -half_w, 0); cairo_line_to(cr, half_w, 0); cairo_stroke(cr); // horizontal line cairo_rotate(cr, 90.*(m_pi/180.)); cairo_move_to(cr, -half_w, 0); cairo_line_to(cr, half_w, 0); cairo_stroke(cr); // vertical line
Comments
Post a Comment