[DX] 좌표 변경 변환 (Coordinate Transformation)

김진우·2025년 6월 29일

DirectX

목록 보기
9/32
post-thumbnail

정의

좌표 변경 변환(Coordinate Transformation)은 어떤 점이나 객체의 위치를 한 좌표계에서 다른 좌표계로 변환하는 것을 의미한다.

즉,"같은 위치를 다른 기준으로 바라보기"라고 할 수 있다.

용어

3D 공간에서 점을 렌더링하거나 처리하기 위해 일반적으로 다음과 같은 변환 계층 구조가 존재한다.
Model Space / Local Space : 객체 기준 좌표 (상대 좌표)
World Space : 전체 세계 기준 좌표 (절대 좌표)
View Space / Camera Space : 카메라 기준 좌표계
Clip Space : GPU가 투영 및 클리핑을 위해 사용하는 공간(정규화된 화면 공간)

3D 좌표 변환은 Model Space→World Space→View Space (Camera)→Clip Space 순서대로 진행한다.

변환 행렬 구성

3D에서 사용되는 대표적인 변환 행렬은 다음과 같다.

  1. 이동 (Translation)
T(tx,ty,tz)=[100tx010ty001tz0001]T(t_x, t_y, t_z) = \begin{bmatrix} 1 & 0 & 0 & t_x \\ 0 & 1 & 0 & t_y \\ 0 & 0 & 1 & t_z \\ 0 & 0 & 0 & 1 \end{bmatrix}
  1. 스케일 (Scaling)
S(sx,sy,sz)=[sx0000sy0000sz00001]S(s_x, s_y, s_z) = \begin{bmatrix} s_x & 0 & 0 & 0 \\ 0 & s_y & 0 & 0 \\ 0 & 0 & s_z & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}
  1. 회전 (예: Z축 회전)
Rz(θ)=[cosθsinθ00sinθcosθ0000100001]R_z(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 & 0 \\ \sin\theta & \cos\theta & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

전체 좌표 변환

1. 로컬 → 월드

객체의 로컬 좌표 plocal\mathbf{p}_{local}월드 좌표 pworld\mathbf{p}_{world}로 바꾸는 식:

pworld=Mmodelplocal\mathbf{p}_{world} = M_{model} \cdot \mathbf{p}_{local}

여기서 MmodelM_{model}은 스케일, 회전, 이동을 곱한 모델 행렬이다.

Mmodel=TRSM_{model} = T \cdot R \cdot S

2. 월드 → 뷰

객체의 월드 좌표 pworld\mathbf{p}_{world}뷰 좌표 pview\mathbf{p}_{view}로 바꾸는 식:

pview=Mviewpworld\mathbf{p}_{view} = M_{view} \cdot \mathbf{p}_{world}

여기서 MviewM_{view}카메라(또는 관찰자) 기준의 변환 행렬이다.
즉, 월드 공간에 있는 점을 카메라 위치에서 바라본 위치로 바꾸는 행렬이며, 다음 구성으로 만들어진다.

Mview=[rightxupxlookx0rightyupylooky0rightzupzlookz0drightdupdlook1]M_{view} = \begin{bmatrix} \text{right}_x & \text{up}_x & \text{look}_x & 0 \\ \text{right}_y & \text{up}_y & \text{look}_y & 0 \\ \text{right}_z & \text{up}_z & \text{look}_z & 0 \\ -d_{\text{right}} & -d_{\text{up}} & -d_{\text{look}} & 1 \end{bmatrix}
  • right,up,look\text{right}, \text{up}, \text{look}: 카메라의 3축 벡터
  • daxis=dot(eye,axis)d_{\text{axis}} = \text{dot}(eye, axis): 카메라 위치(eye)와의 내적

3. 뷰 좌표 → 클립 공간 (투영 변환)

뷰 좌표 pview\mathbf{p}_{view}클립 공간 pclip\mathbf{p}_{clip}으로 바꾸는 식:

pclip=Mprojpview\mathbf{p}_{clip} = M_{proj} \cdot \mathbf{p}_{view}

여기서 MprojM_{proj}투영 행렬 (Projection Matrix)이다. 원근 투영(perspective projection)에서는 화면이 멀어질수록 작게 보이게 해 준다.

최종 MVP 행렬

그래픽스 파이프라인에서는 이 세 가지 행렬을 한 번에 곱해 사용한다.

pclip=MmodelMviewMprojplocal\mathbf{p}_{clip} = M_{model} \cdot M_{view} \cdot M_{proj} \cdot \mathbf{p}_{local}

0개의 댓글