User click on window : where is it in 3D space ?

Started by
2 comments, last by tonypr 17 years, 10 months ago
Hi, I'm currently programming a chess game (with C# and MDX). I managed to make the camera moving smoothly around the chessboard using spherical coordinates, but I don't know how to detect where user clicked. If a user clicks somewhere on screen, I need to know on which cell he clicked. And I don't have any clue how to do it... Collision ? Computing knowing the camera position ? I really don't have a clue. I guess a lot of maths are behind that problem so I'm just asking here. screenshot : http://xboxemul.free.fr/screen.jpg sourcecode : http://xboxemul.free.fr/esieaChess.zip Regards.
Advertisement
Did you try D3DXVec3Unproject?
You need to send a ray from the point that the user clicked along the view point of the camera. I believe this is called picking, which would be a good keyword for you to [google]

If you cannot find the resources yourself, post back here and I will give you some sample code.
Mike Popoloski | Journal | SlimDX
Thank you for the tip, I googled "Picking DirectX" and I came across that page.

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

In fact there's a picking demo in the DX SDK but it's a C++ sample and the code is pretty unclear (everything is in a big cpp file...). Well I guess I have to work around this now. Thanks a lot.

This topic is closed to new replies.

Advertisement