Sign in to follow this  

Detect mouse movement after left click

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

Hello.This is my first post.I am developing a strategy game like AoE 2 with OpenGL.I need to calculate mouse move amount after left click.My codes so far:


bool mouseMove = false;

POINT firstMouse;

POINT lastMouse;

.
.
.
Render()
{

     float x =firstMouse.x;
     float y =firstMouse.y;


   if(mouse.buttonDown(Mouse::BUTTON_LEFT) && (mouseMove) )
	{

	glColor3f(1.0,0.0,0.0); 

	glLineWidth(2);

	float lastX = lastMouse.x;
	float lastY = lastMouse.y; 
	

	glBegin(GL_LINE_LOOP);
         glVertex2i(x,y);
	     glVertex2i(lastX ,y);
	     glVertex2i(lastX ,lastY);
	     glVertex2i(x,lastY);
	glEnd();

	glFlush();

	glColor3f(1.0,1.0,1.0); 

         }



}

.
.
.

WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{

case WM_MOUSEMOVE:
		mouseMove = true;
             GetCursorPos(&lastMouse);
            break;
default:
		mouseMove = false;
           GetCursorPos(&firstMouse);
        break;

}

Thanks.

Share this post


Link to post
Share on other sites

in your wndproc, catch the mouse button down event (not sure what its called in Windows but msdn should list all events), it should also give you the position as either wParam or lParam (so you shouldn't have to call GetCursorPos)

 

store the position when the button goes down. (The event is only sent once per click), then you can get the position either when the button is released or when the mouse moves and calculate the distance from there.

Share this post


Link to post
Share on other sites

Thanks a lot smile.png  It worked with a little change.I am sharing.Maybe, it requires to someone

 

LRESULT CALLBACK CWindow::WndProc(HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam)
{

	case WM_LBUTTONDOWN:
		GetCursorPos(&lastMouse);
                 break;

	case WM_MOUSEMOVE:
		mouseMove = true;
		break;

	default:
		mouseMove = false;
		GetCursorPos(&firstMouse);
                break;

}

Share this post


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