Can We Read Yaw Axis Without Compass?

This is my code:

What problem do you have if you tilt it? What output do you expect? If you have a 3 axis magnetometer, you can calculate the facing direction even if the device is tilted

I want to make 3 axis gimbal, and the problem is on the yaw axis. SO far, i can calculate the heading degree, but when i tilt it, the value is change. I have tried tilt compensation compass algorithm from many reference, but still not works well. Are we must calibrate the magnetometer Max and Min value for each axis first? For Example like this:

#define M_X_MIN -421
#define M_Y_MIN -639
#define M_Z_MIN -238
#define M_X_MAX 424
#define M_Y_MAX 295
#define M_Z_MAX 472