Jump to content
  • Advertisement
Sign in to follow this  
Pushapjit

mouce capture

This topic is 4093 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 developing a 3D virtual environemnt using DirectX APIs. In this virtual environment I am able to move the user camera using keyboard keys. Now, I want to move teh camera using mouse but not able to do it. following is the code used for mouse capture. Problem is camera is not moving with the mouse click. Any Suggestion please.
[source lang = "cpp"]
// Mause Capture
	BOOL m_bCapture;
	D3DXMATRIXA16 m_matTrackBall;


m_bCapture          = FALSE;


HRESULT My3DApplication::OneTimeSceneInit()
{
	 D3DXMatrixIdentity( &m_matTrackBall );
	return S_OK;
}


HRESULT My3DApplication::FrameMove()
{

// When the window has focus, let the mouse adjust the camera view
    if( m_bCapture )
    {
        D3DXMATRIXA16 matCursor;
        D3DXQUATERNION qCursor=D3DUtil_GetRotationFromCursor( m_hWnd );
        D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
        D3DXMatrixMultiply( &m_matView, &m_matTrackBall, &matCursor );

        D3DXMATRIXA16 matTrans;
        D3DXMatrixTranslation( &matTrans, 0.0f, 0.0f, 3.0f );
        D3DXMatrixMultiply( &m_matView, &m_matView, &matTrans );
    }
}




LRESULT My3DApplication::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                                    LPARAM lParam )
{
// Capture mouse when clicked
    if( WM_LBUTTONDOWN == uMsg )
    {
        D3DXMATRIXA16 matCursor;
        D3DXQUATERNION qCursor=D3DUtil_GetRotationFromCursor( m_hWnd );
        D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
        D3DXMatrixTranspose( &matCursor, &matCursor );
        D3DXMatrixMultiply( &m_matTrackBall, &m_matTrackBall, &matCursor );

        SetCapture( m_hWnd );
        m_bCapture = TRUE;
        return 0;
    }

    if( WM_LBUTTONUP == uMsg )
    {
        D3DXMATRIXA16 matCursor;
        D3DXQUATERNION qCursor=D3DUtil_GetRotationFromCursor( m_hWnd );
        D3DXMatrixRotationQuaternion( &matCursor, &qCursor );
        D3DXMatrixMultiply( &m_matTrackBall, &m_matTrackBall, &matCursor );

        ReleaseCapture();
        m_bCapture = FALSE;
        return 0;
    }
}

Share this post


Link to post
Share on other sites
Advertisement
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!