Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Trouble making draw shapes follow mouse

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    7

    Trouble making draw shapes follow mouse

    I'm new to OpenGL and I'm trying to make a shape that I've drawn follow my mouse. However, the shape is currently following the mouse but with an offset. I want to change this so that the shape follows directly where the mouse is. I don't want to use external libraries such as GLUT either. This is my code for how I'm getting the mouse position. I think it is getting the mouse position in relation to the window and not the openGL window.

    Code :
    LRESULT CALLBACK OGLApplication::WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
    {
    	int windowMessageId, windowMessageEvent;
     
    	switch(message)
    	{
    	case WM_SIZE:
    		s_oglApplication->GetApplicationWindow()->Resize(LOWORD(lparam),HIWORD(lparam));
    		break;
     
    	case WM_CLOSE:
    		s_oglApplication->GetApplicationWindow()->DestroyOGLWindow();
    		break;
     
    	case WM_MOUSEMOVE:
    		//inform the cursor position to OGLWindow
    		s_oglApplication->GetApplicationWindow()->MouseMove(GET_X_LPARAM(lparam), -GET_Y_LPARAM(lparam));
    		break;
     
    	case WM_LBUTTONUP:
    		s_oglApplication->GetApplicationWindow()->MouseLBUp(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
    		break;
     
    	case WM_LBUTTONDOWN:
    		s_oglApplication->GetApplicationWindow()->MouseLBDown(GET_X_LPARAM(lparam), GET_Y_LPARAM(lparam));
    		break;
     
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		break;
     
    	default:
    		return DefWindowProc(hwnd, message, wparam, lparam);
    	}

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,106
    Code :
    s_oglApplication->GetApplicationWindow()->MouseMove(GET_X_LPARAM(lparam), -GET_Y_LPARAM(lparam));

    try
    Code :
     
    s_oglApplication->GetApplicationWindow()->MouseMove(GET_X_LPARAM(lparam), window_height-GET_Y_LPARAM(lparam));

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    7
    Thanks for the code, it worked. I had to do s_oglApplication->GetApplicationWindow()->MouseMove(GET_X_LPARAM(lparam), window_height / 2 -GET_Y_LPARAM(lparam)); to fix the shape to the y axis however there is still a problem with the x axis. Any suggestions?

    Here is my code for MouseMove in my shape class if that helps
    Code :
    bool Shape::MouseMove( int x, int y )
    {
    	_topLeft.SetX((float) x );
    	_topLeft.SetY((float) y );
     
    	_bottomRight.SetX( (float) x + 100.0f );
    	_bottomRight.SetY( (float) y + 100.0f);
     
    	return true;
    }

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    7
    I have now changed the code again so that the shape follows the x and y co-ordinates of the mouse however there is an offset between the shape and mouse. Here is my code

    Code :
    s_oglApplication->GetApplicationWindow()->MouseMove(+GET_X_LPARAM(lparam), s_oglApplication ->GetApplicationWindow() ->GetHeight() / 2 - GET_Y_LPARAM(lparam));

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •