DirectX SDK |
This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.
This tutorial uses the application-defined subroutine FrameMove to rotate the viewpoint around in a circle. The viewpoint is most conveniently defined by three D3DVECTOR types: an eye point, a look-at point, and a vector defining the up direction, as shown in the following code:
Dim vEyePt As D3DVECTOR, _ vLookatPt As D3DVECTOR, _ vUpVec As D3DVECTOR vEyePt = MakeVector(5 * Sin(stepVal), 3, 5 * Cos(stepVal)) vLookatPt = MakeVector(4 * Sin(stepVal + 0.1), 2.5, 4 * Cos(stepVal + 0.1)) vUpVec = MakeVector(0, 1, 0)
Now, you can use the three vectors to create and set a new view matrix:
Dim matView As D3DMATRIX Call g_dx.ViewMatrix(matView, vEyePt, vLookatPt, vUpVec, stepVal / 360) g_d3dDevice.SetTransform D3DTRANSFORMSTATE_VIEW, matView
The preceding code creates a new view matrix for each rendered frame of the scene by passing the new location of the camera to the DirectX7.ViewMatrix method. Next the Direct3DDevice7.SetTransform method sets the newly-generated view matrix for the device. The value of stepValue (passed into the application-defined method, FrameMove) rotates the viewpoint one degree at a time. As a result, the wall segments and the cone appear to rotate 360 degrees.
At this point, you have nearly completed your scene; however, you still need to manually rotate, transform, and scale the cube's vertices. First, use the DirectX7.CreateD3DTLVertex method to fill the array of D3DTLVERTEX types with untransformed data for the cube. Note that the first three parameters of DirectX7.CreateD3DTLVertex represent the untransformed position of each vertex in screen coordinates:
g_dx.CreateD3DTLVertex -1, -1, -1, 0, &HFFFFFF, 0, 0, 0, g_vCube(0) g_dx.CreateD3DTLVertex 1, -1, -1, 0, &HFF&, 0, 0, 0, g_vCube(1) g_dx.CreateD3DTLVertex -1, 1, -1, 0, &HFF00&, 0, 0, 0, g_vCube(2) g_dx.CreateD3DTLVertex 1, 1, -1, 0, &HFF0000, 0, 0, 0, g_vCube(3) g_dx.CreateD3DTLVertex -1, -1, 1, 0, &HFFFF&, 0, 0, 0, g_vCube(4) g_dx.CreateD3DTLVertex 1, -1, 1, 0, &HFF0066, 0, 0, 0, g_vCube(5) g_dx.CreateD3DTLVertex -1, 1, 1, 0, &H9966FF, 0, 0, 0, g_vCube(6) g_dx.CreateD3DTLVertex 1, 1, 1, 0, &HFF00FF, 0, 0, 0, g_vCube(7)
Now, you can let the application transform the cube's eight vertices:
Call TransformVertices(g_d3dDevice, g_vCube, NUM_CUBE_VERTICES)
The cube's vertices are transformed by the application-defined function, TransformVertices, which is explained in Step 2.2: Perform the 3-D Transformation.