Модератор: Mikle
Mikle писал(а):Если сетка ландшафта регулярная, мне кажется высоту можно найти раз в сто проще.
Maxwell писал(а):Так, как особых навыков программирования не имею и DX8 начал заниматься сравнительно недавно. Не мог бы ты примечик кинуть? Тогда с меня два пива.
Option Explicit
Dim map(3, 3) As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim XX As Single, YY As Single
Me.Cls
Randomize Timer
For YY = 0 To 3 'Заполняем массив
For XX = 0 To 3
map(XX, YY) = Rnd
Next XX
Next YY
Me.DrawWidth = 1 'Рисуем сетку
Me.ForeColor = RGB(0, 0, 255)
For YY = 0 To 3 Step 0.05
For XX = 0 To 3 Step 0.05
If Button = 1 Then
Plot XX, YY, Val1(XX, YY)
Else
Plot XX, YY, Val2(XX, YY)
End If
Next XX
Next YY
Me.DrawWidth = 3 'Рисуем узлы
Me.ForeColor = RGB(255, 0, 0)
For YY = 0 To 3
For XX = 0 To 3
Plot XX, YY, map(XX, YY)
Next XX
Next YY
End Sub
Private Function Val0(X As Single, Y As Single) As Single
Dim sx As Single, sy As Single, ix As Integer, iy As Integer
ix = Int(X): sx = X - ix
iy = Int(Y): sy = Y - iy
Val0 = map(ix, iy) * (1! - sx) * (1! - sy)
Val0 = Val0 + map(ix + 1, iy) * sx * (1! - sy)
Val0 = Val0 + map(ix, iy + 1) * (1! - sx) * sy
Val0 = Val0 + map(ix + 1, iy + 1) * sx * sy
End Function
Private Function Val1(X As Single, Y As Single) As Single
Dim sx As Single, sy As Single, ix As Integer, iy As Integer
ix = Int(X): sx = X - ix
iy = Int(Y): sy = Y - iy
If sx + sy < 1 Then
Val1 = map(ix, iy + 1) + map(ix + 1, iy) - map(ix, iy)
Val1 = Val1 * sx * sy + map(ix, iy) * (1! - sx) * (1! - sy)
Else
Val1 = map(ix, iy + 1) + map(ix + 1, iy) - map(ix + 1, iy + 1)
Val1 = Val1 * (1! - sx) * (1! - sy) + map(ix + 1, iy + 1) * sx * sy
End If
Val1 = Val1 + map(ix + 1, iy) * sx * (1! - sy)
Val1 = Val1 + map(ix, iy + 1) * (1! - sx) * sy
End Function
Private Function Val2(X As Single, Y As Single) As Single
Dim sx As Single, sy As Single, ix As Integer, iy As Integer
ix = Int(X): sx = X - ix
iy = Int(Y): sy = Y - iy
If sx - sy < 0 Then
Val2 = map(ix + 1, iy + 1) + map(ix, iy) - map(ix, iy + 1)
Val2 = Val2 * sx * (1! - sy) + map(ix, iy + 1) * (1! - sx) * sy
Else
Val2 = map(ix + 1, iy + 1) + map(ix, iy) - map(ix + 1, iy)
Val2 = Val2 * (1! - sx) * sy + map(ix + 1, iy) * sx * (1! - sy)
End If
Val2 = Val2 + map(ix, iy) * (1! - sx) * (1! - sy)
Val2 = Val2 + map(ix + 1, iy + 1) * sx * sy
End Function
Private Sub Form_Load()
Me.ScaleMode = 3
Me.Width = Screen.TwipsPerPixelX * 450
Me.Height = Screen.TwipsPerPixelY * 400
End Sub
Private Sub Plot(X As Single, Y As Single, v As Single)
Me.PSet (X * 100 + 30 + Y * 30, Y * 100 + 70 - v * 70)
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 35