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

小结

相关推荐
淡海水19 小时前
01-10-认知篇-对比-方案选型矩阵
矩阵·c#·excel·游戏开发·luban
凌冰_1 天前
数据结构 - 矩阵(九)
算法·矩阵
RoseRyan2 天前
企业如何选型AI模型平台:从业务目标到多模型矩阵的七步决策框架
人工智能·线性代数·矩阵
凌冰_2 天前
数据结构 - 数组(八)
数据结构·算法·矩阵
EatFan2 天前
扩散大模型推理加速进入工程化:d3LLM、DeepInfer 与 Dynamo 兼容矩阵怎么接
线性代数·矩阵
林中漫步—柚2 天前
线性代数期末判断题总错?矩阵的秩与方程组结论清单(带成立条件)
线性代数·学习笔记·概率论·考研数学·期末复习
小小-猿3 天前
CATLASS:昇腾上的高性能矩阵乘模板库
线性代数·矩阵·cann·catlass
小白的高手之路3 天前
【LeetCode 热题 100】240. 搜索二维矩阵 II|矩阵、二分查找、Z 字形查找(Python)
python·算法·leetcode·矩阵·力扣
Regulus-Moon8 天前
人工智能数学基础:矩阵特征分解与压缩实战
人工智能·线性代数·矩阵