デバイスの画面がユーザーに向いているかどうか、またはたとえば、画面が上を向いているか下を向いているテーブルの上に平らにあるかどうかを知る方法を理解しようとしています.
回転マトリックスを使用しているため、方向センサーは使用していません。その情報を取得するには、ピッチとロールの値が適切であることはわかっていますが、これらの値を取得する前に、座標系を再マッピングし、どの車軸がどの車軸であるかを知る必要があります。 X と Y はどちらが画面に向いているかを知る必要があります。
例: 画面がユーザーの方を向いている場合、このマッピング テーブルを使用できます。
ROTATION_0 X Y
ROTATION_90 -Y X
ROTATION_180 -X -Y
ROTATION_270 Y -X
画面が空を向いている場合は、Y 軸を Z 軸と交換する必要があるかもしれませんが、画面がどこを向いているかを知る方法がわかりません。
何か案は?
また、Web で見つけたこの方法も使用しています (http://code.google.com/p/the-schwartz-unsheathed/source/browse/trunk/src/com/android/app/schwarz/PhoneOrientation) .java?r=12)
public static int getOrientation(float roll, float pitch) {
int orientation = ORIENTATION_INVALID;
if (Math.abs(roll) == 0.0 && Math.abs(pitch) == 0.0){
return ORIENTATION_INVALID;
}
if(roll >= -90 && roll <= -(90-mTolerance)){
orientation = ORIENTATION_FACE_LEFT;
}
else if(roll <= 90 && roll >= (90-mTolerance)){
orientation = ORIENTATION_FACE_RIGHT;
}
if(pitch >= (90-mTolerance) && pitch <= (90+mTolerance)) {
if(orientation != ORIENTATION_INVALID){
orientation = ORIENTATION_INVALID;
}
else {
orientation = ORIENTATION_FACE_FORWARD;
}
} else if(pitch <= -(90-mTolerance) && pitch >= -(90+mTolerance)) {
if(orientation != ORIENTATION_INVALID) {
orientation = ORIENTATION_INVALID;
}
else {
orientation = ORIENTATION_FACE_BACKWARD;
}
}
if((roll >= -mTolerance && roll <= mTolerance)) {
if((pitch >= -mTolerance && pitch <= mTolerance)) {
if(orientation != ORIENTATION_INVALID) {
orientation = ORIENTATION_INVALID;
}
else {
orientation = ORIENTATION_FACE_UP;
}
} else if((pitch <= -(180-mTolerance) && pitch >= -180) || (pitch >= (180-mTolerance) && pitch <= 180)) {
if(orientation != ORIENTATION_INVALID) {
orientation = ORIENTATION_INVALID;
}
else {
orientation = ORIENTATION_FACE_DOWN;
}
}
}
return orientation;
}
誰かがより良いものを持っていますか?