Jump to content
  • Advertisement
Sign in to follow this  
NekoCode

Terrain editing

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

Hey guys & girls,

 

I am doing 3d terrain editor and I got question. I already made mouse ray casting, which works right. So the question itself: 

How can I detect when line "touches" or intersects the terrain vertice? I have vertice array with positions, but, unfortunately, can't figure it out.

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

You can calculate the distance to a vertex and then use a radius to choose if it's close enough or not.

 

Edit. If it's just an uniform grid, shouldn't it be quite easy to just grab the closest vertex on the grid depending on where you hit? Just divide the hit coordinates with the size of a tile on the grid and you should get the x and y for the vertex position. And with those you should get the actual vertex nicely from the array, vertices[y*w+x].

Edited by Sponji

Share this post


Link to post
Share on other sites

You can calculate the distance to a vertex and then use a radius to choose if it's close enough or not.

Yup, that's right! Just figured out one thing:

 

xPos and yPos are Mouse Ray coordinates. 1024 - Terrain width/height. ( It's equal of two, 1024x1024 ).

  xPos += 1024/2;
    zPos += 1024/2;
    
    if(xPos < 0)
        xPos = 0;
    else if(xPos >= 1024)
        xPos = 1024-1;
    
    if(zPos < 0)
        zPos = 0;
    else if(zPos >= 1024)
        zPos = 1024-1;

    vertexIndex = (int)(xPos) + (int)(zPos) * 1024;
    m_buffer.m_pos[vertexIndex] = ncVec3(....

This works great and returns right vertex index for me, but this is strange way.

Edited by NekoCode

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!