1. Vector:
Dot multiplication: float m3ddotproduce3 (U,V): Returns the cosine of two unit vectors
Cross multiplication: float m3dcrossproduct3 (RESULT,U,V): Returns a vector perpendicular to the two-vector-defined plane
2. Matrix:
OpenGL uses a column-first-order matrix
The unit matrix (diagonal 1, others 0): Any vector multiplied by one unit matrix will not change anything
3. Transformation:the resulting transformation matrix is applied to each vertex
view matrix x model matrix x projection Matrix--projection camera position transformation, object position transformation, projection cropping transformation
If the vertex vector is Vert, the transformation formula is: P * MV * Vert
Visual Coordinates: a virtual fixed coordinate system used as a reference coordinate system
View transformation: In fact, the position of the camera in the scene transformation, the melancholy view transformation will move the current working coordinate system, so the view transformation must be before the other model transformation
model Transformations: Transformations of objects in a scene, and the results of transformations are related to the order of transformations
Model View: The combination of the view matrix and the model matrix
Projection Transformation: Defines the scene body and creates a clipping plane.
Viewport Transformations: The mapping process for clipping planes and physical windows
4, the Model View matrix transformation function:
fast or get a unit matrix: void M3dloadidentity44 (M)
translation matrix: void m3dtranslationmatrix44 (M,X,Y,Z)
rotation matrix: void m3drotationmatrix44 (M,ANGLE,X,Y,Z): counterclockwise, radians, XYZ specifies the components on each axis
If you need to select by angle, you can call m3drotationmatrix44 (M,m3ddegtorad (angle), x, Y, z)
scaling matrix: void m3dscalematrix44 (M,xscale,yscale,zscale)
matrix multiplication: void M3dmatrixmultiply44 (product,a,b)->product = A*b
5. Transformation Pipeline:
Vert * V: vertices based on the transformation of the View matrix transformation, fall in the new view coordinate system
* M: Vertex for model transformation, fall in new position of attempt coordinates
* P: Vertices are cropped in the new trim coordinates after they are projected
viewport transformations: Vertices end up in Windows viewport coordinates
6. Use of matrix stacks:glmatrixstack, the unit matrix has been included in the stack at initialization time
Load Unit Matrix: glmatrixstack::loadidentity ()
load any matrix: Glmatrixstack::loadmatrix (m)
multiply any matrix by the stack top element and press stack: Glmatrixstack::multmatrix (m)
Get stack top matrix: 1.const m3dmatrix44f& Glmatrixstack::getmatrix ()
2.void Glmatrixstack::getmatrix (m)
stack: Copy the current matrix (or specify a matrix) and press into the top of the stack
1, Glmatrixstack::P Ushmatrix ()
2, Glmatrixstack::P Ushmatrix (m)
3, Glmatrixstack::P Ushmatrix (frame)
out of Stack: glmatrixstack::P Opmatrix ()
Stack Top transform: Transform the current stack top matrix
Rotate (angle,x,y,z)
Translate (x, Y, z)
Scale (x, Y, z)
7, Pipeline management: Glgeometrytransform
a class for managing the stack of vertex transformation matrix stacks and light normal matrices
Protected:m3dmatrix44f_mmodelviewprojection; M3dmatrix33f_mnormalmatrix; glmatrixstack* _mmodelview; Glmatrixstack* _mprojection;
Used to pass the corresponding matrix to the shader at render time.
8. Role frames and abstract cameras
A role frame is a data structure used to replace an object's transformation matrix within the scene: a position in the containing space, a vector pointing to the front, and a vector pointing upwards. Mainly used for transformation of camera objects
Class glframe{protected:m3dvector3f vlocation; m3dvector3f vUp; m3dvector3f Vforward;}
the vector of the X column can be derived from the cross of Y and Z, so there is no need to store
Glframe->matrix Get the matrix of a frame: Glframe::getmatrix (m,brotationonly)
camera: Used to manage the observer, in order to use the camera transform, we use the camera's role transform to invert it, so moving the camera backwards is equivalent to moving the entire scene forward .
Typical rendering cycle flow in a 3D environment:
9. Illumination Transformation:The position of the light source needs to be converted into a visual coordinate system, so the position of the light source needs to be transformed to the camera and then passed to the shader
<span style= "White-space:pre" ></span>m3dvector4f Vlightpos = {0.0f,10.0f,5.0f,1.0f}; m3dvector4f Vlighteyepos;m3dtransformvector4 (Vlighteyepos,vlightpos,mcamera); Shadermanager.usestockshader (GLT_ Shader_point_light_diff,transformpipline.getmodelviewmatrix (), Transformpipline.getprojectionmatrix (), Vlighteyepos,vtorcolor);
OpenGL Super Treasure Note two-basic transformations