반응형



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


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)

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

D3DXVecNDot(U, V)

Result = U ⋅ V = ∑iUiVi

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

/1000\/V1\
||||
|0010||V2|
Out = (1,s,s²s³)||||
|−33−2−1||T1|
||||
\2−211/\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 = V1 − V2


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)

/1000\
||
|0100|
Out = E =||
|0010|
||
\0001/

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

/lxuxvx0\
||
|lyuyvy0|
Out =||
|lzuzvz0|
||
\−l⋅Eye−u⋅Eye−v⋅Eye1/

D3DXMatrixLookAtLH(Out, Eye, At, Up)

v = Normalized(AtEye)
r = Up×v
u = v×r

/rxuxvx0\
||
|ryuyvy0|
Out =||
|rzuzvz0|
||
\−r⋅Eye−u⋅Eye−v⋅Eye1/

D3DXMatrixMultiply(Out, M1, M2)

Out = M1×M2

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

Q = (f−n)−1

/2w000\
||
|02h00|
Out =||
|00−Q0|
||
\00−Qn1/

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

Q = (f−n)−1

/2w000\
||
|02h00|
Out =||
|00Q0|
||
\00−Qn1/

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

Q = (f−n)−1
w = r−l
h = b−t

/2w000\
||
|02h00|
Out =||
|00−Q0|
||
\−(r+l)2−(t+b)2−Qn1/

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

Q = (f−n)−1
w = r−l
h = b−t

/2w000\
||
|02h00|
Out =||
|00Q0|
||
\−(r+l)2−(t+b)2−Qn1/

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

Q = (f−n)−1

/2w000\
||
|02h00|
Out =||
|00−Qf−1|
||
\00−Qnf0/

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

Q = (f−n)−1

/2w000\
||
|02h00|
Out =||
|00Qf1|
||
\00−Qnf0/

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

Q = (f−n)−1
y = cotg(Fovy)2

/yAspect000\
||
|0y00|
Out =||
|00−Qf−1|
||
\00−Qnf0/

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

Q = (f−n)−1
y = cotg(Fovy)2

/yAspect000\
||
|0y00|
Out =||
|00Qf1|
||
\00−Qnf0/

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

Q = (f−n)−1
w = r−l
h = b−t

/2w000\
||
|02h00|
Out =||
|(r+l)w(t+b)h−Qf−1|
||
\00−Qnf0/

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

Q = (f−n)−1
w = r−l
h = b−t

/2w000\
||
|02h00|
Out =||
|−(r+l)w−(t+b)hQf1|
||
\00−Qnf0/

D3DXMatrixReflect(Out, Plane)

(a,b,c,d) = (Planea,Planeb,Planec,Planed)√(Planea²+Planeb²+Planec²)

/1−2a²−2ba−2ca0\
||
|−2ab1−2b²−2cb0|
Out =||
|−2ac−2bc1−2c²0|
||
\−2ad−2bd−2cd1/

D3DXMatrixRotationAxis(Out, V, Angle)

s = sin Angle
c = cos Angle
d = 1−c
(x,y,z) = V

/dx²+cdxy+zsdxz−ys0\
||
|dxy−zsdy²+cdyz+xs0|
Out =||
|dxy+ysdyz−xsdz²+c0|
||
\0001/

D3DXMatrixRotationQuaternion(Out, Q)

(x,y,z,w) = Q

/1−2y²−2z²2xy+2zw2xz−2yw0\
||
|2xy−2zw1−2x²−2z²2yz+2xw0|
Out =||
|2xz+2yw2yz−2xw1−2x²−2y²0|
||
\0001/

D3DXMatrixRotationX(Out, Angle)

s = sin Angle
c = cos Angle

/1000\
||
|0cs0|
Out =||
|0−sc0|
||
\0001/

D3DXMatrixRotationY(Out, Angle)

s = sin Angle
c = cos Angle

/c0−s0\
||
|0100|
Out =||
|s0c0|
||
\0001/

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⋅sccb⋅sc0\
||
|sa⋅cbca⋅cb−sb0|
Out =||
|−ca⋅sc+sa⋅sb⋅ccsa⋅sc+ca⋅sb⋅cccb⋅cc0|
||
\0001/

D3DXMatrixRotationZ(Out, Angle)

s = sin Angle
c = cos Angle

/cs00\
||
|−sc00|
Out =||
|0010|
||
\0001/

D3DXMatrixScaling(Out, x, y, z)

/x000\
||
|0y00|
Out =||
|00z0|
||
\0001/

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\
||
|−xbf−yb−zb−wb|
Out =||
|−xc−ycf−zc−wc|
||
\−xd−yd−zdf−wd/

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

D3DXMatrixTranslation(A, -Scenterx, -Scentery, -Scenterz)
D3DXMatrixScaling(B, Scalingx, Scalingy, Scalingz)
D3DXMatrixRotationQuaternion(CSrot)
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)

/1000\
||
|0100|
Out =||
|0010|
||
\xyz1/

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 = V − U
Out = U − d(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 = (B − A) × (C − A)
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

반응형

+ Recent posts