방법: 카메라 이동 및 대상 지정

업데이트: 2007년 11월

뷰 변형을 사용하여 Direct3D 장면에서 카메라를 이동하고 대상을 지정할 수 있습니다.

참고:

관리되는 Direct3D 모바일 응용 프로그램을 사용하려면 Pocket PC 및 Smartphone용 Windows Mobile 버전 5.0 소프트웨어가 필요합니다. Windows Mobile 소프트웨어 및 SDK에 대한 내용은 .NET Compact Framework용 외부 리소스를 참조하십시오.

뷰 변형은 Direct3D 개체를 전역 공간에서 화면 공간으로 변환합니다. 뷰 변형을 수행할 때는 카메라(뷰어) 위치, 카메라 대상 및 좌표계를 알고 있어야 화면에서 결과를 조작할 수 있으며 전역 공간 좌표를 화면 공간 좌표로 올바르게 변형할 수 있습니다.

전역 공간은 왼손 좌표계를 기반으로 합니다. 즉, 양의 y축 값은 위로 이동하고, 양의 x축 값은 오른쪽으로 이동하며, 양의 z축 값은 가상의 뷰어에서 바깥쪽으로 이동합니다. 반대로 오른손 좌표계에서는 양의 z축 값이 뷰어 쪽으로 이동합니다.

장치의 Transform 속성은 변형 상태를 설명하는 Matrix 구조체를 반환합니다. 카메라를 이동하고 대상을 지정하려면 LookAtLH 메서드를 사용하여 뷰 변형 매트릭스를 장치 개체에 전달하여 변형을 처리합니다.

다음 예제에서는 카메라를 처음에는 z축 상의 양의 위치인 장면 뒤쪽에서 시작하고 원점 부근의 위치를 대상으로 지정합니다. 카메라는 장면 뒤쪽에 있으므로 z축 값이 양수이면 개체가 카메라에서 멀리 떨어져 있는 것이 아니라 가까이에 있습니다. 또한 x축 값이 양수이면 개체가 오른쪽이 아니라 왼쪽에 있습니다.

예제

다음 코드 예제에서는 배를 나타내는 기본 상자 망상 조직의 애니메이션을 그리는 뷰 변형을 보여 줍니다. 전체 예제 코드는 방법: Direct3D 개체 변형을 참조하십시오.

다음 코드 예제에는 다음과 같은 몇 개의 개체가 포함되어 있습니다.

  • 배를 나타내는 기본 Mesh 개체

  • Device 개체

' Set up the view matrix. You can define a view matrix with a camera position,
' a point to look at (camera target), and an "up" direction.
' First vector passed to LookAtLH is the camera position.
' Second vector passed to LookAtLH is the camera target.
' Third vector passed to LookAtLH defines the "up" direction.
' In this example, you set the camera seven units up along the z-axis ("behind"
' the scene), down one unit, and left two units. You then point the camera
' just above the origin and define "up" to be in the y-direction.
If Not isShipDeparted Then
    device.Transform.View = Matrix.LookAtLH(New Vector3(- 2, - 1, 7), New Vector3(0, 1, 0), New Vector3(0, 1, 0))
Else
    ' Handles movement of camera after 
    ' the ship "fires" the main engines.
    device.Transform.View = Matrix.LookAtLH(New Vector3(xCameraPosition, yCameraPosition, 7), New Vector3(0, 1, 0), New Vector3(0, 1, 0))
    xCameraPosition += 0.01F
    yCameraPosition += 0.01F
End If
// Set up the view matrix. You can define a view matrix with a camera position,
// a point to look at (camera target), and an "up" direction.
// First vector passed to LookAtLH is the camera position.
// Second vector passed to LookAtLH is the camera target.
// Third vector passed to LookAtLH defines the "up" direction.
// Here, you set the camera seven units up along the z-axis ("behind"
// the scene), down one unit, and left two units. You then point the camera
// just above the origin and define "up" to be in the y-direction.
if (!isShipDeparted)
{
    device.Transform.View = Matrix.LookAtLH(new Vector3(-2, -1, 7),
        new Vector3(0, 1, 0), new Vector3(0, 1, 0));
}
else
{
    // Handles movement of camera after 
    // the ship "fires" the main engines.
    device.Transform.View = Matrix.LookAtLH(new Vector3(xCameraPosition, 
        yCameraPosition, 7), new Vector3(0, 1, 0), new Vector3(0, 1, 0));
    xCameraPosition += 0.01f;
    yCameraPosition += 0.01f;
}

코드 컴파일

이 예제를 실행하려면 방법: Direct3D 개체 변형의 전체 샘플 코드가 필요합니다.

참고 항목

개념

.NET Compact Framework 방법 항목

기타 리소스

.NET Compact Framework의 모바일 Direct3D 프로그래밍