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

小结

相关推荐
WenGyyyL21 小时前
深度学习数学基础(一)——线性代数、线性代数和微积分
人工智能·深度学习·线性代数
CoderYanger1 天前
递归、搜索与回溯-记忆化搜索:40.矩阵中的最长递增路径
java·线性代数·算法·leetcode·矩阵·1024程序员节
qq_430855881 天前
线性代数第一章第一课: 二阶三阶行列式
线性代数·算法·矩阵
C.L.L1 天前
C++ vscode调试——如何方便查看动态二维矩阵
开发语言·c++·矩阵
oscar9991 天前
线性代数第四章 线性方程组
线性代数·线性方程组
劈星斩月2 天前
3Blue1Brown《线性代数的本质》线性组合、张成空间与基
线性代数·基向量·线路组合·张成空间
nianniannnn2 天前
Eigen 矩阵操作笔记
c++·笔记·线性代数·矩阵
狂野有理2 天前
线性代数&【第四章:向量空间与线性相关性】
线性代数
ACERT3332 天前
01矩阵理论复习-线性空间和线性变换
线性代数·矩阵
数据与后端架构提升之路2 天前
自动驾驶仿真数据闭环:如何利用大数据构建“上帝视角”的虚拟矩阵?(硬核指南)
大数据·矩阵·自动驾驶