Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Painter and transformations
Re: Painter and transformations [message #38851 is a reply to message #38850] |
Thu, 24 January 2013 08:07   |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
You are not doing transformations right:
Xform2D trsf;
trsf = Xform2D::Translation(-center.x, -center.y);
trsf = trsf * Xform2D::Rotation(angle);
trsf = trsf * Xform2D::Translation(sz.cx / 2, sz.cy / 2);
You have reversed order of operands there, that is why you are getting different results.
Please refer to
http://en.wikipedia.org/wiki/Transformation_matrix#Composing _and_inverting_transformations
I have spend some time with your example to find out what is going on and it seems to me that everything behaves as expected (apart from the fact that the whole thing is perhaps not doing what you expect 
void Transformations::PaintImage(PaintingPainter &painter, Color color)
{
Size sz = imageCtrl.GetSize();
painter.Rectangle(0, 0, sz.cx, sz.cy);
painter.Stroke(10, color);
painter.Circle(0, 0, 50);
painter.Fill(color);
Pointf center(2000, 2000);
painter.Text(2000, 2000, "A", Roman(400));
painter.Fill(color);
}
void Transformations::Paint1()
{
Size sz = imageCtrl.GetSize();
PaintingPainter painter(sz);
painter.Clear(White());
painter.Scale(0.1, 0.1);
painter.Translate(3000, 3000);
painter.Scale(1, -1);
painter.Translate(0, -sz.cy);
PaintImage(painter, Black());
Pointf center(2000, 2000);
double angle = -45.0 * M_PI / 180;
painter.Translate(-center);
PaintImage(painter, Red());
painter.Rotate(-angle);
PaintImage(painter, Green());
painter.Translate(sz.cx / 2, sz.cy / 2);
PaintImage(painter, Blue());
ImageDraw dw(sz);
dw.DrawPainting(0, 0, sz.cx, sz.cy, painter);
imageCtrl.SetImage(dw);
}
|
|
|
Goto Forum:
Current Time: Sun May 11 20:33:28 CEST 2025
Total time taken to generate the page: 0.02862 seconds
|