Skip to main content
GameDev.net gamedev.net
🔒 Locked

Quaternion rotation going wrong

Started by Toastmastern Dec 9, 2019 at 8:45 PM 3 replies 4.9k views
Original Post
Toastmastern
Toastmastern

So I'm building an engine to try and learn some math and programming and right now Im implemting camera movement and rotation. But I got a bug
Here is my video of my bug I have right now

https://www.youtube.com/watch?v=z1L5nySqRiw&feature=youtu.be

Here is the log file showing that the up-vector is being changed while the camera is at the polar regions looking down towards origin. When I yaw the camera at this position the only forward and right should change, but the up vector is also being changed right now.


[code][17:18:21:727] Camera Forward x: -0.000000

[17:18:21:728] Camera Forward y: -0.965925

[17:18:21:728] Camera Forward z: -0.258819

[17:18:21:728] Camera Position x: 0.000000

[17:18:21:728] Camera Position y: 9659.257813

[17:18:21:728] Camera Position z: 2588.190674

[17:18:21:728] Camera Up x: -0.000000

[17:18:21:728] Camera Up y: 0.258819

[17:18:21:728] Camera Up z: -0.965925

[17:18:21:729] Camera Right x: -1.000000

[17:18:21:729] Camera Right y: 0.000000

[17:18:21:729] Camera Right z: 0.000000

[/code]

[code][17:21:41:530] Camera Forward x: -0.061187

[17:21:41:533] Camera Forward y: -0.965925

[17:21:41:534] Camera Forward z: -0.251483

[17:21:41:534] Camera Position x: 0.000000

[17:21:41:534] Camera Position y: 9659.257813

[17:21:41:534] Camera Position z: 2588.190674

[17:21:41:534] Camera Up x: -0.228352

[17:21:41:534] Camera Up y: 0.258819

[17:21:41:534] Camera Up z: -0.938545

[17:21:41:534] Camera Right x: -0.971654

[17:21:41:534] Camera Right y: 0.000000

[17:21:41:534] Camera Right z: 0.236407

[/code]

And lastely here is the code controlling all of this:

https://pastebin.com/NSfWWwHi

YouTube

Johan Karlsson

Mars - The Next Frontier Rotation bug

Pastebin

[C++] //Pitch, Yaw, Roll called by from another class mCamera->Ro...



Toastmastern
Toastmastern

After doing alot of research and testing the use of Quaternions doesn't seems to be the problem. I did the same by using a rotation Matrix instead and the issue is still the same, the up vector is being affected when I yaw when up is any other then 0,1,0. The search continues!

Mike.Stallone
Mike.Stallone

I didn’t look at the code, but if you’re seeing minor deviation in a single tick, you might be bumping into float point precision issues.

bmarci
bmarci

Typically this happens if you construct the rotation matrix/quaternion from angles. Each axis rotation is stacked on top of an other in a particular order, usually in global space. This is good for fps camera but not good for your case.

Try using "relative" rotations (rotate the current camera matrix with an other). And the rotation can be constructed using the current camera's local axes.

somehing like:
q = CreateAxisRotation(camera.GetUpVector(), relative_angle);
camera *= q;

There should be something doing this in XMMath.
And don't forget to normalize! :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.