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

小结

相关推荐
The_Killer.1 小时前
格密码--数学基础--06对偶空间与对偶格
学习·线性代数·密码学
passxgx8 小时前
9.2 埃尔米特矩阵和酉矩阵
线性代数·矩阵
盛寒8 小时前
等价矩阵和等价向量组
线性代数·算法·矩阵
WoShop商城源码8 小时前
短视频矩阵系统的崛起:批量发布功能与多平台矩阵的未来
人工智能·线性代数·其他·矩阵
dongzhenmao16 小时前
P1484 种树,特殊情形下的 WQS 二分转化。
数据结构·c++·windows·线性代数·算法·数学建模·动态规划
mit6.8241 天前
矩阵 | 时域频域傅里叶变换
线性代数·矩阵
The_Killer.1 天前
格密码--数学基础--02基变换、幺模矩阵与 Hermite 标准形
线性代数·矩阵·密码学
Brian Xia1 天前
深度学习入门教程(三)- 线性代数教程
人工智能·深度学习·线性代数
এ᭄画画的北北1 天前
力扣-240.搜索二维矩阵 II
算法·leetcode·矩阵
盛寒2 天前
向量空间 线性代数
python·线性代数·机器学习