Re: Coordinate from device to user space without a context

Donn <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On 07/11/2013 03:44, ed44 wrote:
>> public void move(double mx, double my) {
>>   double xnew = mymatrix.xx * mx + mymatrix.x0;
>>   double ynew = mymatrix.yy * my + mymatrix.y0;
>>   stdout.printf("mx my: %G|%G maps to xnew ynew: %G|%G\n",mx,my, xnew,
>> ynew);
>>   x=xnew; y=ynew;
> With that matrix, points are transformed from user space to device space
> ( coords to pixels here).
> You need the other way around.

I don't know which forumula to use. I'm that thick :P
(I thought Bryce's use of "x_new" meant the new value I needed from the 
mouse's x going in.)


> Using the cairo matrix api you could do :
> --get the matrix
> --invert the matrix
> --cairo_matrix_transform_point_with_that_matrix.
Gave this a go. It's promising, but has a weird result:

   public void move(double mx, double my) {
     var tm = mymatrix; //copies on assignment.
     tm.invert();
     double px = mx; double py=my;
     stdout.printf("BEFORE mx my: %G | %G\n", px, py);
     tm.transform_point(ref px, ref py);
     stdout.printf("AFTER mx my: %G | %G\n", px, py);
     x=px;y=py;

The dragged object jumps left, then right, then left, etc. Here's some 
output. Look at the x coords for example.

DRAGGING 3
BEFORE mx my: 201,665 | 252,93
AFTER mx my: 1,6646 | 2,93018
DRAGGING 3
BEFORE mx my: 200,665 | 252,93
AFTER mx my: -51 | 0
DRAGGING 3
BEFORE mx my: 199,665 | 252,93
AFTER mx my: 0,664597 | 2,93018
DRAGGING 3
BEFORE mx my: 198,665 | 252,93
AFTER mx my: -52 | 0
DROPPED 3



Thanks for your help,
\d
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.