[Top][All Lists]
[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: |
Wed, 11 Oct 2006 11:53:52 +0100 |
> (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
^^^^^^^ that's scale_y, right ?
You are right of course. I'll do lesson 2 then...
(This has nothing to do with Gnash-dev really; it is just the basis of
most 2D vector graphics)
To be able to apply a transformation matrix, those two equations
tell you everything you need to know.
Generating them is a bit harder, and I hope you'll never need to do
this, but if you grok what follows, you will definitely have no more
problems with them.
Ok, so taking a *single* value out of the matrix is surely
wrong in all our cases, correct ?
Not necessarily... but you need to know what it means.
If [0][1] and [1][0] are both ==0, then you *do* just have a zoom
[zooming on (0,0)] followed by a translation - in the character code
you cited they seem to be ignoring any rotation.
Suppose you want a matrix that will rotate things N degrees about a
point (cx,cy). Now it gets hairy because the rotation is about the
origin (0,0) so you need to compensate in the translation to keep the
object in the same place. I can figure out how to rotate an object N
degrees around (0,0) just by thinking what happens to points (1,0) and
(0,1) when you rotate them about (0,0) a little bit. The matrix turns
out to be:
(cos(N) -sin(N) 0)
(sin(N) cos(N) 0)
(0 0 1)
[There's nothing magic about which terms are positive and which are
negative here... they just depend on which direction you consider to
be "positive" when you rotate, clockwise or anticlockwise, and whether
positive Y is upwards or downwards. I'm assuming positive Y is upwards
and anticlockwise is positive rotation here]
To rotate it about (cx,cy) instead, we could translate the object so
that its centre of rotation is at the origin by multiplying each point
by
(1 0 -cx)
(0 1 -cy)
(0 0 1 )
then do the rotation (as above), then translate it back using
(1 0 cx)
(0 1 cy)
(0 0 1)
Multiply the three together (first two first, then the result by the
third) and you get a single matrix that will achieve this for you
Matrix multiplication: to get one term of the result matrix, pick any
row in the first matrix and any column in the second matrix, multiply
each pair of terms, then add the products together. The number you get
is a single term in the result matrix at the row/column you first
thought of.
For example, to multiply two 3x3s:
(a b c) (A B C) (aA+bD+cG aB+bE+cH aC+bF+cI)
(d e f) (D E F) = (dA+eD+fG dB+eE+fH dC+eF+fI)
(g h i) (G H I) (gA+hD+iG gB+hE+iH gC+hF+iI)
[aA means a*A]
Multiplying the first two (1 0 -cx...) and the sin/cos thing gives you
(cos(N) -sin(N) -cx)
(sin(N) cos(N) -cy)
(0 0 1)
and multiplying that by the third one (1 0 cx...) gives you
(cosN -sinN cosN*cx-sinN*cy-cx)
(sinN cosN sinN*cx+cosNcy-cy)
(0 0 1)
THis is the matrix that will rotate all point in an object N degrees
about (cx,cy). Precalculate it, and you can rotate things quickly.
If you want to hammer this stuff home, then here's one you can try:
What single matrix will zoom a figure by scale factor S with respect
to its centre (cx,cy) instead of having it zoom towards/away from
(0,0)?
Hint: think about translating the object so that the zooming centre
is at 0,0 then scale it, then translate it back to where it was.
In case you're still wondering about the pointless (0 0 1) on the
bottom of each matrix, and why I talk about (x y 1) instead of (x y),
it's because to multiply matrices, the height of each column in the
first one has to equal the width of each row in the second. So in math
terms a point is really
(x)
(y)
(1)
and the (1) is what gets multiplied by the translate terms so that
they add into the result.
The (0 0 1) at the bottom of the transformation matrix is not totally
useless. If you set the first two to anything other than 0, that
applies a shearing effect to the objects, something that is not used
in Flash, which is why it is omitted from the code.
your explanation should be included in the source code or documentation
Help yourself. I tried to find a strightforward explanation on
Wolfram's mathworld but failed. Does anyone else know of a good and
short intro tutorial that we could cite for programmers who haven't
come across this stuff yet?
M
- Re[2]: [Gnash-dev] does _height work??, (continued)
- Re[2]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/11
- Re[2]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/11
- Re[2]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/11
- Re[2]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/12
- Re[2]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/12
- Re: Re[2]: [Gnash-dev] does _height work??, strk, 2006/10/11
- Re: Re[2]: [Gnash-dev] does _height work??,
Martin Guy <=
- Re[4]: [Gnash-dev] does _height work??, Udo Giacomozzi, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/11
- Re: [Gnash-dev] does _height work??, strk, 2006/10/11