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

小结

相关推荐
xier_ran1 天前
Python 切片(Slicing)完全指南:从基础到多维矩阵
开发语言·python·矩阵
lijil1681 天前
Hypermesh估算发动机缸体质量矩阵
线性代数·矩阵
FanXing_zl2 天前
快速掌握线性代数:核心概念与深度解析
线性代数·算法·机器学习
点云SLAM2 天前
四元数 (Quaternion)微分-四元数导数的矩阵表示推导(8)
线性代数·算法·计算机视觉·矩阵·机器人·slam·四元数
西西弗Sisyphus2 天前
四元数(Quaternion)、叉积(Cross Product)与点积(Dot Product)之间的关系
线性代数·机器学习·行列式·叉积·点积·四元数
YaraMemo2 天前
对称/Hermitian矩阵相关记号
线性代数·5g·矩阵·信息与通信
ChoSeitaku2 天前
线代强化NO7|秩|矩阵的秩|向量组的秩|极大线性无关组|公式
线性代数·矩阵·概率论
不穿格子的程序员3 天前
从零开始写算法——二分-搜索二维矩阵
线性代数·算法·leetcode·矩阵·二分查找
dingzd953 天前
跨平台账号矩阵高效协同术
线性代数·矩阵·web3·facebook·tiktok·instagram·clonbrowser
一勺汤3 天前
YOLO12 改进、魔改|秩增强线性注意力RALA,通过增强 KV 缓冲与输出特征的矩阵秩,增强 YOLO 对小目标、复杂场景目标的识别能力
线性代数·yolo·矩阵·yolov12·yolo12·yolo12改进·小目标