- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我注意到,当我将手机放在地平线以下时,我得到 > -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/
除了 Display.getOrientation() 已弃用之外,Display.getRotation() 和 Display.getOrientation() 之间还有什么区别? 是否都返回等于
我想了解 Android 传感器管理。如果我希望包含陀螺仪以获取手机方向,当我调用 getOrientation(..) 并且手机具有陀螺仪传感器时,它会自动完成,我说得对吗? 因此,如果手机有加速度
安卓getOrientation()函数说: 索引 0 处的值:方位角介于 pi 和 -pi 之间 索引 1 处的值:音高介于 pi 和 -pi 之间 索引 2 处的值:Roll 在 -pi/2 和
我遇到了一个非常烦人的问题,AR View 就像一个指南针。因此,当我纵向握住手机(这样屏幕就指向我的脸)时,我会调用 remapCoordinateSystem纵向握住时音高为0。然后方位角(罗盘功
我正在为平板电脑开发一个应用程序,平板电脑将放在一个围绕给定点旋转的支架上。这意味着当应用程序首次打开时,很少从平板电脑移动。该应用程序将根据平板电脑在支架上的旋转显示各种内容。无论我多么努力地搜索,
我目前在 Android 上使用加速度计,遇到了一个有趣的情况。我需要找出以下各项的最大值,而无需最终用户在某些精心设计的校准程序中翻转手机。我正在寻找的具体值是... @Override publi
我需要检索手机的方向。目前我写了这个: public void onSensorChanged(SensorEvent event) { switch (event.sensor.getType(
我正在创建 3D Compass 应用程序。 我正在使用 getOrientation获取方向的方法(几乎与 here 相同的实现)。如果我将手机放在 table 上,效果很好,但是当手机顶部指向天空
我使用 Sensor.TYPE_ORIENTATION 来确定设备的当前角度,但 TYPE_ORIENTATION 在 API 版本 8 上已弃用。在 SensorManager 手册中,它引用了 g
我有一个在 fragment 中实现的 RecyclerView,我正在尝试向代码中添加分隔符。我让 RecylcerView 按预期工作,但 LinearLayoutManager 无法解析 get
如何用getOrientation函数获取真北和磁北? getOrientation 函数在第二个参数中返回带有方位角、俯仰角和横滚角的 float[3]...我如何根据这些值计算出真正的北方? 谢谢
我在以下的帮助下获得了我的手机方向 SensorManager.getOrientation 但是结果很不稳定,大概+-8度,有什么好的过滤结果的方法吗? 这是我获取值的方式: public void
假设:手机平放(与地面平行)。 我正在使用 getRotationMatrix() 和 getOrientation (float[] R, float[] values) 获取方位角。在这个假设下,
我在使用 getOrientation 时遇到了一些麻烦。我在横向模式下运行我的应用程序,但我在使用一个轴时遇到了问题。代码中有更多解释,一些图像: valuesMagnet = n
我注意到,当我将手机放在地平线以下时,我得到 > -90。当我开始倾斜手机使其指向天空时,它会反射大约 -90 左右、-88、-90、-88。当它从地面倾斜到天空时。 有没有人遇到过这种情况。 (它似
我一直在努力使用 getOrientation 获取设备的实际方向。通过 TYPE_ACCELEROMETER 和 TYPE_MAGNETIC_FIELD 获取加速度计和磁场读数与通过 TYPE_OR
我正在用 android 开发一个应用程序。该应用程序在数据库中保存了一些引号,我想使用手机的传感器在屏幕上滑动引号。所以我希望当手机向左移动时,我可以在屏幕上看到下一个报价,当我将手机向右移动时,我
本文整理了Java中us.ihmc.yoVariables.variable.YoFramePoseUsingYawPitchRoll.getOrientation()方法的一些代码示例,展示了YoF
我想弄清楚 getRotationMatrix() 和 getOrientation() 是如何工作的。 到目前为止,我已经知道在 getRotationMatrix() 函数中,它将重力矢量与磁矢量
要在 Android 中从欧拉角(例如俯仰、滚转、方位角)中获取方向,需要执行以下操作: SensorManager.getRotationMatrix(float[] R, float[] I, f
我是一名优秀的程序员,十分优秀!