Quadtree Terrain

Started by
1 comment, last by 4 20 years, 1 month ago
In order to make a quadtree terrain engine, I must make sure that no neighboring cells differ by more than one level of detail. But how would I keep track of a cell''s neighbors? Right now each cell has a pointer to its parent and its four children (a child is NULL if it doesn''t exist.)
Advertisement
shh -

take the tree, decide how far down you want to traverse. Call
this number d.

 _ _ _ _ _ _ _ _|       |_|_|   ||       |_|o|_ _||       |   |   ||_ _ _ _|_ _|_ _||       |       ||       |       ||       |       ||_ _ _ _| _ _ _ |


we have that the first level is node ( 1,0 )

and for lower levels:
2: (0,0)
3: (1,1)

(2^2*1,2^2*0)+(2^1*(0,0))+(2^0*1,2^0*1)=
(4,0) + (0,0)+(1,1)
= (5,1)

This is the array element.

To express it in more general terms:
matrxElem = ( 2^(d-1) * level1 ) + ( 2^(d-2)*level2 ) +...+(2^(d-n)*leveln )

{ using vector addition and the fact that 2^0 = 1

Dave




----------------------------------------------------------
code projects are like relationship's

Edit 1 and 2: tree diagram messed up.
Edit 3: Said 2^3 by accident

[edited by - ray_intellect on February 28, 2004 6:50:02 PM]

[edited by - ray_intellect on February 28, 2004 6:51:17 PM]

[edited by - ray_intellect on February 28, 2004 7:03:22 PM]
Thank you so much!

I was trying to do this for the past two weeks without any success and your algorithm worked so well!

This topic is closed to new replies.

Advertisement