Math in Direct3DX, Vector

http://mormegil.wz.cz/prog/3dref/D3DXmath.htm

Vector

D3DXVecNAdd(Out, V1, V2) : N 벡터를 덧셈한다.
[latex]Out=V_1+V_2[/latex]

D3DXVecNBaryCentric(Out, V_1, V_2, V_3, f, g) :  N 벡터를 사용해, 중심 좌표의 점을 돌려준다.
[latex]Out = V_1+ f\cdot (V_2 – V_1) + g\cdot (V_3 – V_1 )[/latex]

D3DXVecNCatmullRom(Out, V1, V2, V3, V4, s) : Catmull-Rom SPLine 보간을 실행한다.
[latex]Out=\left(1, s, s^2, s^3\right) \begin{pmatrix}
0&1&0&0\\
-0.5&0&0.5&0\\
1&-2.5&2&-0.5\\
-0.5&1&-1.5&0.5\\
\end{pmatrix}
\begin{pmatrix} V_1\\V_2\\V_3\\V_4\\ \end{pmatrix}
[/latex]

D3DXVecNDot(U, V) : N 벡터의 내적을 계산한다.
[latex]Result=U \cdot V= \sum_{i}U_{i}V_{i}[/latex]

D3DXVecNHermite(Out, V1, T1, V2, T2, s) : Hermite SPLine 보간을 실행한다.
[latex]Out=\left(1, s, s^2, s^3\right) \begin{pmatrix}
1&0&0&0\\
0&0&1&0\\
-3&3&-2&-1\\
2&-2&1&1\\
\end{pmatrix}
\begin{pmatrix} V_1\\V_2\\T_1\\T_2\\ \end{pmatrix}
[/latex]

D3DXVecNLength(V) : N벡터의 길이를 돌려준다.
[latex]Result=\left| V\right|=\sqrt{\left(\sum_{i}V^{2}_{i}\right)}[/latex]

D3DXVecNLengthSq(V) : N벡터의 길이의 2 승을 돌려준다.
[latex]Result=\left| V\right|=\sum_{i}V^{2}_{i}[/latex]

D3DXVecNLerp(Out, V1, V2, s) :  N벡터간의 선형 보간을 실행한다.
[latex]Out = V_1 + s \left( V_2 – V_1 \right)[/latex]

D3DXVecNMaximize(Out, U, V) : N벡터의 최대치로 구성되는 벡터를 만든다
[latex]Out_{i}=max\left(U_{i},V_{i}\right)[/latex]

D3DXVecNMinimize(Out, U, V) : N벡터의 최소치로 구성되는 벡터를 만든다
[latex]Out_{i}=min\left(U_{i}, V_{i}\right)[/latex]

D3DXVecNNormalize(Out, V) : 벡터의 정규화한 벡터를 돌려준다.
[latex]Out=\frac{V}{\left|V\right|}[/latex]

D3DXVecNScale(Out, V, s)
[latex]Out=sV[/latex]

D3DXVecNSubtract(Out, V1, V2)
[latex]Out = V_1-V_2[/latex]

2D Vector

D3DXVec2CCW(U,V) :외적
[latex]Result = U_xV_y – U_yV_x[/latex]

D3DXVec2Transform(Out, V, M) : 행렬에 의한 2D 벡터를 변환 한다.
[latex]a=\left(V_x , V_y , 0, 1\right)[/latex]
[latex]b=\left(a \times M \right)^T[/latex]
[latex]Out=\left(b_x , b_y\right)[/latex]

D3DXVec2TransformCoord(Out, V, M) : w = 1 에 투영된 행렬에 의한 2D벡터 변환
[latex]a=\left(V_x, V_y, 0, 1\right)[/latex]
[latex]b=\left(a \times M \right)^T[/latex]
[latex]Out=\frac{1}{b_w}\left(b_x, b_y\right)[/latex]

D3DXVec2TransformNormal(Out, V, M) : 행렬에 의해 2D 벡터 법선을 변환 한다.
[latex]a=\left(V_x, V_y, 0, 0\right)[/latex]
[latex]b=\left(a\times M\right)^T[/latex]
[latex]Out=\left(b_x, b_y\right)[/latex]

3D Vector

D3DXVec3Cross(Out, V1, V2) : 외적
[latex]Out = V_1 \times V_2[/latex]

D3DXVec3Project(Out, V, Viewport, Proj, View, World) : 월드공간 -> 스크린 공간 투영
[latex]a=\left(V_x, V_y, V_z, 1\right)[/latex]
[latex]b=a\times World\times View\times Proj[/latex]
[latex]c=\frac{b}{b_w}[/latex]
[latex]Out_x=Viewport_X+Viewport_{Width}*\left(1+c_x\right)/2[/latex]
[latex]Out_y=Viewport_Y+Viewport_{Height}*\left(1-c_y\right)/2[/latex]
[latex]Out_z=Viewport_{MinZ}+c_z*\left(Viewport_{MaxZ}-Viewport_{MinZ}\right)[/latex]

D3DXVec3Transform(Out, V, M) : 행렬에 의한 3D 벡터를 변환 한다.
[latex]a=\left(V_x , V_y , V_z, 1\right)[/latex]
[latex]b=\left(a \times M \right)^T[/latex]
[latex]Out=\left(b_x , b_y, b_z\right)[/latex]

D3DXVec3TransformCoord(Out, V, M) : w = 1 에 투영된 행렬에 의한 3D벡터 변환
[latex]a=\left(V_x, V_y, V_z, 1\right)[/latex]
[latex]b=\left(a \times M \right)^T[/latex]
[latex]Out=\frac{1}{b_w}\left(b_x, b_y, b_z\right)[/latex]

D3DXVec3TransformNormal(Out, V, M) : 행렬에 의해 3D 벡터 법선을 변환 한다.
[latex]a=\left(V_x, V_y, V_z, 0\right)[/latex]
[latex]b=\left(a\times M\right)^T[/latex]
[latex]Out=\left(b_x, b_y, b_z\right)[/latex]

D3DXVec3Unproject(Out, V, Viewport, Proj, View, World) : 월드공간 <- 스크린 공간 투영
[latex]M=\left(World\times View\times Proj\right)^{-1}[/latex]
[latex]a_x=\left(V_x-Viewport_x\right)*2/ \left(Viewport_{Width}\right)^{-1}[/latex]
[latex]a_y=1-\left(V_y-Viewport_y\right)*2/Viewport_{Height}[/latex]
[latex]a_z=\left(V_z-Viewport_{MinZ}\right) / \left(Viewport_{MaxZ}-Viewport_{MinZ}\right)[/latex]
[latex]a_w=1[/latex]
[latex]b=\left(a\times M\right)^T[/latex]
[latex]Out=\frac{1}{b_w}\left(b_x, b_y, bz\right)[/latex]

4D Vector

D3DXVec4Cross(Out, U, V, W) : 4차원 벡터의 외적
[latex]a = V_xW_y – V_yW_x[/latex]
[latex]b = V_xW_z – V_zW_x[/latex]
[latex]c = V_xW_w – V_wW_x[/latex]
[latex]d = V_yW_z – V_zW_y[/latex]
[latex]e = V_yW_w – V_wW_y[/latex]
[latex]f = V_zW_w – V_wW_z[/latex]
[latex]Outx = fU_y – eU_z + dU_w[/latex]
[latex]Outy = fU_x + cU_z – bU_w[/latex]
[latex]Outz = eU_x – cU_y + aU_w[/latex]
[latex]Outw = dU_x + bU_y – aU_z[/latex]

D3DXVec4Transform(Out, V, M) : 행렬에 의한 4D 벡터를 변환 한다.
[latex]Out=\left(V\times M\right)^T[/latex]

Matice(4×4)
D3DXMatrixAffineTransformation(Out, s, c, r, t)

[latex]Out=begin{bmatrix}0&0&0&0\0&0&0&0\0&0&0&0\0&0&0&0\end{bmatrix}[latex]

D3DXMatrixfDeterminant(M)
[latex]Result = det M[latex]

D3DXMatrixIdentity(Out)
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixInverse(Out, D, M)
[latex]D = det M[latex]
[latex]Out = M-1[latex]

D3DXMatrixIsIdentity(M)
[latex]Result = M≡E[latex]

D3DXMatrixLookAtRH(Out, Eye, At, Up)
[latex]v = Normalized(Eye-At)[latex]
[latex]l = Uptimes v[latex]
[latex]u = vtimes l[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixLookAtLH(Out, Eye, At, Up)
[latex]v = Normalized(At−Eye)[latex]
[latex]r = Uptimes v[latex]
[latex]u = vtimes r[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixMultiply(Out, M1, M2)
[latex]Out = M1times M2[latex]

D3DXMatrixOrthoRH(Out, w, h, n, f)
[latex]Q = (f-n)-1[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixOrthoLH(Out, w, h, n, f)
[latex]Q = (f−n)−1[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixOrthoOffCenterRH(Out, l, r, t, b, n, f)
[latex]Q = (f-n)-1[latex]
[latex]w = r-l[latex]
[latex]h = b-t[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixOrthoOffCenterLH(Out, l, r, t, b, n, f)
[latex]Q = (f-n)-1[latex]
[latex]w = r-l[latex]
[latex]h = b-t[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveRH(Out, w, h, n, f)
[latex]Q = (f-n)-1[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveLH(Out, w, h, n, f)
[latex]Q = (f−n)−1[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveFovRH(Out, Fovy, Aspect, n, f)
[latex]Q = (f−n)−1[latex]
[latex]y = cotg(Fovy)⁄2[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveFovLH(Out, Fovy, Aspect, n, f)
[latex]Q = (f−n)−1[latex]
[latex]y = cotg(Fovy)⁄2[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveOffCenterRH(Out, l, r, t, b, n, f)
[latex]Q = (f−n)−1[latex]
[latex]w = r−l[latex]
[latex]h = b−t[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixPerspectiveOffCenterLH(Out, l, r, t, b, n, f)
[latex]Q = (f−n)−1[latex]
[latex]w = r−l[latex]
[latex]h = b−t[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixReflect(Out, Plane)
[latex](a,b,c,d) = (Planea,Planeb,Planec,Planed)⁄√(Planea²+Planeb²+Planec²)[latex]
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationAxis(Out, V, Angle)
s = sin Angle
c = cos Angle
d = 1−c
(x,y,z) = V
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationQuaternion(Out, Q)
(x,y,z,w) = Q
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationX(Out, Angle)
s = sin Angle
c = cos Angle
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationY(Out, Angle)
s = sin Angle
c = cos Angle
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationYawPitchRoll(Out, Yaw, Pitch, Roll)
(sa,sb,sc) = sin (Roll, Pitch, Yaw)
(ca,cb,cc) = cos (Roll, Pitch, Yaw)
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixRotationZ(Out, Angle)
s = sin Angle
c = cos Angle
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixScaling(Out, x, y, z)
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixShadow(Out, Light, Plane)
(a,b,c,d) = (Planea,Planeb,Planec,Planed)⁄√(Planea²+Planeb²+Planec²)
(x,y,z,w) = Light
f = Lightx⋅Planea + Lighty⋅Planeb + Lightz⋅Planec + Lightw⋅Planed
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixTransformation(Out, Scenter, Srot, Scaling, Rotcenter, Rot, Trans)
D3DXMatrixTranslation(A, -Scenterx, -Scentery, -Scenterz)
D3DXMatrixScaling(B, Scalingx, Scalingy, Scalingz)
D3DXMatrixRotationQuaternion(C, Srot)
u = Scenter − Rotcenter
D3DXMatrixTranslation(D, ux, uy, uz)
D3DXMatrixRotationQuaternion(E, Rot)
v = Rotcenter + Trans
D3DXMatrixTranslation(F, vx, vy, vz)
Out = A×CT×B×C×D×E×F

D3DXMatrixTranslation(Out, x, y, z)
[latex]Out=E=begin{bmatrix}1&0&0&0\0&1&0&0\0&0&1&0\0&0&0&1\end{bmatrix}[latex]

D3DXMatrixTranspose(Out, M)
Out = MT

Plane

D3DXPlaneDot(P, V)
Result = (Pa, Pb, Pc, Pd)⋅V

D3DXPlaneDotCoord(P, V)
Result = (Pa, Pb, Pc)⋅V + Pd

D3DXPlaneDotNormal(P, V)
Result = (Pa, Pb, Pc)⋅V

D3DXPlaneIntersectLine(Out, P, U, V)
n = (Planea, Planeb, Planec)
d = V − U
Out = U − d⋅(Pd + n⋅U)⁄(d⋅n) [iff d⋅n ≠ 0]

D3DXPlaneFromPointNormal(Out, P, N)
Planea = Nx
Planeb = Ny
Planec = Nz
Planed = −N⋅P

D3DXPlaneNormalize(Out, P)
q = 1⁄√(Pa² + Pb² + Pc²)
Outa = q⋅Pa
Outb = q⋅Pb
Outc = q⋅Pc
Outd = q⋅Pd

D3DXPlaneFromPoints(Out, A, B, C)
v = (B − A) × (C − A)
n = 1⁄|v| v
Outa = nx
Outb = ny
Outc = nz
Outd = −n⋅A

D3DXPlaneTransform(Out, P, M)
Q = P⁄|P|
u = (Qa, Qb, Qc, 0)
D = Qd
A = (−Dux, −Duy, −Duz, 1)
B = A×M
v = u×M
q = 1⁄|v|
Outa = qvx
Outb = qvy
Outc = qvz
Outd = −qv⋅B