'After that workout, we now have to actually set the vertices.
'We do this by locking the surface out of D9 while we "operate" on it.
Dim A As Array = vxbf.Lock(0, LockFlags.None)
'It returns a vanilla array...
vs = DirectCast(A, CustomVertex.PositionNormalTextured())
'So we have to convert it to an array of the appropriate vertices.
'Z = F(X, Y), but this time with texture.
'Our texture should be 0,0 at X,Y = -3,-3 and 1,1 at X,Y = 3,3
'So, we will simply do an interpolation during this process.
'An interpolation is, again, like this:
'Vf = L + Percent * (H - L), where Vf is the texture value, L is the lowest texture value, and H is the highest texture value.
'Percent would also be an interpolation: Percent = (Vo - L) / (H - L)
'where Vo is the loop variable value, L is the lowest loop value, and H is the highest loop value.
'The first formula would be Vf = 0 + Percent * (1 - 0) = Percent.
'The second formula would be Percent = (Vo - -3) / (3 - -3) = (Vo + 3) / 6,
'Therefore, Vf = (Vo + 3) / 6
'with L + dL
'Vf = (Vo + dVo + 3) / 6
For LY = -3.0F To 2.999F Step 0.25F
For LX = -3.0F To 2.999F Step 0.25F
'triangle 1:
vs(Ctr) = New CustomVertex.PositionNormalTextured(LX, LY, F(LX, LY), 0.0F, 0.0F, 0.0F, (LX + 3.0F) / 6.0F, (LY + 3.0F) / 6.0F)
vs(Ctr + 1) = New CustomVertex.PositionNormalTextured(LX + 0.25F, LY, F(LX + 0.25F, LY), 0.0F, 0.0F, 0.0F, (LX + 3.25F) / 6.0F, (LY + 3.0F) / 6.0F)
vs(Ctr + 2) = New CustomVertex.PositionNormalTextured(LX, LY + 0.25F, F(LX, LY + 0.25F), 0.0F, 0.0F, 0.0F, (LX + 3.0F) / 6.0F, (LY + 3.25F) / 6.0F)
'triangle 2:
vs(Ctr + 3) = New CustomVertex.PositionNormalTextured(LX + 0.25F, LY + 0.25F, F(LX + 0.25F, LY + 0.25F), 0.0F, 0.0F, 0.0F, (LX + 3.25F) / 6.0F, (LY + 3.25F) / 6.0F)
vs(Ctr + 4) = vs(Ctr + 2)
vs(Ctr + 5) = vs(Ctr + 1)
Ctr += 6
Next
Next |