/*
* 场景动画:
* mian()函数结构支持动画,只需要设计display()函数随时间改变绘制的东西
* 场景的每一次绘制叫一帧,调用display()函数的频率叫做帧率
* 在程序逻辑中移动的速率可以通过自前一帧到目前经过的时间来控制
* (所以将currentTime作为display()函数的参数)
*/
/*
* 用来构建矩阵变换的GLSL函数:
* 存储自己写的3D变换矩阵的GLSL数据类型是mat4
* GLSL中用于初始化mat4矩阵的语法以列为单位读入值。
*/
//在GLSL中构建变换矩阵:
#include<glm/glm.hpp>
#include<glm/gtc/matrix_transform.hpp>
#include<glm/gtc/type_ptr.hpp>
using namespace glm;
//构建并返回平移矩阵
mat4 bulidTranslate(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轴的旋转矩阵
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轴的旋转矩阵
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轴的旋转矩阵
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;
}
//构建并返回缩放矩阵
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;
}
学习笔记:用来构建矩阵变换的GLSL函数
最新推荐文章于 2023-07-03 11:16:46 发布