by AkramMaTT on Fri Jan 16, 2009 2:22 pm
Look here:
http://pastebin.ca/1297867You may have to modify it a bit to fit your way of storing the height values in the array.
-
- BinW.Write("quad")
- ' Quadtree List 1
-
- ' 16 * 16 quads
- BinW.WriteInt(256)
-
- Dim Vals() As Integer
- For a As Integer = 0 To 15
- For b As Integer = 0 To 15
- Vals = GetHighLow(Heights, a * 4, b * 4, a * 4 + 4, b * 4 + 4)
- BinW.WriteSingle(Vals(0))
- BinW.WriteSingle(Vals(1))
- Next
- Next
-
- ' Quadtree List 2
-
- ' List of values to get the start and end index to get the high and low values in the loops.
- Dim P1()() As Integer = {New Integer() {0, 0}, New Integer() {0, 32}, New Integer() {32, 32}, New Integer() {32, 0}}
- Dim P2()() As Integer = {New Integer() {0, 0}, New Integer() {0, 16}, New Integer() {16, 16}, New Integer() {16, 0}}
- Dim P3()() As Integer = {New Integer() {0, 0}, New Integer() {0, 8}, New Integer() {8, 8}, New Integer() {8, 0}}
-
- ' 1 + 4 + 16 + 64 = 85
- BinW.WriteInt(85)
-
- ' Root
- Vals = GetHighLow(Heights, 0, 0, 64, 64)
- BinW.WriteSingle(Vals(0))
- BinW.WriteSingle(Vals(1))
-
- ' split root in 4 -> 4 results
- ' 64, 64 splitted into 4 => block size = 32, 32
-
- For i As Integer = 0 To 3
- Vals = GetHighLow(Heights, P1(i)(0), P1(i)(1), P1(i)(0) + 32, P1(i)(1) + 32)
- BinW.WriteSingle(Vals(0))
- BinW.WriteSingle(Vals(1))
- Next
-
- ' split each subnode in 4 -> (4 * 4 = 16 results )
- ' 32, 32 splitted into 4 => block size = 16, 16
-
- For i As Integer = 0 To 3
- For a As Integer = 0 To 3
- Vals = GetHighLow(Heights, P1(i)(0) + P2(a)(0), P1(i)(1) + P2(a)(1), P1(i)(0) + P2(a)(0) + 16, P1(i)(1) + P2(a)(1) + 16)
- BinW.WriteSingle(Vals(0))
- BinW.WriteSingle(Vals(1))
- Next
- Next
-
- ' split each subsubnode in 4 -> (4 * 4 * 4 = 64 results)
- ' 16, 16 splitted into 4 => block size = 8, 8
-
- For i As Integer = 0 To 3
- For a As Integer = 0 To 3
- For b As Integer = 0 To 3
- Vals = GetHighLow(Heights, P1(i)(0) + P2(a)(0) + P3(b)(0), P1(i)(1) + P2(a)(1) + P3(b)(1), P1(i)(0) + P2(a)(0) + P3(b)(0) + 8, P1(i)(1) + P2(a)(1) + P3(b)(1) + 8)
- BinW.WriteSingle(Vals(0))
- BinW.WriteSingle(Vals(1))
- Next
- Next
- Next
-
-
-
- Function GetHighLow(ByVal Values(,) As Single, ByVal MinX As Single, ByVal MinY As Single, ByVal MaxX As Single, ByVal MaxY As Single)
- Dim high As Integer
- Dim low As Integer
- high = -9999999
- low = 9999999
-
- For x As Integer = MinX To MaxX
- For y As Integer = MinY To MaxY
- If Values(x, y) > high Then
- high = Values(x, y)
- End If
- If Values(x, y) < low Then
- low = Values(x, y)
- End If
- Next
- Next
-
- Return New Integer() {high, low}
- End Function
-
Last edited by
AkramMaTT on Sat Jan 17, 2009 10:05 pm, edited 7 times in total.