Advertisement

Quaternion camera flipping constantly

Started by October 03, 2014 07:35 PM
3 comments, last by syntens 10 years, 4 months ago

So, I read this tutorial here:

http://content.gpwiki.org/index.php/OpenGL%3aTutorials%3aUsing_Quaternions_to_represent_rotation

and implemented the example camera at the end of the page.

I'll explain the problem.

The camera movement works fine, but the rotation is doing some weird stuff like flickering/flipping...

It looks like there are 3 different rotation matrices being generated from the quaternion, one is actually correct and the other two are flipped or black, or something else.

I'm just trying to pitch and yaw the camera on its local axis...

I've tried normalizing the quaternion before and after each function call but it's not the problem.

So anyone knows what might be wrong in this piece of code? According to the tutorial, it should be working, but I can't get it to work after some hours of research and code tweaking...

Thanks.

I had a similar problem in the past. The problem was that I assumed quat::fromRotation(ang,x,y,z) == quat(ang,x,y,z), which isn't true. See Axis Angle to Quaternion.
Advertisement

I have seen this article and tried to use Quaternion::CreateFromAxisAngle before, but now that you mentioned it again, I gave it another try and noticed that in the tutorial the author did not specify the class constructor, and it seems it really was a wrapper to a Quaternion::CreateFromAxisAngle function.

Now it is working.

The problem when I tried this before was that somehow the camera was not doing a full yaw/pitch as it started to do a roll, I still don't know what was going on and I prefer not to try to replicate that effect again, but I think it might have been the order of operations or I maybe missed some angle conversion or put some function in the wrong place.

Many thanks!

Although the camera is working now, as I rotate to 180 degrees, the scene slowly starts to shrink. Example in this image I am at 180 degrees looking at the object:

1a13498d7f.png

And when I am at 0 degrees, the image is correct:

c0ab02e75c.png

I think that is a property of quaternions used this way, right?

If yes, how can I actually make this work as a free camera that goes wherever you want at any angle without distorting anything?

If not, where the problem might be?

Thanks.

Never mind, I managed to solve the problem by just normalizing the rotation quaternion before calculating the matrix.

I was playing around with other ways to pass the quaternion to the matrix and then remembered that floating point errors build really fast on quaternion operations, thus making it non unit-length and messing up the MV matrix. So just normalizing it before doing some important operation will make it unit-length again and solve the problem.

And now I think there are no more errors, sorry for my posting strafe here.

Thank everyone and I hope that helps someone else.

This topic is closed to new replies.

Advertisement