[cairo] [patch] enable projective transformations
spitzak at gmail.com
Mon Aug 16 16:24:34 PDT 2010
Maarten Bosmans wrote:
> This is a first attempt to add projective transformations to Cairo. It
> is far from complete, but mostly meant to get the discussion going
> about how such a feature should be implemented.
I believe if you want to concatenate transforms you need to keep 12
numbers (a 4x3 matrix) around. Otherwise not enough information is
remembered so that two "rotate about the y axis by 10 degrees" can
produce the same result as one "rotate about the y axis by 20 degrees".
The 8 number cannot distinguish such a rotation from a horizontal scale
by 1-sin(10 degrees).
Treating these as 3 rows (or columns) of a 4x4 matrix will allow you to
multiply them. The last row/column will be [0,0,0,1] always, similar to
the current Cairo matrix.
Perspective can be a single number 'D' that basically says "z makes the
image this much smaller". This value goes in the 3rd number of that
extra row/column. Objects at z are scaled to be 1/(1+Dz) in size.
If you don't want the vanishing point to be forced to be at 0,0 then you
need to apply transforms before and after the perspective matrix. If you
place non-zero at that location in the matrix and multiply, the result
can have values different than the identity in all 16 locations. So it
looks like all 16 numbers must be stored.
The SVG paper does correctly conclude that the final rendering does not
require a 4x4 matrix if the source object is a flat plane with
everything at z = 0. Since z = 0 an entire column of the matrix is
ignored, and since the output z is not relevant (only the w is) an
entire row is ignored. Deleting this row and column and get a 3x3 matrix
that translates x,y,1 into wx,wy,w. However this matrix is useless for
concatenating transforms. Still it might be the API to pixman.
I think the internal matrix may have to be 4x4 with all 16 numbers
unknown so that Cairo can remain transform-independent.
Final rendering only requires 9 of the 16 numbers in the CTM if the
objects are actually "2D".
I do like the SVG/CSS spec of just saying "perspective" with one number.
Would prefer to directly specify it as zero means "flat".
More information about the cairo