Android 陀螺仪 - OpenGL LookAt 位置

标签 android opengl-es sensors gyroscope

我想通过陀螺仪传感器的能力得到我想“”的X、Y、Z位置的精确位置

我能够从陀螺仪传感器获得 9 的值,但我无法计算出从该陀螺仪传感器获得准确位置的公式。

我想要公式或例子来得到正确的答案

这是我想要结果的代码

double standX = 0.0f, standY = 0.0f, standZ = 0.0f;
double lookX = 0.0f, lookY = 0.0f, lookZ = 1.0f;
double headupX = 0.0f, headupY = 1.0f, headupZ = 0.0f;
float[] deltaRotationMatrix = new float[9];
SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);

// code here

// in my onDraw
// I'm trying to make the lookAt position proper
Matrix.setLookAtM(mViewMatrix, 0, 
        eyeX, eyeY, eyeZ, lookX, lookY, lookZ, headupX , headupY, headupZ);

结果示例如下:

example of x=0, y=0, z=-1

example of x=0, y=1, z=0

example of x=1, y=0, z=1

最佳答案

我问完了 这是我的解决方案

首先,我需要制作这 3 个矩阵以获得 x、y、z 位置的结果

private float[] mRotXMatrix = new float[] {
 1, 0, 0, 0, 
 0, 0, 1, 0,
 0, 1, 0, 0,
 0, 0, 0, 1 };
private float[] mRotYMatrix = new float[] {
 0, 0, 1, 0,
 0, 1, 0, 0,
 1, 0, 0, 0,
 0, 0, 0, 1 };
private float[] mRotZMatrix = new float[] { 
 0, 1, 0, 0,
 1, 0, 0, 0,
 0, 0, 1, 0,
 0, 0, 0, 1 };

然后在 onSensorChanged(SensorEvent e) 方法中,我像这样旋转所有这 3 个矩阵以及我的相机 View

Matrix.multiplyMM(mViewMatrix, 0, deltaRotationMatrix, 0, mViewMatrix, 0);
Matrix.multiplyMM(mRotXMatrix, 0, deltaRotationMatrix, 0, mRotXMatrix, 0);
Matrix.multiplyMM(mRotYMatrix, 0, deltaRotationMatrix, 0, mRotYMatrix, 0);
Matrix.multiplyMM(mRotZMatrix, 0, deltaRotationMatrix, 0, mRotZMatrix, 0);

要获取相机 View 的 X、Y、Z,只需从这些矩阵中获取即可

viewX = mRotXMatrix[2];
viewY = -mRotYMatrix[6]; // +/- up to your initial camera view
viewZ = mRotZMatrix[10];

关于Android 陀螺仪 - OpenGL LookAt 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11825993/

相关文章:

java - Android长字符串连接,

java - 在 ListView 数组上使用 strings.xml 项目

android - 这里 SDK Android 缩放到几个标记

android - 中断到我的应用程序的链接

java - 如何在 3D 应用程序中定义和标准化单位?

matlab - 使用卡尔曼滤波器估计位置

iOS 内存警告破坏 EAGLView

opengl-es - 将 DirectX 移植到 OpenGL ES (iPhone)

ios - iphone X 最大加速度计和陀螺仪频率

Arduino 温度传感器倒计时