From: Mikko L. <laz...@us...> - 2004-06-15 19:12:53
|
Update of /cvsroot/rtk/rtk/rtk In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4432 Added Files: Matrix.h Log Message: Added 3x3 (2D) Matrix class --- NEW FILE: Matrix.h --- /** * * RTK * Fast and easy cross-platform GUI ToolKit. * * Copyright (C) 2001-200x RTK Development Team * * This library is free software; you can redistribute it and/or modify it * under the terms of the slightly modified (see the "EXCEPTION NOTICE" part * of RTK Library License) GNU Lesser General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library 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 Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License * and along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA . * * Also you should have received a copy of RTK Library License, if not please * write an e-mail to some of RTK authors (listed in file AUTHORS). * * Bug reports: bu...@rt... * Suggestions: rf...@rt... ***************************************************************************/ /** * $Source: /cvsroot/rtk/rtk/rtk/Matrix.h,v $ ***** * Authors (chronological order): * Mikko Lahteenmaki, mi...@rt... * Contributors (chronological order): * $fname $lname, $email ***** * T0D0 List: * - ***************************************************************************/ #ifndef _RTK_MATRIX_H_ #define _RTK_MATRIX_H_ namespace Rtk { #define DEG2RAD (0.017453292519943295769f) // PI/180 /** The 3x3 Matrix: * .-----------------------. * | m[0][0] | m[0][1] | 0 | * | m[1][0] | m[1][1] | 0 | * | X | Y | 1 | * '-----------------------' */ class Matrix { public: Matrix() { set_identity(); } Matrix(float M11, float M12, float M21, float M22, float X, float Y) { set_matrix(M11, M12, M21, M22, X, Y); } Matrix(const Matrix &m) { copy(m); } Matrix& operator=(const Matrix &m) { return copy(m); } Matrix& copy(const Matrix &m); void set_matrix(float M11, float M12, float M21, float M22, float X, float Y, bool trivial = false); /// X scaling factor float m11; /// Vertical shearing factor. float m12; /// Horizontal shearing factor. float m21; /// Y scaling factor. float m22; /// Horizontal translation. float x; /// Vertical translation. float y; /// Horizontal translation. rounded nearest integer. int ix; /// Vertical translation. rounded nearest integer. int iy; /// Is this matrix trivial? I.e. no scaling or rotating bool trivial; /** * Set the matrix to an identity matrix. * All elements are set to zero, except m[0][0] and m[1][1] (scaling) which are set to 1. */ void set_identity() { set_matrix(1, 0, 0, 1, 0, 0, true); } void translate(float dx, float dy); void translate(int dx, int dy); void transform(float &dx, float &dy) const; void transform(int &dx, int &dy) const; void transform_distance(float &dx, float &dy) const; void rotate(float degrees); void scale(float factor_x, float factor_y); void scale(float factor) { scale(factor, factor); } void shear(float factor_h, float factor_v); /** Multiply this matrix by given values. */ void multiply(float M11, float M12, float M21, float M22, float X, float Y); void multiply(const Matrix &m) { multiply(m.m11, m.m12, m.m21, m.m22, m.x, m.y); } Matrix &operator *= (const Matrix &m) { multiply(m); return *this; } bool operator == (const Matrix &m) const { return ( x==m.x && y==m.y && m11==m.m11 && m12==m.m12 && m21==m.m21 && m22==m.m22 ); } bool operator != (const Matrix &m) const { return ( x!=m.x || y!=m.y || m11!=m.m11 && m12!=m.m12 && m21!=m.m21 && m22!=m.m22 ); } }; }; #endif // _MATRIX_H_ |