Forums Login/signup

JOML translation matrix doesn't work.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
FWIW The posted imaged looks like the yellow rectangle's right side has been rotated away from the viewer in a  3D representation,
+Pie Number of slices to send: Send
 

Norm Radder wrote:FWIW The posted imaged looks like the yellow rectangle's right side has been rotated away from the viewer in a  3D representation,



Yep, though I don't get why.
+Pie Number of slices to send: Send
Have you experimented with the values passed to the translate method to see what happens?
+Pie Number of slices to send: Send
 

Norm Radder wrote:Have you experimented with the values passed to the translate method to see what happens?



Yes, translating in the y-axis rotates it up and down.
+Pie Number of slices to send: Send
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)
+Pie Number of slices to send: Send
 

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)



Yes, why is this, and how do I fix it?
+Pie Number of slices to send: Send
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!
+Pie Number of slices to send: Send
Make sure to read this https://github.com/JOML-CI/JOML/wiki/Common-Pitfalls#matrix-element-subscripts-are-column-then-row and the following sections.
And also read the code snippets on JOML's README.md: https://github.com/JOML-CI/JOML#using-with-lwjgl
Also explore the various JOML demos here: https://github.com/JOML-CI/joml-lwjgl3-demos/tree/master/src/org/joml/lwjgl
+Pie Number of slices to send: Send
hi Kaj.

welcome to the Ranch and enjoy th stay,

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

Let s know how you go!
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders


reply
reply
This thread has been viewed 1127 times.
Similar Threads
windows game programming in C++/DirectX
Jogl 1.1.1.a: GLJPanel no longer works on Windows10 64 bit
float primitive and its.... crazyness?!?!
Fixes for "Error: Could not find or load the", or .jar doing nothing on double clicking
android imageview animation resetting issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Aug 13, 2025 09:34:46.
close