센서 데이터 및 디스플레이 방향(HTML)

[ 이 문서는 Windows 런타임 앱을 작성하는 Windows에서 8.x 및 Windows Phone 8.x 개발자를 대상으로 합니다. Windows 10용으로 개발하는 경우에는 최신 설명서를 참조하세요.]

Accelerometer, Gyrometer, Compass, InclinometerOrientationSensor 클래스의 센서 데이터는 참조 축에 의해 정의됩니다. 이러한 축은 장치의 가로 방향에서 정의되고 사용자가 돌릴 때 장치와 함께 회전합니다. 앱이 자동 회전을 지원하는 경우,즉 사용자가 장치를 회전할 때 장치에 맞게 자동으로 방향이 조정되는 경우사용하기 전에 센서 데이터를 회전에 대해 조정해야 합니다.

디스플레이 방향 및 장치 방향

센서의 참조 축을 이해하려면 디스플레이 방향과 장치 방향을 구분해야 합니다. 디스플레이 방향은 텍스트 및 이미지가 화면에 표시되는 방향이고, 장치 방향은 장치의 실제 위치입니다. 다음 그림에서는 장치 및 디스플레이 방향이 둘 다 Landscape입니다.

디스플레이 및 장치 방향(Landscape)

다음 그림에서는 디스플레이 및 장치 방향이 둘 다 LandscapeFlipped입니다.

디스플레이 및 장치 방향(LandscapeFlipped)

다음 그림에서 디스플레이 방향은 Landscape이고 장치 방향은 LandscapeFlipped입니다.

디스플레이 방향은 Landscape이고 장치 방향은 LandscapeFlipped임

CurrentOrientation 속성과 함께 GetForCurrentView 메서드를 사용하여 DisplayInformation 클래스를 통해 방향 값을 쿼리할 수 있습니다. 그런 다음 DisplayOrientations 열거형과 비교하여 논리를 만들 수 있습니다. 지원하는 각 방향에 대해 참조 축을 해당 방향으로 변환할 수 있도록 지원해야 합니다.

가로 방향 우선 및 세로 방향 우선 장치

이제 제조업체에서 가로 방향 우선 장치와 세로 방향 우선 장치를 둘 다 생산하고 있습니다. 제조업체는 장치에 구성 요소를 통합할 때 모든 장치가 동일한 참조 프레임 내에서 작동하도록 일관된 통합 방식을 사용합니다. 다음 표에서는 가로 방향 우선 장치와 세로 방향 우선 장치의 센서 축을 보여 줍니다.

방향 가로 방향 우선 세로 방향 우선

Landscape

Landscape 방향의 가로 방향 우선 장치 Landscape 방향의 세로 방향 우선 장치

Portrait

Portrait 방향의 가로 방향 우선 장치 Portrait 방향의 세로 방향 우선 장치

LandscapeFlipped

LandscapeFlipped 방향의 가로 방향 우선 장치 LandscapeFlipped 방향의 세로 방향 우선 장치

PortraitFlipped

PortraitFlipped 방향의 가로 방향 우선 장치 PortraitFlipped 방향의 세로 방향 우선 장치

 

디스플레이 방향 및 나침반 제목

나침반 제목은 참조 축에 따라 달라지므로 장치 방향과 함께 변경됩니다. 다음 표에 따라 보완합니다(사용자가 북쪽을 향하고 있다고 가정).

디스플레이 방향 나침반 제목에 대한 참조 축 북쪽을 향하는 경우 API 나침반 제목 나침반 제목 보완

Landscape

-Z

0

제목

Portrait

90

(제목 + 270) % 360

LandscapeFlipped

Z

180

(제목 + 180) % 360

PortraitFlipped

270

(제목 + 90) % 360

 

여기에 표시된 대로 제목을 제대로 표시하기 위해 표와 같이 나침반 제목을 수정합니다.

function readingChanged(e) {
    var heading = e.reading.headingMagneticNorth;
    var displayOffset;

    // Calculate the compass heading offset based on
    // the current display orientation.
    var displayInfo = Windows.Graphics.Display.DisplayInformation.getForCurrentView();
    
    switch (displayInfo.currentOrientation) {
        case Windows.Graphics.Display.DisplayOrientations.landscape:
            displayOffset = 0;
            break;
        case Windows.Graphics.Display.DisplayOrientations.portrait:
            displayOffset = 270;
            break;
        case Windows.Graphics.Display.DisplayOrientations.landscapeFlipped:
            displayOffset = 180;
            break;
        case Windows.Graphics.Display.DisplayOrientations.portraitFlipped:
            displayOffset = 90;
            break;
     }

    var displayCompensatedHeading = (heading + displayOffset) % 360;

    // Update the UI...
}

가속도계 및 회전계를 사용한 디스플레이 방향

다음 표에서는 디스플레이 방향에 대한 가속도계 및 회전계 데이터를 변환합니다.

참조 축 X Z

Landscape

X

Z

Portrait

-X

Z

LandscapeFlipped

-X

-Y

Z

PortraitFlipped

-Y

X

Z

 

다음은 이러한 변환을 회전계에 적용하는 코드 예제입니다.

function readingChanged(e) {
    var reading = e.reading;
    var displayOffset;

    // Calculate the gyrometer axes based on
    // the current display orientation.
    var displayInfo = Windows.Graphics.Display.DisplayInformation.getForCurrentView();
    switch (displayInfo.currentOrientation) {
        case Windows.Graphics.Display.DisplayOrientations.landscape: 
            x_Axis = reading.angularVelocityX;
            y_Axis = reading.angularVelocityY;
            z_Axis = reading.angularVelocityZ;
            break;
        case Windows.Graphics.Display.DisplayOrientations.portrait: 
            x_Axis = reading.angularVelocityY;
            y_Axis = -1 * reading.angularVelocityX;
            z_Axis = reading.angularVelocityZ;
            break; 
        case Windows.Graphics.Display.DisplayOrientations.landscapeFlipped: 
            x_Axis = -1 * reading.angularVelocityX;
            y_Axis = -1 * reading.angularVelocityY;
            z_Axis = reading.angularVelocityZ;
            break; 
        case Windows.Graphics.Display.DisplayOrientations.portraitFlipped: 
            x_Axis = -1 * reading.angularVelocityY;
            y_Axis = reading.angularVelocityX;
            z_Axis = reading.angularVelocityZ;
            break;
     }

    // Update the UI...
}

디스플레이 방향 및 장치 방향

OrientationSensor는 다른 방법으로 변경해야 합니다. 다른 방향을 Z축에 대한 시계 반대 방향 회전으로 간주하므로 사용자 방향을 다시 가져오기 위해 회전을 반대로 해야 합니다. 사원수 데이터의 경우 오일러의 공식을 사용하여 참조 사원수로 회전을 정의할 수 있으며, 참조 회전 행렬을 사용할 수도 있습니다.

오일러의 공식

원하는 상대 방향을 가져오려면 절대 개체에 참조 개체를 곱합니다. 이 수학은 가환성이 아닙니다.

절대 개체에 참조 개체 곱하기

앞의 식에서 절대 개체는 센서 데이터에서 반환됩니다.

디스플레이 방향 Z축을 중심으로 시계 반대 방향 회전 참조 사원수(역회전) 참조 회전 행렬(역회전)

Landscape

0

1 + 0i + 0j + 0k

[1 0 0

0 1 0

0 0 1]

Portrait

90

cos(-45⁰) + (i + j + k)*sin(-45⁰)

[0 1 0

-1 0 0

0 0 1]

LandscapeFlipped

180

0 - i - j - k

[1 0 0

0 1 0

0 0 1]

PortraitFlipped

270

cos(-135⁰) + (i + j + k)*sin(-135⁰)

[0 -1 0

1 0 0

0 0 1]