VB.Net - SmoothMatrix (By Silvester)
Public Sub SmoothMatrix(ByVal Target As DarkGDK.Basic3D.Matrix, ByVal MaxTileX As Integer, ByVal MaxTileZ As Integer, ByVal Times As Integer)
Dim T As Integer
Dim X As Integer
Dim Z As Integer
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long
Dim e As Long
Dim f As Long
Dim g As Long
Dim h As Long
Dim Total As Long
Dim Avg As Long
' DarkGDK.Text.SetColor(Color.Yellow)
For T = 1 To Times
For X = 0 To MaxTileX
For Z = 0 To MaxTileZ
a = Target.GetHeight(X - 1, Z + 1)
b = Target.GetHeight(X, Z + 1)
c = Target.GetHeight(X + 1, Z + 1)
d = Target.GetHeight(X + 1, Z)
e = Target.GetHeight(X + 1, Z - 1)
f = Target.GetHeight(X, Z - 1)
g = Target.GetHeight(X - 1, Z - 1)
h = Target.GetHeight(X - 1, Z)
If X <> 0 And X <> MaxTileX And Z <> 0 And Z <> MaxTileZ Then
Total = a + b + c + d + e + f + g + h
Avg = Total / 8
End If
If X = 0 And Z = 0 Then
Total = b + c + d
Avg = Total / 3
End If
If X = MaxTileX And Z = MaxTileZ Then
Total = f + g + h
Avg = Total / 3
End If
If X = 0 And Z <> 0 Then
Total = b + c + d + e + f
Avg = Total / 5
End If
If Z = 0 And X <> 0 Then
Total = a + b + c + d + h
Avg = Total / 5
End If
If X = MaxTileX And Z <> MaxTileZ Then
Total = a + b + f + g + h
Avg = Total / 5
End If
If Z = MaxTileZ And X <> MaxTileX Then
Total = d + e + f + g + h
Avg = Total / 5
End If
Target.SetHeight(X, Z, Avg)
Target.Update()
' DarkGDK.Text.ShowText(0, 0, "Average Height : " + Str(Avg))
' DarkGDK.Text.ShowText(0, 20, "Total Height : " + Str(Total))
' DarkGDK.Text.ShowText(0, 40, "T : " + Str(T) + "/" + Str(Times) + " X : " + Str(X) + " Z : " + Str(Z))
DarkGDK.Core.Sync()
Next Z
Next X
Next T
End Sub
A rewrite from
This. It's easy to use, just enter the Matrix you want to smooth, the max X tiles, Max Z tiles and the amount of times you want it smoothed, and let it do it's job! Enjoy
C# - Keyboard and Mouse events. (By o2q)
private static Boolean LeftMouseDown;
private static Boolean[] KeyDown = new Boolean[104];
private static int lastScanCode;
public static void SetupKeyEvents() // Must be called once before any of the following functions
{
for(int i=0;i<KeyDown.Length;i++)
KeyDown[i] = false;
}
public static Boolean SingleKeyPress(DarkGDK.IO.Keys kKey)
{
if (DarkGDK.IO.Keyboard.State(kKey) && !KeyDown[DarkGDK.IO.Keyboard.ScanCode])
{
KeyDown[DarkGDK.IO.Keyboard.ScanCode] = true;
lastScanCode = DarkGDK.IO.Keyboard.ScanCode;
return true;
}
else if (DarkGDK.IO.Keyboard.ScanCode == 0) // Means we aren't pressing any key :)
{
KeyDown[lastScanCode] = false;
return false;
}
else
return false;
}
public static Boolean SingleLeftClick()
{
if (DarkGDK.IO.Mouse.LeftClick && !LeftMouseDown)
{
LeftMouseDown = true;
return true;
}
else if (!DarkGDK.IO.Mouse.LeftClick)
{
LeftMouseDown = false;
return false;
}
return false;
}
Instead of constantly checking whether a key is down or not, these functions check if a key is pressed once and won't read it again until it's released.
EDP Map Editor[2D]