I think i need a quadtree but not sure how to make it

Posted By: Elektron

I think i need a quadtree but not sure how to make it - 03/27/10 04:25

I am generating a forest.
I want next generated tree has distance X of all allready generated trees.
I am using vec_dist to generate map but is slow (500) trees
I donīt know if i should make my function calculating distance on 2d for speed up?
Or create a grid over map and only make collisition testing inside the cell?
Or maybe both?
I have the source of octree made on c++ , could be usefull translate to lite-c or the effort donīt pays and is faster to make from sctach?

Any advice or link are welcome.
Thanks in advance

Posted By: Ottawa

Re: I think i need a quadtree but not sure how to make it - 04/01/10 23:49

Hi!

I saw some code in the Lite-c contributions done by Alan
This might be what your looking for.

Use the search and write tcmain.c
Posted By: Superku

Re: I think i need a quadtree but not sure how to make it - 04/02/10 02:45

The algorithm of vec_dist is the following:
Originally Posted By: Manual
temp[0] = vektor1[0] - vektor2[0];
temp[1] = vektor1[1] - vektor2[1];
temp[2] = vektor1[2] - vektor2[2];
distance = sqrt(temp[0]*temp[0] + temp[1]*temp[1] + temp[2]*temp[2]);

That means it is really fast. There must be something different that slows your code/ game down, the fact that you create 500 entities at once should be the problem.
Immediately after creation set their passable flag, this will be much faster:

you = ent_create(tree...)
set(you,PASSABLE);
Posted By: MichaelGale

Re: I think i need a quadtree but not sure how to make it - 04/02/10 14:41

vec_dist is slow because it uses sqrt, especially when you have to use it many times per frame. If you want better speed, you could use the squared length (i.e. the same function as vec_dist but without the sqrt) to compare distances, although at the cost of accuracy on longer distances.
Posted By: Elektron

Re: I think i need a quadtree but not sure how to make it - 04/03/10 02:05

Thank you all for your help.
© 2024 lite-C Forums