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: LookAt uses column major order, but everything else seems to use row major (e.g. Translate) #14360

Open
taezaz opened this issue Feb 17, 2016 · 2 comments
Assignees
Labels
Milestone

Comments

@taezaz
Copy link

@taezaz taezaz commented Feb 17, 2016

I think it should be:

*m = Mat4{
    {s[0], s[1], s[2], -s.Dot(eye)},
    {u[0], u[1], u[2], -u.Dot(eye)},
    {-f[0], -f[1], -f[2], +f.Dot(eye)},
    {0, 0, 0, 1},
}

When sending model or projection matrix to shader using UniformMatrix4fv I need to transpose them to column major order. That's not the case for the view matrix created by LookAt.

Also Perspective() and LookAt() multiplication produces incorrect result, because of inconsistent matrix layout.

@hyangah
Copy link
Contributor

@hyangah hyangah commented Mar 3, 2016

/cc @nigeltao

Loading

@hyangah hyangah added this to the Unreleased milestone Mar 3, 2016
@bmatsuo
Copy link

@bmatsuo bmatsuo commented Mar 24, 2016

I think this may be the source of several hours of confusion I have had trying to work through a tutorial on OpenGL.

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

In the above tutorial the order of multiplication for the MVP matrices is as follows (at the bottom under "Putting it all together")

glm::mat4 mvp = Projection * View * Model; // Remember, matrix multiplication is the other way around

Using golang.org/x/mobile/exp/f32 multiplying in this order does not work, as was stated by @taezaz. But it seems that to match the order of operations in the tutorial I needed to transpose both the P and V matrices before multiplying them

    projection.Perspective(45, float32(float64(sz.WidthPx)/float64(sz.HeightPx)), 0.1, 100.0)
    view.LookAt(viewEye, viewCenter, viewUp)
    transpose4(projection)
    transpose4(view)
    mvp.Mul(projection, view)
    // ... now serializing the mvp matrix to __column major__ order and multiplying MVP*position in the shader work as I think it is supposed to 
    _mvp = [16]float32{
        mvp[0][0],
        mvp[1][0],
        mvp[2][0],
        mvp[3][0],
        mvp[0][1],
        mvp[1][1],
        mvp[2][1],
        mvp[3][1],
        mvp[0][2],
        mvp[1][2],
        mvp[2][2],
        mvp[3][2],
        mvp[0][3],
        mvp[1][3],
        mvp[2][3],
        mvp[3][3],
    }

To me this seems to suggest that both the P and V matrices are using row major (edit: column major) order? But I could be very wrong. I'm very new to OpenGL. It's also been a while since I did much linear algebra. And like I said. I'm pretty confused right now.

Loading

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

Successfully merging a pull request may close this issue.

None yet
5 participants