Jump to content
  • Advertisement
Sign in to follow this  
syntens

Quaternion camera flipping constantly

This topic is 1532 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Edited by syntens

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!