glutPassiveMotionFunc 问题
glutPassiveMotionFunc problems
我对 glut 和 opengl 有点陌生,我正在尝试让相机随着鼠标的移动而移动,但是当试图让鼠标在屏幕上的位置时,我假设你想要将 x 和 y 传递给的方法应该只是在 glutPassiveMotionFunc() 参数中被引用。但是在尝试为函数提供 CameraMove 方法时出现错误。我知道我传递的方法有误,但我不确定如何传递。
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;
}
}
假设 helloGl
是 class。那么答案是,你不能。函数与方法不同。问题是 glutPassiveMotionFunc()
期望:
void(*func)(int x, int y)
但是您要提供的是:
void(helloGl::*CameraMove)(int x, int y)
换句话说一个thiscall. This doesn't work because a thiscall basically has an additional hidden argument in contrast to a cdecl。总之,您可以将 CameraMove()
想象成:
void CameraMove(helloGl *this, int x, int y)
如您所见,这不一样。因此解决方案是将 CameraMove()
移出您的 helloGl
class 或使方法静态化。
我对 glut 和 opengl 有点陌生,我正在尝试让相机随着鼠标的移动而移动,但是当试图让鼠标在屏幕上的位置时,我假设你想要将 x 和 y 传递给的方法应该只是在 glutPassiveMotionFunc() 参数中被引用。但是在尝试为函数提供 CameraMove 方法时出现错误。我知道我传递的方法有误,但我不确定如何传递。
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;
}
}
假设 helloGl
是 class。那么答案是,你不能。函数与方法不同。问题是 glutPassiveMotionFunc()
期望:
void(*func)(int x, int y)
但是您要提供的是:
void(helloGl::*CameraMove)(int x, int y)
换句话说一个thiscall. This doesn't work because a thiscall basically has an additional hidden argument in contrast to a cdecl。总之,您可以将 CameraMove()
想象成:
void CameraMove(helloGl *this, int x, int y)
如您所见,这不一样。因此解决方案是将 CameraMove()
移出您的 helloGl
class 或使方法静态化。