gnash-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re[2]: [Gnash-dev] does _height work??


From: Martin Guy
Subject: Re: Re[2]: [Gnash-dev] does _height work??
Date: Tue, 10 Oct 2006 20:05:10 +0100

s>   // Transform the coords.
s>   float   x_scale = s_render_matrix.m_[0][0];
s>   float   y_scale = s_render_matrix.m_[1][1];
s>   float   x_offset = s_render_matrix.m_[0][2];
s>   float   y_offset = s_render_matrix.m_[1][2]

Whoa, hang on, that code is correct.

The matrix looks like this:
|scale_x  rotate_x  translate_x|
|scale_y  rotate_y  translate_y|

Er, not quite. Try:

|scale_x  x_dep_y  translate_x|
|y_dep_x  scale_y  translate_y|

Scale modifies the size of a object.
Rotate rotates the coordinate around the object's anchor point.
Translate defines it's position.

It's worse than that :) the first two pairs of numbers define scaling
and rotation between them. It's kinda hard to explain without a
blackboard and a voice but here goes...

Those 6 terms are actually the top two rows of a 3x3 matrix whose
bottom row is (0 0 1), which lets you define any combination of
scaling, motion and rotation (including flipping) in just 6 numbers.
Better yet, the same distortion is always represented by the same set
of 6 numbers.

You take (x y 1) , multiply it by the transformation matrix and get
(new_x new_y 1)

In code, the transformation would be:
(x * scale_x + y * x_dep_y + 1 * translate_x) is your new x
(x * y_dep_x + y * scale_x + 1 * translate_y) is your new y
and if you want to do the bottom row too, it's (x*0+y*0+1*1)=1

That may seem absurdly complicated but it lets you separate your
object coordinates (x and y) from the transformation that is being
performed on them. Once you have done that, you can say things like
"apply this transformation to every object in this group", you can
take two or more transformations that need to be applied to objects in
a scene one after the other and multiply the matrices together to
obtain a matrix that performs all those transforms in one go, and
there are functions that, given a transformation matrix will give you
the matrix for the exact opposite transformation to map points back
from the output to where they came from in the original object and so
on.

The values on the diagonal from top left to bottom right *do* scale
the image if all the other values are 0, but so do the values at
[0][1] and [1][0] as well as applying a rotation. I've called them
x_dep_y and y_dep_x because they are how the output x coordinate
depends on the input y coordinate and vice versa.

Here are a few examples. It they're not obvious, try putting a few
coordinates through the above formulae and see where x and y end up:

1. do nothing. the output is the same as the input:
(1 0 0)
(0 1 0)
(0 0 1)

2. swap the x and y values over (flip it about the 45 degree line where x==y)
(0 1 0)
(1 0 0)
(0 0 1)

3. rotate the figure 90 degrees anticlockwise about (0,0)
(0 -1 0)
(1 0 0)
(0 0 1)
...the new y is the old x, and the new x is minus the old y.

rotate the figure 90 degrees about 0,0 and blow it up to twice its size
(0 -2 0)
(2 0 0)
(0 0 1)

Now, suppose you want to rotate a square that is at (0,0) (0,100)
(100,100) (100,0) about its centre. You can rotate it with matrix 2
above, but you'd need to shift it back 100 units right to get it back
where it was, so that would be:
(0 -1 100)
(1 0 0)
(0 0 1)
Or, more precisely,the effect of this matrix is to rotate any object
90 degrees anticlockwise about the position (50,50).

That-s all pretty counter-intuitive, I realise, but once you close
your eyes to what's actually *in* the matrix, things become easy. It
only gets tricky when you have to pick values out of the matrices and
apply them to x and y values to actually perform the transforms.

Does that make any sense?

   M




reply via email to

[Prev in Thread] Current Thread [Next in Thread]