计算机图形学实现查看管道 [英] Computer Graphics implementing Viewing Pipeline

查看:24
本文介绍了计算机图形学实现查看管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是

如您所见,立方体的近面和远面(实际上是从第一个和第二个多边形开始的面)确实具有相同的尺寸,但其他面由于某种原因更薄.

我怀疑由于某种原因,坐标的 x、y 值变得比 z 坐标相距很远.这实际上是有道理的,因为在视口变换中仅缩放 x,y 值(因为我们已经在 2D 中),但我希望立方体看起来会与我上面所说的有所不同......

有什么想法吗?

编辑

添加矩阵和计算,因为我可能在管道中存在错误.

Note 窗口现在是 (-3,-3) 到 (3,3),相机位置是 (2,2,2).

世界观矩阵0.7071 0.0000 -0.7071 -2.0000-0.4082 0.8165 -0.4082 -2.00000.5774 0.5774 0.5774 -2.00000.0000 0.0000 0.0000 1.0000投影矩阵1.0000 0.0000 0.0000 0.00000.0000 1.0000 0.0000 0.00000.0000 0.0000 0.0000 0.00000.0000 0.0000 0.0000 1.0000视口矩阵133.3333 0.0000 0.0000 156.33330.0000 100.0000 0.0000 123.00000.0000 0.0000 0.0000 0.00000.0000 0.0000 0.0000 1.0000

另一个编辑

感谢 Nico 的评论,我以错误的顺序在世界观矩阵中进行乘法运算,在修复此错误后,新矩阵为:

世界观矩阵0.7071 0.0000 -0.7071 0.0000-0.4082 0.8165 -0.4082 0.00000.5774 0.5774 0.5774 -1.73210.0000 0.0000 0.0000 1.0000

解决方案

在正交投影中,面的厚度取决于视角.当您直视一个面时,相邻面的厚度变为零.而当您直视立方体的一个角时(即等距投影),所有面的大小都相同.

以下是一些可视化此行为的示例视图:

This is a continuation to this question.

In a nutshell

I'm implementing viewing pipeline using Java AWT, imitating the behaviour of OpenGL (without using it of course).

Changes from the older question

I've changed projection to Orthographic instead of Perspective (so the transformation is just removing the z-index now, keeping x,y the same).

Changes to input files:

Cube file (notice it contains 6 faces of the cube now instead 12 polylines like before, but it doesn't actually change anything)

8 // number of vertices
0 0 0 // list of vertices indices...
1 0 0
1 1 0
0 1 0
0 0 1
1 0 1
1 1 1
0 1 1
12 // number of polygons
0 1 2 3// first polygon coordinates indices (so the first polygon is 0 0 0, 1 0 0, 1 1 0, 0 1 0)
4 5 6 7 // second polygon vertices indices
1 2 6 5 // and so on
0 3 7 4
2 3 7 6
0 1 5 4

New camera configuration (changed position of camera):

Position 0.7 0.7 2 // position of camera
LookAt 0.5 0.5 0.5 // look at point
Up 0 1 0 // up vector
Window -1 1 -1 1 // window size, (-1,-1) to (1,1) includes all the above polygons in window
Viewport 800 600 // viewport size, not so relevant

The idea was to move the camera abit in the up-right direction, and take a "step back" (z=2), to see the depth of the cube (because if camera was positioned in 0.5,0.5,Z then I wouldn't have seen depth).

I'd expect the cube to appear 'perfect' now, such that each of its' edges would be equal. However, this is what I get:

As you see, the closer and farther faces of the cubes (the ones initiated from the first and second polygons actually) are indeed in the same dimensions, but the other faces are thinner for some reason.

I suspect that for some reason, the x,y values of coordinates becomes way far from each other than the z coordinates. This actually makes sense, since in the Viewport Transformation scales only the x,y values (since we're already in 2D), but I'd expect that the cube would look different as I said above...

Any ideas?

Edit

Adding matrices and calculations since I probably have bug in the pipeline.

Note window is now (-3,-3) to (3,3) and camera position is (2,2,2).

World-View matrix
0.7071    0.0000   -0.7071   -2.0000 
-0.4082    0.8165   -0.4082   -2.0000 
0.5774    0.5774    0.5774   -2.0000 
0.0000    0.0000    0.0000    1.0000 

Projection matrix
1.0000    0.0000    0.0000    0.0000 
0.0000    1.0000    0.0000    0.0000 
0.0000    0.0000    0.0000    0.0000 
0.0000    0.0000    0.0000    1.0000 

Viewport matrix
133.3333    0.0000    0.0000  156.3333 
0.0000  100.0000    0.0000  123.0000 
0.0000    0.0000    0.0000    0.0000 
0.0000    0.0000    0.0000    1.0000 

Another edit

Thanks to Nico's comment I've was multiplying in world-view matrix in the wrong order, after fixing this bug the new matrix is:

World-View matrix
0.7071    0.0000   -0.7071    0.0000
-0.4082    0.8165   -0.4082    0.0000
0.5774    0.5774    0.5774   -1.7321
0.0000    0.0000    0.0000    1.0000

解决方案

In an orthographic projection, the thickness of the faces depends on the view angle. When you look directly at a face, the thickness of adjacent faces becomes zero. Whereas, when you look directly at a corner of the cube (i.e. isometric projection), all faces will have equal size.

Here are some sample views that visualize this behavior:

这篇关于计算机图形学实现查看管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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