Quadtree - Finding the coords

closed account (2NywAqkS)
I'm trying to make a simple 2D voxel quadtree engine that uses as little memory as possible i.e one bit per voxel, which I know can be done. The major problem I encounted is try to get a coordinate of a voxel.

I'm not sure whether it's the standard system but ive organised it so the data is just one big stream. For example; 1001001100111011011000100011

Because of the nature of a quad tree you know that the first 4 are the first branch. Then you times the number of 1s in the first branch by 4 to get how many are in the second branch and so on. This means you can work out it's

1: 1001
2: 00110011
3: 1011011000100011

So, based on the position of it in the stream, it should seem possible to work out the coords but I cant think of the mathmatical way of doing it.

I've made it so in each quad the sections are ordered like this:

1 | 2
-----
3 | 4

Any help is really appreciated
Thanks,
Rowan.
4 8 16

Those are powers of 2

So something like 2^(BranchNumber+1) I would imagine. But thats just for the number of bits per branch.
Last edited on
Topic archived. No new replies allowed.