PDA

View Full Version : Trouble making draw shapes follow mouse



throwaway
11-28-2013, 07:39 AM
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.



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);
}

tonyo_au
11-28-2013, 03:21 PM
s_oglApplication->GetApplicationWindow()->MouseMove(GET_X_LPARAM(lparam), -GET_Y_LPARAM(lparam));


try



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

throwaway
11-29-2013, 04:43 AM
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


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;
}

throwaway
11-29-2013, 05:18 AM
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



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