我正在开发一款应用程序,它涉及到在我的android屏幕上根据方向绘制一条线,并可能需要一些帮助或指针。
这条线是以以下方式绘制的:如果手机保持平坦,那么这条线就会收缩,变成一个点,随着手机倾斜和定位,线变得更大-即手机站起来,线指向下,最大幅度为9.8,保持平坦,这是一个小点。重要的是,无论手机以什么角度握住,箭头总是指向下方--即重力线。
现在我知道了如何计算电话的偏航、俯仰和滚动角,但在数学上,我有点迷茫于如何从这些信息中推导出这条线的向量-任何指针都将是最受欢迎的。
谢谢
发布于 2011-02-28 04:00:09
好的,我在复制岛源和Nvidia论文的帮助下弄明白了这一点。
一旦你有了TYPE_ORIENTATION传感器的俯仰、侧滚和偏航读数:
@Override
public void onSensorChanged(SensorEvent event)
{
synchronized (this)
{
m_orientationInput[0] = x;
m_orientationInput[1] = y;
m_orientationInput[2] = z;
canonicalOrientationToScreenOrientation(m_rotationIndex, m_orientationInput, m_orientationOutput);
// Now we have screen space rotations around xyz.
final float horizontalMotion = m_orientationOutput[0] / 90.0f;
final float verticalMotion = m_orientationOutput[1] / 90.0f;
// send details to renderer....
}
}下面是canonicalOrientationToScreenOrientation函数:
// From NVIDIA http://developer.download.nvidia.com/tegra/docs/tegra_android_accelerometer_v5f.pdf
private void canonicalOrientationToScreenOrientation(int displayRotation, float[] canVec, float[] screenVec)
{
final int axisSwap[][] =
{
{ 1, -1, 0, 1 }, // ROTATION_0
{-1, -1, 1, 0 }, // ROTATION_90
{-1, 1, 0, 1 }, // ROTATION_180
{ 1, 1, 1, 0 } // ROTATION_270
};
final int[] as = axisSwap[displayRotation];
screenVec[0] = (float)as[0] * canVec[ as[2] ];
screenVec[1] = (float)as[1] * canVec[ as[3] ];
screenVec[2] = canVec[2];
}https://stackoverflow.com/questions/5131292
复制相似问题