Exploring the Android OpenGL projection matrix in depth of "rooting at the foot"

Source: Internet
Author: User
Tags skia

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
  1. void Skcamera3d::p atchtomatrix (const skpatch3d& Quilt, skmatrix* matrix) Const {
  2. if (fneedtoupdate) {
  3. this->doupdate ();
  4. Fneedtoupdate = false;
  5. }
  6. const skscalar* MAPPTR = (const skscalar*) (const void*) &fOrientation;
  7. Const skscalar* PATCHPTR;
  8. Skpoint3d diff;
  9. Skscalar dot;
  10. diff.fx = quilt.forigin.fx-flocation.fx;
  11. Diff.fy = Quilt.forigin.fy-flocation.fy;
  12. DIFF.FZ = QUILT.FORIGIN.FZ-FLOCATION.FZ;
  13. Dot = Skunit3d::D ot (* (const skunit3d*) (const void*) &diff,
  14. * (const skunit3d*) ((constskscalar*) (const void*) &forientation) + 6);
  15. //The structure of the patchptr is {u,v,origin} where the u,v represents the column vector
  16. //Origin is the origin of the coordinates.
  17. PATCHPTR = (const skscalar*) &quilt;
  18. /* 
  19. where matrix represents a 3x3 matrix
  20. The first line represents the coefficient of U, the second row is the coefficient of V, the third line is the coefficient of diff
  21. Each column in the matrix represents an axis.
  22. */
  23. //First column
  24. Matrix->set (Skmatrix::kmscalex, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
  25. Matrix->set (Skmatrix::kmskewy, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
  26. Matrix->set (Skmatrix::kmpersp0, Skscalardotdiv (3, Patchptr, 1, mapptr+6, 1, dot));
  27. //second column
  28. Patchptr + = 3;
  29. Matrix->set (Skmatrix::kmskewx, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
  30. Matrix->set (Skmatrix::kmscaley, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
  31. Matrix->set (SKMATRIX::KMPERSP1, Skscalardotdiv (3, Patchptr, 1, mapptr+6, 1, dot));
  32. //Third column
  33. PATCHPTR = (const skscalar*) (const void*) &diff;
  34. Matrix->set (SKMATRIX::KMTRANSX, Skscalardotdiv (3, Patchptr, 1, Mapptr, 1, dot));
  35. Matrix->set (Skmatrix::kmtransy, Skscalardotdiv (3, Patchptr, 1, mapptr+3, 1, dot));
  36. Matrix->set (SKMATRIX::KMPERSP2, SK_UNITSCALAR1);
  37. }

Exploring the Android OpenGL projection matrix in depth of "rooting at the foot"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.