Not logged in, Join Here! or Log In Below:  
 
News Articles Search    
 

 Home / 3D Theory & Graphics / D3D Menu Account Manager
 
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.
 
khm

March 21, 2005, 09:45 AM

I'm desging a GUI in D3D , to click on button i project a ray from mouse position and test if it hit a triangle -button- useing D3DXIntersectTri(), but the code aint accurate at all here is the code :

  1.  
  2.  
  3. D3DXMATRIXA16 matWorld, matView;
  4. D3DXMATRIX m;
  5. POINT ptCursor;
  6. D3DXVECTOR3 vPickRayDir;
  7. D3DXVECTOR3 vPickRayOrig;
  8.  
  9. GetCursorPos( &ptCursor );
  10. ScreenToClient( hwnd, &ptCursor );
  11. d3d_device->GetTransform(D3DTS_VIEW, &matView);
  12. d3d_device->GetTransform(D3DTS_WORLD, &matWorld);
  13.  
  14.  
  15.     // Compute the vector of the pick ray in screen space
  16. D3DXVECTOR3 v;
  17.         v.x =  ( ( ( 2.0f * ptCursor.x ) / screenWidth  ) - 1 ) / matWorld._11;
  18.         v.y = -( ( ( 2.0f * ptCursor.y ) / screenHeight ) - 1 ) / matWorld._22;
  19.     v.z =  1.0f;
  20.  
  21.         // Get the inverse view matrix
  22.        
  23.     D3DXMatrixInverse( &m, NULL, &matView );
  24.  
  25.         // Transform the screen space pick ray into 3D space
  26.     vPickRayDir.x  = v.x*m._11 + v.y*m._21 + v.z*m._31;
  27.     vPickRayDir.y  = v.x*m._12 + v.y*m._22 + v.z*m._32;
  28.     vPickRayDir.z  = v.x*m._13 + v.y*m._23 + v.z*m._33;
  29.         D3DXVec3Normalize(&vPickRayDir,&vPickRayDir);
  30.     vPickRayOrig.x = m._41;
  31.     vPickRayOrig.y = m._42;
  32.     vPickRayOrig.z = m._43;
  33. ///p1 , p2, p3 are triangle vertices
  34. if(D3DXIntersectTri(p1,p2,p3,&vPickRayOrig,&vPickRayDir,NULL, NULL,NULL))
  35. {
  36.         /////do smthing when button pressed
  37. }
  38.  


whats wrong with this ,i tried it for mesh but using D3DXIntersect it worked fine, any one know ?
is there a better way to create buttons and GUI using D3D and check mouse click on it,i dont want to use GUI from DX sample browser.

 
Goz

March 21, 2005, 12:10 PM

Erm presumably its a 2D display?

If it is then surely its pretty easy to work out where the buttons are. Your only issue is converting your mosue cursor from screen coords to the -1 -> 1 range D3D uses for rendering. However not exactl insurmountable.

  1.  
  2. POINT p;
  3. GetCursorPos( &p );
  4.  
  5. ScreenToClient( hRenderWindow, &p );
  6.  
  7. float x = ((p.x / windowWidth)  * 2.0f) - 1.0f;
  8. float y = ((p.y / windowHeight) * 2.0f) - 1.0f;
  9.  


x and y now contain the position of your mouse in D3D device co-ordinates.

Hope thats some help :)

 
This thread contains 2 messages.
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.