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.
Picking: Finding out if/where a mouse click lies on a 3d plane
Hi,
I am currently working on the same issue. Take a look at the tutorial pointed by Scotto1001 (toymaker), it might help.
I am currently working on the same issue. Take a look at the tutorial pointed by Scotto1001 (toymaker), it might help.
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.
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.
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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement