opengl 第四课(矩阵变换)

不学细节,只看概念

见字如面:
glutMainLoop
glutSetWindowTitle
glClear
glEnable
glDisable
glPointSize
glLineWidth
gltMakeTorus

GLTriangleBatch
甜甜圈的批次类

颜色
GLfloat vGreen[] = { 0.0f, 1.0f, 0.0f, 1.0f };

M3DMatrix44f
typedef float M3DMatrix44f[16]

GLShaderManager

1
2
// 使用固定管线(固定管线类型,矩阵,颜色)
GLint UseStockShader(GLT_STOCK_SHADER nShaderID, ...);

GLMatrixStack
矩阵堆栈,数据结构[单元矩阵/矩阵/矩阵相乘/压栈/出栈/缩放/平移/旋转]

1
2
3
4
5
6
7
8
9
10
11
12
// 复制一个矩阵到栈中
inline void LoadMatrix(const M3DMatrix44f mMatrix)

// 栈顶矩阵 与 mMatrix 相乘的结果,并入栈
inline void MultMatrix(const M3DMatrix44f mMatrix)

// 顶部载入单元矩阵
inline void LoadIdentity(void)

// 压入一个矩阵
void PushMatrix(GLFrame& frame)
inline void PopMatrix(void)

GLBatch
传输顶点/光照/纹理/颜色数据到存储着色器中

1
2
3
4
5
6
7
8
9
10
11
// 开始一个批次(点的连接方式9种,顶点数)
void Begin(GLenum primitive, GLuint nVerts, GLuint nTextureUnits = 0)

// 复制 顶点数据
inline void CopyVertexData3f(GLfloat *vVerts)

// 配置完毕
void End(void)

// 提交批次
virtual void Draw(void)

GLGeometryTransform
几何变换管道

1
2
3
4
5
// 初始化管道,关联 模型矩阵栈、投影矩阵栈
inline void SetMatrixStacks(GLMatrixStack& mModelView, GLMatrixStack& mProjection)

// 获取 MVP 矩阵
const M3DMatrix44f& GetModelViewProjectionMatrix(void)

GLFrame
矩阵变换工具类

1
2
3
4
5
6
7
8
9
10
11
// 设置摄像机位置,延 Z轴 移动
inline void MoveForward(float fDelta)

// 调整观察者位置
void RotateWorld(float fAngle, float x, float y, float z)

// 获取 顶部矩阵
void GetMatrix(M3DMatrix44f matrix, bool bRotationOnly = false)

// 获取 m 摄像机矩阵
void GetCameraMatrix(M3DMatrix44f m, bool bRotationOnly = false)

GLFrustum
投影[空间|盒子]模型【正投影、透视投影】[3D->2D]

1
2
3
4
5
6
7
8
/*
1. 透视投影 (角度,宽高比W/H, 近点,远点),
2. 默认生成透视投影矩阵
*/
void SetPerspective(float fFov, float fAspect, float fNear, float fFar)

// 返回上面生成的 透视投影矩阵
const M3DMatrix44f& GetProjectionMatrix(void) { return projMatrix; }

第二部分:实战画图

待续…