OpenGL (five) three-dimensional transformation of the Model View matrix

Source: Internet
Author: User

In computer three-dimensional graphics, a basic task is how to describe the change of an object's position in three-dimensional space, that is, how to describe the motion of an object. Typically, the change in the position of the object consists of three basic changes: translation, rotation, and scaling, and the movement of the object can be described by a combination of these three basic motion forms.


The mathematical expression of object motion in graphics is the process of mapping the initial position coordinate P0 of a point to a new position P1 after translation, rotation, and bloom.


panning:

Translation is the amount of translation in the original three-dimensional space coordinate points, respectively, plus the corresponding direction:




Rotation:

Rotation is divided into two categories: rotation in two-dimensional plane and three-dimensional space.

Rotation on a two-dimensional plane:



Relative sitting callout origin rotation angle θ:




expressed in matrix form:




Expand to three-dimensional space, first look at a simple rotation around an axis of the case.


Rotate around the Z axis:




Rotate around X axis:




Rotate around the y axis:




The rotation transformation of arbitrary axes around the specified three-dimensional space can be decomposed into the superposition of a rotation transformation and a translation transformation that are about three axes respectively.

A scaling transformation is a scaling factor that is multiplied by one of the three dimensions:




Summing up the above, you can see the transformed coordinate points in addition to the translation transformation is to add a translation vector in the original coordinates, rotation, scaling is at the original coordinate point with a transformation matrix.


in order to unify the translation transformation into matrix multiplication, the homogeneous coordinates are introduced . The homogeneous coordinates are represented by a vector of n+1 dimensions, which is originally n-Dimensional. In homogeneous coordinates, 4 components are used to represent a point in a three-dimensional space, the first three components are the same as normal three-dimensional coordinates, and the fourth component is set to 1.


In homogeneous coordinates, the translation transformation can be expressed as:




In this way, in the homogeneous coordinate system, the movement of three-dimensional space is uniformly shifted, rotated and scaled in the form of a transformation matrix of the left multiply.

The movement of an object is examined by first translating and then rotating, and the two motions can be expressed as:




R*t is also a 4*4 transformation matrix, which contains a translation and a rotation overlay.


Generalized to more complex transformations, only need to on the current r*t matrix on the left-hand side of the corresponding transformation matrix, the resulting transformation matrix contains all the objects of the transformation of the superposition, and this series of transformations only needs to use the initial coordinates on the left multiply the final transformation matrix can be achieved, this matrix is "Model Matrix".


For example, for a straight line in a three-dimensional space, the line passes through a point (x0,y0,z0), and the direction is (A,B,C), the motion transformation of an object around the line with θ angle can be decomposed into:

Pan (-x,-y,-z) pan to the origin point around the x-axis rotation angle p causes the specified rotation axis to rotate at the y-axis on the x-z plane to the angle q so that the specified rotation axis coincides with the z-axis around the y-axis rotation angle-Q around the x-axis rotation angle-p translation (x, y, z)

As you can see, the model matrix describes a series of transformations of three-dimensional space objects. In the case that the object is a rigid body model (the rigid body is the object with the same shape and size, and the relative position of the interior points), all the vertices of the object can realize the specified motion of the object by the left multiplicative model matrix, so the model matrix greatly reduces the complexity of the motion model.


Model View Matrix


In the model matrix, it is concerned with the change of the position coordinate point of the object after the movement in the world coordinate system. More generally, we are more concerned about the position of objects relative to the observer , not just about changes in the world coordinate system. Observers, for example, observe the transformation of another car in a moving car, when the observer and the observed object are moving. Such observers are also moving in situations that are more prevalent in the real world. This also increases the complexity of determining the motion model.


Fortunately, we can look at the problem from another perspective, that is, when the observer's position and direction change (the transformation can be expressed by a matrix of models), it can be seen as the object observed by the movement of the opposite motion of the viewer, That is, it is necessary to multiply the inverse of an observer transformation matrix on the basis of the model matrix, which is called the "View Matrix", and the matrix of the view matrix multiplied by the model matrix is the so-called "Model View Matrix".


The new position (shape) obtained by the object's left multiplicative model view matrix describes the change in the coordinate point (shape) of the object in the observer's eye when both the observer and the object are moving.


Mathematics is so wonderful, it complicates a very simple problem, and then simplifies it to show its good points.


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.