Note: this article aims to record the author’s learning process, only represents the author’s personal understanding, if there are inaccurate expressions, welcome to correct! Because the concept involved comes from the network, so if there is infringement, also hope to inform!

preface

In the development process we involve the transformation of graphics, will involve matrix, vector calculation, so this article will simply understand the concept of vector and matrix.

The body of the

What is a vector

Geometrically, a vector is a directed line segment with magnitude and direction.In 3D Cartesian coordinates, basically a vertex is a position in the XYZ coordinate space. Given in spaceA position is precisely defined by a single XYZ, and such XYZ is a vector.

The dot product of vectors

Vectors can be added and subtracted, but there is a very valuable operation in vector development called”
The dot product “.

Definition: We have two non-zero vectorsa,b,OA=a,OB=b, so Angle AOB is called the vectoraAnd the vectorbtheThe Angle, asTheta.0 or less and regulationsTheta.PI or less.The dot product of two vectorsPhi is a scalar (without direction), let’s call it phiA. b..ifa,bNot collinear, then.We calledA vector of length 1 is a unit vector.

So by definition, when I dot my 2 unit vectors,
It’s the Angle between two vectors.

OpenGL uses: The Math3D library provides an API for dot products

//1. M3dDotProduct3 is the dot product between two vectors;
float m3dDotProduct3(const M3DVector3f u,const M3DVector3f v);
/ / (2) of the Angle between two vectors is m3dGetAngleBetweenVector3 radian value;
float m3dGetAngleBetweenVector3(const M3DVector3f u,const 
M3DVector3f v);

The cross product of the vector

The same vector has another operation that is very valuable in development, called the “cross product.”

Definition: The geometric representation of the cross product of two vectors A and b is a vector, called a×b. If a and b are not collinear, a * b mode is: ∣ a * b ∣ = | a |, | | b, sin < a, b >; The directions of A × B are: perpendicular to A and B, and A, B, and a× B form the right-handed system in this order. If a and b, vertical ∣ a * b ∣ = | | | | * b (unlike the dot product here, please note), if a * b = 0, a and b is parallel. A cross product is a set of normal vectors in the plane of two noncollinear nonzero vectors.

Two vector
The cross product will give you another vector, and the new vector will be perpendicular to the plane defined by the original two vectors. Simultaneous fork
Times, it doesn’t have to be a unit vector.

OpenGL uses: The Math3D library provides an API for cross products

//1. The m3dCrossProduct3 function takes the cross product between two vectors to produce a new vector
void m3dCrossProduct3(M3DVector3f result,const M3DVector3f u ,const 
M3DVector3f v);

What is a matrix

Definition: m × n number A
ijThe number table of m rows and n columns is called the matrix of M rows and n columns, or m by N matrix for short.

The number AIj is located in the ith row and j column of matrix A and is called the (I,j) element of matrix A. The matrix with the number AIj as the (I,j) element can be denoted as (AIj) or (aij)m × N. The m× N matrix A is also denoted as Amn.

So how do we define matrices in OpenGL? In other programming standards, many matrix libraries use two-dimensional arrays when defining a matrix. OpenGL’s conventions tend to favor one-dimensional arrays, and the reason for this is that OpenGL uses the column-major matrix sorting convention.

// Three dimensional matrix/four dimensional matrix declaration
typedef float M3DMatrix33f[9];
typedef float M3DMatrix44f[16];

Matrix calculation

Suppose we have a point in space, and we describe its position in terms of xyz, and then we rotate it by a certain Angle around any position, and we need to know the new position of that point, and we need to calculate it by a matrix. In addition,
It makes sense for a matrix to have only one row or one column, and just one row or one column of numbers can be called a vector or a matrix.

As we know, in OpenGL we render graphics to the screen, and we go through a lot of matrix transformations, among which the most commonly involved changes are model matrix transformation, view matrix transformation, projection matrix transformation. For example, the following formula:

Transform vertex vector = M_pro * M_view * M_model * V_local
Transform vertex vector = Projection matrix * View transform matrix * Model matrix * vertex