I'm just putting the finishing touches on a project I've been working on to render a scene in OpenGL - I based some of it on some old code I wrote for a Camera class (since I didn't want to have to re-figure out the maths!), however I'd included the Camera class as part of main.cpp before, and I wanted to move it to it's own seperate .h/.cpp files for the sake of reusability/clarity/general good practice.
I also replaced a basic Struct to hold the x and y position of the mouse with a Mouse class that I wrote.
I changed some code in the Windows Message Handler to have the Camera update when the Left Mouse Button is released - however I am getting a strange linking error -
1>main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Camera::moveCamera(int,int,int,int)" (?moveCamera@Camera@@QAEXHHHH@Z)
The code in the Windows Message Handler is -
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;
The parameters I'm passing to Camera.moveCamera() are integers as they are supposed to be.
The moveCamera() function is as follows -
//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" is included as it should be, as is "mouse.h", and instances of both classes are set up -
Mouse Mouse;
Camera Camera;
I'm at a loss as to what could be missing.
Please let me know if you would like more information.
Maybe you included that definition of moveCamera()
in a .cpp file with the " inline
" keyword. This may be interpreted that this method is local to the .cpp in which it is defined. Try removing the inline
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.