BigWinston

Hey,

I'm looking to obtain the screen (X and Y) co-ordinates of vertices.

Whenever I move my mouse over a vertex I want to change it's color, but don't know how to compare the mouse position with my vertices.

Any suggestions

Thanks



Re: XNA Game Studio Express Get Screen Coordinates of Vertices?

jnog

Hello,

Perhaps you should obtain the vertices rendered on some X,Y screen coordinate instead of obtaining the ScreenX, ScreenY coordinates for all your scene's vertices. DirectX does this for you and calls it picking. As far as I know there is no such feature in XNA yet but here's a good tutorial on the subject:

http://www.thehazymind.com/archives/2005/10/tutorial_9_picking_objects_fro.htm

Cheers

Joao Nogueira






Re: XNA Game Studio Express Get Screen Coordinates of Vertices?

Jon Watte

There are three ways of doing this:

1) Cast the ray in world space, collision test against the bounding sphere of each mesh, and for the meshes that overlap, transform the vertices into screen space and compare. This requires software transform of the vertices, which might be a waste of CPU. (screen position = meshvertex * WORLD * VIEW * PROJECTION / W * VIEWPORT)

2) Render each vertex as a small quad with a unique color for each (there are 16 million unique colors, should be enough). Read back the framebuffer, and read the color at the pixel location.

3) Cast the ray in world space, do early culling with bounding spheres, then do a raycast into the mesh, doing vertex picking against the ray in mesh space. This needs less transform work. You can transform a pixel into world space using the Unproject function.

I'd go for 2 or 3, depending on what I was doing.