Recurring For Loop

closed account (2NywAqkS)
In a voxel project I'm working on in order to be the most efficient with my draw calls I need to work down the octree. currently it looks like this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for (unsigned i = 0; i < octree[size-3].voxels.size(); i++) // Fisrts For
{
	if (octree[size-3].voxels[i].active)
	{
		unsigned childPos = octree[size-3].voxels[i].pos * 8;
		for (unsigned i = childPos; i < childPos + 8; i++) // Second For
		{
			if (octree[size-2].voxels[i].active)
			{
				unsigned childPos = octree[size-2].voxels[i].pos * 8;
				for (unsigned i = childPos; i < childPos + 8; i++) // Third For
				{
					if (octree[size-1].voxels[i].active)
					{
						octree[size-1].voxels[i].Draw();
					}
				}
			}
		}
	}
}


Note: the the second and third for loop are near identical.

However I don't want this to be limited to just three loops. I need it to be dynamic. There must be a way I can have a dynamic number of nested for loops.

Any help is much appreciated.
Thanks,
Rowan.
Sounds like a case for recursion. That is the use of a recursive function which can call itself as required.
closed account (2NywAqkS)
Thanks!
Topic archived. No new replies allowed.