• Advertisement
Sign in to follow this  

Please help me with picking objects in Direct3d world

This topic is 4520 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

Sorry for bad english (i'm from Russia) I have X and Y screen coordinates (from mouse) I need to find objects in the 3d world that lie under mouse cursor. My UpdateScreenFunction: D3DXMATRIX T, Rx, Ry, S, R; D3DXMatrixTranslation(&T, sceneSettings->Tx, sceneSettings->Ty, 0.0f); D3DXMatrixRotationX(&Rx, sceneSettings->Rx); D3DXMatrixRotationY(&Ry, sceneSettings->Ry); D3DXMatrixScaling(&S, sceneSettings->Scaling, sceneSettings->Scaling, sceneSettings->Scaling); R = Ry*Rx*S*T; m_device->SetTransform(D3DTS_WORLD, &R); m_device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( sceneSettings->BackgroundColor[0], sceneSettings->BackgroundColor[1], sceneSettings->BackgroundColor[2]), 1.0f, 0); m_device->BeginScene(); //*************************** drawind 3d objects //*************************** m_device->EndScene(); m_device->Present(0, 0, 0, 0); so, how can i find D3DXVECTOR3 vPickRayDir - Direction D3DXVECTOR3 vPickRayOrig - Position ?????

Share this post


Link to post
Share on other sites
Advertisement
Hi there CEA,
How are you doing?

The Problem
Ray picking examples and implementation.

The Solution
Cea, I thought that I might refer you to this implementation in C# which goes through the logic and is pretty easy to follow.

Ray Picking example, post.

The basic idea would be the following.

1) Get mouse coordinates in screen space
2) The near vector is near = new Vector3(cursor.X, cursor.Y, 0);
3) The far vector would be far = new Vector3(cursor.X, cursor.Y, 1);
4) You have 2 vectors now and if you unproject them you would go from screen space to world space using the D3DXVec3Unproject method in c++.
5) If you then subtract the 2 vectors from each other you get a ray.
6) You would then have the Ray Position and the Ray Direction. They are...
If you subtract the near from the far vector you get the ray direction and the ray position is the near vector. This means you have all the information needed for the D3DXIntersect method and you can test if it intersects the mesh.

I hope this helps buddy.
Take care.

Share this post


Link to post
Share on other sites

In addition to Armadon notes you could check the Toymaker page, you will find a tutorial on DirectX raypicking:
http://www.toymaker.info/Games/html/picking.html

Share this post


Link to post
Share on other sites
Thank you very much guys, all works now!!!!!!!!!!!!!!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement