## Andorra 2D - how to zoom/pan ?

General
2011-07-19
2013-05-14
• Claus Falkenstein - 2011-07-19

Hello companions,

I want to develop a little vector based graphics editor with Delphi / Andorra 2D

I looked around in all available docs and sources, but I couldn't find out how to scale the display (zoom) and how
to move around in the drawing (if it is larger than the display size)

Here is what I tried to do:

I can translate    OR   I can scale, but how can I do both?

Am I on the right way or is there another way to manage this things?

P.S: If I (later) want to paint on the zommed and translated drawing via mouse actions,
will I also have to recalculate the mouse coordinates?

• Andreas Stöckel - 2011-07-19

You can combine the two linear mappings by calculating the matrix product. In order to transform the mouse coordinates, use the inverse matrix - its just a bit of mathematics ;-)

• Claus Falkenstein - 2011-07-20

@igel457:

Matrix product … hmmm …  time at school lies long ahead, but I think with pen and paper I could manage that.

But to be honest:  I'm a bloody novice with Andorra2D, I only know that this a wonderful product, as far as I can judge it.
Years ago I tried to do some of the things that Andorra can do by scratch, this is why I have pretty gray hairs now.

It really would be great if you could drop me a few lines how to multiplicate and inverse those matrices in Andorra2D …

• Andreas Stöckel - 2011-07-20

You can multiply matrices using the AdMatrix_Multiply function.

Andorra 2D has no function to invert matrices, but in your case this can also be done by scaling by 1/s and translating by -x and -y.

At all, I think it is very hard to write a vector-graphics application without some knowledge about linear algebra, and Andorra 2D won't be doing the math for you.

• Claus Falkenstein - 2011-07-21

@igel457:

Sure, I am aware that linear algebra is necessary to do the desired things.

But there are a lot of other questions, maybe you can give me a few hints or a tip for a good tutorial,
if and how I can do the things I like to do.

In another of your postings I read, that it's possible to move a camera over a 2D-Scene. Maybe I could do zooming/panning
this way?

Maybe I describe a little better what my problems are:

I want to create a component (inherited from TPanel), lets call it cfAndorraPanel.

This panel sould display a grid, and handle mouse-events (mouse down, mouse up, mousewheel etc)

By  clicking on the canvas and dragging I should be able to draw lines, polygones etc.
and store it in an internal list with extra properties (color, line style etc.) besides the coordinates.
(This already  works partially, I also have created a rudimentary algorithm to select a line via mouse-pos and click )

Now I want to zoom  in (at mousepos) or click in the canvas and drag the whole scene to a new position)
( Dragging also works, but unfortunatelly my grid is also dragged away :-(  )

If I scale with the mouse-wheel the whole scene is scaled  (thanks your hint to use mat-multiplication)
but also moved in x- and y- direction (because scene shrinks or expands)
but I want it   "scale around the mouse-pointer" (sorry, I'm German and can't explain it better in Englisch)

It would be really great if you could tell me if I am on the right way or if this things can be done better with
Andorra functionality   …

• Claus Falkenstein - 2011-07-21

P.S: I tried with moving a camera in x, y and z direction (camera up and down to zoom), but my result was not orthogonal,
when I moved up, down, right or left with the camera the figures had a perspectively distortion.
If all my zoom/pan-problems can done by moving around the camera, is there a way to switch to orthogonal mode?