缩放平移2D矢量图形C ++ [英] Zooming Panning 2D vector graphics C++

查看:84
本文介绍了缩放平移2D矢量图形C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

2D C ++程序中图形屏幕上缩放和平移的首选方法是什么?



我正在阅读我的旧线性代数书,我在想一个简单的缩放和翻译矩阵可以实现这一点。但是像AutoCAD或Orcad这样的真实CAD程序如何完成这样的任务呢?



我意识到缩放和转换矩阵是打算修改点/顶点但它们是否也用于缩放和平移?有人能让我开始正确处理这样的问题吗?我不想使用DX或OpenGL。我将使用WinAPI绘制原始像素和线条绘制功能





提前致谢

Hi, What is the preferred method for zooming and panning on the graphics screen in a 2D C++ program?

I was reading my old linear algebra book and I was thinking a simple scaling and translation matrix could accomplish this. But how does a real CAD program like AutoCAD or Orcad accomplish such a task?

I realize scaling and translation matrices are intend for modifying points/vertices but are they also used for Zooming and panning? Can someone get me started on the correct approach to such a problem? I don't want to use a DX or OpenGL. I will just be drawing with WinAPI and the raw pixel and line drawing functions


Thanks in advance

推荐答案

这似乎是进一步调查的合理起点。

sourceforge.net:/ free-cad / code / ci / master / tree / src / Gui / GLPainter.cpp



我意识到你不是在执行openGL之后,但在一天结束时 - 它实际上只归结为执行的内容计算 - 你或你的gpu。没有什么可以阻止你以这种方式重新实现他们的方法,允许你处理不同的输出方法 - 即软件而不是硬件。



我是只需使用矩阵从模型空间转换到视口空间,执行任何简单的剔除,其中整个线段在屏幕外,然后让GDI子系统处理部分不可见线的剪切。鉴于实施剔除所需的复杂性增加,我现在暂时跳过这一步并尝试将全部内容扔到GDI(或GDI +)。
This seems like a reasonable starting-point for further investigation.
sourceforge.net: /free-cad/code/ci/master/tree/src/Gui/GLPainter.cpp

I realize you're not after an openGL implementation, but at the end of the day - it really only boils down to what performs the calculations - you or your gpu. There's nothing to stop you re-implementing their approach in such a manner that allows you to handle a different method of output- i.e software rather than hardware.

I'd just use matrices to transform from model-space to viewport-space, perform any simple culling where the entire line segment was off-screen, followed by letting the GDI subsystem handle clipping of partially not-visible lines. Given the added complexity required to implementing culling, I'd just skip this step for now and try throwing the whole lot at GDI (or GDI+).


最好的方法是实现一些矢量图形。你可以从头开始。在这种情况下,您的缩放将不会显示任何像素化,将直接在屏幕上从模型中呈现。我们的想法是处理Windows消息WM_PAINT,您可以在每次请求时呈现图形。 Windows消息系统具有特殊规定,可优化此特定消息的抽取。例如,如果在所有消息都是处理程序之前使某些区域无效,则只有最后一条消息是处理程序,并且所有失效都是OR在一起。



也就是说,系统确实如此不存储您输出的图形。这是控制反转的示例,当您提供在请求完全或部分重新绘制图形时调用的处理程序。此机制称为无效。因此,您必须在代码中存储一些数据,并且此数据应该是表示矢量图形的数据结构:表示线,矩形,椭圆,颜色等的数据对象的集合。您开发了一个通用方法,在一些图形上下文对象上绘制所有这些数据。



请参阅: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85% 29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/windows/desktop/dd162759%28v=vs.85%29.aspx [ ^ ],

另见: https://msdn.microsoft.com/en-us/library/windows/desktop/dd162761%28v=vs.85%29.aspx [ ^ ]。



在某些部分更改模型时,请使用失效功能之一:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd145002%28v=vs.85% 29.aspx [ ^ ],

https://msdn.microsoft.com/en-us/library/windows/desktop/dd145003%28v=vs.85%29.aspx [ ^ ]。



现在,这是什么变化?它可能是逻辑更改,例如添加,删除或转换模型中的某些对象。另一类改变是观点:缩放级别,平移参数,我甚至会添加旋转,甚至更多:要显示或隐藏的图层集。所有这些更改都需要适当的失效,但观点更改需要完全失效所有场景(渲染控件的窗口)。



所以,你必须要有模型的两个层次:语义,逻辑 - 图形本身和视点数据:当前缩放级别,角度等。改变任何东西,然后使你拥有的任何东西无效。这将导致您的WM_PAINT处理程序调用,这是通用的,使用所有参数呈现所有图形。



另请参阅我过去的答案:MFC绘制的线条消失了 [ ^ ]。

(请参阅即使你不打算使用MFC。)



-SA
The best way to do it is implementing some vector graphics. You can do it from scratch. In this case, your zoom won't show any pixellation, will be rendered from the model directly on screen. The idea is to handle the Windows message WM_PAINT where you render the graphics each time it is requested. Windows messages system has special provision to optimize pumping of this specific message. For example, if you invalidate some region before all messages are handler, only the last message is handler, and all invalidation are ORed together.

That said, the system does not store the graphics you output. This is the example of inversion of control, when you supply a handler which is called when the graphics is requested to be re-drawn, fully or partially. This mechanism is called invalidation. Therefore, you have to store some data in your code, and this data should be the data structure representing your vector graphics: collections of data objects representing lines, rectangles, ellipses, colors, and so on. You develop one universal method drawing all this data on some graphic context object.

Please see: https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213%28v=vs.85%29.aspx[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/dd162759%28v=vs.85%29.aspx[^],
see also: https://msdn.microsoft.com/en-us/library/windows/desktop/dd162761%28v=vs.85%29.aspx[^].

When your model is changed in some part, use one of invalidation functions:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145002%28v=vs.85%29.aspx[^],
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145003%28v=vs.85%29.aspx[^].

Now, what is that change? It could be logical change, such as adding, removing or transforming some of those objects of your model. Another class of changing is the "point of view": zoom level, pan parameters, I would even add rotations, and even more: set of layers to show or to hide. All these changes require appropriate invalidation, but "point of view" changes require full invalidation of all scene (window of your rendering control).

So, you have to have two levels of the model: "semantic", "logical" — graphics itself, and "point of view" data: current zoom level, angle, and so on. Change anything and then invalidate whatever you have to. That will lead to the call of your WM_PAINT handler, which is universal, renders all your graphics with all the parameters.

See also my past answer: MFC Drawed lines is disappeared[^].
(Please see it even if you are not planning to use MFC.)

—SA


这篇关于缩放平移2D矢量图形C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆