This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

JOML translation matrix doesn't work.

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 4507
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FWIW The posted imaged looks like the yellow rectangle's right side has been rotated away from the viewer in a  3D representation,
 
John Appleseed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Norm Radder
Rancher
Posts: 4507
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you experimented with the values passed to the translate method to see what happens?
 
John Appleseed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Bartender
Posts: 4677
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
John Appleseed
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Kai Burjack
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Piet Souris
Bartender
Posts: 4677
183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
reply
    Bookmark Topic Watch Topic
  • New Topic