Jump to content

  • Log In with Google      Sign In   
  • Create Account

Detect mouse movement after left click


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 oenda   Members   -  Reputation: 141

Like
0Likes
Like

Posted 18 May 2013 - 01:15 PM

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.



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 6303

Like
1Likes
Like

Posted 18 May 2013 - 01:20 PM

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.


I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#3 oenda   Members   -  Reputation: 141

Like
0Likes
Like

Posted 18 May 2013 - 02:25 PM

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;

}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS