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

This topic is 3351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
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.

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
14
5. 5
A4L
13

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013643
×