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

小结

相关推荐
qq_433554542 小时前
C++ 状压DP(01矩阵约束问题)
c++·算法·矩阵
Zevalin爱灰灰4 小时前
线性代数 第一章——行列式
线性代数
牧歌悠悠5 小时前
【Random Matrices】第一章-随机矩阵入门
线性代数·数学·概率论·随机矩阵·高维概率
iAkuya1 天前
(leetcode)力扣100 21搜索二维矩阵2(z型搜索)
linux·leetcode·矩阵
一碗姜汤1 天前
LS性能边界、QR分解、RLS自适应
线性代数·机器学习
CreasyChan1 天前
数学基础-矩阵与变换
线性代数·矩阵
com_4sapi1 天前
2026年矩阵系统三家优质服务商可靠支撑
线性代数·矩阵
会编程是什么感觉...1 天前
算法 - FOC
线性代数·算法·矩阵·无刷电机
MicroTech20251 天前
MLGO微算法科技发布改进量子ODE算法,支持不可对角化矩阵与非齐次系统实现指数级误差优化
科技·算法·矩阵
不解风水2 天前
【教程笔记】KalmanFilter
笔记·学习·算法·矩阵·ekf