Hi,
I have watched a video about matrices from this guy
about matrices with a parent matrix.
So when you have a box on a merry-go-round with a matrix describing the position of the box and a matrix describing the merry-go-round, how to combine them together like if the box would be mounted on the merry-go-round.
However I don't really get how this is working. I tried to recode his example but get a total different result
(I can't see the rest of his code so I can only do what he says).
2D Example
This is my matrix describing the merry-go-round:
Matrix4f m_mgr = new Matrix4f();
m_mgr.translate( 10, 10 );
m_mgr.rotate( 30 );
m_mgr.scale( 5, 5 );
This is my matrix describing the box in general:
Matrix4f m_box = new Matrix4f();
m_box.translate( 0, 0 );
m_box.rotate( 45 );
m_box.scale( 2, 2 );
When drawing the objects I am doing this (as said in the video) (My mgr is not constantly spinning like in the example)
ogl.setTexture( t_mgr );
ogl.sendMatrix( m_mgr );
ogl.draw();
// set textures and stuff for box
ogl.setTexture( t_box );
ogl.sendMatrix( m_mgr.invert() * m_box );
ogl.draw();
Sadly this seems totally wrong and not at all like in the video.
He says that to get the local matrix we have to calculate m_mgr.invert() * m_box
However now I have a tiny hard to see box at the origin.
What my expected behaviour is, that the box is relative in space to the merry go round.
A space ship in a game i.e. has a lot single turrets mounted on it. When the space ship moves and turns the turrets also move and turn relative to the space ship. When creating a boss enemy which is in many games just a big version of the standard units, the turrets are also relative to the spaceship bigger and placed relative correctly.
I thought thats what matrices are actually for. If this is acquired by calculating the matrices manually for every turret, I lost my confidence that matrices are actually good for anything.
So again, what am I doing wrong?
Thanks you very much in advance,
- Icca