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

小结

相关推荐
清 晨3 小时前
TikTok矩阵运营的提速方法
线性代数·矩阵·web3·facebook·tiktok·instagram·clonbrowser
ChoSeitaku13 小时前
线代强化NO4|行列式的计算
线性代数·机器学习·矩阵
西西弗Sisyphus15 小时前
如何找到一个矩阵的特征值和特征向量
线性代数·矩阵·特征值·特征向量
学好statistics和DS1 天前
三个好思路:SQL并行化处理、混淆矩阵和特征交叉
数据库·sql·矩阵
前端炒粉1 天前
21.搜索二维矩阵 II
前端·javascript·算法·矩阵
爱代码的小黄人1 天前
一般角度的旋转矩阵的推导
线性代数·算法·矩阵
西西弗Sisyphus2 天前
线性代数 - 特征值和特征向量可视化是什么样的
线性代数·特征值·特征向量
passxgx2 天前
10.7 密码学中的线性代数
线性代数·密码学
phoenix@Capricornus2 天前
多项分布 (Multinomial Distribution)
线性代数·机器学习·概率论
在路上看风景2 天前
1.8 分块矩阵
线性代数·矩阵