Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in glm::decompose #448

Closed
beyondlwm opened this issue Nov 19, 2015 · 2 comments
Closed

bug in glm::decompose #448

beyondlwm opened this issue Nov 19, 2015 · 2 comments

Comments

@beyondlwm
Copy link

Hi,

Please try this:
glm::mat4 rotationMat = glm::yawPitchRoll(0, glm::radians(-90), 0);
glm::vec3 translate, scale, skew;
glm::vec4 perspective;
glm::quat WRONG_QUAT;
glm::decompose(rotationMat, scale, WRONG_QUAT, translate, skew, perspective);

I will get WRONG_QUAT = {x=0.707106769 y=-0.000000000 z=0.000000000 w=0.707106769}
While I think the right result is
{x=-0.707106769 y=-0.000000000 z=0.000000000 w=0.707106769}

Am I right ? is it a bug?

Regards

@volcoma
Copy link

volcoma commented Nov 8, 2016

i believe the last part in the function that gets the quaternion is kinda wrong
this version works way bettter with consistent results. I suggnest to replace it with this

int i, j, k = 0;
float root, trace = Row[0].x + Row[1].y + Row[2].z;
if (trace > static_cast<T>(0))
{
    root = sqrt(trace + static_cast<T>(1.0));
    Orientation.w = static_cast<T>(0.5) * root;
    root = static_cast<T>(0.5) / root;
    Orientation.x = root * (Row[1].z - Row[2].y);
    Orientation.y = root * (Row[2].x - Row[0].z);
    Orientation.z = root * (Row[0].y - Row[1].x);
} // End if > 0
else
{
    static int Next[3] = { 1, 2, 0 };
    i = 0;
    if (Row[1].y > Row[0].x) i = 1;
    if (Row[2].z > Row[i][i]) i = 2;
    j = Next[i];
    k = Next[j];

    root = sqrt(Row[i][i] - Row[j][j] - Row[k][k] + static_cast<T>(1.0));

    Orientation[i] = static_cast<T>(0.5) * root;
    root = static_cast<T>(0.5) / root;
    Orientation[j] = root * (Row[i][j] + Row[j][i]);
    Orientation[k] = root * (Row[i][k] + Row[k][i]);
    Orientation.w = root * (Row[j][k] - Row[k][j]);
} // End if <= 0
`

@Groovounet Groovounet added the bug label Nov 20, 2016
Groovounet added a commit that referenced this issue Nov 20, 2016
@Groovounet Groovounet added this to the GLM 0.9.9 milestone Nov 20, 2016
@Groovounet Groovounet self-assigned this Nov 20, 2016
@Groovounet
Copy link
Member

This issue was fixed using @volcoma resolution in master branch for GLM 0.9.9 release. This feature barely has unit tests so it would be better than one of you have a look.

Thanks for contributing,
Christophe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants