Модератор: The trick
Public Function MatrixDeterminant(pM As D3DMATRIX) As Single
Dim Minor As D3DVECTOR4
Dim v1 As D3DVECTOR4
Dim v2 As D3DVECTOR4
Dim v3 As D3DVECTOR4
v1.x = pM.m11: v1.y = pM.m21: v1.z = pM.m31: v1.w = pM.m41
v2.x = pM.m12: v2.y = pM.m22: v2.z = pM.m32: v2.w = pM.m42
v3.x = pM.m13: v3.y = pM.m23: v3.z = pM.m33: v3.w = pM.m43
v4Cross Minor, v1, v2, v3
MatrixDeterminant = -(pM.m14 * Minor.x + pM.m24 * Minor.y + pM.m34 * Minor.z + pM.m44 * Minor.w)
End Function
Public Function MatrixInverse(mOut As D3DMATRIX, Determinant As Single, Mtrx As D3DMATRIX) As Boolean
Dim a As Long
Dim i As Long
Dim j As Long
Dim v As D3DVECTOR4
Dim Vec(2) As D3DVECTOR4
Dim Det As Single
Dim M(3, 3) As Single
Dim o(3, 3) As Single
Dim IDet As Single
Det = MatrixDeterminant(Mtrx)
If Det = 0 Then Exit Function
Determinant = Det
IDet = 1 / Det
MemCpy M(0, 0), Mtrx, 64
For i = 0 To 3
For j = 0 To i - 1
Vec(j).x = M(j, 0)
Vec(j).y = M(j, 1)
Vec(j).z = M(j, 2)
Vec(j).w = M(j, 3)
Next j
For j = i To 2
Vec(j).x = M(j + 1, 0)
Vec(j).y = M(j + 1, 1)
Vec(j).z = M(j + 1, 2)
Vec(j).w = M(j + 1, 3)
Next j
v4Cross v, Vec(0), Vec(1), Vec(2)
o(0, i) = v.x * IDet
o(1, i) = v.y * IDet
o(2, i) = v.z * IDet
o(3, i) = v.w * IDet
IDet = -IDet
Next i
MemCpy mOut, o(0, 0), 64
MatrixInverse = True
End Function
Private Sub v4Cross(vOut As D3DVECTOR4, v1 As D3DVECTOR4, v2 As D3DVECTOR4, v3 As D3DVECTOR4)
vOut.x = v1.y * (v2.z * v3.w - v3.z * v2.w) - v1.z * (v2.y * v3.w - v3.y * v2.w) + v1.w * (v2.y * v3.z - v2.z * v3.y)
vOut.y = -(v1.x * (v2.z * v3.w - v3.z * v2.w) - v1.z * (v2.x * v3.w - v3.x * v2.w) + v1.w * (v2.x * v3.z - v3.x * v2.z))
vOut.z = v1.x * (v2.y * v3.w - v3.y * v2.w) - v1.y * (v2.x * v3.w - v3.x * v2.w) + v1.w * (v2.x * v3.y - v3.x * v2.y)
vOut.w = -(v1.x * (v2.y * v3.z - v3.y * v2.z) - v1.y * (v2.x * v3.z - v3.x * v2.z) + v1.z * (v2.x * v3.y - v3.x * v2.y))
End Sub
Хакер писал(а):если кто-то портирует код — не важно, с DX8VB или с DX9 на другом языке — в обоих случаях человек запнётся о несовместимость по набору параметров
Mikle писал(а):Вроде, набор тот же самый, в том же порядке.
Mikle писал(а): зато сохранится совместимость со всем остальным dx8 и dx9 кодом, которого гораздо больше.
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 4