1

I'm having trouble working with transformation in OpenGL. Sometimes, I messed up the transformation matrix, my objects became nowhere to be seen. It's either too far from the camera, or transformed in a weird way so it couldn't be drawn.

I can't tell the difference between a right transform and a wrong transform. I tried printing out the transform matrix, but it is just a bunch of numbers, I don't understand anything by looking at them.

My solution is rechecking my own code, super sure every step is OK before move on. That way, the bug will eventually be fixed, but it takes alot of time.

So I'm asking, how do you debug when it related to transformation matrix? Is there a way to visualize the result, or any trick to reveal the error in my code?

Rahul Singh Chandrabhan
  • 2,531
  • 5
  • 22
  • 33
hucancode
  • 111
  • 4
  • 1
    "*I don't understand anything by looking at them.*" Well, fixing that is step 1. You need to look at what the math says the transformation matrix ought to look like, then look at the matrix and see if it's something approach what it says it is. – Nicol Bolas Mar 20 '18 at 06:01
  • 2
    see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) so you shuld render each matrix as in the image there that will give you a hint if you screw the orthogonality, or scaling or position ... – Spektre Mar 20 '18 at 07:47
  • Use a spreadsheet with matrix calculations you build on your own, better depending on parameters (far/near distance, angle of rotation, translations, etc). Test different "input" points and watch how they are transformed. – Ripi2 Mar 20 '18 at 17:16
  • Try leaving out as much stuff as possible. A few examples are blending, depth test, projection, view matrix or transformation matrix. Try scaling everything down in your shader - be creative. This way you will find out where the error is, and you can fix it or edit your question to be more specific. – eliaspr Mar 20 '18 at 19:56
  • I read the math, but I think my brain is too slow to obviously point out the bug from the numbers. Scaling down seems clever. I also never think of spreadsheet. Nice ideas, I will give it a try. – hucancode Mar 21 '18 at 08:43

0 Answers0