OpenGL:2D 顶点坐标到 2D 观看坐标?
我正在为一个类项目实现一个光栅化器,目前我坚持使用什么方法/如何将顶点坐标转换为查看窗格坐标。
例如,我得到了三角形的 2d 坐标顶点列表,例如
0 0 1
2 0 1
0 1 1
,我在大小为 400X400 像素的查看窗格(使用 OpenGL 和 GLUT)中进行绘制。
我的问题是如何决定在查看窗格中放置这些顶点的位置,假设
1) 我希望坐标以屏幕中心的 0,0 为中心
2)我想填满屏幕的大部分(假设在这个例子中,屏幕是最大x坐标+1长度宽,等等)
3) 我可以使用所有 OpenGL 和 GLUT 的标准库函数。
谢谢!
I'm implementing a rasterizer for a class project, and currently im stuck on what method/how i should convert vertex coordinates to viewing pane coordinates.
I'm given a list of verticies of 2d coordinates for a triangle, like
0 0 1
2 0 1
0 1 1
and im drawing in a viewing pane (using OpenGL and GLUT) of size 400X400 pixels, for example.
My question is how do i decide where in the viewing pane to put these verticies, assuming
1) I want the coordinate's to be centered around 0,0 at the center of the screen
2) I want to fill up most of the screen (lets say for this example, the screen is the maximum x coordinate + 1 lengths wide, etc)
3) I have any and all of OpenGL's and GLUT's standard library functions at my disposal.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
http://www.opengl.org/sdk/docs/man/xhtml /glOrtho.xml
要以 0 为中心,请使用对称的左/右和下/上。请注意近/远,它们有些任意,但通常(在示例中)选择为 -1..+1,这对于 z=1 处的三角形可能是个问题。
如果您关心宽高比,请确保左右和上下与窗口的宽度/高度成比例。
http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml
To center around 0 use symmetric left/right and bottom/top. Beware the near/far which are somewhat arbitrary but are often chosen (in examples) as -1..+1 which might be a problem for your triangles at z=1.
If you care about the aspect ratio make sure that right-left and bottom-top are proportional to the window's width/height.
您应该考虑作为体积视图的平截头体,并通过转换对象以考虑其位置来计算坐标,this 相当彻底地解释了这个理论。
基本上,您必须使用根据视图特征计算的指定投影矩阵来投影对象:
You should consider the frustum which is your volumetric view and calculate the coordinates by transforming the your objects to consider their position, this explains the theory quite thoroughly..
basically you have to project the object using a specified projection matrix that is calculated basing on the characteristics of your view: