Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

java - Computer Graphics implementing Viewing Pipeline

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:

enter image description here

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

0° 11.25° 22.5° 33.75° 45° - isometry


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...