vector

  • The three values (x, y, and z) together represent two important values, direction, and quantity.
  • The vector dot product
Method 1: returns the value between -1, 1. It represents the cosine of these two vectors.
float m3dDotProduct3(const M3DVector3f u,const M3DVector3f v);
// Method 2: Return radians between 2 vectors.
float m3dGetAngleBetweenVector3(const M3DVector3f u,const M3DVector3f v);
Copy the code
  • Vector cross product (to get a normal line)
void m3dCrossProduct3(M3DVector3f result,const M3DVector3f u ,const M3DVector3f v);
Copy the code

matrix

// 3d matrix (x,y,z)
typedef float M3DMatrix33f[9];
// Four dimensional matrix (x,y,z,w)
typedef float M3DMatrix44f[16];
Copy the code
  • Identity matrix (diagonal 1) You multiply a matrix by an identity matrix and you get the same matrix.
  • Row spacing matrix and column matrix

    Transpose matrix: Transforms the row matrix A into the matrix obtained by the same sequence, called the transformation matrix of A.

Transpose: Transpose rows and columns.

The column vectors are specially commented: the last row in the matrix is 0, and only the last element is 1.

transform

transform application
view Specifies the position of the observer
model Move objects around the scene
Model view Describes the duality of view/model transformations
projection Change the viewframe size and set its projection mode
viewport Pseudo change, scaling the final output on the window

translation

The cube is translated along the Z axis.

rotating

The zoom

1. Move the observer

Move the coordinate system

The matrix stack

  • Vertex transformation pipeline
  • Use the matrix stack function
/ / type
GLMatrixStack::GLMatrixStack(int iStackDepth = 64);
// Load a cell matrix at the top of the stack
void GLMatrixStack::LoadIdentity(void);
// Load any matrix at the top of the stack with arguments :4*4 matrix
void GLMatrixStack::LoadMatrix(const M3DMatrix44f m);
// Multiply the matrix by the matrix at the top of the stack and store the result at the top of the stack
void GLMatrixStack::MultMatrix(const M3DMatrix44f);
// Get the value GetMatrix function at the top of the matrix stack // To accommodate GLShaderMananger, or get a copy of the top matrix
const M3DMatrix44f & GLMatrixStack::GetMatrix(void);
void GLMatrixStack::GetMatrix(M3DMatrix44f mMatrix);
Copy the code
  • Push the stack
// Push the current matrix onto the stack (copy the top matrix onto the stack)
void GLMatrixStack::PushMatrix(void);
// Push the M3DMatrix44f matrix object onto the current matrix stack
void PushMatrix(const M3DMatrix44f mMatrix);
// Press the GLFrame object into the matrix object
void PushMatrix(GLFame &frame);
// Unstack (unstack refers to removing the top matrix object)
void GLMatrixStack::PopMatrix(void)
Copy the code

  • Affine transformation
The Rotate function Angle argument is the number of degrees passed, not radians
void MatrixStack::Rotate(GLfloat angle,GLfloat x,GLfloat y,GLfloat z);
void MatrixStack::Translate(GLfloat x,GLfloat y,GLfloat z);
void MatrixStack::Scale(GLfloat x,GLfloat y,GLfloat z);
Copy the code
  • Affine transformation
// Push any matrix at the top of the stack
void GLMatrixStack::LoadMatrix(GLFrame &frame);
// Matrix times the matrix at the top of the matrix stack. The multiplication results are stored at the top of the stack
void GLMatrixStack::MultMatrix(GLFrame &frame);
// Push the current matrix
void GLMatrixStack::PushMatrix(GLFrame &frame);
Copy the code
  • A typical rendering loop in a 3D environment
  • Camera management
//GLFrame function, this function is used to retrieve the appropriate photographic matrix
void GetCameraMatrix(M3DMatrix44f m,bool bRotationOnly = flase);
Copy the code