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

Open
bmatsuo opened this issue Mar 27, 2016 · 0 comments
Labels
mobile Android, iOS, and x/mobile
Milestone

Comments

@bmatsuo
Copy link

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).

http://play.golang.org/p/INyRQCldPm

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.

https://github.com/golang/mobile/blob/467d8559f22b81884dfbc37d1cef95d0fab78049/exp/f32/mat4.go#L157-L160

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],
        0,
    }

And that looks like it works.

The following demonstrates the altered Rotate function: http://play.golang.org/p/8ZrOpdv_AY

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
@gopherbot gopherbot added the mobile Android, iOS, and x/mobile label Jul 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Android, iOS, and x/mobile
Projects
None yet
Development

No branches or pull requests

3 participants