The problem could appear because your

vec_rotate(trace_coords.x, camera.pan);
vec_add(trace_coords.x, player.x);

lines of code rotate trace_coords in the direction given by the camera but add to it the position of the player. They should both be camera or player, depending on what you need.

Let's try to solve the problems one by one, please. No need to open multiple threads.