[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] gnash ChangeLog server/Makefile.am server/gnash...
From: |
Sandro Santilli |
Subject: |
[Gnash-commit] gnash ChangeLog server/Makefile.am server/gnash... |
Date: |
Wed, 11 Oct 2006 08:08:36 +0000 |
CVSROOT: /sources/gnash
Module name: gnash
Changes by: Sandro Santilli <strk> 06/10/11 08:08:36
Modified files:
. : ChangeLog
server : Makefile.am gnash.h movie.h types.cpp
Added files:
server : matrix.cpp matrix.h
Log message:
moved matrix class in its own files and added/fixed documentation.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.1130&r2=1.1131
http://cvs.savannah.gnu.org/viewcvs/gnash/server/Makefile.am?cvsroot=gnash&r1=1.69&r2=1.70
http://cvs.savannah.gnu.org/viewcvs/gnash/server/gnash.h?cvsroot=gnash&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/gnash/server/movie.h?cvsroot=gnash&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/gnash/server/types.cpp?cvsroot=gnash&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/gnash/server/matrix.cpp?cvsroot=gnash&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/gnash/server/matrix.h?cvsroot=gnash&rev=1.1
Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.1130
retrieving revision 1.1131
diff -u -b -r1.1130 -r1.1131
--- ChangeLog 11 Oct 2006 01:23:17 -0000 1.1130
+++ ChangeLog 11 Oct 2006 08:08:36 -0000 1.1131
@@ -1,3 +1,10 @@
+2006-10-11 Sandro Santilli <address@hidden>
+
+ * server/Makefile.am, server/gnash.h, server/matrix.cpp,
+ server/matrix.h, server/movie.h, server/types.cpp:
+ moved matrix class in its own files and added/fixed
+ documentation.
+
2006-10-11 Markus Gothe <address@hidden>
* macros/agg.m4: Added /usr/pkg/include.
Index: server/Makefile.am
===================================================================
RCS file: /sources/gnash/gnash/server/Makefile.am,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -b -r1.69 -r1.70
--- server/Makefile.am 6 Oct 2006 22:25:33 -0000 1.69
+++ server/Makefile.am 11 Oct 2006 08:08:36 -0000 1.70
@@ -97,6 +97,7 @@
shm.cpp \
sound.cpp \
sprite_instance.cpp \
+ matrix.cpp \
movie_instance.cpp \
stream.cpp \
StreamProvider.cpp \
@@ -108,7 +109,8 @@
swf/ASHandlers.cpp \
swf/TagLoadersTable.cpp \
swf/tag_loaders.cpp \
- types.cpp
+ types.cpp \
+ $(NULL)
noinst_HEADERS = \
action.h \
@@ -123,6 +125,7 @@
as_prop_flags.h \
as_object.h \
button_character_instance.h \
+ matrix.h \
mouse_button_state.h \
dlist.h \
character.h \
Index: server/gnash.h
===================================================================
RCS file: /sources/gnash/gnash/server/gnash.h,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- server/gnash.h 7 Oct 2006 14:20:27 -0000 1.57
+++ server/gnash.h 11 Oct 2006 08:08:36 -0000 1.58
@@ -35,7 +35,7 @@
//
//
-/* $Id: gnash.h,v 1.57 2006/10/07 14:20:27 tgc Exp $ */
+/* $Id: gnash.h,v 1.58 2006/10/11 08:08:36 strk Exp $ */
/// \mainpage
///
@@ -87,6 +87,7 @@
class character;
class execute_tag;
class font;
+class matrix;
class movie;
class movie_interface;
class movie_definition;
@@ -478,108 +479,6 @@
//
-// matrix type, used by render handler
-//
-
-class point;
-
-/// Matrix type, used by render handler
-class DSOEXPORT matrix
-{
-public:
- /// [x,y][scale,rotate,translate]
- float m_[2][3];
-
- /// The identity matrix (no transforms)
- static matrix identity;
-
- /// Defaults to identity
- matrix();
-
- /// Check validity of the matrix values
- bool is_valid() const;
-
- /// Set the matrix to identity.
- void set_identity();
-
- /// Concatenate m's transform onto ours.
- //
- /// When transforming points, m happens first,
- /// then our original xform.
- void concatenate(const matrix& m);
-
- /// Concatenate a translation onto the front of our matrix.
- //
- /// When transforming points, the translation
- /// happens first, then our original xform.
- ///
- void concatenate_translation(float tx, float ty);
-
- /// Concatenate a uniform scale onto the front of our matrix.
- //
- /// When transforming points, the scale
- /// happens first, then our original xform.
- ///
- void concatenate_scale(float s);
-
- /// Set this matrix to a blend of m1 and m2, parameterized by t.
- void set_lerp(const matrix& m1, const matrix& m2, float t);
-
- /// Set the scale & rotation part of the matrix. angle in radians.
- void set_scale_rotation(float x_scale, float y_scale, float
rotation);
-
- /// Initialize from the SWF input stream.
- void read(stream* in);
-
- /// Debug log.
- void print() const;
-
- /// Transform point 'p' by our matrix.
- //
- /// Put the result in *result.
- ///
- void transform(point* result, const point& p) const;
-
- /// Transform vector 'v' by our matrix. Doesn't apply translation.
- //
- /// Put the result in *result.
- ///
- void transform_vector(point* result, const point& p) const;
-
- /// Transform point 'p' by the inverse of our matrix.
- //
- /// Put result in *result.
- ///
- void transform_by_inverse(point* result, const point& p) const;
-
- /// Set this matrix to the inverse of the given matrix.
- void set_inverse(const matrix& m);
-
- /// Return true if this matrix reverses handedness.
- bool does_flip() const;
-
- /// Return the determinant of the 2x2 rotation/scale part only.
- float get_determinant() const;
-
- /// Return the maximum scale factor that this transform applies.
- //
- /// For assessing scale, when determining acceptable
- /// errors in tesselation.
- ///
- float get_max_scale() const;
-
- /// return the magnitude scale of our x coord output
- float get_x_scale() const;
-
- /// return the magnitude scale of our y coord output
- float get_y_scale() const;
-
- /// return our rotation component (in radians)
- float get_rotation() const;
-};
-
-
-//
// point: used by rect which is used by render_handler (otherwise would be in
internal gnash_types.h)
//
Index: server/movie.h
===================================================================
RCS file: /sources/gnash/gnash/server/movie.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- server/movie.h 29 Sep 2006 10:08:29 -0000 1.19
+++ server/movie.h 11 Oct 2006 08:08:36 -0000 1.20
@@ -44,7 +44,6 @@
#endif
#include "gnash.h"
-//#include "action.h"
#include "types.h"
#include "log.h"
#include "container.h"
@@ -52,6 +51,7 @@
#include "smart_ptr.h"
#include "movie_interface.h" // for inheritance
#include "action.h" // for event_id definitions
+#include "matrix.h" // for return of get_world_matrix
#include <cstdarg>
#include <cassert>
Index: server/types.cpp
===================================================================
RCS file: /sources/gnash/gnash/server/types.cpp,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- server/types.cpp 27 Aug 2006 18:30:38 -0000 1.10
+++ server/types.cpp 11 Oct 2006 08:08:36 -0000 1.11
@@ -36,273 +36,6 @@
//
- // matrix
- //
-
- matrix matrix::identity;
-
- matrix::matrix()
- {
- // Default to identity.
- set_identity();
- }
-
-
- bool matrix::is_valid() const
- {
- return isfinite(m_[0][0])
- && isfinite(m_[0][1])
- && isfinite(m_[0][2])
- && isfinite(m_[1][0])
- && isfinite(m_[1][1])
- && isfinite(m_[1][2]);
- }
-
-
- void matrix::set_identity()
- // Set the matrix to identity.
- {
- memset(&m_[0], 0, sizeof(m_));
- m_[0][0] = 1;
- m_[1][1] = 1;
- }
-
-
- void matrix::concatenate(const matrix& m)
- // Concatenate m's transform onto ours. When
- // transforming points, m happens first, then our
- // original xform.
- {
- matrix t;
- t.m_[0][0] = m_[0][0] * m.m_[0][0] + m_[0][1] * m.m_[1][0];
- t.m_[1][0] = m_[1][0] * m.m_[0][0] + m_[1][1] * m.m_[1][0];
- t.m_[0][1] = m_[0][0] * m.m_[0][1] + m_[0][1] * m.m_[1][1];
- t.m_[1][1] = m_[1][0] * m.m_[0][1] + m_[1][1] * m.m_[1][1];
- t.m_[0][2] = m_[0][0] * m.m_[0][2] + m_[0][1] * m.m_[1][2] +
m_[0][2];
- t.m_[1][2] = m_[1][0] * m.m_[0][2] + m_[1][1] * m.m_[1][2] +
m_[1][2];
-
- *this = t;
- }
-
-
- void matrix::concatenate_translation(float tx, float ty)
- // Concatenate a translation onto the front of our
- // matrix. When transforming points, the translation
- // happens first, then our original xform.
- {
- m_[0][2] += infinite_to_fzero(m_[0][0] * tx + m_[0][1] * ty);
- m_[1][2] += infinite_to_fzero(m_[1][0] * tx + m_[1][1] * ty);
- }
-
-
- void matrix::concatenate_scale(float scale)
- // Concatenate a uniform scale onto the front of our
- // matrix. When transforming points, the scale
- // happens first, then our original xform.
- {
- m_[0][0] *= infinite_to_fzero(scale);
- m_[0][1] *= infinite_to_fzero(scale);
- m_[1][0] *= infinite_to_fzero(scale);
- m_[1][1] *= infinite_to_fzero(scale);
- }
-
-
- void matrix::set_lerp(const matrix& m1, const matrix& m2, float t)
- // Set this matrix to a blend of m1 and m2, parameterized by t.
- {
- m_[0][0] = flerp(m1.m_[0][0], m2.m_[0][0], t);
- m_[1][0] = flerp(m1.m_[1][0], m2.m_[1][0], t);
- m_[0][1] = flerp(m1.m_[0][1], m2.m_[0][1], t);
- m_[1][1] = flerp(m1.m_[1][1], m2.m_[1][1], t);
- m_[0][2] = flerp(m1.m_[0][2], m2.m_[0][2], t);
- m_[1][2] = flerp(m1.m_[1][2], m2.m_[1][2], t);
- }
-
-
- void matrix::set_scale_rotation(float x_scale, float y_scale, float
angle)
- // Set the scale & rotation part of the matrix.
- // angle in radians.
- {
- float cos_angle = cosf(angle);
- float sin_angle = sinf(angle);
- m_[0][0] = infinite_to_fzero(x_scale * cos_angle);
- m_[0][1] = infinite_to_fzero(y_scale * -sin_angle);
- m_[1][0] = infinite_to_fzero(x_scale * sin_angle);
- m_[1][1] = infinite_to_fzero(y_scale * cos_angle);
- }
-
-
- void matrix::read(stream* in)
- // Initialize from the stream.
- {
- in->align();
-
- set_identity();
-
- int has_scale = in->read_uint(1);
- if (has_scale)
- {
- int scale_nbits = in->read_uint(5);
- m_[0][0] = in->read_sint(scale_nbits) / 65536.0f;
- m_[1][1] = in->read_sint(scale_nbits) / 65536.0f;
- }
- int has_rotate = in->read_uint(1);
- if (has_rotate)
- {
- int rotate_nbits = in->read_uint(5);
- m_[1][0] = in->read_sint(rotate_nbits) / 65536.0f;
- m_[0][1] = in->read_sint(rotate_nbits) / 65536.0f;
- }
-
- int translate_nbits = in->read_uint(5);
- if (translate_nbits > 0)
- {
- m_[0][2] = (float) in->read_sint(translate_nbits);
- m_[1][2] = (float) in->read_sint(translate_nbits);
- }
-
- //IF_VERBOSE_PARSE(log_msg(" mat: has_scale = %d, has_rotate =
%d\n", has_scale, has_rotate));
- }
-
-
- void matrix::print() const
- // Debug log.
- {
- IF_VERBOSE_PARSE(
- log_parse("| %4.4f %4.4f %4.4f |", m_[0][0], m_[0][1],
TWIPS_TO_PIXELS(m_[0][2]));
- log_parse("| %4.4f %4.4f %4.4f |", m_[1][0], m_[1][1],
TWIPS_TO_PIXELS(m_[1][2]));
- );
- }
-
- void matrix::transform(point* result, const point& p) const
- // Transform point 'p' by our matrix. Put the result in
- // *result.
- {
- assert(result);
-
- result->m_x = m_[0][0] * p.m_x + m_[0][1] * p.m_y + m_[0][2];
- result->m_y = m_[1][0] * p.m_x + m_[1][1] * p.m_y + m_[1][2];
- }
-
- void matrix::transform_vector(point* result, const point& v) const
- // Transform vector 'v' by our matrix. Doesn't apply translation.
- // Put the result in *result.
- {
- assert(result);
-
- result->m_x = m_[0][0] * v.m_x + m_[0][1] * v.m_y;
- result->m_y = m_[1][0] * v.m_x + m_[1][1] * v.m_y;
- }
-
- void matrix::transform_by_inverse(point* result, const point& p)
const
- // Transform point 'p' by the inverse of our matrix. Put result in
*result.
- {
- // @@ TODO optimize this!
- matrix m;
- m.set_inverse(*this);
- m.transform(result, p);
- }
-
-
- void matrix::set_inverse(const matrix& m)
- // Set this matrix to the inverse of the given matrix.
- {
- assert(this != &m);
-
- // Invert the rotation part.
- float det = m.m_[0][0] * m.m_[1][1] - m.m_[0][1] * m.m_[1][0];
- if (det == 0.0f)
- {
- // Not invertible.
- //assert(0); // castano: this happens sometimes!
(ie. sample6.swf)
-
- // Arbitrary fallback.
- set_identity();
- m_[0][2] = -m.m_[0][2];
- m_[1][2] = -m.m_[1][2];
- }
- else
- {
- float inv_det = 1.0f / det;
- m_[0][0] = m.m_[1][1] * inv_det;
- m_[1][1] = m.m_[0][0] * inv_det;
- m_[0][1] = -m.m_[0][1] * inv_det;
- m_[1][0] = -m.m_[1][0] * inv_det;
-
- m_[0][2] = -(m_[0][0] * m.m_[0][2] + m_[0][1] *
m.m_[1][2]);
- m_[1][2] = -(m_[1][0] * m.m_[0][2] + m_[1][1] *
m.m_[1][2]);
- }
- }
-
-
- bool matrix::does_flip() const
- // Return true if this matrix reverses handedness.
- {
- float det = m_[0][0] * m_[1][1] - m_[0][1] * m_[1][0];
-
- return det < 0.f;
- }
-
-
- float matrix::get_determinant() const
- // Return the determinant of the 2x2 rotation/scale part only.
- {
- return m_[0][0] * m_[1][1] - m_[1][0] * m_[0][1];
- }
-
-
- float matrix::get_max_scale() const
- // Return the maximum scale factor that this transform
- // applies. For assessing scale, when determining acceptable
- // errors in tesselation.
- {
- // @@ not 100% sure what the heck I'm doing here. I
- // think this is roughly what I want; take the max
- // length of the two basis vectors.
- float basis0_length2 = m_[0][0] * m_[0][0] + m_[0][1] *
m_[0][1];
- float basis1_length2 = m_[1][0] * m_[1][0] + m_[1][1] *
m_[1][1];
- float max_length2 = fmax(basis0_length2, basis1_length2);
- return sqrtf(max_length2);
- }
-
- float matrix::get_x_scale() const
- {
- float scale = sqrtf(m_[0][0] * m_[0][0] + m_[0][1] *
m_[0][1]);
-
- // Are we turned inside out?
- if (get_determinant() < 0.f)
- {
- scale = -scale;
- }
-
- return scale;
- }
-
- float matrix::get_y_scale() const
- {
- return sqrtf(m_[1][1] * m_[1][1] + m_[1][0] * m_[1][0]);
- }
-
- float matrix::get_rotation() const
- {
- if (get_determinant() < 0.f)
- {
- // We're turned inside out; negate the
- // x-component used to compute rotation.
- //
- // Matches get_x_scale().
- //
- // @@ this may not be how Macromedia does it! Test
this!
- return atan2f(m_[1][0], -m_[0][0]);
- }
- else
- {
- return atan2f(m_[1][0], m_[0][0]);
- }
- }
-
-
- //
// cxform
//
Index: server/matrix.cpp
===================================================================
RCS file: server/matrix.cpp
diff -N server/matrix.cpp
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/matrix.cpp 11 Oct 2006 08:08:36 -0000 1.1
@@ -0,0 +1,350 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+// Original author: Thatcher Ulrich <address@hidden> 2003
+//
+// $Id: matrix.cpp,v 1.1 2006/10/11 08:08:36 strk Exp $
+//
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "matrix.h"
+#include "stream.h" // for reading from SWF
+#include "types.h" // for TWIPS_TO_PIXEL define
+ // (should probably not use it though)
+#include "log.h"
+
+#ifndef HAVE_ISFINITE
+# ifndef isfinite
+# define isfinite finite
+# endif
+#endif
+
+namespace gnash {
+
+matrix matrix::identity;
+
+matrix::matrix()
+{
+ // Default to identity.
+ set_identity();
+}
+
+
+bool
+matrix::is_valid() const
+{
+ return isfinite(m_[0][0])
+ && isfinite(m_[0][1])
+ && isfinite(m_[0][2])
+ && isfinite(m_[1][0])
+ && isfinite(m_[1][1])
+ && isfinite(m_[1][2]);
+}
+
+
+void
+matrix::set_identity()
+// Set the matrix to identity.
+{
+ memset(&m_[0], 0, sizeof(m_));
+ m_[0][0] = 1;
+ m_[1][1] = 1;
+}
+
+
+void
+matrix::concatenate(const matrix& m)
+// Concatenate m's transform onto ours. When
+// transforming points, m happens first, then our
+// original xform.
+{
+ matrix t;
+ t.m_[0][0] = m_[0][0] * m.m_[0][0] + m_[0][1] * m.m_[1][0];
+ t.m_[1][0] = m_[1][0] * m.m_[0][0] + m_[1][1] * m.m_[1][0];
+ t.m_[0][1] = m_[0][0] * m.m_[0][1] + m_[0][1] * m.m_[1][1];
+ t.m_[1][1] = m_[1][0] * m.m_[0][1] + m_[1][1] * m.m_[1][1];
+ t.m_[0][2] = m_[0][0] * m.m_[0][2] + m_[0][1] * m.m_[1][2] + m_[0][2];
+ t.m_[1][2] = m_[1][0] * m.m_[0][2] + m_[1][1] * m.m_[1][2] + m_[1][2];
+
+ *this = t;
+}
+
+
+void
+matrix::concatenate_translation(float tx, float ty)
+// Concatenate a translation onto the front of our
+// matrix. When transforming points, the translation
+// happens first, then our original xform.
+{
+ m_[0][2] += infinite_to_fzero(m_[0][0] * tx + m_[0][1] * ty);
+ m_[1][2] += infinite_to_fzero(m_[1][0] * tx + m_[1][1] * ty);
+}
+
+
+void
+matrix::concatenate_scale(float scale)
+// Concatenate a uniform scale onto the front of our
+// matrix. When transforming points, the scale
+// happens first, then our original xform.
+{
+ m_[0][0] *= infinite_to_fzero(scale);
+ m_[0][1] *= infinite_to_fzero(scale);
+ m_[1][0] *= infinite_to_fzero(scale);
+ m_[1][1] *= infinite_to_fzero(scale);
+}
+
+
+void
+matrix::set_lerp(const matrix& m1, const matrix& m2, float t)
+// Set this matrix to a blend of m1 and m2, parameterized by t.
+{
+ m_[0][0] = flerp(m1.m_[0][0], m2.m_[0][0], t);
+ m_[1][0] = flerp(m1.m_[1][0], m2.m_[1][0], t);
+ m_[0][1] = flerp(m1.m_[0][1], m2.m_[0][1], t);
+ m_[1][1] = flerp(m1.m_[1][1], m2.m_[1][1], t);
+ m_[0][2] = flerp(m1.m_[0][2], m2.m_[0][2], t);
+ m_[1][2] = flerp(m1.m_[1][2], m2.m_[1][2], t);
+}
+
+
+void
+matrix::set_scale_rotation(float x_scale, float y_scale, float angle)
+// Set the scale & rotation part of the matrix.
+// angle in radians.
+{
+ float cos_angle = cosf(angle);
+ float sin_angle = sinf(angle);
+ m_[0][0] = infinite_to_fzero(x_scale * cos_angle);
+ m_[0][1] = infinite_to_fzero(y_scale * -sin_angle);
+ m_[1][0] = infinite_to_fzero(x_scale * sin_angle);
+ m_[1][1] = infinite_to_fzero(y_scale * cos_angle);
+}
+
+
+void
+matrix::read(stream* in)
+// Initialize from the stream.
+{
+ in->align();
+
+ set_identity();
+
+ int has_scale = in->read_uint(1);
+ if (has_scale)
+ {
+ int scale_nbits = in->read_uint(5);
+ m_[0][0] = in->read_sint(scale_nbits) / 65536.0f;
+ m_[1][1] = in->read_sint(scale_nbits) / 65536.0f;
+ }
+ int has_rotate = in->read_uint(1);
+ if (has_rotate)
+ {
+ int rotate_nbits = in->read_uint(5);
+ m_[1][0] = in->read_sint(rotate_nbits) / 65536.0f;
+ m_[0][1] = in->read_sint(rotate_nbits) / 65536.0f;
+ }
+
+ int translate_nbits = in->read_uint(5);
+ if (translate_nbits > 0)
+ {
+ m_[0][2] = (float) in->read_sint(translate_nbits);
+ m_[1][2] = (float) in->read_sint(translate_nbits);
+ }
+
+ //IF_VERBOSE_PARSE(log_msg(" mat: has_scale = %d, has_rotate = %d\n",
has_scale, has_rotate));
+}
+
+
+void
+matrix::print() const
+// Debug log.
+{
+ IF_VERBOSE_PARSE(
+ log_parse("| %4.4f %4.4f %4.4f |", m_[0][0], m_[0][1],
TWIPS_TO_PIXELS(m_[0][2]));
+ log_parse("| %4.4f %4.4f %4.4f |", m_[1][0], m_[1][1],
TWIPS_TO_PIXELS(m_[1][2]));
+ );
+}
+
+void
+matrix::transform(point* result, const point& p) const
+// Transform point 'p' by our matrix. Put the result in
+// *result.
+{
+ assert(result);
+
+ result->m_x = m_[0][0] * p.m_x + m_[0][1] * p.m_y + m_[0][2];
+ result->m_y = m_[1][0] * p.m_x + m_[1][1] * p.m_y + m_[1][2];
+}
+
+void
+matrix::transform_vector(point* result, const point& v) const
+// Transform vector 'v' by our matrix. Doesn't apply translation.
+// Put the result in *result.
+{
+ assert(result);
+
+ result->m_x = m_[0][0] * v.m_x + m_[0][1] * v.m_y;
+ result->m_y = m_[1][0] * v.m_x + m_[1][1] * v.m_y;
+}
+
+void
+matrix::transform_by_inverse(point* result, const point& p) const
+// Transform point 'p' by the inverse of our matrix. Put result in *result.
+{
+ // @@ TODO optimize this!
+ matrix m;
+ m.set_inverse(*this);
+ m.transform(result, p);
+}
+
+
+void
+matrix::set_inverse(const matrix& m)
+// Set this matrix to the inverse of the given matrix.
+{
+ assert(this != &m);
+
+ // Invert the rotation part.
+ float det = m.m_[0][0] * m.m_[1][1] - m.m_[0][1] * m.m_[1][0];
+ if (det == 0.0f)
+ {
+ // Not invertible.
+ //assert(0); // castano: this happens sometimes! (ie.
sample6.swf)
+
+ // Arbitrary fallback.
+ set_identity();
+ m_[0][2] = -m.m_[0][2];
+ m_[1][2] = -m.m_[1][2];
+ }
+ else
+ {
+ float inv_det = 1.0f / det;
+ m_[0][0] = m.m_[1][1] * inv_det;
+ m_[1][1] = m.m_[0][0] * inv_det;
+ m_[0][1] = -m.m_[0][1] * inv_det;
+ m_[1][0] = -m.m_[1][0] * inv_det;
+
+ m_[0][2] = -(m_[0][0] * m.m_[0][2] + m_[0][1] * m.m_[1][2]);
+ m_[1][2] = -(m_[1][0] * m.m_[0][2] + m_[1][1] * m.m_[1][2]);
+ }
+}
+
+
+bool
+matrix::does_flip() const
+// Return true if this matrix reverses handedness.
+{
+ float det = m_[0][0] * m_[1][1] - m_[0][1] * m_[1][0];
+
+ return det < 0.f;
+}
+
+
+float
+matrix::get_determinant() const
+// Return the determinant of the 2x2 rotation/scale part only.
+{
+ return m_[0][0] * m_[1][1] - m_[1][0] * m_[0][1];
+}
+
+
+float
+matrix::get_max_scale() const
+// Return the maximum scale factor that this transform
+// applies. For assessing scale, when determining acceptable
+// errors in tesselation.
+{
+ // @@ not 100% sure what the heck I'm doing here. I
+ // think this is roughly what I want; take the max
+ // length of the two basis vectors.
+ float basis0_length2 = m_[0][0] * m_[0][0] + m_[0][1] * m_[0][1];
+ float basis1_length2 = m_[1][0] * m_[1][0] + m_[1][1] * m_[1][1];
+ float max_length2 = fmax(basis0_length2, basis1_length2);
+ return sqrtf(max_length2);
+}
+
+float
+matrix::get_x_scale() const
+{
+ float scale = sqrtf(m_[0][0] * m_[0][0] + m_[0][1] * m_[0][1]);
+
+ // Are we turned inside out?
+ if (get_determinant() < 0.f)
+ {
+ scale = -scale;
+ }
+
+ return scale;
+}
+
+float
+matrix::get_y_scale() const
+{
+ return sqrtf(m_[1][1] * m_[1][1] + m_[1][0] * m_[1][0]);
+}
+
+float
+matrix::get_rotation() const
+{
+ if (get_determinant() < 0.f)
+ {
+ // We're turned inside out; negate the
+ // x-component used to compute rotation.
+ //
+ // Matches get_x_scale().
+ //
+ // @@ this may not be how Macromedia does it! Test this!
+ return atan2f(m_[1][0], -m_[0][0]);
+ }
+ else
+ {
+ return atan2f(m_[1][0], m_[0][0]);
+ }
+}
+
+
+} // end namespace gnash
+
+
+// Local Variables:
+// mode: C++
+// c-basic-offset: 8
+// tab-width: 8
+// indent-tabs-mode: t
+// End:
Index: server/matrix.h
===================================================================
RCS file: server/matrix.h
diff -N server/matrix.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ server/matrix.h 11 Oct 2006 08:08:36 -0000 1.1
@@ -0,0 +1,186 @@
+//
+// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+// Linking Gnash statically or dynamically with other modules is making a
+// combined work based on Gnash. Thus, the terms and conditions of the GNU
+// General Public License cover the whole combination.
+//
+// As a special exception, the copyright holders of Gnash give you
+// permission to combine Gnash with free software programs or libraries
+// that are released under the GNU LGPL and with code included in any
+// release of Talkback distributed by the Mozilla Foundation. You may
+// copy and distribute such a system following the terms of the GNU GPL
+// for all but the LGPL-covered parts and Talkback, and following the
+// LGPL for the LGPL-covered parts.
+//
+// Note that people who make modified versions of Gnash are not obligated
+// to grant this special exception for their modified versions; it is their
+// choice whether to do so. The GNU General Public License gives permission
+// to release a modified version without this exception; this exception
+// also makes it possible to release a modified version which carries
+// forward this exception.
+//
+//
+// Original author: Thatcher Ulrich <address@hidden> 2003
+//
+// $Id: matrix.h,v 1.1 2006/10/11 08:08:36 strk Exp $
+//
+
+#ifndef GNASH_MATRIX_H
+#define GNASH_MATRIX_H
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "tu_config.h"
+
+namespace gnash {
+
+class point;
+class stream;
+
+/// Matrix type, used by render handler.
+//
+/// This type stores the top two rows of a 3x3 matrix whose
+/// bottom row is (0 0 1). This matrix 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.
+///
+/// The matrix looks like this (last line implicit):
+///
+/// | scale_x x_dep_y translate_x |
+/// | y_dep_x scale_y translate_y |
+/// | 0 0 1 |
+///
+class DSOEXPORT matrix
+{
+public:
+ /// \brief
+ /// Top two rows of a 3x3 matrix whose bottom row is
+ /// assumed to be | 0 0 1 |
+ ///
+ /// | scale_x x_dep_y translate_x |
+ /// | y_dep_x scale_y translate_y |
+ ///
+ float m_[2][3];
+
+ /// The identity matrix (no transforms)
+ //
+ /// Identity matrix is:
+ ///
+ /// | 1 0 0 |
+ /// | 0 1 0 |
+ ///
+ static matrix identity;
+
+ /// Defaults to identity
+ matrix();
+
+ /// Check validity of the matrix values
+ bool is_valid() const;
+
+ /// Set the matrix to identity.
+ void set_identity();
+
+ /// Concatenate m's transform onto ours.
+ //
+ /// When transforming points, m happens first,
+ /// then our original xform.
+ ///
+ void concatenate(const matrix& m);
+
+ /// Concatenate a translation onto the front of our matrix.
+ //
+ /// When transforming points, the translation
+ /// happens first, then our original xform.
+ ///
+ void concatenate_translation(float tx, float ty);
+
+ /// Concatenate a uniform scale onto the front of our matrix.
+ //
+ /// When transforming points, the scale
+ /// happens first, then our original xform.
+ ///
+ void concatenate_scale(float s);
+
+ /// Set this matrix to a blend of m1 and m2, parameterized by t.
+ void set_lerp(const matrix& m1, const matrix& m2, float t);
+
+ /// Set the scale & rotation part of the matrix. angle in radians.
+ void set_scale_rotation(float x_scale, float y_scale, float
rotation);
+
+ /// Initialize from the SWF input stream.
+ void read(stream* in);
+
+ /// Debug log.
+ void print() const;
+
+ /// Transform point 'p' by our matrix.
+ //
+ /// Put the result in *result.
+ ///
+ void transform(point* result, const point& p) const;
+
+ /// Transform vector 'v' by our matrix. Doesn't apply translation.
+ //
+ /// Put the result in *result.
+ ///
+ void transform_vector(point* result, const point& p) const;
+
+ /// Transform point 'p' by the inverse of our matrix.
+ //
+ /// Put result in *result.
+ ///
+ void transform_by_inverse(point* result, const point& p) const;
+
+ /// Set this matrix to the inverse of the given matrix.
+ void set_inverse(const matrix& m);
+
+ /// Return true if this matrix reverses handedness.
+ bool does_flip() const;
+
+ /// Return the determinant of the 2x2 rotation/scale part only.
+ float get_determinant() const;
+
+ /// Return the maximum scale factor that this transform applies.
+ //
+ /// For assessing scale, when determining acceptable
+ /// errors in tesselation.
+ ///
+ float get_max_scale() const;
+
+ /// return the magnitude scale of our x coord output
+ float get_x_scale() const;
+
+ /// return the magnitude scale of our y coord output
+ float get_y_scale() const;
+
+ /// return our rotation component (in radians)
+ float get_rotation() const;
+};
+
+
+} // namespace gnash
+
+#endif // GNASH_MATRIX_H
+
+
+// Local Variables:
+// mode: C++
+// indent-tabs-mode: t
+// End:
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] gnash ChangeLog server/Makefile.am server/gnash...,
Sandro Santilli <=