0

I have to create a pseudo wolfenstein 3D as an assignement in school, and I need a structure to represent the map. As all the calculations will be based on a two-dimensionnal grid, I thought that a quad tree would be what I needed.

How would you parse a file that contains this for example:

1 1 1 1 1 1 1 1

1 0 0 0 0 0 0 1

1 0 0 1 0 0 0 1

1 0 0 1 0 0 0 1

1 0 0 1 0 0 0 1

1 1 1 1 1 1 1 1

where the 1s are wall blocks and the 0s empty blocks, into a quad tree structure?

Matt K
  • 13,370
  • 2
  • 32
  • 51
Mathieu_Du
  • 787
  • 4
  • 10
  • heh old and already done I hope but I need to add if you coded Wolfenstein (pseudo) 3D style it uses just 2D map no trees ... so simple 2D array will suffice see http://stackoverflow.com/a/32733650/2521214 trees only complicate things for the ray-caster (for such small resolutions). – Spektre Nov 25 '15 at 10:55

2 Answers2

0

You have a couple of options here. One way would be to read the entire file into memory into some kind of array, and then build the quadtree top-down from there. This is probably the most straightforward way to do this, as long as the map is not extremely huge.

Another option would be to build the tree bottom-up from each individual node at the bottom, then once you have parsed enough nodes to form a parent node from what you have read, do so. In this example, you would form leaf nodes for each value read. Then on even columns on even rows, after you have formed your leaf node, form your second-level nodes from there.

You will get this kind of structure:

1 1 1 1 1 1 1 1
1 2 1 2 1 2 1 2
1 1 1 1 1 1 1 1
1 2 1 3 1 2 1 3
1 1 1 1 1 1 1 1
1 2 1 2 1 2 1 2
1 1 1 1 1 1 1 1
1 2 1 3 1 2 1 4

Each number represents the highest level of node to form once reading the number in that position. Also form all levels below each (i.e. on level 3, also form a level 2 node and a leaf (level 1) node).

David Brigada
  • 594
  • 2
  • 10
0

You could build the tree in a top-down manner: Asumming that the whole array (let's say it's dimension is 8x8) is mixed with zeros and ones, partition it, e. g. in 4x4 tiles. Now check whether each tile contains only ones or zeros or both. When a tile contains both, then partition it again (2x2) and recheck. Repeat until you are on "pixel"-level (1x1). You can store this in a struct containing pointers to the four neighboring tiles.

This picture on Wikipedia shows it pretty good.

Sebastian
  • 8,046
  • 2
  • 34
  • 58