Controling OpenSceneGraph camera with Cartesian coordinates and Euler angles

谁都会走 提交于 2019-12-04 19:36:04

Part 1

The issue was the order in which I added my angles to the quaternion.

rotationQuat.makeRotate(
    deg2rad(rotation[1] + 90.0f), pitchAxis,
    deg2rad(rotation[2]), rollAxis, 
    -deg2rad(rotation[0]), headingAxis);

Pitch had to be added first as it rotates around the X-Axis

Part 2

A couple of things were wrong here.

First, I needed to grab the inverse view matrix. I'm not 100% sure why, maybe someone with more knowledge can leave a comment, but it works.

auto rotation = this->camera->getViewInverseMatrix().getRotate();

Secondly, Assuming the conversion function was correct turned out to be bad. I wrote a unit test that was missing for this function and it turns out it was wrong.

// Assuming this conversion is correct
auto ypr = Quaternion2YawPitchRoll(quat);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!