Hey! I've been trying to translate a quad model like this:
However, for some reason, instead of getting a quad moved 0.5 units to the right, I get this:
Weird, right?
Does anyone know what's gone wrong and how I may fix it? I'm more than happy to show more code if required.
If you are using a perspective projection, then this effect is to be expected. A translation in the y-axis will have a similar effect, but for the top (or bottom)
Piet Souris wrote:If you are using a perspective projection, then this effect is to be expected. A translation in the y-axis will have a similar effect, but for the top (or bottom)
You are very likely uploading the matrix in its transposed form. You will get such a distortion even with an otherwise orthographic projection, simply using 0.5 as the m03 matrix element (i.e. first column, fourth row).
JOML's matrices are column-major and the subscripts/indices of a matrix element mCR reads as C = column and R = row.
When you upload a matrix to a shader you would simply call glUniformMatrix4fv(mat4Location, false, matrix.get(buffer)) when using LWJGL. Do not transpose the matrix (i.e. by using true as the second argument) and also do not call Matrix4f.transpose() before uploading!
@John
for a good understanding of what happens, if not already explained by Kaj, is this:
you are standing with your bike before a railroad crossing, the barrier just closed, and the train just passing by. Now, in front of you is the locomotive, followed by a huge train. After a while, right in front of you is wagon nr umpteen, almost as big as the loco, but the loco, being far away to the right, is now only looking tiny. Now, the train is not a continuous figure like your rectangle, but nevertheless the same happens.
I don't know this JOML, Kaj seems to know much about it, but if all you want to do is shift your image to the left or right, then no doubt you can change the part of the screen where your image gets rendered. In JOGL you have the method 'glviewport(xleft, ybottom, xright, ytop). See if one of Kaj's links offer a simpler way, or the JOML way.