DirectX 8 - Tutorials - Direct3D - Matrix (Untransformed Vertex Formats)

Introduction to Matrices and Matrices with DirectX 8
How do you do "things" with Matrices in Visual Basic with DirectX8
How to prepare the Matrices for these tutorials

Introduction to Matrices and Matrices with DirectX 8

A matrix is something very complicating, so I will show some definitions of a matrix so everyone can understand (hopefully).

Eric Coleman A rectangular array of numbers, the dimensions of this array is generally designated by m X n. m is the number of rows, n is the number of columns,
an element of a matrix called "A" is written in the form a_ij where i and j are subscripts of "a." i is the i'th row, and j is the j'th column.
A 1 x n matrix is called a row vector, and a n x 1 matrix is called a column vector.
http://www.dictionary.com 1 . A rectangular array of numeric or algebraic quantities subject to mathematical operations.
2 . Something resembling such an array, as in the regular formation of elements into columns and rows.
http://www.yourdictionary.com a : a rectangular array of mathematical elements (as the coefficients of simultaneous linear equations) that can be combined to form sums and products with similar arrays having an appropriate number of rows and columns
b : something resembling a mathematical matrix especially in rectangular arrangement of elements into rows and columns
c : an array of circuit elements (as diodes and transistors) for performing a specific function

Now, there are ONLY 3 matricies used in Direct3D 8. They are the world, view and perspective.

The world matrix is how things are placed. Rotating/moving the world one way will make it like you are rotating the view the oposite way. For simpleness in programming, simply use a matrix that was made with D3DXMatrixIdentity.

The view matrix is basically the camera. For simpleness in programming, simply use a matrix that was made with the D3DXMatrixLookAtLH.

The perspective matrix is the way you see the world matrix through the view matrix. Like how far you can see, and how close can you see.

Now, there is a lot of things you can do with these three matricies. I will just show you some demonstrations on how to do those "things".

How do you do "things" with Matrices in Visual Basic with DirectX8

This SUB will move the world from the arguments passed by the user:

Public Sub D3DMatrixWorld(ByVal vX As Single, ByVal vY As Single, ByVal vZ As Single)
    Dim matWorldX As D3DMATRIX
    Dim matWorldY As D3DMATRIX
    Dim matWorldZ As D3DMATRIX
    Dim matworld As D3DMATRIX
    D3DXMatrixRotationX matWorldX, vX
    D3DXMatrixRotationY matWorldY, vY
    D3DXMatrixRotationZ matWorldZ, vZ
    D3DXMatrixMultiply matworld, matWorldX, matWorldY
    D3DXMatrixMultiply matworld, matWorldZ, matworld
    D3DDEV.SetTransform D3DTS_WORLD, matworld
End Sub

This SUB will move and rotate the view from the arguments passed by the user. Used for games that will NOT be first person.

Public Sub D3DMatrixView(ByVal vFX As Single, ByVal vFY As Single, ByVal vFZ As Single, ByVal vTX As Single, ByVal vTY As Single, ByVal vTZ As Single)
    Dim matview As D3DMATRIX
    Dim VF As D3DVECTOR
    Dim VT As D3DVECTOR
    Dim VU As D3DVECTOR
    VF.X = vFX
    VF.y = vFY
    VF.Z = vFZ
    VT.X = vTX
    VT.y = vTY
    VT.Z = vTZ
    VU.y = 1
    D3DXMatrixLookAtLH matview, VF, VT, VU
    D3DDEV.SetTransform D3DTS_VIEW, matview
End Sub

This SUB will move and rotate the view from the arguments passed by the user. The proper way. This one requires that you make some global variables. The way this SUB works is that if you tell it to rx=1, it will not set the rotation to 1 radian, it will rotate the camera in 1 radian. This can be used by any type of game since it is really flexable.

Being Made...

This SUB will change the perspective from the arguments passed by the user.

Public Sub D3DMatrixPerspective(Optional ByVal vFOV As Single = 0.785398163397448, Optional ByVal vASPECT As Single, Optional ByVal vZMIN As Single = 1, Optional ByVal vZMAX As Single = 1000)
    Dim matProj As D3DMATRIX
    D3DXMatrixPerspectiveFovLH matProj, vFOV, vASPECT, vZMIN, vZMAX
    D3DDEV.SetTransform D3DTS_PROJECTION, matProj
End Sub

How to prepare the Matrices for these tutorials

This sub can be changed all you want, but again, for simplicity, we made one simple sub.

Public Sub PrepareMatrices()
    Dim matworld As D3DMATRIX
    Dim matview As D3DMATRIX
    Dim matProj As D3DMATRIX
    Dim VF As D3DVECTOR
    Dim VT As D3DVECTOR
    Dim VU As D3DVECTOR

    D3DXMatrixIdentity matworld
    D3DDEV.SetTransform D3DTS_WORLD, matworld

    VF.Z = -5
    VU.y = 1
    D3DXMatrixLookAtLH matview, VF, VT, VU
    D3DDEV.SetTransform D3DTS_VIEW, matview

    D3DXMatrixPerspectiveFovLH matProj, PI / 4, 1, 1, 1000
    D3DDEV.SetTransform D3DTS_PROJECTION, matProj
End Sub