기기의 화면이 사용자를 향하고 있는지, 예를 들어 화면이 위를 향하거나 아래를 향하고 있는지 등을 알 수있는 방법을 이해하려고합니다.안드로이드에서 핸드폰을 향한 위치 얻기
오리엔테이션 센서를 사용하지 않습니다. 저는 회전 매트릭스를 사용하고 있습니다. 피치와 롤 값은 정보를 얻는 것이 좋지만, 그 값을 얻기 전에 remapcoordinatesystem과 어느 차축이 X이고 어떤 차축이 화면인지를 알아야합니다. 예를 들어
: 화면은 사용자에 직면하면 나는이 매핑 테이블
ROTATION_0 X Y
ROTATION_90 -Y X
ROTATION_180 을 사용할 수 있습니다 -X -Y
ROTATION_270 Y -X
화면이 어쩌면 내가 Z 축과 Y 축 교체해야하지만 내가 직면하고있는 화면 어디 있는지 알 수있는 방법을 모르는 하늘을 향하게됩니다.
아이디어가 있으십니까?
나는 웹에서이 방법을 사용하고 있습니다. (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;
}
사람은 하나 더있다?
누군가가 화면을 거꾸로 읽으면 어떻게 될까요? 침대에 누워있을 때? 그렇다면이 솔루션은 전혀 작동하지 않습니다. 당신은 또한 얼굴 인식을 할 수있을 것 같아요. 조금 지나친 것 같아요. –