Reputation: 109
How does concatenation of matrices makes sense when defining operators? Why are there even 3 dimensional matrices when we are dealing with 2 dimensions? I feel really stupid asking this but I lack any kind of information about this even though I'm quite familiar with vector analysis and algebra... Why aren't just the transformation or scaling matrices multiplied and then applied as an operator to the coordinates?
I'm trying to make a zoom-to-mouse feature to my already translatable-by-mouse grid and for 2 days I just can't. Is there a way to use setTranslate or setScale on the transformer without resetting the already existing operator? How does the composition of concatenation work?
EDIT Finally I got the zoom-to-and-from-a-point algorithm right... The trick is to apply translations that are dependent on the zoomLevel itself before you apply anything else, while saving the previous operator: (In case someone is interested in this..)
AffineTransform savedTransform = new AffineTransform(transformer);
AffineTransform tempTransform = new AffineTransform();
tempTransform.translate(-0.25*(mouseX-transOfGridXD-game.curWS*sF*sqSize/2), -0.25*(mouseY-transOfGridYD-game.curWS*sF*sqSize/2)); //sF is the zoom level, game.curWS*sqSize is the grid size in pixels, transOfGrid is the translation of the transform
tempTransform.concatenate(savedTransform);
transformer.setTransform(tempTransform );
transformer.translate(-(game.curWS)*sqSize*0.125, -(game.curWS)*sqSize*0.125);
transformer.scale(1.25, 1.25);
Upvotes: 0
Views: 171
Reputation: 77454
Wikipedia has a lot on affine transformations. By using a 3x3 matrix multiplication, you can perform rotation, reflection and translation at the same time.
I.e. instead of computing D*(C*(B*(x+a)+b)+c)+d all of these operations can be put into a single matrix operation M*x' (where x' is the vector x with an extra row). Now this matrix multiplication can be implemented in hardware (that's essentially what 3D graphics cards do - optimize 4D multiplications - but also your printer likely has optimized circuits for 3D multiplication!)
Upvotes: 2