Matematika v Direct3DX

(English info)

V této kapitole je seznam matematických funkcí Direct3DX (což je jakýsi toolkit pro Direct3D (DirectXGraphics), jistá obdoba knihovny GLUT pro OpenGL), spolu s popisem matematiky, kterou tyto funkce provádí.

Upozorňuji, že toto není oficiální dokumentace k Direct3DX (ta se nalézá někde na MSDN).

Vektory

D3DXVecNAdd(Out, V1, V2)

Out = V1 + V2

D3DXVecNBaryCentric(Out, V1, V2, V3, f, g)

Out = V1 + f⋅(V2V1) + g⋅(V3V1)

D3DXVecNCatmullRom(Out, V1, V2, V3, V4, s)

/ 0 1 0 0 \/V1\
| |||
| −0,5 0 0,5 0 ||V2|
Out = (1,s,s²,s³) | |||
| 1 −2,5 2 −0,5 ||V3|
| |||
\ −0,5 1,5 −1,5 0,5 /\V4/

D3DXVecNDot(U, V)

Result = UV = ∑iUiVi

D3DXVecNHermite(Out, V1, T1, V2, T2, s)

/ 1 0 0 0 \/V1\
| |||
| 0 0 1 0 ||V2|
Out = (1,s,s²s³) | |||
| −3 3 −2 −1 ||T1|
| |||
\ 2 −2 1 1 /\T2/

D3DXVecNLength(V)

Result = |V| = √(∑iVi²)

D3DXVecNLengthSq(V)

Result = |V|² = ∑iVi²

D3DXVecNLerp(Out, V1, V2, s)

Out = V1 + s(V2V1);

D3DXVecNMaximize(Out, U, V)

Outi = max(Ui, Vi)

D3DXVecNMinimize(Out, U, V)

Outi = min(Ui, Vi)

D3DXVecNNormalize(Out, V)

Out = 1|V|V

D3DXVecNScale(Out, V, s)

Out = sV

D3DXVecNSubtract(Out, V1, V2)

Out = V1V2


2D Vektory

D3DXVec2CCW(U, V)

Result = UxVy − UyVx

D3DXVec2Transform(Out, V, M)

a = (Vx, Vy, 0, 1)
b = (a×M)T
Out = (bx, by)

D3DXVec2TransformCoord(Out, V, M)

a = (Vx, Vy, 0, 1)
b = (a×M)T
Out = 1bw(bx, by)

D3DXVec2TransformNormal(Out, V, M)

a = (Vx, Vy, 0, 0)
b = (a×M)T
Out = (bx, by)


3D Vektory

D3DXVec3Cross(Out, V1, V2)

Out = V1 × V2

D3DXVec3Project(Out, V, Viewport, Proj, View, World)

a = (Vx, Vy, Vz, 1)
b = a×World×View×Proj
c = bbw
Outx = ViewportX + ViewportWidth*(1+cx)/2
Outy = ViewportY + ViewportHeight*(1-cy)/2
Outz = ViewportMinZ + cz*(ViewportMaxZ-ViewportMinZ)

D3DXVec3Transform(Out, V, M)

a = (Vx, Vy, Vz, 1)
b = (a×M)T
Out = (bx, by, bz)

D3DXVec3TransformCoord(Out, V, M)

a = (Vx, Vy, Vz, 1)
b = (a×M)T
Out = 1bw(bx, by, bz)

D3DXVec3TransformNormal(Out, V, M)

a = (Vx, Vy, Vz, 0)
b = (a×M)T
Out = (bx, by, bz)

D3DXVec3Unproject(Out, V, Viewport, Proj, View, World)

M = (World×View×Proj)−1
ax = (Vx-Viewportx)*2/ViewportWidth - 1
ay = 1 - (Vy-Viewporty)*2/ViewportHeight
az = (Vz-ViewportMinZ)/(ViewportMaxZ-ViewportMinZ)
aw = 1
b = (a×M)T
Out = 1bw(bx, by, bz)


4D Vektory

D3DXVec4Cross(Out, U, V, W)

a = VxWy − VyWx
b = VxWz − VzWx
c = VxWw − VwWx
d = VyWz − VzWy
e = VyWw − VwWy
f = VzWw − VwWz
Outx = fUy − eUz + dUw
Outy = fUx + cUz − bUw
Outz = eUx − cUy + aUw
Outw = dUx + bUy − aUz

D3DXVec4Transform(Out, V, M)

Out = (V×M)T


Matice (4×4)

D3DXMatrixAffineTransformation(Out, s, c, r, t)

/ s(2(ry² + rz²) − 1) 2s(rxry + rzrw) 2s(rxrz − ryrw) 0 \
| |
| 2s(rxry − rzrw) s(2(rx² + rz²) − 1) 2s(ryrz + rxrw) 0 |
Out = | |
| 2s(rxrz + ryrw) 2s(ryrz − rxrw) s(2(rx² + ry²) − 1) 0 |
| |
\ tx+2(cxry²+cxrz²−cyrxry+cyrzrw−czrxrz−czryrw) ty+2(cyrx²+cyrz²−cxrxry−cxrzrw−czryrz+czrxrw) tz+2(czrx²+czry²−cxrxrz+cxryrw−cyryrz−cyrxrw) 1 /

D3DXMatrixfDeterminant(M)

Result = det M

D3DXMatrixIdentity(Out)

/ 1 0 0 0 \
| |
| 0 1 0 0 |
Out = E = | |
| 0 0 1 0 |
| |
\ 0 0 0 1 /

D3DXMatrixInverse(Out, D, M)

D = det M
Out = M−1

D3DXMatrixIsIdentity(M)

Result = ME

D3DXMatrixLookAtRH(Out, Eye, At, Up)

v = Normalized(EyeAt)
l = Up×v
u = v×l
/ lx ux vx 0 \
| |
| ly uy vy 0 |
Out = | |
| lz uz vz 0 |
| |
\ −l⋅Eye −u⋅Eye −v⋅Eye 1 /

D3DXMatrixLookAtLH(Out, Eye, At, Up)

v = Normalized(AtEye)
r = Up×v
u = v×r
/ rx ux vx 0 \
| |
| ry uy vy 0 |
Out = | |
| rz uz vz 0 |
| |
\ −r⋅Eye −u⋅Eye −v⋅Eye 1 /

D3DXMatrixMultiply(Out, M1, M2)

Out = M1×M2

D3DXMatrixOrthoRH(Out, w, h, n, f)

Q = (f−n)−1
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 −Q 0 |
| |
\ 0 0 −Qn 1 /

D3DXMatrixOrthoLH(Out, w, h, n, f)

Q = (f−n)−1
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 Q 0 |
| |
\ 0 0 −Qn 1 /

D3DXMatrixOrthoOffCenterRH(Out, l, r, t, b, n, f)

Q = (f−n)−1
w = r−l
h = b−t
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 −Q 0 |
| |
\ −(r+l)2 −(t+b)2 −Qn 1 /

D3DXMatrixOrthoOffCenterLH(Out, l, r, t, b, n, f)

Q = (f−n)−1
w = r−l
h = b−t
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 Q 0 |
| |
\ −(r+l)2 −(t+b)2 −Qn 1 /

D3DXMatrixPerspectiveRH(Out, w, h, n, f)

Q = (f−n)−1
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 −Qf −1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixPerspectiveLH(Out, w, h, n, f)

Q = (f−n)−1
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| 0 0 Qf 1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixPerspectiveFovRH(Out, Fovy, Aspect, n, f)

Q = (f−n)−1
y = cotg(Fovy)2
/ yAspect 0 0 0 \
| |
| 0 y 0 0 |
Out = | |
| 0 0 −Qf −1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixPerspectiveFovLH(Out, Fovy, Aspect, n, f)

Q = (f−n)−1
y = cotg(Fovy)2
/ yAspect 0 0 0 \
| |
| 0 y 0 0 |
Out = | |
| 0 0 Qf 1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixPerspectiveOffCenterRH(Out, l, r, t, b, n, f)

Q = (f−n)−1
w = r−l
h = b−t
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| (r+l)w (t+b)h −Qf −1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixPerspectiveOffCenterLH(Out, l, r, t, b, n, f)

Q = (f−n)−1
w = r−l
h = b−t
/ 2w 0 0 0 \
| |
| 0 2h 0 0 |
Out = | |
| −(r+l)w −(t+b)h Qf 1 |
| |
\ 0 0 −Qnf 0 /

D3DXMatrixReflect(Out, Plane)

(a,b,c,d) = (Planea,Planeb,Planec,Planed)√(Planea²+Planeb²+Planec²)
/ 1−2a² −2ba −2ca 0 \
| |
| −2ab 1−2b² −2cb 0 |
Out = | |
| −2ac −2bc 1−2c² 0 |
| |
\ −2ad −2bd −2cd 1 /

D3DXMatrixRotationAxis(Out, V, Angle)

s = sin Angle
c = cos Angle
d = 1−c
(x,y,z) = V
/ dx²+c dxy+zs dxz−ys 0 \
| |
| dxy−zs dy²+c dyz+xs 0 |
Out = | |
| dxy+ys dyz−xs dz²+c 0 |
| |
\ 0 0 0 1 /

D3DXMatrixRotationQuaternion(Out, Q)

(x,y,z,w) = Q
/ 1−2y²−2z² 2xy+2zw 2xz−2yw 0 \
| |
| 2xy−2zw 1−2x²−2z² 2yz+2xw 0 |
Out = | |
| 2xz+2yw 2yz−2xw 1−2x²−2y² 0 |
| |
\ 0 0 0 1 /

D3DXMatrixRotationX(Out, Angle)

s = sin Angle
c = cos Angle
/ 1 0 0 0 \
| |
| 0 c s 0 |
Out = | |
| 0 −s c 0 |
| |
\ 0 0 0 1 /

D3DXMatrixRotationY(Out, Angle)

s = sin Angle
c = cos Angle
/ c 0 −s 0 \
| |
| 0 1 0 0 |
Out = | |
| s 0 c 0 |
| |
\ 0 0 0 1 /

D3DXMatrixRotationYawPitchRoll(Out, Yaw, Pitch, Roll)

(sa,sb,sc) = sin (Roll, Pitch, Yaw)
(ca,cb,cc) = cos (Roll, Pitch, Yaw)
/ ca⋅cc+sa⋅sb⋅sc −sa⋅cc+ca⋅sb⋅sc cb⋅sc 0 \
| |
| sa⋅cb ca⋅cb −sb 0 |
Out = | |
| −ca⋅sc+sa⋅sb⋅cc sa⋅sc+ca⋅sb⋅cc cb⋅cc 0 |
| |
\ 0 0 0 1 /

D3DXMatrixRotationZ(Out, Angle)

s = sin Angle
c = cos Angle
/ c s 0 0 \
| |
| −s c 0 0 |
Out = | |
| 0 0 1 0 |
| |
\ 0 0 0 1 /

D3DXMatrixScaling(Out, x, y, z)

/ x 0 0 0 \
| |
| 0 y 0 0 |
Out = | |
| 0 0 z 0 |
| |
\ 0 0 0 1 /

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
/ f−xa −ya −za −wa \
| |
| −xb f−yb −zb −wb |
Out = | |
| −xc −yc f−zc −wc |
| |
\ −xd −yd −zd f−wd /

D3DXMatrixTransformation(Out, Scenter, Srot, Scaling, Rotcenter, Rot, Trans)

D3DXMatrixTranslation(A, -Scenterx, -Scentery, -Scenterz)
D3DXMatrixScaling(B, Scalingx, Scalingy, Scalingz)
D3DXMatrixRotationQuaternion(C, Srot)
u = ScenterRotcenter
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)

/ 1 0 0 0 \
| |
| 0 1 0 0 |
Out = | |
| 0 0 1 0 |
| |
\ x y z 1 /

D3DXMatrixTranspose(Out, M)

Out = MT


Roviny

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 = VU
Out = Ud(Pd + nU)(dn) [iff dn ≠ 0]

D3DXPlaneFromPointNormal(Out, P, N)

Planea = Nx
Planeb = Ny
Planec = Nz
Planed = −NP

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 = (BA) × (CA)
n = 1|v| v
Outa = nx
Outb = ny
Outc = nz
Outd = −nA

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 = −qvB

NAVRCHOLU.cz