将glm四元数转换为旋转矩阵并将其与opengl一起使用 [英] Converting glm quaternion to rotation matrix and using it with opengl

查看:729
本文介绍了将glm四元数转换为旋转矩阵并将其与opengl一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我将对象的方向存储在glm :: fquat中,我想用它来旋转我的模型.我该怎么办?

so i have the orientation of my object stored in a glm::fquat and i want to use it to rotate my model. how do i do that?

我尝试过:

glPushMatrix();
   glTranslatef(position.x, position.y, position.z);
   glMultMatrixf(glm::mat4_cast(orientation));
   glCallList(modelID);
glPopMatrix();

但是我得到了这个错误:

but i got this error:

error: cannot convert 'glm::detail::tmat4x4<float>' to 'const GLfloat* {aka const float*}' for argument '1' to 'void glMultMatrixf(const GLfloat*)'|

我显然做错了什么,那正确的方法是什么?

im obviously doing something wrong so whats the correct way to do it?

推荐答案

GLM不会/不能(?)自动将mat4强制转换为GLfloat*,因此

GLM won't/can't(?) automagically cast a mat4 to GLfloat* so you have to help it along a bit.

尝试一下:

#include <glm/gtc/type_ptr.hpp> 
glMultMatrixf( glm::value_ptr( glm::mat4_cast(orientation) ) );

这也可能起作用:

glMultMatrixf( &glm::mat4_cast(orientation)[0][0] );

这篇关于将glm四元数转换为旋转矩阵并将其与opengl一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆