I need help with some math related stuff.
I need to rotate a model on the screen with my mouse, but this rotation also needs to be based on the current yaw and pitch of the camera. I've got the first part down, but I don't know how to go on with transforming my roll and pitch to be relative to the camera. Right now, the rotation only works if the camera has not been rotated yet (which is to be expected considering that's what the current code was made to do.)
Also, do note that I do mean roll instead of yaw. I want the roll to be controlled with the left and right swipes of the mouse.
I've read that quaternions can solve the problem, but being a learn-by-example learner, I haven't been able to figure out how to do this.
Here is my current code (Note that PI2 is simply Pi * 2):
float dx = (input.getMouseDX() * prefs.mouseSensitivity);
float dy = (input.getMouseDY() * prefs.mouseSensitivity);
double roll = rollAngle, pitch = pitchAngle;
roll = (roll+dx) % PI2;
if(roll < 0){
roll += PI2;
}
pitch += dy;
rollAngle = (float) yaw;
pitchAngle = (float) pitch;
Also, here's a GIF of the desired effect at all angles (but the GIF was taken at a non-rotated camera, the only point where I mentioned it worked.)