Invert grapics in 2D
-
Hi! I have made an application with a panel showing 2d graphics. Now I have found out that the grapichs are inverted, the x axis is pointing in the right direction but y is downwards when it should be upwards on the screen. I can´t really find any good way to invert the axis. I could just change code doing the drawing, but the panel is accessed from a lot of places and it would take a lot of time. What I would like to do is invert the axix at startup and that all the 2d graphics in the panel is drawn in the right way every time a graphics object is created via panel.CreateGraphics(). Help would be much appreciated! Regards! / Mikke
-
Hi! I have made an application with a panel showing 2d graphics. Now I have found out that the grapichs are inverted, the x axis is pointing in the right direction but y is downwards when it should be upwards on the screen. I can´t really find any good way to invert the axis. I could just change code doing the drawing, but the panel is accessed from a lot of places and it would take a lot of time. What I would like to do is invert the axix at startup and that all the 2d graphics in the panel is drawn in the right way every time a graphics object is created via panel.CreateGraphics(). Help would be much appreciated! Regards! / Mikke
GDI and GDI+ all use an axis with the origin in the upper-left corner. This has always been the case. DirectX and I assume OpenGL (never worked with it) use the lower-left corner unless you transform the point of origin. The painting code will just have to be changed. You should encapsulate this in a derivative class of the
Panel
you should make, rather than doing the drawing outside thePanel
that is responsible for showing the graphics. Encapsulation is a major feature of OOP.Microsoft MVP, Visual C# My Articles
-
GDI and GDI+ all use an axis with the origin in the upper-left corner. This has always been the case. DirectX and I assume OpenGL (never worked with it) use the lower-left corner unless you transform the point of origin. The painting code will just have to be changed. You should encapsulate this in a derivative class of the
Panel
you should make, rather than doing the drawing outside thePanel
that is responsible for showing the graphics. Encapsulation is a major feature of OOP.Microsoft MVP, Visual C# My Articles
ok, thank you! I thought it might be like that, but wanted to be sure. I have used a OOD doing the class hierachy and have encapsulated all the important features. Altough some of the functionallity has been placed outside the class because some of components in the application are drawing some graphics om the panel, mainly debug information. Looks like I will have to do some changes in the painting routines then.. / Mikke ( by the way, I think that openGL uses upper right corner too. If I remember correctly, I have not used it in a while.. )