#### Archived

This topic is now archived and is closed to further replies.

This topic is 5403 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.)

##### Share on other sites
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]

##### Share on other sites
Thank you so much!

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

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 9
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633717
• Total Posts
3013514
×