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

小结

相关推荐
救救孩子把1 天前
88-机器学习与大模型开发数学教程-8-6 矩阵分解与低秩近似在推荐系统中的应用
人工智能·机器学习·矩阵
不辣的皮蛋君1 天前
2026年短视频矩阵系统实战:如何用工具实现多平台一键分发,效率提升300%
人工智能·线性代数·矩阵
じ☆冷颜〃1 天前
Picard-Lindelöf 定理的多视角证明、推广与加权范数方法
经验分享·笔记·线性代数·数学建模
San813_LDD1 天前
[量化]《从 L1/L2 缓存到 SIMD:矩阵乘法性能优化完全指南》
线性代数·矩阵·架构
小欣加油1 天前
leetcode542 01矩阵
数据结构·c++·算法·leetcode·矩阵·bfs
armwind1 天前
openISP学习7-CCM — Color Correction Matrix(色彩校正矩阵)
python·学习·矩阵
AI科技星2 天前
精细结构常数α的多维度物理比值特性及空间螺旋模型研究
人工智能·线性代数·架构·概率论·学习方法
AI科技星2 天前
基于奇合数边界的离散解析数论与双螺旋宇大统一体系(中英文双语纯净终稿)
人工智能·线性代数·架构·概率论·学习方法
写代码写到手抽筋2 天前
PMI预编码矩阵全解:矩阵含义\+系统作用\+实战案例
线性代数·矩阵·预编码算法
chsmiao3 天前
深度学习之线性代数
人工智能·深度学习·线性代数