Computer Graphics implementing Viewing Pipeline

2019-09-19 14:47发布

问题:

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

回答1:

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: