gnash-dev
[Top][All Lists]

## [Gnash-dev] Re:Matrix math (strk)

 From: zou lunkai Subject: [Gnash-dev] Re:Matrix math (strk) Date: Sun, 31 Aug 2008 21:50:36 +0800

```> So we now cache matrix parameters in the character class
> and recompute the matrix from all scales and a rotation
> when needed.
>
> Question now is: does it still make sense to have
> matrix methods: set_x_scale, set_y_scale, set_rotation ?
>
> The core only uses set_scale_rotation now...
>
> Only user of the others is the testcase, which fails.
> It seems to me that there's no way to tell original parameters
> from the matrix itself, while the final transformation might
> be good enough.

> See the testcase testsuite/libcore.all/MatrixTest.cpp
> There you see how setting scale to -scale fails to remember
> scale got negative and instead introduces a rotation of 180 degrees.
>
> So, should we take that as correct or expect the failure or
> drop those parameters setting methods ?
>

I didn't do much research on the math itself when refactorying the
matrix class,  all the math was borrowed from the old code IIRC.

This is the math from AGG, in file  agg_trans_affine.cpp, you might
want to have a look.

//
// get the rotation from a matrix.
//
double trans_affine::rotation() const
{
double x1 = 0.0;
double y1 = 0.0;
double x2 = 1.0;
double y2 = 0.0;
transform(&x1, &y1);
transform(&x2, &y2);
return atan2(y2-y1, x2-x1);
}

//
//get the translation from a matrix
//
void trans_affine::translation(double* dx, double* dy) const
{
*dx = tx;
*dy = ty;
}

//
// get scaling x and y from a matrix.
//
void trans_affine::scaling(double* x, double* y) const
{
double x1 = 0.0;
double y1 = 0.0;
double x2 = 1.0;
double y2 = 1.0;
trans_affine t(*this);
t *= trans_affine_rotation(-rotation());
t.transform(&x1, &y1);
t.transform(&x2, &y2);
*x = x2 - x1;
*y = y2 - y1;
}

--zou

```