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

小结

相关推荐
LayZhangStrive8 小时前
线性代数 - 第1章 行列式
人工智能·线性代数·机器学习
CreBee13 小时前
CreBee功能大全:新媒体矩阵运营有哪些能力?
矩阵·新媒体运营·媒体
爱吃提升1 天前
MATLAB矩阵运算完全指南:从生成到索引操作
数据结构·matlab·矩阵
天天有money1 天前
API中转站在社媒矩阵里的价值:多平台文案如何统一改写
gpt·线性代数·ai·chatgpt·矩阵
哈德森hh2 天前
Twitter矩阵号怎么搭建?如何通过矩阵运营提升引流效果?
矩阵·twitter
小小帅呀2 天前
CUDA编程实战09:CUDA Graph 实战——降低重复 Kernel 与流水线提交开销
c++·人工智能·矩阵
良木林2 天前
矩阵 - LeetCode hot 100
线性代数·算法·leetcode·矩阵
小小帅呀2 天前
CUDA编程实战06:矩阵乘法优化——从朴素 GEMM 到共享内存分块
线性代数·矩阵
TKcloudmaster_H2 天前
规避风控稳运营!TK云大师定制脚本赋能TikTok矩阵规模化运营
大数据·人工智能·矩阵·自动化·新媒体运营·流量运营
cxr8282 天前
第3章 技术端——弹性矩阵与破格协议
线性代数·矩阵