I've been having difficulty with a problem which I thought was going to be a simple solution.
I have a camera facing downwards on a character. The can camera be lowered and when it's lowered it remains the same distance away from the character that it was (basically rotating around the X axis of the target). Now what I want it to be able to do is spin around the character on the Y axis as well, but to maintain the same distance and to remain upwards all the time. The problem I'm having is that if I do something similar to the way I did it on the X axis everything becomes a mess. First of all it doesn't remain facing up, as it spins the camera ends up upside down and i'm not really sure how to recalculate the up vector for it. But ontop of that it doesn't maintain the same distance from the character at all times.
This is what I have right now:
cameraUp = new Vector3(0, 1, 0);
cameraPosition = new Vector3(cameraOffset.X, cameraOffset.Y, cameraOffset.Z);
cameraPosition = Vector3.Transform(cameraPosition - cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitX, tippingAngle)) + cameraTarget;
//This is the part that I'm having difficulty with, the rest works fine.
cameraPosition = Vector3.Transform(cameraPosition, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle));
view = Matrix.CreateLookAt(cameraPosition, cameraTarget, cameraUp);
EDIT:
Thank you to everyone, all of your comments helped. The biggest issue was that somehow I let it slip past that the cameraUp value was wrong, I think it happened as a typo when I was tidying the code up. Anyway, after fixing that the code above was exactly what I needed. I had tried that before but because the up vector was wrong I was getting really weird results so thanks to everyone. :)
cameraUp = new Vector3(0, 0, -1);
becameraUp = new Vector3(0, 1, 0);
if you want Y+ to be up (assuming y is your horizontal axis). \$\endgroup\$cameraPosition
is in world-space before the comment. So you need to docameraPosition = Vector3.Transform(cameraPosition -cameraTarget, Matrix.CreateFromAxisAngle(Vector3.UnitY, rotationAngle)) + cameraTarget;
. Just like with the X rotation. \$\endgroup\$