OK, another one question - why view matrix need to be updated only once per frame?
How to get rid of camera z-axis rotation
You only need to update the view matrix before rendering as that is where it is used (obviously if you needed the camera or the view matrix for some math reason, i.e. culling, you could grab it sooner). Using the code above, you can call your "UpdateViewMatrix2" as much as you want but it's just going to be a waste if you aren't actually about to use that matrix.
You only need to update the view matrix before rendering as that is where it is used (obviously if you needed the camera or the view matrix for some math reason, i.e. culling, you could grab it sooner). Using the code above, you can call your "UpdateViewMatrix2" as much as you want but it's just going to be a waste if you aren't actually about to use that matrix.
One more time:
I have camera on quaternions and I have 2 issues:
First:
If I multiply quaternionslike this:
qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitY, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
qRotation = Quaternion.Multiply(Quaternion.RotationAxis(Vector3.UnitX, MathUtil.DegreesToRadians(_degree_angle)), qRotation);
I will get camera Z axis rotation as addition to X and Y rotations when trying to move it in any direction, BUT...
It wll make my camera full circle during rotation on any axis (especially if I rotate on X and Y at the same time)
I want to get rid of that camera rotation, but keep possibility to rotate it the full circle arount itself.
But for now I dont how to do this.
Second:
If I change quetrnion mutiply order, I will get rid of Z-Axis rotation without any limitations needed fo X axis, BUT...
camera starts to move on different way. It flips on 180 degreez on z axis when reach +90 or -90 degrees and come back to object in flipped position.
I want to combine first and second positive results and get rid of Z-axis rotation in first variant still keeping normal rotation arount camera center OR prevent it from fliping on 180 degrees and still not turn on Z Axis.
One of these 2 variants.
I attach images to show the difference between this 2 camera behaviors.
1. with z rotation
2. with fliping.
Let's forget about code and quaternions and everything else for a minute. I start looking North at the horizon. If I progressively look up and keep going (I may have to lie down to reach far back enough), I will end up looking South at the horizon but the world will be upside down. If I do this on a rotating platform that rotates 180 degrees during the process, I will end up looking North with the world upside down. Is that what you mean by "If I move camera on diagonal in any side it will flip on 180 degrees after full turn and instead of normal view, I will receive exactly 180 degrees flipped camera view"?
It looks to me you have discovered a feature of reality that you don't like. Now, what exactly do you want to do about it?
It looks to me you have discovered a feature of reality that you don't like. Now, what exactly do you want to do about it?
Interesting here is that In first variant which I described, I don`t have such "feature". Why?
I don't think there is a solution to your requirements. But let me try to suggest something else, in case it's good enough for you: Keep track of a position on the sphere that you are looking at, and then complete the attitude by imposing the condition that the "up" direction is what you want it to be (search the interwebs for "LookAt matrix"). This will not allow you to rotate 360 degrees around the x axis without the image flipping at some point, but perhaps that's acceptable to you.
So, to be clear, you'll keep track of a point in a sphere (equivalently, a unit-length vector). You'll rotate that point around the x and y axis, in the style of your first variant. Then you'll construct the LookAt matrix or LookAt quaternion from that direction and (0, 1, 0) as "up" vector.
I am curious to know if that comes close to what you had in mind.
After long search I at last know what that I need and can describe it.
I implement a 6DOF quaternion based camera and have accumulated roll rotation.
I need to implement auto-leveling feature to set camera back to 0,1,0 on Y axis to get rid of roll rotation. I didn`t find for now how to implement auto-leveling feature.
Alvaro (or someone else), do you know how to do it? You can write some pseudocode to show the idea.
Figure out where your current "up" vector is pointing to. You can then compute the most natural rotation that would bring that vector to (0,1,0). Then there are a few things you can do with that rotation: Apply it directly to enforce the no-roll constraint strictly, or apply a small fraction of it every frame so you smoothly get rid of the roll, apply a torque in that direction with some drag...
Can you describe more detail please? How to find current "up"? I Have 0,1,0 as my standart and some new "up", which I need to find, but how correctly do it?
Can you describe more detail please? How to find current "up"? I Have 0,1,0 as my standart and some new "up", which I need to find, but how correctly do it?
Do you know how to apply your quaternion to a vector to rotate it? It's something like v' = q * v * conj(q). Plug in (0,1,0) and see what comes out.