I've been hacking away for a while at the engine code for the FPS camera so that I can make it rotate all the way around upside-down, etc. I removed some code that prevented the camera from looking past the 90 or -90 degree position, but when trying to flip over backwards the camera would flip itself over such that it will never be upside-down, effectively inverting the mouse y-axis in the process and screwing everything up.
So, I finally figured out that I need to constantly change the vector, UpVector, of the FPSCamera which is used to determine the direction that is up for the camera. See the UpVector is set to the positive Y direction, but since I want my camera to rotate in all directions I need UpVector to constantly change depending on my Target vector, which is the vector that is used to determine the current look at target of the camera. So, I must constantly update UpVector and make it a vector that is perpindicular to the Target vector, or in other words, UpVector must constantly point straight up outta the camera's head. I tried to add in this code
Code: Select all
core::vector3df samePlane = Target + core::vector3df(1,0,0);
UpVector = Target.crossProduct(samePlane);
and this somewhat works; you can rotate all the way around upside-down but the left and right direction of the mouse gets switched, that could be fixed. The main problem is when you turn to look along the x-axis. The vector samePlane creates another vector off of the Target vector and adds 1 to it's x component so that it is a slightly different vector in the same horizontal plane as the target vector. And if you have 2 vectors in the same plane then the cross product of those 2 vectors is a vector straight up and perpindicular to them both, which is what I need. But, when you move the camera to look along the x-axis the 2 vectors become the same vector and the cross product of the same vector is 0. This is bad, it makes the camera now flip over when turning past either the + or - x-axis. So I still have a flip over problem, now along the x-axis instead of the y-axis. I need to use the Target vector and somehow constantly get a 2nd vector that is always in the same plane as the Target vector so that I can get their cross product vector and make the UpVector = it. So does anyone have any ideas?