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 CHallEnge of THe BrAve3 小时前
工业相机中CCM使能参数-色彩校正矩阵
数码相机·线性代数·矩阵
小美爱刷题3 小时前
力扣DAY63-67 | 热100 | 二分:搜索插入位置、搜索二维矩阵、排序数组查找元素、搜索旋转排序数组、搜索最小值
算法·leetcode·矩阵
NorthFish北海有鱼4 小时前
python三维矩阵的维度
python·矩阵·numpy
该怎么办呢21 小时前
webgl入门实例-11模型矩阵 (Model Matrix)基本概念
线性代数·矩阵·webgl
海码0071 天前
【Hot100】 73. 矩阵置零
c++·线性代数·算法·矩阵·hot100
烟锁池塘柳01 天前
齐次坐标系下的变换矩阵
线性代数·数学建模·矩阵
该怎么办呢1 天前
webgl入门实例-11WebGL 视图矩阵 (View Matrix)基本概念
数码相机·矩阵·webgl
蔗理苦1 天前
2025-04-18 李沐深度学习3 —— 线性代数
人工智能·深度学习·线性代数
电气外传1 天前
小小矩阵设计
线性代数·矩阵
爱的叹息1 天前
软考高级信息系统项目管理师的【干系人参与度评估矩阵】详解
线性代数·矩阵