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

小结

相关推荐
菜鸡儿齐9 小时前
leetcode-搜索二维矩阵
算法·leetcode·矩阵
炽烈小老头9 小时前
【每天学习一点算法 2026/02/24】矩阵置零
学习·算法·矩阵
有为少年9 小时前
Monarch矩阵:从设计直觉到数学推导与实际应用
人工智能·深度学习·学习·线性代数·机器学习·计算机视觉·矩阵
壹通GEO1 天前
AI-GEO内容矩阵:打造永不枯竭的流量池
人工智能·线性代数·矩阵
xhyu611 天前
【学习笔记】推荐系统 (3.召回:矩阵补充、线上服务、双塔模型)
笔记·学习·矩阵
好记忆不如烂笔头abc1 天前
不同 Oracle 版本的客户端/服务器互操作性支持矩阵
服务器·oracle·矩阵
YGGP2 天前
【Golang】LeetCode 54. 螺旋矩阵
算法·leetcode·矩阵
逆境不可逃2 天前
LeetCode 热题 100 之 73.矩阵置零(含图解)
线性代数·矩阵
0 0 02 天前
CCF-CSP 34-2 矩阵重塑(其二)(reshape2)【C++】考点:矩阵转置模拟
开发语言·c++·算法·矩阵
AI科技星3 天前
时空的几何本源与物理现象的建构:论统一场论的宇宙二元论与观察者中心范式
人工智能·线性代数·算法·矩阵·数据挖掘