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 小时前
【leetcode hot 100 74】搜索二维矩阵
算法·leetcode·矩阵
crescent_悦6 小时前
PTA 1097-矩阵行平移
线性代数·矩阵
mit6.8246 小时前
[Lc17_多源 BFS_最短路] 矩阵 | 飞地的数量 | 地图中的最高点 | 地图分析
算法·leetcode·矩阵
老了,不知天命7 小时前
神聖的綫性代數速成例題21. 酉空間的基本概念、酉變換與酉矩陣的性質及應用、矩陣的奇異值分解及其應用
线性代数·考研·物理·筆記·數學
黄金芝士11 小时前
矩阵可相似对角化
线性代数·矩阵
亭台1 天前
【Matlab笔记_22】Matlab地图矩阵左右置换
笔记·matlab·矩阵
Ronin-Lotus1 天前
矩阵篇---矩阵的应用
线性代数·矩阵
夜松云1 天前
线性代数核心概念与NumPy科学计算实战全解析
数据结构·人工智能·python·线性代数·算法·机器学习·numpy
jz_ddk1 天前
细说卫星导航:测距定位原理
线性代数·算法
唐豆豆*2 天前
笛卡尔轨迹规划之齐次变换矩阵与欧拉角、四元数的转化
线性代数·矩阵