views:

86

answers:

3

I was looking at this vector drawing application called Creative Docs .Net . I noticed that I can have hundreds of shapes and moving, rotating and scaling do not lag at all. Given that all verticies must be modified, how do applications generally do these transformations as quickly as possible?

Thanks

+1  A: 

One typical way to do it is to apply a 3x3 (or 3x2, or 2x3) affine transformation matrix to the coordinates, which can describe things like position, rotation, scale and shear.

If you use OpenGL or Direct3D you can use the graphics hardware to do the actual transformations for you.

If you do it in software, rasteration is probably going to be the bottleneck, not transforming the vertices.

Staffan
Is the matrix always applied? ex: I start with (50,50) and then constantly reapply the transformation?
Milo
@user146780: In OpenGL, the matrix is applied as a state. So when you apply the transformation, it continues to apply until another transformation is applied or the matrix is loaded with the identity.
greyfade
@user146780: Not exactly sure what you mean, but if you change the transformation (or the vertices) you will have to re-transform the vertices, yes. If you have a vertex x=(a,b,1)^T you get the transformed vertex x'=M*x, where M is a 3x3 matrix. The first two colums in M describe the rotation and scale and the third the translation. The last element in x is 1 for points and 0 for vectors. It's a pretty fun and easy exercise to derive the 2x2 rotation matrix for 2D points!
Staffan
@user146780 Yes the matrix is constantly reapplied, but that doesn't mean, that Your shape will move across the screen because You're using a translation matrix for example. This is because the shapes vertices are transformed by the gpu using the matrix, drawn and then discarded. So the vertices always start untransformed in their own local coordinate system in the beginning of each frame.
Dave
A: 

Typically this is done via transformation matrices. This allows the individual points to be transformed fairly quickly, and is the most common technique used by most 2D (and 3D) vector based drawing.

That application, in particular, is built on top of Anti-Grain Geometry - a fairly high-performance open source 2D rendering engine. It provides many of the "primitives" which could be used for this type of application.

Reed Copsey
Cairo (http://cairographics.org/) is another library similar to Anti-Grain Geometry. It's used in Gtk+, for example.
Staffan
A: 

In addition to using matrices to mimic affine transformation (linear transformations with translation), you might be interested in the use of Quaternions to perform those operations in R3.

andand