Recalculating view limits for camera depending on actor up vector

I’m trying to implement a first person shooter camera, whose ViewYawMin/Max, ViewPitchMin/Max, ViewRollMin/Max would be calculated from character orientation instead of being fixed to world.

I’m using the dynamic gravity pull (1773) and trying to integrate it with the shooter game example. I’ve put in some tiny planets which you can walk around as they recalculate the player’s gravity, but I ran into some problems with the camera as it is limited to real world rotations instead of character up vector rotations.

Basically what I am thinking of is the following:
PlayerCameraManager.cpp has limitview functions for each cartesian axis that get called from ProcessViewRotation(). The limitview functions just clamp the angle inside the definable ViewPitchMin - View PitchMax -values.
My thought is to take these out and replace them with a calculation from the pawn’s up/forward/right vector (the pawn is aligning properly on the planet’s surface) so that there is a free movement around the up vector of the player, but restricted to +87 and -87 degrees on the right and forward vectors of the character. So basically there are virtual circles on the feet and head of the character that the center of the view can’t be rotated to (this helps me visualise it in 3D).
I can’t figure out how I should do this. I’ve been reading about quaternions and they seem to be one possibility, but I don’t understand them properly enough to use them.

Any ideas on how to go about this?

Actually the problem is a bit more complicated.

I need to redo the mouse inputs to be local space in relation to the character - now the mouse input rotates the camera and the player in world space, ie. if I’m on the surface of a planet “sideways” in relation to the world coordinates, the mouse does not work at all. But this might also be the solution to the camera pitch max and min, as it needs also to work in local space only.

I’m currently battling with the ProcessViewRotation() and trying to turn the camera into quaternion version. For the life of me I can’t figure these things out. Trying to it like this now, but it doesn’t work:

FVector UpVector = MyPawn->GetActorUpVector();
FQuat Orig = FQuat(UpVector, 0);
FQuat Delta = OutDeltaRot.Quaternion();
FQuat Result1 = Orig*Delta;
FRotator Result = Result1.Rotator();
OutViewRotation += Result;

Where in OutViewRotation is the rotation applied to the camera. I’ve tried to change the order of the Quat multiplication, but I’m still getting either gimbal locked or end up with a dancing camera.

I solved most of these problems with my other question:

Thanks to rcdarcey.