2016-07-01 2 views
0

XMVector3Unproject()를 사용하여 DirectX11에서 레이 - 캐스팅 카메라를 만들려고합니다. 내 이해에서, 나는 near plane의 픽셀의 (Vector3) 위치를 전달할 것이고, 별도의 호출에서는 far plane의 해당 위치를 전달할 것이다. 그렇다면이 벡터를 빼서 광선의 방향을 얻습니다. 원점은 가까운 평면상의 투영되지 않은 좌표입니다. 여기에 레이의 출처를 계산하는 내 문제는 전달합니다.XMVector3Unproject(), DirectX11에서 사용할 카메라 광선 위치를 계산하는 방법은 무엇입니까?

// assuming screenHeight and screenWidth are the number of pixels. 
    const uint32_t screenHeight = 768; 
    const uint32_t screenWidth = 1024; 

    struct Ray 
    { 
     XMFLOAT3 origin; 
     XMFLOAT3 direction; 
    }; 

    Ray rays[screenWidth * screenHeight]; 

    for (uint32_t i = 0; i < screenHeight; ++i) 
    { 
     for (uint32_t j = 0; j < screenWidth; ++j) 
     { 
      // 1. ***calculate and store the current pixel position on the near plane*** 
      // 2. ***calculate the corresponding point on the far plane*** 
      // 3. ***pass both positions separately into XMVector3Unproject() (2 total calls to the function)*** 
      // 4. ***store the returned vectors' difference into rays[i * screenWidth + j].direction*** 
      // 5. ***store the near plane pixel position's returned vector into rays[i * screenWidth + j].origin*** 
     } 
    } 

다행스럽게도 필자는이 문제를 제대로 이해하고있어

예. 레이의 기원이나 정정에 도움이된다면 크게 도움이 될 것입니다.

답변

0

에 따르면 XMVector3Unproject 함수는 카메라 공간 (정규화 된 장치 좌표), 객체 공간 (모델 행렬에서 제공)에서 제공 한 광선의 좌표를 제공합니다.

모든 빛이 카메라 (0, 0, 0) 하나 포인트를 통과하면 (카메라 핀홀을 고려, 카메라 광선을 생성하려면, 당신은 당신의 선 방향을 선택합니다., 루프의 힘이 W*H 카메라 광선을 생성 할 가정 해 봅시다 당신은 또한 흥미

소리 this link 좀보고 할 수 있습니다이

Vector3 ray_origin = Vector3(0, 0, 0); 
for (float x = -1.f; x <= 1.f; x += 2.f/W) { 
    for (float y = -1.f; y <= 1.f; y += 2.f/H) { 
     Vector3 ray_direction = Normalize(Vector3(x, y, -1.f)) - ray_origin; 
     Vector3 ray_in_model = Unproject(ray_direction, 0.f, 0.f, 
             width, height, znear, zfar, 
             proj, view, model); 
    } 
} 

처럼

관련 문제