Jump to content
  • Advertisement
Sign in to follow this  
falki02

move picture around the screen - DirectX9

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

well i'm loading a picture with a big resolution as a texture and i would like to be able to move this picture around the screen using the mouse. i found out that i can capture mouse event with WM_MOUSEMOVE , WM_LBUTTONDOWN ... but i'm doing something wrong while calculating the new position of the picture. How can i update the position of the picture on the screen ? From now it sometimes disappears from the screen. I would appriciate if u guys could give some help. thx below the code for WindowProc() method
<pre>
LRESULT CALLBACK WindowProc( HWND   hWnd, 
							 UINT   msg, 
							 WPARAM wParam, 
							 LPARAM lParam )
{
    static POINT pointLastMousePosition;
    static POINT pointtCurrentMousePosition;
    static bool bMousing;

    switch( msg )
	{	
        case WM_KEYDOWN:
		{
			switch( wParam )
			{
				case VK_ESCAPE:
					PostQuitMessage(0);
					break;
			}
		}
        break;

		case WM_MOUSEMOVE:
        {
            pointtCurrentMousePosition.x = LOWORD (lParam);
            pointtCurrentMousePosition.y = HIWORD  (lParam);

            if( bMousing )
            {
				g_fSpinX = (pointtCurrentMousePosition.x - pointLastMousePosition.x);
                g_fSpinY = (pointtCurrentMousePosition.y - pointLastMousePosition.y);
            }
            
            pointLastMousePosition.x = pointtCurrentMousePosition.x;
            pointLastMousePosition.y = pointtCurrentMousePosition.y;
        }
        break;

		case WM_LBUTTONDOWN:
        {
            pointtCurrentMousePosition.x = LOWORD (lParam);
            pointtCurrentMousePosition.y = HIWORD  (lParam);
            bMousing = true;
        }
        break;

		case WM_LBUTTONUP:
        {
             pointtCurrentMousePosition.x = LOWORD (lParam);
            pointtCurrentMousePosition.y = HIWORD  (lParam);
            bMousing = false;
        }
		break;

		case WM_CLOSE:
		{
			PostQuitMessage(0);	
		}
		
        case WM_DESTROY:
		{
            PostQuitMessage(0);
		}
        break;

		default:
		{
			return DefWindowProc( hWnd, msg, wParam, lParam );
		}
		break;
	}

	return 0;
}
</pre>

and somewhere in the render()
<pre>
void render( void )
{
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 );

	g_pd3dDevice->BeginScene();

	D3DXMATRIX mWorld;
	D3DXMATRIX mTrans;
	D3DXMATRIX mIdent;
	D3DXMatrixTranslation( &mTrans, g_fSpinX, g_fSpinY, 1.2f );

	D3DXMatrixIdentity( &mIdent );
	
	mTrans._11*=2;
	mTrans._22*=2;
	mWorld= mIdent*mTrans;

	g_pd3dDevice->SetTransform( D3DTS_WORLD, &mWorld );
	g_pd3dDevice->SetTexture(0 , g_pTexture1);
	g_pd3dDevice->SetStreamSource( 0, g_pSquare1_VB, 0, sizeof(Vertex) );
	g_pd3dDevice->SetFVF( D3DFVF_MY_VERTEX );
	g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP  , 0, 4);

	g_pd3dDevice->EndScene();
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

</pre>

Share this post


Link to post
Share on other sites
Advertisement
What debugging and analysis have you done? Throw in some breakpoints and watches and find out what your calculations are doing. It's trivial maths so work it through in your head - if your program computes it wrong step back through your code until you find the offending operation. Verify that the input you get from Win32 is sane and correct.

If you are unfamiliar with debugging then look up Richard's Introduction to debugging article.


Should it be an actual Direct3D issue, what is D3DFVF_MY_VERTEX?? Are you using D3DFVF_XYZRHW by any chance? Why are you manually trying to scale the X and Y components of the matrix? Why not use the D3DX routines, or is it because you're trying to do some sort of 2D-in-3D?


hth,
Jack

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!