Jump to content
  • Advertisement
Sign in to follow this  
TheChubu

Probably a stupid question...

This topic is 1849 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

Hi! See, I have a regular grid of points for a heightmap, and I want to modify the heights of the points in a radius around an arbitrary point in the grid (sort of like a radial gradient). I cant figure out how to do that without hardcoding each point offset in my code.

 

Could someone help me with this? I know it should be doable in a few loops but I can't wrap my head around how to do it...

Share this post


Link to post
Share on other sites
Advertisement
I would imagine that each point.z is a function of the radius. As the distance from the mouse cursor increases, height decreases.

Share this post


Link to post
Share on other sites

Go over the points in your grid, calculate distance from center point of circle to that point.  If it's less than the radius of the circle, then do point.z+=(1-distance_away/radius)*height_change to get a gradient

Share this post


Link to post
Share on other sites

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

 

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

Share this post


Link to post
Share on other sites

Thanks for the answers. It is necessary to go all over the grid for calculating each single gradient? Since its a heightmap I'd have grids of 512x512 to 4k x 4k, maybe 8k x 8k. I have to calculate a few hundred small gradients (10 to 20 point radius). Seems wasteful.

 

Hm... You give me an idea... I can define a bounding box from the radius, loop over the points inside those bounds instead of the whole grid, and then calculate the gradient the way you described.

Yes that is precisely what I would do.

Share this post


Link to post
Share on other sites

 Sweet! Not only worked but its also way shorter than my previous half finished method (90 lines against 30 biggrin.png).

 

The gradients end in massive black holes since there are still a few things I need to fix, but it looks good. Thanks again!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!