Skip to main content
GameDev.net gamedev.net
🔒 Locked

Direct Input problem

Started by _Josh Jul 7, 2000 at 3:09 AM 0 replies 200+ views
Original Post
_Josh
_Josh
    
int di7::UpdateMouse()
{
	myResult = myMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &myDIMS2);
	if (!good(myResult))
	{
		myError->Add("Error getting mouse state.\n", true);
		return(0);
	}

	myMX += myDIMS2.lX;
	myMY += myDIMS2.lY;

	if (myMX >= myScreenWidth)
		myMX = myScreenWidth - 1;
	else if (myMX < 0)
		myMX = 0;

	if (myMY >= myScreenHeight)
		myMY = myScreenHeight - 1;
	else if (myMY < 0)
		myMY = 0;

	return(1);
}
    
After I call this function in my main game loop, I draw the mouse cursor at position (myMX, myMY). The problems occur when the mouse coords go below 0 x or 0 y. When it goes below either, the coordinates will reset to the other side of the screen, when they should just reset to 0. At first I figured that it was my coordinate values rolling over (they were originally unsigned, and I suppose they would roll over to 2^32 - 1), but I changed my coords to regular longs and the problem still remains. If anyone can point me in the right direction I would appreciate it! BTW, I'm sure the formatting will be screwed up on the code above. How do I get pasted text to retain the formatting? Edited by - _Josh on 7/7/00 5:34:35 PM
+AA_970+
+AA_970+
Well first you probably shouldn''t use an unsigned variable type because you will get coordinates less than 0 since myDIMS2.lX and myDIMS2.lY will have values depending on how fast the mouse is moved. For example if the mouse is moved really fast and it''s subtracting in increments of 3 and the current coordinates are (2,2) your next set of coordinates will be (-1,-1)!

Since that dosen''t seem to be the problem you should check the clipping when you draw the mouse cursor.

+AA_970+

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.