如何将glRotatef()转换为glMultMatrixd()的乘法矩阵
How to convert glRotatef() to multiplication matrice for glMultMatrixd()
我需要用不同的openGL函数执行一些操作。
我有一个初始化为glList的多维数据集。我要做的是对标准函数的变换我喜欢对矩阵乘法做完全相同的操作。但是我被旋转函数困住了。我想让立方体绕x轴旋转,例如90°:
glRotatef(90.0, 1.0f, 0.0f, 0.0f);
应替换为:
GLdouble m[16] ={1.0, 0.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0,-1.0, 0.0, 0.0,
0.0, 0.0, 0.0, 1.0 };
glMultMatrixd(m);
我发现这个非常有用的网站,但是它的功能与上面的不完全相同。是否有一个通用的原则如何将glRotatef()函数转换为gl变换矩阵?
更新:对不起,我错过了文档开头的重要说明,即文档中的矩阵需要转置才能在openGL中使用。
在x轴
| 1 0 0 0 |
M = | 0 cos(A) -sin(A) 0 |
| 0 sin(A) cos(A) 0 |
| 0 0 0 1 |
在Y-Axsis | cos(A) 0 sin(A) 0 |
M = | 0 1 0 0 |
| -sin(A) 0 cos(A) 0 |
| 0 0 0 1 |
在Z-Axsis | cos(A) -sin(A) 0 0 |
M = | sin(A) cos(A) 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
注意:OpenGL中的矩阵使用列主内存布局
的例子:
#include <math.h>
#define PI 3.14159265
// Rotate -45 Degrees around Y-Achsis
GLdouble cosA = cos(-45.0f*PI/180);
GLdouble sinA = sin(-45.0f*PI/180);
// populate matrix in column major order
GLdouble m[4][4] = {
{ cosA, 0.0, -sinA, 0.0}, // <- X column
{ 0.0, 1.0, 0.0, 0.0}, // <- Y column
{ sinA, 0.0, cosA, 0.0}, // <- Z column
{ 0.0, 0.0, 0.0, 1.0} // <- W column
};
//Apply to current matrix
glMultMatrixd(&m[0][0]);
//...
相关文章:
- 防止主数据类型C++的隐式转换
- 模板参数替换失败,并且未完成隐式转换
- 努力将整数转换为链表。不知道我在这里做错了什么
- HEX值到wchar_t字符(UTF-8)的转换
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将 Qvector<uint8_t> 转换为 QString
- 如何在cuSparse中使用cusparseXcoo2csr从coo转换为csc
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 在c++中使用nlohmann从类到json的转换
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 将Integer转换为4字节的unsined字符矢量(按大端字节顺序)
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- 复制列表初始化的隐式转换的等级是多少
- 正在将指针转换为范围
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 是否可以从int转换为enum类类型
- 了解 GLM- openGL 中的相机转换
- 如何将glRotatef()转换为glMultMatrixd()的乘法矩阵