Matrix Construction and Operators (Structure and operation of the matrix)

Monday to Friday, a day, 7 am Beijing time on time updates -

OpenGL represents a 4 × 4 matrix not as a two-dimensional array of floating values, but rather as a single array of 16 floating-point values ​​(OpenGL floating-point represented by 16 matrix, rather than a two-dimensional array of floating point ). By default, OpenGL uses a columnmajor or column-primary layout for matrices (by default, OpenGL using column sequence matrix). that is, for a 4 × 4 matrix, the first four elements represent the first column of the matrix, the next four elements represent the second column, and so on (meaning that, for a 4x4 matrix elements, the floating point representation of the first four columns of the matrix first, followed by the second four float is the second column of the matrix, and so on). this approach is different from many math libraries, which do take the two-dimensional array approach (a lot of math library does not like this, they use a two-dimensional array to achieve) . For example, OpenGL prefers the first of these two examples :( choose such as OpenGL former example below :)

GLfloat matrix[16]; // Nice OpenGL-friendly matrix
GLfloat matrix[4][4]; // Not as convenient for OpenGL programmers

OpenGL can use the second variation, but the first is a more efficient representation (OpenGL can use a second, but first an expression of more efficient). The reason for this will become clear in a moment ( Why is it so, one will clear). These 16 elements represent the 4 × 4 matrix, as shown below (16 standard elements of a 4x4 matrix is shown below). When the array elements traverse down the matrix columns one by one, we call this column-major matrix Ordering (when we traverse the array elements we call sequence column matrix). in memory, the 4 × 4 approach of the two-dimensional array (the second option in the preceding code) is laid out in a row-major order (in memory, line-sequential two-dimensional array is stored). in math terms, the two orientations are the transpose of each other ( in mathematics, the two mutually transposed manner)
Matrix Construction and Operators (Structure and operation of the matrix)
Representing in Matrix the above colum- major order in memory produces an array as follows :( sequence column matrix is shown below)

static const float A[] =
{
    A00, A01, A02, A03, A10, A11, A12, A13,
    A20, A21, A22, A23, A30, A31, A32, A33
};

In contrast, representing it in row-major order would require a layout such as this :( order to express the matrix rows is as follows :)

static const float A[] =
{
    A00, A10, A20, A30, A01, A11, A21, A31,
    A20, A21, A22, A23, A30, A31, A32, A33,
};

The real magic lies in the fact that these 16 values ​​can represent a particular position in space and an orientation of the three axes with respect to the viewer (magical place this is, these 16 digital matrix can be expressed as a space relative a specific position and orientation for the viewer in this position). Interpreting these numbers is not hard at all (not difficult to explain these numbers). the four columns each represent a four-element vector (four elements are four vectors). to keep things simple for this book, we focus our attention on just the first three elements of the vectors in the first three columns (in order to make the content easier, we mainly focus on the first three of the previous three vectors the element). the fourth column vector contains the x, y, and z values ​​of the transformed coordinate system's origin (the fourth column represents the element displacements xyz).

The first three elements of the first three columns are just directional vectors that represent the orientation (vectors here are used to represent a direction) of the x, y, and z axes in space of the first three elements of the expression of the first three columns (a rotation). For most purposes, these three vectors are always at 90 ° angles from each other and are usually each of unit length (unless you are also under applying a scale or shear) (in most cases, two of these three vectors are two vertical, and is a unit vector). the mathematical term for this (in case you want to impress your friends) is orthonormal when the vectors are unit length, and orthogonal when they are not (in the mathematical sense, if this Sa is not is the unit vector orthogonal, if it is orthonormal). Figure 4.5 shows the 4 × 4 transformation matrix with its components highlighted (Figure 4.5 these elements are denoted by a 4x4 matrix). Notice that the last row of the matrix is all 0s with the exception of the very last element, which is 1. (note that all the columns The last element amount is 0, the last element of the last column vector is a 1)
Matrix Construction and Operators (Structure and operation of the matrix)
The upper-left 3 × 3 sub-matrix of the matrix shown in Figure 4.5 represents a rotation or orientation (3x3 matrix top left expressed rotation). The last column of the matrix represents a translation or position. (Expression of the last column vector is the location) The most amazing thing is that if you have a 4 × 4 matrix that contains the position and orientation of a coordinate system, and you multiply a vertex expressed in the identity coordinate system (written as a column matrix or vector) by this matrix, the result is a new vertex that has been transformed to the new coordinate system (the most amazing thing is that after you use a 4x4 matrix by multiplying the coordinates to a point, this point will be converted to another coordinate system to go) . As a result, any position in space and any desired orientation can be uniquely defined by a 4 × 4 matrix, and if you multiply all of an object's vertices by this matrix, you transform the entire object to the given location and orientation in space !(Therefore, any one of the position and orientation in space, can be used only with a 4x4 matrix expressed, if all the points multiplied by this matrix with an object, then the object will be converted to all points on that position posture up)

In addition, if you transform an object 's vertices from one space to another using one matrix, you can then transform those vertices by yet another matrix, transforming them again into another coordinate space ( add, you can put an object from one coordinate system conversion to another coordinate system, but also can continue to re-convert the points to the next coordinate system). given matrices a and B and vector v, we know that ( given in a, B both matrix and vector v, we know :)
Matrix Construction and Operators (Structure and operation of the matrix)
it is equivalent to (equivalent to)
Matrix Construction and Operators (Structure and operation of the matrix)
this relationship arises because the matrix multiplication iS associative (because matrix multiplication can accumulate, so they have such a relationship) Here in lies the magic:. it is possible to stack a whole bunch of transforms together by multiplying the matrices that represent those transforms and using the resulting matrix as a single term in the final product ( that is to say: you can put all the transformation matrix multiply in advance of all, and then you go get the result matrix objects related operations)

The final appearance of your scene or object can depend greatly on the order in which the modeling transformations are applied (the object you render the final result depends on the order of multiplying the transformation matrix). This is particularly true of translation and rotation. We can see this as a consequence of the associativity and commutativity rules for matrix multiplication (which is due to the nature of the matrix determined drops). We can group together sequences of transformations in any way we like because matrix multiplication is associative, but the order in which the matrices appear in the multiplication matters because matrix multiplication is not commutative (we can use any way to make a bunch of matrix multiplication, but in a different order will get different results)

Figure 4.6 (a) illustrates a progression of a square rotated first about the z axis and then translated down the newly transformed x axis, and Figure 4.6 (b) illustrates first translating the same square along the x axis and then rotating it around around the z axis (FIG. 4.6a shows the rotational movement of the first effect, FIG 4.6b shows the effect of the rotational movement after the first). the difference in the final dispositions of the square occurs because each transformation is performed with respect to the last transformation performed (the reason for this difference is produced because, with respect to each transform result of the last transformation carried out). in Figure 4.6 (a), the square is rotated with respect to the origin first (FIG. 4.6a, rotation relative to the origin to do). in figure 4.6 (b), after the square is translated, the rotation is performed around the newly translated origin (figure 4.6b, rotational position relative to do after the movement)

Matrix Construction and Operators (Structure and operation of the matrix)
Translations of this day to get here, see you tomorrow, bye ~

Get the latest plot first time, please pay attention to the Eastern Han Dynasty academy and the heart of the public graphic No.

Han College, waiting for you to play Oh

Guess you like

Origin blog.51cto.com/battlefire/2425812