0

Im kinda new to glut and opengl and I'm trying to make camera movement on mouse movement but when trying to get the mouse position on the screen I assumed the method you want to pass the x and y to should just be referenced in the glutPassiveMotionFunc() parameter. But I'm getting errors when trying to give the function the CameraMove method. I know I'm passing the method wrong but Im not sure how.

void helloGl::CameraMove(int x, int y)
{
oldMouseX = mouseX;
oldMouseY = mouseY;

// get mouse coordinates from Windows
mouseX = x;
mouseY = y;

// these lines limit the camera's range
if (mouseY < 60)
    mouseY = 60;
if (mouseY > 450)
    mouseY = 450;

if ((mouseX - oldMouseX) > 0)       // mouse moved to the right
    angle += 3.0f;`enter code here`
else if ((mouseX - oldMouseX) < 0)  // mouse moved to the left
    angle -= 3.0f;
}




void helloGl::mouse(int button, int state, int x, int y)
{
switch (button)
{
    // When left button is pressed and released.
case GLUT_LEFT_BUTTON:

    if (state == GLUT_DOWN)
    {
        glutIdleFunc(NULL);

    }
    else if (state == GLUT_UP)
    {
        glutIdleFunc(NULL);
    }
    break;
    // When right button is pressed and released.
case GLUT_RIGHT_BUTTON:
    if (state == GLUT_DOWN)
    {
        glutIdleFunc(NULL);
        //fltSpeed += 0.1;
    }
    else if (state == GLUT_UP)
    {
        glutIdleFunc(NULL);
    }
    break;
case WM_MOUSEMOVE:

    glutPassiveMotionFunc(CameraMove);

    break;

default:
    break;
}
}
JackCross
  • 37
  • 5

1 Answers1

1

Assuming helloGl is a class. Then the answer is, you can't. A function is not the same as a method. The thing is that glutPassiveMotionFunc() expects:

void(*func)(int x, int y)

But what you're trying to give it is:

void(helloGl::*CameraMove)(int x, int y)

In other words a thiscall. This doesn't work because a thiscall basically has an additional hidden argument in contrast to a cdecl. In all it's simplicity you can imagine your CameraMove() as:

void CameraMove(helloGl *this, int x, int y)

As you can see, that isn't the same. So the solution is then to move CameraMove() out of your helloGl class or making the method static.

vallentin
  • 23,478
  • 6
  • 59
  • 81