2017-04-13 14 views
0

Im 다소 glut 및 opengl에 새로운 기능이 있습니다. 마우스 동작에서 카메라 움직임을 만들려고 노력하고 있지만 화면에서 마우스 위치를 얻으려고하면 x 및 y를 전달할 메서드를 가정합니다. glutPassiveMotionFunc() 매개 변수에서 참조됩니다. 하지만 CameraMove 메서드에 함수를 제공하려고 할 때 오류가 발생합니다. 나는 방법을 잘못 전달하고 있지만 확실하지는 않다는 것을 압니다.glutPassiveMotionFunc 문제

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

답변

1

가정하면 helloGl은 클래스입니다. 그렇다면 대답은 할 수 없다는 것입니다. 함수는 메소드와 같지 않습니다.

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

을하지만 당신이 그것을 제공하려고하는 것은 : 즉 thiscall을에서

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

것은 glutPassiveMotionFunc()가 기대하는 것입니다. thiscall기본적으로에는 cdecl과 달리 숨겨진 인수가 추가되어 작동하지 않습니다. 모든 그것의 단순에서 당신은 상상할 수 있습니다 CameraMove() 같이

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

당신이 볼 수 있듯이, 즉 동일하지 않습니다. 따라서 해결책은 helloGl 클래스에서 CameraMove()을 이동하거나 메소드를 정적으로 만드는 것입니다.