Given your description, your camera representation might look like this. I also included the headers of your maths library GLM needed for the following implementation.
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/constants.hpp>
using namespace glm;
struct Camera
{
vec3 Position;
vec2 Angles;
mat4 View, Projection;
};
Camera cam;
To more your camera, you can first calculate the vector for the directions forward and sidewards (in this implementation to the right side). Then update the position based on that vector, the speed of movement, and the elapsed time Delta. Relying on the time is important to make the movement independent from the FPS of your game. Otherwise the camera rotation would be faster on faster machines and vise versa.
Calculating the forward vector is just basic trigonometry. If you have no basic understanding of sine and cosine you can look it up on Wikipedia or somewhere else. After computing the forward vector, we can derive the sidewards vector like shown in the code.
void Move(vec3 Amount, float Delta, float Speed = 10.f)
{
vec3 forward = vec3(sinf(cam.Angles.x), 0, cosf(cam.Angles.x));
vec3 right = vec3(-forward.z, 0, forward.x);
cam.Position += forward * Amount.x * Speed * Delta;
cam.Position.y += Amount.y * Speed * Delta;
cam.Position += right * Amount.z * Speed * Delta;
}
As you can see we only depend on the view direction for the X and Z coordinate. Otherwise the player could fly if the player walks facing the sky.
Because you haven't especially asked about rotation, I guess you already implemented that. But as a reference this might help other users. The negation because of the different direction of the world coordinates and the mouse coordinates.
void Rotate(ivec2 Amount, float Delta, float Speed = .08f)
{
cam.Angles += vec2(-Amount.x, -Amount.y) * Speed * Delta;
}
The last step is to create the view matrix. Since you use GLM you can use its lookAt function to do so. Before, I wrap the horizontal angle if it exceeds 360 degrees and I limit the maximum vertical angle a bit. So the player wouldn't loose orientation if he looks straight to the top or to the bottom and rotate the camera then.
void Calculate()
{
const float pi = glm::pi<float>();
if (cam.Angles.x < -pi) cam.Angles.x += pi*2;
else if (cam.Angles.x > pi) cam.Angles.x -= pi*2;
const float margin = 0.2f;
if (cam.Angles.y < -pi/2+margin) cam.Angles.y = -pi/2+margin;
else if (cam.Angles.y > pi/2-margin) cam.Angles.y = pi/2-margin;
vec3 lookat(
sinf(cam.Angles.x) * cosf(cam.Angles.y),
sinf(cam.Angles.y),
cosf(cam.Angles.x) * cosf(cam.Angles.y)
);
cam.View = lookAt(cam.Position, cam.Position + lookat, vec3(0, 1, 0));
}
If you still have questions about that, feel free to ask.