Fix matrix multiplication, add transform function.

svn path=/branches/work/kwin_composite/; revision=559061
This commit is contained in:
Luboš Luňák 2006-07-06 14:20:03 +00:00
parent 0516e1e73b
commit a9cec042cb
2 changed files with 23 additions and 3 deletions

View file

@ -55,7 +55,7 @@ Matrix operator*( const Matrix& m1, const Matrix& m2 )
for( int k = 0;
k < 4;
++k )
s += m1.m[ i ][ k ] * m2.m[ k ][ j ];
s += m1.m[ k ][ j ] * m2.m[ i ][ k ];
r.m[ i ][ j ] = s;
}
return r;
@ -102,6 +102,24 @@ bool Matrix::isOnlyTranslate() const
&& m[ 3 ][ 3 ] == 1;
}
QPoint Matrix::transform( const QPoint& p ) const
{
int vec[ 4 ] = { p.x(), p.y(), 0, 1 };
int res[ 4 ];
for( int i = 0;
i < 4;
++i )
{
double s = 0;
for( int j = 0;
j < 4;
++j )
s += m[ i ][ j ] * vec[ j ];
res[ i ] = int( s );
}
return QPoint( res[ 0 ], res[ 1 ] );
}
//****************************************
// Effect
//****************************************

View file

@ -13,8 +13,9 @@ License. See the file "COPYING" for the exact licensing terms.
#ifndef KWIN_EFFECTS_H
#define KWIN_EFFECTS_H
#include <QMap>
#include <QTimer>
#include <qmap.h>
#include <qpoint.h>
#include <qtimer.h>
namespace KWinInternal
{
@ -32,6 +33,7 @@ class Matrix
double xTranslate() const;
double yTranslate() const;
double zTranslate() const;
QPoint transform( const QPoint& p ) const;
double m[ 4 ][ 4 ];
};