Jump to content
  • Advertisement
Sign in to follow this  

Help With Converting Mouse Position to 3D

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

I am using DX8 and have a mixed 2D/3D scene. In this scene I place several 3D quads and at different distances from the camera. I am trying to take a given mouse position and see if the 2D point is within a quad's width & height. I am assuming that a ray or something may have to be cast out into the screen but I am not 100% sure if that is the only, best, or easist way nor have I have never done this. Below is the code I use for the camera (which never moves) and the viewport if any of this helps.... #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600 // I create the viewport first.... D3DVIEWPORT8 Viewport; Viewport.X = 0; Viewport.Y = 0; Viewport.MinZ = 0.0f; Viewport.MaxZ = 1.0f; Viewport.Width = SCREEN_WIDTH; Viewport.Height= SCREEN_HEIGHT ; m_pd3dDevice->SetViewport( &Viewport ); //then I create the projection matrix.... D3DXMATRIX ProjMatrix; ZeroMemory( &ProjMatrix, sizeof( D3DXMATRIX ) ); float ScrAspect = (float)SCREEN_WIDTH/ (float)SCREEN_HEIGHT; float FOV = D3DX_PI / 4; D3DXMatrixPerspectiveFovLH( &ProjMatrix, FOV, ScrAspect, 1.0f, 1000.0f ); m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &ProjMatrix ); // finally I set the camera position which never changes D3DXMATRIX ViewMatrix; D3DXMatrixLookAtLH( &ViewMatrix, &D3DXVECTOR3( 0.0f, 0.0f, -5.0f ), &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),&D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) ); m_pd3dDevice->SetTransform( D3DTS_VIEW, &ViewMatrix );

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!