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

x/mobile/exp/f32: Mat4.Rotate incorrectly rotates around axes with non-zero X values #14989

bmatsuo opened this issue Mar 27, 2016 · 0 comments


Copy link

@bmatsuo bmatsuo commented Mar 27, 2016

I have put together the following example to demonstrate a problem with Rotate method on f32.Mat4. I attempt to rotate a vector v (edit: vector u) around the X axis. The resulting vector does not have the same length (in this extreme case the "rotation" has collapsed a unit vector to zero-length).

When I actually use the resulting transformation in OpenGL what I have observed is that my models gets flattened onto a plane (presumably the Y-Z plane, perpendicular to the X axis, at X=0).

I believe the problem lies in how the first row of the rotation matrix is constructed.

I kind of suck at this stuff. But you can see the subsequent rows in the matrix have a pattern which is not observed in the first row. So I tried changing the first row of the rotation matrix to the following.

        c + d*a[0]*a[0],
        0 + d*a[0]*a[1] + s*a[2],
        0 + d*a[0]*a[2] - s*a[1],

And that looks like it works.

The following demonstrates the altered Rotate function:

This second example confirms rotation of [1, 0, 0] around the X axis yields [1, 0, 0]. Obviously length was preserved.

@bradfitz bradfitz added this to the Unreleased milestone Apr 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants