gpt4 book ai didi

android - getOrientation() 俯仰反射(reflect)地平线

转载 作者:行者123 更新时间:2023-11-30 04:04:33 37 4
gpt4 key购买 nike

我注意到,当我将手机放在地平线以下时,我得到 > -90。当我开始倾斜手机使其指向天空时,它会反射大约 -90 左右、-88、-90、-88。当它从地面倾斜到天空时。

有没有人遇到过这种情况。 (它似乎与 remapCoordinateSystem 无关)。 (我之前已将其注释掉)。当手机摄像头指向地面时,俯仰读数为零。当它指向天花板时,它也为零。

感谢您的帮助。

    @Override
public void onSensorChanged(SensorEvent event) {
synchronized (MainActivity.this) { // TilteController
switch (event.sensor.getType()) {
case Sensor.TYPE_MAGNETIC_FIELD:
mMagneticValues = event.values.clone();
break;
case Sensor.TYPE_ACCELEROMETER:
mAccelerometerValues = event.values.clone();
break;
}

if (mMagneticValues != null && mAccelerometerValues != null) {
SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();

switch (rotation)
{
case Configuration.ORIENTATION_LANDSCAPE:
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_MINUS_X, R);//shouldnt be the same R in and out
case Configuration.ORIENTATION_PORTRAIT:
SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_X, R);//shouldnt be the same R in and out
}


float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);

mAzimuth = orientation[0];
mPitch = orientation[1];
mRoll = orientation[2];

dirText.setText("Azimuth, Pitch, Roll || " + radStr(mAzimuth) +", "+ radStr(mPitch) +", "+ radStr(mRoll));

glView.rotate((float)Math.toDegrees(mAzimuth),(float)Math.toDegrees(mPitch),(float)Math.toDegrees(mRoll));
//glView.azimuth=(float)Math.toDegrees(smooth(mAzimuth));
glView.pitch=(float)(Math.toDegrees(smooth(mPitch)));//-90 makes it cenetr
//glView.roll=(float)Math.toDegrees(smooth(-mRoll));
//Log.i("Azimuth, Pitch, Roll", mAzimuth+", "+mPitch+", "+mRoll);
}
}
}

针对我的需要的临时解决方案是在调用获取方向之前旋转矩阵。

Matrix.rotateM(R, 0, 90, 0, 1, 0);

无论你如何进行完整的翻转,它都会遇到同样的问题。 (这应该通过添加方位角来解决)但这不是一个绝妙的解决方案。

因此,如果其他人正在阅读本文并试图将地平线设为 0 度。之前旋转矩阵,而不是旋转显示器(我使用的是 OpenGL)

最佳答案

结束横向锁定应用程序并应用以下内容

    SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);

Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();

SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, R);//shouldnt be the same R in and out

float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);

关于android - getOrientation() 俯仰反射(reflect)地平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957503/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com