The world is changing really fast, the previous period of time Windows development technology hot still in full swing, web technology began menacing, just as the web presents a thriving, Android small robot, bite the apple, Winphone development platform and lightning-like cut the chaotic web world.
I believe many developers are wondering why the world is not around me. But I'm around the world turning. My answer is that the Shaolin monks learn to fight, the first to learn to stand pile. To practise, occupy three years first. The Shaolin monk fights never revolve around others, but others revolve around him.
The principle of the world is the same, developers like to do the foot rooting.
Looking at OpenGL's projection matrix in recent days, I've also implemented a projection matrix:
"1 0 0 0"
"0 1 0 0"
"0 0 1 1/d]
[0 0 0 0]
where D stands for the near-plane distance.
Do anything, must take the question to study, this is my principle, otherwise do not learn, do not believe the book is better than no book, is understand not understand better than do not understand. My question is why the projection matrix of OpenGL is so complicated, I think the complexity must have its complicated reason. After some research, the fundamental reason is to map the real body to a cube, the range is " -1,1" side length of 2 cubes. Instead of switching directly to the screen. This is the idea of OpenGL. So it's not right to switch directly to the screen like I did. X, y passes through this transformation to -1,1. The transformation of z must satisfy the rules of linear transformation. The process of derivation is not complicated. The principle is that x, Y is compressed in linear proportions. The z-axis is a linear transformation to meet the requirements of the linear matrix. These derivation is very simple, do not say.
The next thing to say is even more surprising, since the study of the underlying implementation of the UI cannot be limited to OpenGL alone. So I went back to anatomy the Skia library. The Skia library on 3D can be said to be a piece of cake in front of OpenGL. But in 2D graphics processing, it can be said that OpenGL is a piece of cake. They are therefore complementary to each other. Of course, my research is Skia also added some 2D graphics for 3D effects. Some of these matrix transformations. It just confirms how correct my matrix is. Refer to the SkCamera.cpp file for details. The specific inside of those mathematical matrix operations how to do not say. The underlying principle is the projection matrix I mentioned above.
These things are very simple. Isn't it?
Specific OpenGL is how to calculate, a little bit of linear algebra knowledge of people, advanced algebra, etc. can be understood, the following is the link.
http://hi.baidu.com/dych_cnu/item/a7b78ba58a86e0208819d30f
Java code
- void Skcamera3d::p atchtomatrix (const skpatch3d& Quilt, skmatrix* matrix) Const {
- if (fneedtoupdate) {
- this->doupdate ();
- Fneedtoupdate = false;
- }
- const skscalar* MAPPTR = (const skscalar*) (const void*) &fOrientation;
- Const skscalar* PATCHPTR;
- Skpoint3d diff;
- Skscalar dot;
- diff.fx = quilt.forigin.fx-flocation.fx;
- Diff.fy = Quilt.forigin.fy-flocation.fy;
- DIFF.FZ = QUILT.FORIGIN.FZ-FLOCATION.FZ;
- Dot = Skunit3d::D ot (* (const skunit3d*) (const void*) &diff,
- * (const skunit3d*) ((constskscalar*) (const void*) &forientation) + 6);
- //The structure of the patchptr is {u,v,origin} where the u,v represents the column vector
- //Origin is the origin of the coordinates.
- PATCHPTR = (const skscalar*) &quilt;
- /*
- where matrix represents a 3x3 matrix
- The first line represents the coefficient of U, the second row is the coefficient of V, the third line is the coefficient of diff
- Each column in the matrix represents an axis.
- */
- //First column
- Matrix->set (Skmatrix::kmscalex, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
- Matrix->set (Skmatrix::kmskewy, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
- Matrix->set (Skmatrix::kmpersp0, Skscalardotdiv (3, Patchptr, 1, mapptr+6, 1, dot));
- //second column
- Patchptr + = 3;
- Matrix->set (Skmatrix::kmskewx, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
- Matrix->set (Skmatrix::kmscaley, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
- Matrix->set (SKMATRIX::KMPERSP1, Skscalardotdiv (3, Patchptr, 1, mapptr+6, 1, dot));
- //Third column
- PATCHPTR = (const skscalar*) (const void*) &diff;
- Matrix->set (SKMATRIX::KMTRANSX, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
- Matrix->set (Skmatrix::kmtransy, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
- Matrix->set (SKMATRIX::KMPERSP2, SK_UNITSCALAR1);
- }
Exploring the Android OpenGL projection matrix in depth of "rooting at the foot"