Jump to content
  • Advertisement
Sign in to follow this  
DrunkenBrit

More DX Mouse problems...

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

Hey! I'm messing about with DX input using the mouse...I'm moving a QUAD via the mouse position on the screen for testing purposes...the problem is the QUAD overtakes the mouse position the more I move it i.e. It seems that it is accumalting more than it should with adding the dx and dy mouse position per frame to the mouse x and y position, here is my mouse update function:

bool DxMouse::Update()
{
	assert( m_Initialised && "DxMouse not initialised!" );

	HRESULT hResult = m_pMouse->GetDeviceState( sizeof(DIMOUSESTATE2),
												(LPVOID)&m_MouseState );

	if( FAILED( hResult ) )
	{
		hResult = m_pMouse->Acquire();

		while( hResult == DIERR_INPUTLOST )
			hResult = m_pMouse->Acquire();
		
		return false;
	}

	m_Dx = m_MouseState.lX;
	m_Dy = m_MouseState.lY;

	m_X += m_Dx + m_WindowRECT.left;
	
	if( m_YDown )
		m_Y -= m_Dy - m_WindowRECT.top;
	else
		m_Y += m_Dy + m_WindowRECT.top;

	if( m_X < 0.0f )
		m_X = 0.0f;

	if( m_Y < 0.0f )
		m_Y = 0.0f;

	return true;
}


Can anybody see something obvious that I'm doing wrong? I did try storing the dx and dy of the mouse position from the previous frame and then subtract that from the new mouse dx and dy, that ended up with flickering of the QUAD and drawing two of them :S Thanks!

Share this post


Link to post
Share on other sites
Advertisement
The m_WindowRECT.left and m_WindowRECT.top are not needed, they just increase your deltas which result in exactly the effect you describe.

Since the mouse movement is given relative the windows position has no relation to it.

Share this post


Link to post
Share on other sites
Hi DrukenBrit,

The general concensus for handling keyboard/mouse input seems to favour standard Windows messages now, rather than DX Input.

I do use DX Input occasionally now, but generally only for joystick input.

Either way, I guess the problem may be a difference between mouse coordinates and your viewport coodinates.

I guess the problem may be of your mapping of mouse coordinates to viewport coordinates.

Sorry, I can't be more specific, but I would look for something along those lines.

Could you show your code where you map the mouse coordinates to your quads position (in the viewport)?

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Hi Cambo_frog,

Thank for your reply. My viewport is:



glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluOrtho2D( 0.0, (double)g_ScreenWidth, 0.0, (double)g_ScreenHeight );

glMatrixMode(GL_MODELVIEW);
glViewport( 0, 0, g_ScreenWidth, g_ScreenHeight );


// Below is my main render loop:

void Display()
{
glClear( GL_COLOR_BUFFER_BIT );
glClearColor( 0, 0, 0, 0 );

DxMouse::Get().Update();

f32 x = DxMouse::Get().GetMouseX();
f32 y = DxMouse::Get().GetMouseY();

glPushMatrix();
glTranslatef( x, y, 0.0f );
test.Render();
glPopMatrix();

glutSwapBuffers();
}




I have also tried to use GetMousePos() and I get the same results with that...

Thanks mate!

Share this post


Link to post
Share on other sites
Hi DrukenBrit,
That looks like OGL code rather than DX code!

Or is it a mix of both?

Sorry, but I am not familiar with OGL coordinate systems.

TIA,
Cambo_frog

Share this post


Link to post
Share on other sites
Yup, It's OpenGL and DX for input.

Well the OpenGL is trivial, I'm using screen coordinates which are the same in DX afaik.

The screen is 800 * 600 dimensions. If I render a QUAD drawn at the origin to 100, 100, then the QUAD will be at 100, 100 in screen coordinates.

Thanks.

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!