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;
}

小结

相关推荐
闻缺陷则喜何志丹7 小时前
【计算几何 线性代数】仿射矩阵的秩及行列式
c++·线性代数·数学·矩阵·计算几何·行列式·仿射矩阵得秩
iAkuya11 小时前
(leetcode)力扣100 18矩阵置零(哈希)
leetcode·矩阵·哈希算法
点云侠11 小时前
粒子群优化算法求解三维变换矩阵的数学推导
线性代数·算法·矩阵
c#上位机13 小时前
halcon计算仿射变换矩阵的逆矩阵
计算机视觉·矩阵·c#
AI科技星1 天前
圆柱螺旋运动方程的一步步求导与实验数据验证
开发语言·数据结构·经验分享·线性代数·算法·数学建模
劈星斩月1 天前
线性代数-3Blue1Brown《线性代数的本质》逆矩阵、列空间、秩与零空间(8)
线性代数·逆矩阵·列空间·秩与零空间
拾贰_C2 天前
【Linear Mathematics | 线性代数 | Matrix Theory |矩阵论】RREF的Pivot(主元)是什么?怎么找主元?
线性代数·矩阵
拼命鼠鼠2 天前
【算法】矩阵链乘法的动态规划算法
算法·矩阵·动态规划
式5162 天前
线性代数(八)非齐次方程组的解的结构
线性代数·算法·机器学习
式5162 天前
线性代数(六)列空间和零空间
线性代数