Picking: Finding out if/where a mouse click lies on a 3d plane

Started by
14 comments, last by ktuluorion 18 years, 7 months ago
I use a similar code in my app and it works.
I use the world matrix of my object, not the one stored in device.
Advertisement
Book of hook article
2 + 2 = 5 for extremely large values of 2
Hi,
I am currently working on the same issue. Take a look at the tutorial pointed by Scotto1001 (toymaker), it might help.

My project`s facebook page is “DreamLand Page”

Your sample code looks ok so far, but:

If you've got a pure device the GetTransform functions will fail. Check with the SUCCEEDED or FAILED macro.

A D3DXPlane can be constructed from three random points with the function D3DXPlaneFromPoints.

Then use D3DXPlaneIntersectLine function with the plane and the two points you got from the D3DXVec3Unproject calls.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>


Here you go. This is how I have done it in my 3D Mesh Builder:
/////////////////////////////////////////////////////////////// get a line from the mouse cursor projected into the world/////////////////////////////////////////////////////////////    POINT m1;    GetCursorPos( &m1 );    pActiveView->ConvertMouseToLocal( m1 );			    D3DXVECTOR3 result;    D3DXVECTOR3 result2;    D3DXMATRIX world;    D3DXMatrixIdentity( &world );    D3DVIEWPORT9 viewport;    pActiveView->GetDXDevice()->GetViewport( &viewport );    D3DXVec3Unproject( &result, &D3DXVECTOR3( m1.x, m1.y, 0 ), &viewport,   &pActiveView->GetCamera()->GetProjection(), &pActiveView->GetCamera()->GetView(), &world );    D3DXVec3Unproject( &result2, &D3DXVECTOR3( m1.x, m1.y, 0.5f ), &viewport, &pActiveView->GetCamera()->GetProjection(), &pActiveView->GetCamera()->GetView(), &world );    IntersectLine line;    if( pActiveView->GetCamera()->IsViewProjected() )    {	line.start = pActiveView->GetCamera()->GetPos();	line.end = line.start + (10 * (result2-result));    }    else    {	line.start = result;	line.end = result2;    }///////////////////////////////////////////////// this code is to test my poly select methods///////////////////////////////////////////////    int index = appData.pActiveMesh->GetPolyIndexOnLine( line );

Hope that helps. : )
Quote:Original post by Endurion
Your sample code looks ok so far, but:

If you've got a pure device the GetTransform functions will fail. Check with the SUCCEEDED or FAILED macro.

A D3DXPlane can be constructed from three random points with the function D3DXPlaneFromPoints.

Then use D3DXPlaneIntersectLine function with the plane and the two points you got from the D3DXVec3Unproject calls.


Pure device? What does that mean?

[Piebert Entertainment] [Ask The All-Knowing Oracle A Question]------------------------------------------------------------GDSFUBY GameDev Society For UnBanning YodaTheCodaIf you want to see yoda unbanned then put this in your sig ------------------------------------------------------------DAIAGA Dave Astle is a God Association. To join, put this in your sig!Founder and High Priest of DAIAGA[edited by - YodaTheCoda on December 10, 2003 1:57:54 PM]

This topic is closed to new replies.

Advertisement