Jump to content
  • Advertisement

Archived

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

Mihail121

QuadTree???

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can anybody show me how to build a quadtree.I''ve checked some examples over the net but they are in chiniese.10x The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Advertisement
have a look here, its for terrain rendering:

http://www.gamasutra.com/features/20000228/ulrich_pfv.htm

Share this post


Link to post
Share on other sites
I''ve checked it but it''s not what i need.PLEEEEEEEESE!!!!!!SOMEBODY A LITTLE QUADTREE CODE FOR THE DUMM ONE.A reward is offered for everyone who can help me(a trip to a unknown island with no return :-)))))))I''m just too desparate to try everything.



The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
I DON''T EVEN TRY!I SPEND THE LAST WEEK IN TRYING TO CODE A QUADTREE!

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
I can''t show it cause i deleted the junk but here is the deal:i''ve alredy started to re-writed it.If i encouter a problem again i''ll post the funckin'' code cause i definelty need some explanation on what the hell is going wrong.I suspect the reason is in me :-)))))))))))))))))

The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
Ok here is some code.If somebody tells me what''s wrong i''ll require a picture of him and i''ll put it on my room''s wall!:

void qt_create(void)
{
quad_tree = (NODE*)g_mem->Alloc(sizeof(NODE));

memset(quad_tree,0,sizeof(NODE));

quad_tree->type = TYPE_NODE;

SET3(quad_tree->mins,0,0,0);
SET3(quad_tree->maxs,TERRAIN_SIZE,0,TERRAIN_SIZE);

qt_calc_geometry(&quad_tree);

qt_subdivide_node(&quad_tree);
}

void qt_delete(void)
{
qt_delete_node(&quad_tree);
}

void qt_subdivide_node(NODE **node)
{
NODE *p = (*node);

if(!p || p->type != TYPE_NODE)
return;

Vector3 mp;

SET3(mp,(p->maxs[X] - p->mins[X]) / 2,
(p->maxs[Y] - p->mins[Y]) / 2,
(p->maxs[Z] - p->mins[Z]) / 2);

for(int k = 0;k < 4;k++)
{
p->children[k] = (NODE*)g_mem->Alloc(sizeof(NODE));

memset(p->children[k],0,sizeof(NODE));

switch(k)
{
case 0:SET3(p->children[k]->mins,p->mins[X],0,p->mins[Z]);
SET3(p->children[k]->maxs,mp[X],0,mp[Z]);
break;
case 1:SET3(p->children[k]->mins,mp[X],0,p->mins[X]);
SET3(p->children[k]->maxs,p->maxs[X],0,mp[Z]);
break;
case 2:SET3(p->children[k]->mins,p->mins[X],0,mp[Z]);
SET3(p->children[k]->maxs,mp[X],0,p->maxs[Z]);
break;
case 3:SET3(p->children[k]->mins,mp[X],0,mp[Z]);
SET3(p->children[k]->maxs,p->maxs[X],0,p->maxs[Z]);
break;
}

qt_calc_geometry(&p->children[k]);

if(p->children[k]->num_faces < 1000)
p->children[k]->type = TYPE_LEAF;
else
p->children[k]->type = TYPE_NODE;
}

qt_subdivide_node(&p->children[0]);
qt_subdivide_node(&p->children[1]);
qt_subdivide_node(&p->children[2]);
qt_subdivide_node(&p->children[3]);
}

void qt_delete_node(NODE **node)
{
if((*node))
{
if((*node)->faces)
g_mem->Free((*node)->faces);

if((*node)->type != TYPE_LEAF)
{
for(int k = 0;k < 4;k++)
qt_delete_node(&(*node)->children[k]);
}
}
}

void qt_calc_geometry(NODE **node)
{
int num_faces = 0;

if(!(*node))
return;

for(int k = 0;k < NUM_TERRAIN_FACES;k++)
{
for(int m = 0;m < 4;m++)
{
int v = faces[k][m];

if(verts[v][X] >= (*node)->mins[X] && verts[v][X] <= (*node)->maxs[X] &&
verts[v][Z] >= (*node)->mins[Z] && verts[v][Z] <= (*node)->maxs[Z])
{
memcpy(vis_faces[num_faces++],faces[k],sizeof(face));
break;
}
}
}

(*node)->faces = (face*)g_mem->Alloc(num_faces * sizeof(face));
(*node)->num_faces = num_faces;
}



The PAIN is coming...this summer!!!In cinemas everywhere.

Share this post


Link to post
Share on other sites
God fuck, dude. At least ask nicely and lay off the caps lock.

Yes I remember, you were flamed at help wanted for the same reason.

I posted some quadtree code that should be easy to understand into my post again the link is:
http://www.suicidesolutions.com/quadtree.zip

It is java, but when you see node.something . usually means pointer. Anyhow, it should not be that hard.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!