Opengl why 4x4 matrix




















It would be great to combine these transformations. This is done by multiplying the matrices together, for instance :. This is how matrix multiplication works. As a matter of fact, the order above is what you will usually need for game characters and other items : Scale it first if needed; then set its direction, then translate it.

For instance, given a ship model rotations have been removed for simplification :. The Model, View and Projection matrices are a handy tool to separate transformations cleanly. But you should. This model, just as our beloved red triangle, is defined by a set of vertices. Your vertices are now in World Space. This is the meaning of the black arrow in the image below : We went from Model Space all vertices defined relatively to the center of the model to World Space all vertices defined relatively to the center of the world.

When you think about it, the same applies to cameras. It you want to view a moutain from another angle, you can either move the camera… or move the mountain. While not practical in real life, this is really simple and handy in Computer Graphics. So initially your camera is at the origin of the World Space. In order to move the world, you simply introduce another matrix. This is equivalent to moving your whole world meshes included 3 units to the LEFT! So, I rather don't understand PS Also I suppose there is some kind of magic 3 for the 3x3 matrix which is used for the 2D-transformations, am I right?

Improve this question. And the last row is not always [0, 0, 0, 1]. Projection matrixes put other values in there which is why all the functions have to do math on them.

Add a comment. Active Oldest Votes. Lets start with a bit of theory: In general, all transformations in OpenGL are mappings between different vector spaces. Improve this answer. Peter O. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

Uniform scaling by multiplying by a scalar. But an appropriately crafted 4x4 matrix can do anything. So using 4x4's consistently makes code and interfaces much simpler. You pay some complexity in understanding these 4x4's, but then lots of things get easier and faster because of it.

If all you are ever going to do is move along a single axis and never apply any other transformation then what you are suggesting is fine. The real power of using a matrix is that you can easily concatenate a series of complex operations together, and apply the same series of operations to multiple objects.

Most cases aren't that simple and if you rotate you object first, and want to transform along its local axes instead of the world axes you'll find you can't simply add 10 to one of the numbers and have it work out correctly. The same thing is done in the 2d case using a 3x3 matrix.

The reason for using homogeneous coordinates is so that all 3 geometric tansformations can be done using one operation; otherwise one would need to do a 3x3 matrix multiply and a 3x3 matrix addition for the translation. See this video to understand the concepts of model, view and projection. See this to understand how the vertices in the world are represented as 4D Matrices and how they are transformed.

Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Learn more. Why do we use 4x4 matrices to transform things in 3D? Ask Question. Asked 7 years, 8 months ago. Active 4 months ago. Viewed 32k times. We can just add 10 to the mat[0][0], and we got the same result too.

Improve this question. Add a comment. They are the 3 axes x,y,z and the origin. When you want to transform vertices, you really want to change the local coordinate system.



0コメント

  • 1000 / 1000