Search code examples
javaopengllwjgllinear-algebra

OpenGL transformation matrix not translating properly


I've been running into a problem with a 3D engine I've been working on. The translation applied by the transformation matrix isn't correct, and frankly, I have no idea why.

The transformation matrix I am using:

{ 1f, 0, 0, 0,
  0, 1f, 0, 1f,
  0, 0, 1f, 0,
  0, 0, 0, 1f }

This transformation matrix is applied to a normal cube consisting of two triangles, which then warps the edges of the cube instead of applying a translation.

Original rectangle:

Original rectangle

Warped rectangle:

Warped rectangle

P.S. Any translations on the z-axes(near/far) works properly, only the x-(left/right), and y-axes(up/down) warp the cube.


Solution

  • Im new to OpenGL, but as far as I know, matrices in OpenGL are represented using column-major matrix ordering: That means you should use the transposed transformation matrix:

    { 1f, 0, 0, 0,
      0, 1f, 0, 0,
      0, 0, 1f, 0,
      0, 1f, 0, 1f }
    

    Source: https://stackoverflow.com/a/13294326/6163527