gnash-commit
[Top][All Lists]
Advanced

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

[Gnash-commit] /srv/bzr/gnash/trunk r9877: Swap the matrix scale sign ap


From: Benjamin Wolsey
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r9877: Swap the matrix scale sign appropriately. Fixes the _xscale and _yscale tests
Date: Tue, 30 Sep 2008 17:15:39 +0200
User-agent: Bazaar (1.5)

------------------------------------------------------------
revno: 9877
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Tue 2008-09-30 17:15:39 +0200
message:
  Swap the matrix scale sign appropriately. Fixes the _xscale and _yscale tests
  in MovieClip.as and matrix_test.c. Fixes mario.swf and snowy.swf, no FAILs
  in the testsuite. Senocular transform_grabber.swf also works again.
modified:
  libcore/character.cpp
  libcore/matrix.cpp
  testsuite/actionscript.all/MovieClip.as
  testsuite/misc-ming.all/matrix_test.c
    ------------------------------------------------------------
    revno: 9875.1.1
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-09-30 13:49:17 +0200
    message:
      Tests for _xscale and _yscale.
    modified:
      testsuite/actionscript.all/MovieClip.as
    ------------------------------------------------------------
    revno: 9875.1.2
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-09-30 14:35:25 +0200
    message:
      Invert the SWF matrix signs on set _xscale or _yscale only if the sign
      has changed.
    modified:
      libcore/character.cpp
      libcore/matrix.cpp
    ------------------------------------------------------------
    revno: 9875.1.3
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-09-30 15:29:58 +0200
    message:
      Passes old tests as well as new ones.
    modified:
      libcore/character.cpp
    ------------------------------------------------------------
    revno: 9875.1.4
    committer: Benjamin Wolsey <address@hidden>
    branch nick: work
    timestamp: Tue 2008-09-30 16:46:27 +0200
    message:
      Don't invert matrix scale if scales were 0 before.
    modified:
      libcore/character.cpp
      libcore/matrix.cpp
=== modified file 'libcore/character.cpp'
--- a/libcore/character.cpp     2008-09-30 07:39:32 +0000
+++ b/libcore/character.cpp     2008-09-30 15:15:39 +0000
@@ -504,7 +504,7 @@
        const double oldwidth = bounds.width();
        assert(oldwidth >= 0); // can't be negative can it?
 
-        double yscale = fabs(_yscale / 100.0); // see MovieClip.as. TODO: this 
is likely same as m.get_y_scale..
+        double yscale = std::abs(_yscale / 100.0); // see MovieClip.as. TODO: 
this is likely same as m.get_y_scale..
         double xscale = (newwidth / oldwidth);
         double rotation = _rotation * PI / 180.0;
 
@@ -668,9 +668,10 @@
 void
 character::set_matrix(const matrix& m, bool updateCache)
 {
-        assert(m.is_valid());
-        if (!(m == m_matrix))
-        {
+
+    if (!(m == m_matrix))
+    {
+        //log_debug("setting matrix to: %s", m);
                set_invalidated(__FILE__, __LINE__);
                m_matrix = m;
 
@@ -682,9 +683,13 @@
                        _rotation = m_matrix.get_rotation() * 180.0 / PI;
                }
 #endif
-        }
-       else log_debug("set_matrix of character %s: matrix not changed..", 
getTarget());
-       
+    }
+    else
+    {
+        //log_debug("set_matrix of character %s: matrix "
+        //"not changed", getTarget());
+    }
+
 }
 
 void
@@ -815,20 +820,30 @@
 character::set_x_scale(double scale_percent)
 {
 #ifdef USE_MATRIX_CACHES
-       _xscale = scale_percent;
+    double xscale = scale_percent / 100.0;
+
+    if (xscale != 0.0 && _xscale != 0.0)
+    {
+        if (scale_percent * _xscale < 0.0)
+        {
+            log_debug("Flipping x scale (%d, %d)", scale_percent, _xscale);
+            xscale = -std::abs(xscale);
+         }
+        else xscale = std::abs(xscale);
+    }
+
+    _xscale = scale_percent;
 
     // As per misc-ming.all/matrix_test.{c,swf}
     // we don't need to recompute the matrix from the 
     // caches.
 
-       double xscale = _xscale / 100.0;
-       //double yscale = _yscale / 100.0;
-       //double rotation = _rotation * PI / 180.0;
 
        matrix m = get_matrix();
-       //m.set_scale_rotation(xscale, yscale, rotation);
-       m.set_x_scale(xscale);
-       set_matrix(m); // we updated the cache ourselves
+
+    m.set_x_scale(xscale);
+
+    set_matrix(m); // we updated the cache ourselves
 #else
     double xscale = scale_percent / 100.0;
        matrix m = get_matrix();
@@ -843,7 +858,7 @@
 character::set_rotation(double rot)
 {
        // Translate to the -180 .. 180 range
-       rot = fmod (rot, 360.0);
+       rot = std::fmod (rot, 360.0);
        if (rot > 180.0)
                rot -= 360.0;
        else if (rot < -180.0)
@@ -860,13 +875,17 @@
 
        matrix m = get_matrix();
 
-       if ( ! get_parent() ) {
-               // doesn't have an original matrix, so always rebuild
-               m.set_scale_rotation(xscale, yscale, rotation);
-       } else {
-               if ( _xscale < 0 && _yscale < 0 ) rotation += PI;
-               m.set_rotation(rotation);
-       }
+    //log_debug("xscale cached: %d, yscale cached: %d", _xscale, _yscale);
+
+    if (get_parent())
+    {
+        if (_xscale < 0 || _yscale < 0) rotation += PI;
+        m.set_rotation(rotation);
+    }
+    else
+    {
+        m.set_scale_rotation(xscale, yscale, rotation);
+    }
 
        set_matrix(m); // we updated the cache ourselves
 #else
@@ -882,26 +901,24 @@
 void
 character::set_y_scale(double scale_percent)
 {
-#ifdef USE_MATRIX_CACHES
+    double yscale = scale_percent / 100.0;
+    
+    if (yscale != 0.0 && _yscale != 0.0)
+    {
+        if (scale_percent * _yscale < 0.0)
+        {
+            log_debug("Flipping y scale (%d, %d)", scale_percent, _yscale);
+            yscale = -std::abs(yscale);
+        }
+        else yscale = std::abs(yscale);
+    }
+    //log_debug("yscale factor: %d, old percent: %d", yscale, _yscale);
+
        _yscale = scale_percent;
 
-       double xscale = _xscale / 100.0;
-       double yscale = _yscale / 100.0;
-       double rotation = _rotation * PI / 180.0;
-
-       matrix m = get_matrix();
-       if ( ! get_parent() ) {
-               // doesn't have an original matrix, so always rebuild
-               m.set_scale_rotation(xscale, yscale, rotation);
-       } else {
-               m.set_y_scale(yscale);
-       }
-       set_matrix(m); // we updated the cache ourselves
-#else
-       matrix m = get_matrix();
-    m_matrix.set_y_scale(scale_percent / 100.0);
-       set_matrix(m); // we updated the cache ourselves
-#endif
+       matrix m = get_matrix();
+    m.set_y_scale(yscale);
+       set_matrix(m); // we updated the cache ourselves
 
        transformedByScript(); 
 }

=== modified file 'libcore/matrix.cpp'
--- a/libcore/matrix.cpp        2008-09-29 15:18:20 +0000
+++ b/libcore/matrix.cpp        2008-09-30 14:46:27 +0000
@@ -191,9 +191,14 @@
 matrix::set_y_scale(double yscale)
 {
 #ifdef NEW_MATRIX_MATH
-    double rot_y = atan2((double)(-shy), (double)(sy));
-    shy = -DoubleToFixed16(yscale * sin(rot_y));
-    sy  =  DoubleToFixed16(yscale * cos(rot_y));
+    double rot_y = std::atan2((double)(-shy), (double)(sy));
+
+    shy = -DoubleToFixed16(yscale * std::sin(rot_y));
+    sy  =  DoubleToFixed16(yscale * std::cos(rot_y));
+
+    log_debug("yscale %d, shy: %d, sy: %d", yscale, shy, sy);
+
+
 #else
     double angle = get_rotation();
     double cos_v = cos(angle);

=== modified file 'testsuite/actionscript.all/MovieClip.as'
--- a/testsuite/actionscript.all/MovieClip.as   2008-09-29 20:09:34 +0000
+++ b/testsuite/actionscript.all/MovieClip.as   2008-09-30 15:15:39 +0000
@@ -103,7 +103,7 @@
 #endif
 
 #if OUTPUT_VERSION >= 8
-       check_totals(783); // SWF8+
+       check_totals(797); // SWF8+
 #endif
 
        play();
@@ -1404,6 +1404,41 @@
 // Test transform
 //----------------------------------------------
 
+#if OUTPUT_VERSION >=8
+tmp = _root.createEmptyMovieClip("tmp", getNextHighestDepth());
+tmptr = tmp.transform;
+
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0, c=0, d=1, tx=0, 
ty=0)");
+tmp._yscale = 200;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0, c=0, d=2, tx=0, 
ty=0)");
+tmp._rotation = Math.PI / 4;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.01, c=-0.03, 
d=2, tx=0, ty=0)");
+tmp._yscale = -100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.01, c=0.01, 
d=-1, tx=0, ty=0)");
+tmp._yscale = -100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.01, c=0.01, 
d=-1, tx=0, ty=0)");
+tmp._yscale = 100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.01, c=-0.01, 
d=1, tx=0, ty=0)");
+tmp._xscale = -100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=-1, b=-0.01, c=-0.01, 
d=1, tx=0, ty=0)");
+tmp._rotation = Math.PI / 2;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=-1, b=-0.03, c=-0.03, 
d=1, tx=0, ty=0)");
+tmp._xscale = 100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=-0.03, 
d=1, tx=0, ty=0)");
+tmp._yscale = -100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=0.03, 
d=-1, tx=0, ty=0)");
+tmp._x = 3;
+tmp._y = 6;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=0.03, 
d=-1, tx=3, ty=6)");
+tmp._yscale = 100;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=-0.03, 
d=1, tx=3, ty=6)");
+tmp._yscale = -0;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=0, d=0, 
tx=3, ty=6)");
+tmp._yscale = 0;
+check_equals(printMatrix(tmp.transform.matrix, 2), "(a=1, b=0.03, c=0, d=0, 
tx=3, ty=6)");
+#endif
+
+
 #if OUTPUT_VERSION < 8
 check_equals(typeof(_root.transform), 'undefined'); 
 #else

=== modified file 'testsuite/misc-ming.all/matrix_test.c'
--- a/testsuite/misc-ming.all/matrix_test.c     2008-09-30 08:20:05 +0000
+++ b/testsuite/misc-ming.all/matrix_test.c     2008-09-30 15:15:39 +0000
@@ -911,24 +911,24 @@
        check_equals(mo, "printBounds(staticmc.getBounds(_root))", 
"'169.95,169.95 230.05,230.05'");
     check_equals(mo, "staticmc.transform.matrix.toString()", "'(a=1, b=0, c=0, 
d=1, tx=200, ty=200)'");
        add_actions(mo, "staticmc._yscale = 0 - staticmc._yscale;"); // swap 
_yscale sign using ActionScript
-    xcheck_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=1, 
b=0, c=0, d=-1, tx=200, ty=200)'");
+    check_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=1, b=0, 
c=0, d=-1, tx=200, ty=200)'");
        check_equals(mo, "printBounds(staticmc.getBounds(_root))", 
"'169.95,169.95 230.05,230.05'");
 
        check_equals(mo, "staticmc._xscale", "100");
        add_actions(mo, "staticmc._xscale = 0 - staticmc._xscale;"); // swap 
_xscale sign using ActionScript
-    xcheck_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=0, c=0, d=-1, tx=200, ty=200)'");
+    check_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=0, c=0, d=-1, tx=200, ty=200)'");
        check_equals(mo, "staticmc._xscale", "-100");
        check_equals(mo, "printBounds(staticmc.getBounds(_root), 0)", "'170,170 
230,230'");
 
        add_actions(mo, "staticmc._rotation = 2;"); // change _rotation using 
ActionScript
-    xcheck_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=-0.03, c=0.03, d=-1, tx=200, ty=200)'");
+    check_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=-0.03, c=0.03, d=-1, tx=200, ty=200)'");
        check_equals(mo, "staticmc._yscale", "100");
        check_equals(mo, "staticmc._xscale", "-100");
        check_equals(mo, "staticmc._rotation", "2");
        check_equals(mo, "printBounds(staticmc.getBounds(_root), 0)", "'169,169 
231,231'");
 
        add_actions(mo, "staticmc._rotation = -2;"); // change _rotation using 
ActionScript
-    xcheck_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=0.03, c=-0.03, d=-1, tx=200, ty=200)'");
+    check_equals(mo, "printMatrix(staticmc.transform.matrix, 2)", "'(a=-1, 
b=0.03, c=-0.03, d=-1, tx=200, ty=200)'");
        check_equals(mo, "staticmc._yscale", "100");
        check_equals(mo, "staticmc._xscale", "-100");
        check_equals(mo, "staticmc._rotation", "-2");


reply via email to

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