• ### What is your GameDev Story?

Public Group

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

## Recommended Posts

Can anyone help me solve this problem? It first resize to 2^2 but then the other statement raises it again ad infinitum Do i need to change the criteria? What is the best method for this ? /* Check here if we need to resize the grid */ if(object_count>1) { if(((grid_size*grid_size)/object_count<2) { grid_size+=1; fprintf(stderr,"Increasing: grid_size:%d [%d]\n",grid_size*grid_size,grid_size); /* Reset collisions */ collisions=0; } else if((grid_size*grid_size)/object_count/collisions>2) { grid_size-=1.0; fprintf(stderr,"Decreasing: grid_size:%d [%d]\n",grid_size*grid_size,grid_size); while(tmp!=NULL) { free(tmp->x); free(tmp->y); free(tmp->z); assign_coordinate(tmp); tmp=tmp->next;} } }

##### Share on other sites
Don't forget to a) give your posts meaningful titles, and b) format your code using 'code' or 'source' tags.

##### Share on other sites
It might help if you tell us what problem you're trying to solve. [wink]

What should that snippet of code do if it were functioning correctly? What (if anything) does it do now? Looks like it's something to do with resizing a grid, but if you can tell us exactly what's supposed to be going on we'll probably be better able to offer suggestions.

##### Share on other sites
Yes i'm trying to resize a grid accordingly to how many objects there are. It's a 2d grid in 3d space.
I a) need a simple formula to calculate this
and b) need to fix this problem

So the grid is 45^2, if i have 3 objects, it would be way to large so i downsize it. Vice versa the other
way around. Currently it first downsize to 2^2, which is ok, but then the other if statement kicks in
en increases it again, so from 2^2 to 2^3 and then it goes from 2^3 to 2^2 again, a loop so to speak.

I also am not to happy with the current formula for determining when to enlarge or make it smaller.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 11
• 15
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
634150
• Total Posts
3015814
×