opengl中的旋转、平移、缩放矩阵生成函数

构建并返回平移矩阵

cpp 复制代码
mat4 buildTranslate(float x, float y, float z)
{ mat4 trans = mat4(1.0, 0.0, 0.0, 0.0, 
                    0.0, 1.0, 0.0, 0.0, 
                    0.0, 0.0, 1.0, 0.0, 
                    x, y, z, 1.0 ); 
  return trans;
} 

构建并返回绕x轴的旋转矩阵

cpp 复制代码
mat4 buildRotateX(float rad)
{ mat4 xrot = mat4(1.0, 0.0, 0.0, 0.0, 
                   0.0, cos(rad), -sin(rad), 0.0, 
                   0.0, sin(rad), cos(rad), 0.0, 
                   0.0, 0.0, 0.0, 1.0 ); 
  return xrot;
}

构建并返回绕y轴的旋转矩阵

cpp 复制代码
mat4 buildRotateY(float rad)
{ mat4 yrot = mat4(cos(rad), 0.0, sin(rad), 0.0, 
                   0.0, 1.0, 0.0, 0.0, 
                   -sin(rad), 0.0, cos(rad), 0.0, 
                   0.0, 0.0, 0.0, 1.0 ); 
  return yrot;
}

构建并返回绕z轴的旋转矩阵

cpp 复制代码
mat4 buildRotateZ(float rad)
{ mat4 zrot = mat4(cos(rad), -sin(rad), 0.0, 0.0, 
                   sin(rad), cos(rad), 0.0, 0.0, 
                   0.0, 0.0, 1.0, 0.0, 
                   0.0, 0.0, 0.0, 1.0 ); 
  return zrot;
}

构建并返回缩放矩阵

cpp 复制代码
mat4 buildScale(float x, float y, float z)
{ mat4 scale = mat4(x, 0.0, 0.0, 0.0, 
                    0.0, y, 0.0, 0.0, 
                    0.0, 0.0, z, 0.0, 
                    0.0, 0.0, 0.0, 1.0 ); 
  return scale;
}

小结

相关推荐
劈星斩月3 小时前
线性代数-3Blue1Brown《线性代数的本质》行列式(7)
线性代数·行列式
咚咚王者1 天前
人工智能之数学基础 线性代数:第一章 向量与矩阵
人工智能·线性代数·矩阵
ACERT3332 天前
04矩阵理论复习-矩阵的分解
算法·矩阵
ACERT3332 天前
03矩阵理论复习-内积空间和正规矩阵
算法·矩阵
simon_skywalker2 天前
线性代数及其应用习题答案(中文版)第二章 矩阵代数 2.3 可逆矩阵的特征(2)
线性代数·矩阵
simon_skywalker2 天前
线性代数及其应用习题答案(中文版)第二章 矩阵代数 2.4 分块矩阵(1)
线性代数·矩阵
simon_skywalker2 天前
线性代数及其应用习题答案(中文版)第二章 矩阵代数 2.3 可逆矩阵的特征(1)
线性代数
黑色的山岗在沉睡2 天前
滤波算法数学前置——线性化
线性代数·算法
千天夜2 天前
线性代数核心概念:正定矩阵、合同矩阵与正交矩阵
线性代数·矩阵
勇气要爆发2 天前
【第一阶段—数学基础】第六章:AI数学入门:线性代数基础—变形金刚的骨架
人工智能·线性代数·机器学习