Jump to content
  • Advertisement
Sign in to follow this  
sobeit

How does 3D game get the vertex's pixel-coordinate?

This topic is 3276 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 have used D3DX9 to draw a chessboard, now I confuse how can i get pixel-coordinate of the vertex which has been transformed by projective matrix, so that i can compare it with mouse cooodinate ,then put the chessman. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
To answer your question, you simply apply the graphics transformation yourself, which looks something like this (look up the official version in the d3d docs):

screen pos = viewport * projection * view * world * input;

You're setting those matrices to the d3d pipeline and internally it is concatenating them to transform each vertex. You can just do this yourself.

But, i'll give you a hint. This is not how you do what is referred to as picking. There's no sense in transforming the entire scene in screen space twice, once for rendering and once for picking. Also any spatial partitioning you may (but unlikely) have implemented is going to be in world space. Picking should be done in world space.

This means that you actually transform the mouse coordinates into a ray which points into the scene as if a laser is shot out of the camera. You then compare this ray to the objects in the scene to determine which one was clicked.

It's very easy to do a ray vs plane intersection to determine the XY coordinate of your cheese board that was clicked. You dont even need to reference the vertices if the size of each grid space and a corner point is known.

There other methods. In opengl you can attribute a name to each polygon rendered. Then you can query the names that were drawn to a particular pixel. Some people draw each object or polygon a different color in a special off screen rendering. They then find the color for the clicked pixel and lookup which object that refers to. For your case you'd draw each grid space a different color. You could encode the indices in the R and G components so grid space 2,3 would have a color RGB(2,3,0).

Good luck.

Share this post


Link to post
Share on other sites
Quote:
Original post by sobeit
I have used D3DX9 to draw a chessboard, now I confuse how can i get pixel-coordinate of the vertex which has been transformed by projective matrix, so that i can compare it with mouse cooodinate ,then put the chessman.

Thanks in advance.





Look for the directx tutorial program sample for 'Pick' which demonstrates
how the cursor input can be used to 'pick' a facet triangle in a list of triangles (like ones making up the squares of your 3d chess board).

Basickly the program identifies a line from your camera eyepoint thru a pixel on the screen (a calculated plane) pointed to by the mouse and then does a Line Intersect Triangle test on a list of triangles you provide.

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!