- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一款 Android 游戏,我想弄清楚用户是将设备向左倾斜还是向右倾斜(类似于将人左右移动时 Temple Run 的工作原理)。
我已经阅读了许多教程和示例并制作了示例应用程序,但我从陀螺仪和加速度计返回的数据量非常大。我是否需要两组硬件来确定用户是否倾斜设备以及朝哪个方向倾斜?
我当前的应用程序正在检测每一个轻微的运动,这显然是不正确的。
public class Main extends Activity {
private SensorManager mSensorManager;
private float mAccel; // acceleration apart from gravity
private float mAccelCurrent; // current acceleration including gravity
private float mAccelLast; // last acceleration including gravity
private RelativeLayout background;
private Boolean isleft = true;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
this.background = (RelativeLayout) findViewById(R.id.RelativeLayout1);
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 0.00f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
/* float x1, x2, y1, y2;
String direction;
switch(event.getAction()) {
case(MotionEvent.ACTION_DOWN):
x1 = event.getX();
y1 = event.getY();
break;
case(MotionEvent.ACTION_UP) {
x2 = event.getX();
y2 = event.getY();
float dx = x2-x1;
float dy = y2-y1;
// Use dx and dy to determine the direction
if(Math.abs(dx) > Math.abs(dy)) {
if(dx>0) directiion = "right";
else direction = "left";
} else {
if(dy>0) direction = "down";
else direction = "up";
}
}
}*/
}
private final SensorEventListener mSensorListener = new SensorEventListener() {
public void onSensorChanged(SensorEvent se) {
float x = se.values[0];
float y = se.values[1];
float z = se.values[2];
if((mAccelLast<mAccelCurrent)&&(isleft == true)){
background.setBackgroundResource(R.drawable.bg_right);
isleft = false;
}
if((mAccelLast>mAccelCurrent)&&(isleft == false)){
background.setBackgroundResource(R.drawable.bg_left);
isleft = true;
}
mAccelLast = mAccelCurrent;
mAccelCurrent = (float) Math.sqrt((double) (x*x + y*y + z*z));
float delta = mAccelCurrent - mAccelLast;
Log.d("FB", "delta : "+delta);
mAccel = mAccel * 0.9f + delta; // perform low-cut filter
// Log.d("FB", "mAccel : "+mAccel);
}
我只使用加速度计、陀螺仪会更好还是两者都需要?
最佳答案
这篇文章链接到两者之间的区别:Android accelerometer and gyroscope
http://diydrones.com/profiles/blogs/faq-whats-the-difference
http://answers.oreilly.com/topic/1751-mobile-accelerometers-and-gyroscopes-explained/
文档也有帮助:http://developer.android.com/guide/topics/sensors/sensors_motion.html
根据我非常有限的经验,陀螺仪不断测量 x、y、z 旋转并不断更新。用于在游戏中驾驶汽车/飞机/角色。加速度计有点像 Wii-mote,用于摆动或拾取摇动手势。
关于Android 陀螺仪与加速度计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12140521/
我需要一种方法来从局部获取全局引用系中旋转的欧拉角。我正在使用 c#、wpf 3d 和陀螺仪。我在屏幕上有一个地球仪,它应该以与陀螺仪相同的方式移动。由于陀螺仪发送相对于自身的运动,我需要使用四元数来
我试图理解不同的运动/位置陀螺仪、运动和加速度所代表的含义。 (startGyroUpdates、startDeviceMotionUpdates 等)。 但是,经过一些研究后,我很难看出陀螺仪和运动
我想使用陀螺仪、加速度计和磁力计来获得 3 轴完全平滑的旋转。 第一个问题是我的输出有很大的噪音,我想知道如何消除它。 第二个问题是陀螺仪漂移,我认为应该用卡尔曼滤波器来解决。 第三个问题是加速度计。
我正在开发一个游戏,需要检测设备是否向上或向下移动以向上或向下移动角色,因为我正在使用陀螺仪(如果有更好的方法请纠正我) 但是陀螺仪对我来说非常复杂(因为我不太了解 phisyc),所以我不知道如何根
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and t
我一直在尝试确定如何将 iPhone 陀螺仪用于驾驶员安全应用程序,但我对此感到非常困惑。我知道手机中的陀螺仪可以测量手机本身的变化和旋转,但是它可以用来测量手机在行驶的汽车中发生的变化吗? 例如,如
我正在尝试创建一个应用程序来跟踪设备在 2D 空间中的移动。在网上查了下,我能找到的一种方法是积分两次线性加速,但是错误很可怕。 这个问题有什么解决办法吗?我希望能够向上移动手机,这会导致在屏幕上绘制
我正在使用 Unity 制作一款使用陀螺仪的游戏。我正在尝试检测设备围绕穿过屏幕的轴的旋转,我假设它是 Unity Space 中的 Z 轴。我尝试使用 Input.gyro.attitude.eul
我正在学习使用 iOS 中的陀螺仪传感器编写应用。是否有处理陀螺仪的类,类似于加速度计的 UIAcceleration/UIAccelerometer/UIAccelerometerDelegate?
我想通过陀螺仪传感器的能力得到我想“看”的X、Y、Z位置的精确位置 我能够从陀螺仪传感器获得 9 的值,但我无法计算出从该陀螺仪传感器获得准确位置的公式。 我想要公式或例子来得到正确的答案 这是我想要
最近我做了一些研究,使用加速度计 + 陀螺仪来使用这些传感器在没有 GPS 帮助的情况下跟踪智能手机(见这篇文章) Indoor Positioning System based on Gyrosco
我正在测试 Core Motion 并使用陀螺仪。现在我得到了我不理解的值(value)观。我的假设是对于每个 x、y 和 z,我会得到一个 0-360 之间的值,这将是一个完整的旋转,但事实并非如此
我正在尝试使用陀螺仪制作一个简单的应用程序,其中角色会根据 iPad 1 的旋转进行移动。 我的代码无法正常工作,因此我测试了原始、俯仰、偏航的值,无论我如何移动设备,它们实际上都保持为零。我确定 i
我有一个非常简单的应用程序,我试图通过核心运动使用陀螺仪。 此时,出于测试目的,我只是获取滚动、俯仰和偏航的值并在屏幕上打印。根据下图,据我所知,roll、pitch、yaw分别对应红、绿、蓝轴,对吗
我正在使用 Core Motion,并且收到“展开可选值时意外发现 nil”,但只有大约一半的时间加载应用程序。如何更正下面的代码,使其稳定? import UIKit import CoreMoti
我有一些代码旨在测量移动设备上的设备运动,它曾经可以在移动浏览器中运行,但现在不再可以了。以下是直接取自 Mozilla 网络文档的示例: function handleMotionEvent(eve
Original Question 我正尝试在我的 iPhone 6s 上使用 A-Frame 运行一个 webVR 程序,而我测试过的这三个浏览器无法访问我的陀螺仪。 Safari Chrome F
我想知道 Apple 开发人员是否可以澄清 API 是否可用。 互联网上有一些猜测,似乎没有人回答这个问题。 或多或少,Apple Watch OS 2.0 并不是最容易使用的测试版,甚至发行版似乎也
我想制作一个应用程序来获取 Android 手机的所有读数,例如加速度计、GPS、陀螺仪、摄像头等。记录所有这些数据并将其发送到云端以供使用。 我是一名初学者 android 开发人员,想基本了解如何
我是一名优秀的程序员,十分优秀!