Sign in to follow this  

Terrain editing

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

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

This topic is 1119 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this