• Advertisement

Archived

This topic is now archived and is closed to further replies.

Clicking on terrain

This topic is 5525 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 know this has been asked before but since the search feature still is down I''m going to ask it once again. I have my terrain represented as a grid. I know the height on each point and I can calculate the height between points. What I want to do now is get the closest point to the mouse cursor when I click the mouse. In addition to the terrain data I know my own position, my view vector and the mouse 2d coordinates. If someone could give me some hints of what I should do next or point me in the direction of a tutorial that would be very helpful. Thanks

Share this post


Link to post
Share on other sites
Advertisement
You assume the mouse click is on the z-near plane. So first you have to convert your screen coordinates to the x and y value of the z-near plane. That is a simple transform and scaling. Then you have to cast a ray from the camera through the point on the z-near screen and find the first plane it intersects. I think that is easiest done using the depth buffer. The depth buffer will not give you the exact z, but rather just an approximate one. That is enough to give you an approximate x and y of the point. You then have to transform that to world coordinates. That gives you a starting place to check actual terrain triangles against the ray cast from the camera.

Share this post


Link to post
Share on other sites
Pardon my ignorance but what do you mean by z-near plane?

I have thought about what you said but I can't understand how to transform the mouse coordiantes. I could probably manage to trace the cameras view vector untill it intersects the terrain but that won't give me the position I want. Any tips about how I should transform the mouse coordiantes so that I get a more correct position to start my trace from? I take it that was sort of what you meant.

[edited by - ArchMiffo on December 3, 2002 2:11:36 PM]

Share this post


Link to post
Share on other sites
z-near is the near clipping plane. Anything on the same side of that plane as the camera is not drawn. It is like being off the left, right, top or bottom of the screen. z-far is the opposite limit of your view. Using z-near is mainly a way to avoid things like extreme magnification of textures and extreme distortion of objects due to perspective projection. Think of one finger over the lense when you snap a picture with a camera. The tip of one little tiny finger can block out the entire Golden Gate Bridge you are trying to take a picture of. z-near basically eliminates that since it would keep the finger from being rendered when used properly.

Share this post


Link to post
Share on other sites
Thanks, that cleared that up. So what you are suggesting is that I project the coordinates on that plane and then trace a line from the cameras position through the point on the plane. Was that anywhere close? If it was just one problem remains and that is how to transform the cordinates

Share this post


Link to post
Share on other sites
I just based my Terrain Engine off the object selection tutorial at GameTutorials.com


i applied a name (unsigned integer) to each square using glPushName / glPopName combos and let it return the value

Share this post


Link to post
Share on other sites

  • Advertisement