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

Quaternion vector rotation optimisation #205

Closed
legends2k opened this issue May 22, 2014 · 1 comment
Closed

Quaternion vector rotation optimisation #205

legends2k opened this issue May 22, 2014 · 1 comment
Assignees
Milestone

Comments

@legends2k
Copy link

The current code

template <typename T, precision P>
    GLM_FUNC_QUALIFIER detail::tvec3<T, P> operator*
    (
        detail::tquat<T, P> const & q,
        detail::tvec3<T, P> const & v
    )
    {
        T Two(2);
        detail::tvec3<T, P> uv, uuv;
        detail::tvec3<T, P> QuatVector(q.x, q.y, q.z);
        uv = glm::cross(QuatVector, v);
        uuv = glm::cross(QuatVector, uv);
        uv *= (Two * q.w);
        uuv *= Two;
        return v + uv + uuv;
    }

does two multiplications of 2.0 which is avoided in this implementation

    const detail::tvec3<T, P> axis(q.x, q.y, q.z);
    return v + T(2) * glm::cross(axis, glm::cross(axis, v) + q.w * v);

This implementation is based on these two sites https://code.google.com/p/kri/wiki/Quaternions and http:https://molecularmusings.wordpress.com/2013/05/24/a-faster-quaternion-vector-multiplication/.

@Groovounet Groovounet added this to the GLM 0.9.5 milestone May 23, 2014
@Groovounet Groovounet self-assigned this May 23, 2014
@Groovounet
Copy link
Member

This issue is fixed in GLM 0.9.5 branch for GLM 0.9.5.4 release.

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

2 participants