我只是对我一直致力于在OpenGL中渲染场景的项目进行了最后的修改 - 我将其中一些基于我为Camera类编写的一些旧代码(因为我不想必须重新计算出数学!),但是之前我已将Camera类作为main.cpp的一部分包含在内,为了可重用性/清晰度,我想将它移动到它自己的单独.h / .cpp文件中/一般的良好做法。
我还用一个我编写的Mouse类替换了一个基本的Struct来保存鼠标的x和y位置。
我更改了Windows消息处理程序中的一些代码,以便在释放鼠标左键时更新相机 - 但是我收到一个奇怪的链接错误 -
1> main.obj:错误LNK2001:未解决 外部符号“public:void __thiscall Camera :: moveCamera(int,int,int,int)“ (?moveCamera @ @@相机@ QAEXHHHH Z)
Windows消息处理程序中的代码是 -
case WM_LBUTTONUP:
Mouse.SetPos(lParam);
x_mouse_end = Mouse.GetXPos();
y_mouse_end = Mouse.GetYPos();
Camera.moveCamera(x_mouse_start, y_mouse_start, x_mouse_end, y_mouse_end);
SetCamera();
break;
我传递给Camera.moveCamera()的参数是它们应该是的整数。
moveCamera()函数如下 -
//Moves the camera based on a user dragging the mouse
inline void Camera::moveCamera(int old_x, int old_y, int new_x, int new_y)
{
//To store the differences between the old and new mouse positions
int x_difference, y_difference;
//If the mouse was dragged to the right, move the camera right
if(new_x > old_x)
{
x_difference = new_x - old_x;
x_difference = x_difference / 25;
if(yaw > 350)
{
yaw = 0;
}
else
{
yaw = yaw + x_difference;
}
}
//If the mouse was dragged to the left, move the camera left
if(new_x < old_x)
{
x_difference = old_x - new_x;
x_difference = x_difference / 25;
if(yaw < 10)
{
yaw = 360;
}
else
{
yaw = yaw - x_difference;
}
}
//If the mouse was dragged down, move the camera down
if(new_y < old_y)
{
y_difference = new_y - old_y;
y_difference = y_difference / 20;
if(pitch < 10)
{
pitch = 360;
}
else
{
pitch = pitch - y_difference;
}
}
//If the mouse was dragged up, move the camera up
if(new_y > old_y)
{
y_difference = old_y - new_y;
y_difference = y_difference / 20;
if(pitch > 350)
{
pitch = 0;
}
else
{
pitch = pitch + y_difference;
}
}
//Update the camera position based on the new Yaw, Pitch and Roll
cameraUpdate();
}
“camera.h”包含在内,因为它应该是“mouse.h”,并且两个类的实例都已设置 -
Mouse Mouse;
Camera Camera;
我对可能遗漏的东西感到茫然。
如果您想了解更多信息,请与我们联系。
答案 0 :(得分:2)
也许您已将moveCamera()
的定义包含在带有“inline
”关键字的.cpp文件中。这可以解释为此方法对于定义它的.cpp是本地的。请尝试删除inline
。