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_4308558812 小时前
线代第五章线性方程组第五节:矩阵的对角化
线性代数·矩阵
知识在于积累14 小时前
在指定条件下获取布尔矩阵中的索引矩阵
矩阵·索引·布尔矩阵
wa的一声哭了16 小时前
矩阵分析 方阵幂级数与方阵函数
人工智能·python·线性代数·算法·自然语言处理·矩阵·django
wa的一声哭了17 小时前
矩阵分析 单元函数矩阵微积分和多元向量值的导数
linux·c语言·c++·线性代数·算法·矩阵·云计算
老歌老听老掉牙17 小时前
SymPy 中矩阵乘法的顺序与元素类型分析
python·矩阵·sympy
POLITE317 小时前
Leetcode 54.螺旋矩阵 JavaScript (Day 8)
javascript·leetcode·矩阵
鲨莎分不晴18 小时前
从“像素对”到“纹理感”:深度解析灰度共生矩阵 (GLCM)
线性代数·矩阵
轻微的风格艾丝凡18 小时前
模型拆解--Variable Inductance Modeling
线性代数·simulink
雾喔20 小时前
1970. 你能穿过矩阵的最后一天 + 今年总结
线性代数·算法·矩阵
AI科技星1 天前
张祥前统一场论宇宙大统一方程的求导验证
服务器·人工智能·科技·线性代数·算法·生活