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

小结

相关推荐
豆沙沙包?11 小时前
2025年--Lc169--H36.有效的数独(矩阵)--Java版
线性代数·矩阵
MoRanzhi120314 小时前
12. Pandas 数据合并与拼接(concat 与 merge)
数据库·人工智能·python·数学建模·矩阵·数据分析·pandas
flashlight_hi1 天前
LeetCode 分类刷题:74. 搜索二维矩阵
python·算法·leetcode·矩阵
一袋米扛几楼982 天前
【机器学习】混淆矩阵(confusion matrix)TP TN FP FN
人工智能·机器学习·矩阵
一水鉴天2 天前
整体设计 逻辑系统程序 之14 彻底分析了的四类文字/三种数字/三套符号
线性代数
WWZZ20252 天前
ORB_SLAM2原理及代码解析:单应矩阵H、基础矩阵F求解
线性代数·算法·计算机视觉·机器人·slam·基础矩阵·单应矩阵
zhangfeng11332 天前
R语言 表达矩阵 count_table 筛选出 行名是 某个 基因的 数据或者某个列中的数据是某个基因的数据
矩阵·r语言·生物信息
FS_tar4 天前
高斯消元矩阵
c++·算法·矩阵
云手机掌柜4 天前
技术深度解析:指纹云手机如何通过设备指纹隔离技术重塑多账号安全管理
大数据·服务器·安全·智能手机·矩阵·云计算
agilearchitect4 天前
MATLAB线性代数函数完全指南
线性代数·其他·决策树·matlab