我有一些来自传感器设备的数据,比如加速度计x,y,z和一个四元数。使用这些信息,我想在安卓OpenGL视图中渲染一个“线条图像”。关于如何将加速度值转换为可由OpenGL glTranslatef和glRotatef函数使用的内容,有人能帮我一下吗?
发布于 2015-03-15 02:30:05
您不应该使用不推荐使用的glrotate或glrotate。相反,只需直接管理正确的转换矩阵。
可以使用以下命令将四元数转换为矩阵:(sourced from my previous code)
float[] quatToMat(quaternion q, float* result)
{
//based on algorithm on wikipedia
// http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion
float w = q.scalar ();
float x = q.x();
float y = q.y();
float z = q.z();
float n = x*x + y*y + z*z + w*w;
float s = n == 0? 0 : 2 / n;
float wx = s * w * x, wy = s * w * y, wz = s * w * z;
float xx = s * x * x, xy = s * x * y, xz = s * x * z;
float yy = s * y * y, yz = s * y * z, zz = s * z * z;
return new float[]{ 1 - (yy + zz), xy + wz , xz - wy ,0,
xy - wz , 1 - (xx + zz), yz + wx ,0,
xz + wy , yz - wx , 1 - (xx + yy),0,
0 , 0 , 0 ,1 };
}如果你仍然想使用固定的函数管道,那就把它推到glMultMatrix中。
https://stackoverflow.com/questions/29052557
复制相似问题