from local/model position to the position of final clip space
Three Transformation Maxtrix:
Projection: Projection Transformation Matrix
transform view coordinate system to clip space coodinate system
View: View Transformation Matrix
transform model coordinate system to view coordinnate system(move the position of camera)
Model: Model Transformation Matrix
transform local coordinate into model coordinate system/game world coordinate system(absolute coordinate)
Postition: The local coordinates of the vertices
local coordinate system(relative coordinate system)
the origin of coordinate system of position and model is defined by developer based on requirment.
the coordinate system of world and model cooresponding to model and postion matrix data respectly:
Absolute(World) Y+ axis Y (0, 1, 0) | | Local(Model) Y+ axis | | / | | / | | | ---------- o (1, 0, 1) ← Local(Model) Origin ---- Local X+ axis | / | | / | | / | | / | | / | |______________________/______|__________ X (1, 0, 0) Absolute(World) X+ axis / Local(Model) Z+ axis / / / Z (0, 0, 1) Absolute(World) Z+ axis
In WebGL, matrices are stored in column-major order, which affects matrix arrangement and calculation order. This storage method influences how matrices are defined and used in WebGL. Here are some common practices when working with column-major matrices in WebGL:
M = | m11 m21 m31 m41 | | m12 m22 m32 m42 | | m13 m23 m33 m43 | | m14 m24 m34 m44 |
In WebGL, this matrix is represented as a one-dimensional array in column-major order:
const matrix = [ m11, m21, m31, m41, // First column m12, m22, m32, m42, // Second column m13, m23, m33, m43, // Third column m14, m24, m34, m44 // Fourth column ];
gl.uniformMatrix4fv(location, false, matrix);
Here, false indicates that the matrix should not be transposed. Since WebGL uses column-major order by default, ensure that the data format matches this requirement, as JavaScript’s standard Math library may use row-major order by default.
The resulting matrix M can be expressed as the product of transformation matrices T, R, and S:
M = T ⋅ R ⋅ S
In this equation:
In column-major order, this sequence first applies scaling, then rotation, and finally translation.
let modelMatrix = mat4.create();// create a Identity matrix
Absolute(World) Y+ axis Y (0, 1, 0) | | Local(Model) Y+ axis | | / | | / | | | ---------- o (1, 0, 1) ← Local(Model) Origin ---- Local X+ axis | / | | / | | / | | / | | / | |______________________/______|__________ X (1, 0, 0) Absolute(World) X+ axis / Local(Model) Z+ axis / / / Z (0, 0, 1) Absolute(World) Z+ axis
The above is the detailed content of [WebGL] [basic] non-skinned model. For more information, please follow other related articles on the PHP Chinese website!