Jump to content
  • Advertisement
Sign in to follow this  
Andy474

[XNA] Selecting Vertices with the Mouse. Can it be Done?

This topic is 3265 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 guys. So I have a 3D Map drawn. I was wondering. is it possible to Select One if these Vertices or a Tile (2 Triangles forming a Square)? I am attempting to make a map Editor for my 3D game and want to implement Terra forming, e.g. Raising / Lowering the height of the Terrain. My thoughts.
1/ Turn the 3D Co-Ordinates into 2D coordinates 
2/ Check they are within the View port Rectangle
3/ Check them Against the Mouse position.

4/ If the mouse is Pressed down
5/ if the Mouse is moved up, adjust the Y value of the vertex by the amount the mouse moved up.
6/ if the mouse is released, leave the vertex Alone.
Now the Only Problem I find with this is, I dont know how to convert a Vector3D into a Vector2D ... this is going to be key in my game for clicking on items and can Obviously be done, so any help is appreciated .... [EDIT] While Googling I have found Viewpot.Project, seems to do what I want it do, is this the right Function or is there an Alternative?

Share this post


Link to post
Share on other sites
Advertisement
Yes, that should project 3D points to 2D points. You can also use UnProject to turn 2D points into 3D points, if you'd rather do it that way. One popular way is to UnProject the mouse position into a 3D point very far away, and then calculate the intersection of the line from the camera to that far away point with the world, to know what part of the world is clicked.
This was discussed just now in another thread that might give you some ideas: my gluUnProject calls is way to costly.

EDIT: Further reading: http://www.google.com/search?q=3d%20object%20mouse%20xna+site:www.gamedev.net =).

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!