Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

Terrain intersection?

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

I want to edit my heightmap-based terrain using brushes. What's the standard way of figuring out which vertex the mouse cursor is pointing at?

Share this post


Link to post
Share on other sites
Advertisement
Raycasting. Test a ray against the heightmap mesh, to find the nearest triangle. Then you can find the nearest vertex (or if you want, you can then test a bounding sphere to get all vertices near the intersection)

Share this post


Link to post
Share on other sites
If the vertices are aligned in a grid it's just like indexing into an array. If your terrain origin is at xyz(0, 0, 0) then just divide the cursor world position by the horizontal distance of each vertice and then you have the index.
Since you're working with heightmaps, you can also easily paint to your maps using a shader, which is very easy to implement.

Share this post


Link to post
Share on other sites

I want to edit my heightmap-based terrain using brushes. What's the standard way of figuring out which vertex the mouse cursor is pointing at?


If you are using a heatmap you should be able to avoid going into the geometry at all similar to this (lower bit of the page). Not sure if that will net you more performance, but it might as you would be querying directly against the heatmap rather than querying against the geometry than translating that to the heatmap.

I imagine the cost of querying the geometry would be less, but the cost of the translation to the heatmap might be made up for by querying directly against the heatmap.

PURELY SPECULATIVE.

Share this post


Link to post
Share on other sites

If the vertices are aligned in a grid it's just like indexing into an array. If your terrain origin is at xyz(0, 0, 0) then just divide the cursor world position by the horizontal distance of each vertice and then you have the index.
Since you're working with heightmaps, you can also easily paint to your maps using a shader, which is very easy to implement.


This only works if using a overview camera or something similar, otherwise you cannot directly translate screen coordinates to world coordinates (assuming OP wants to use the mouse to edit the terrain)

Share this post


Link to post
Share on other sites

[quote name='froop' timestamp='1323787187' post='4893511']
If the vertices are aligned in a grid it's just like indexing into an array. If your terrain origin is at xyz(0, 0, 0) then just divide the cursor world position by the horizontal distance of each vertice and then you have the index.
Since you're working with heightmaps, you can also easily paint to your maps using a shader, which is very easy to implement.


This only works if using a overview camera or something similar, otherwise you cannot directly translate screen coordinates to world coordinates (assuming OP wants to use the mouse to edit the terrain)
[/quote]

I'm talking about unprojected coordinates. I didn't say screen space. You unproject the cursor position from screen- to view- to world space.

Edit: Ok, i can see how this could cause problems from certain views(?) but that's how I actually edit my terrain right now and I'm fine with it.

New suggestion: Render terrain world space positions to buffer, read back pixel below cursor.

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!