summaryrefslogtreecommitdiffstats
path: root/kpovmodeler/pmmatrix.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit47d455dd55be855e4cc691c32f687f723d9247ee (patch)
tree52e236aaa2576bdb3840ebede26619692fed6d7d /kpovmodeler/pmmatrix.h
downloadtdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz
tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kpovmodeler/pmmatrix.h')
-rw-r--r--kpovmodeler/pmmatrix.h188
1 files changed, 188 insertions, 0 deletions
diff --git a/kpovmodeler/pmmatrix.h b/kpovmodeler/pmmatrix.h
new file mode 100644
index 00000000..62747aea
--- /dev/null
+++ b/kpovmodeler/pmmatrix.h
@@ -0,0 +1,188 @@
+//-*-C++-*-
+/*
+**************************************************************************
+ description
+ --------------------
+ copyright : (C) 2000-2001 by Andreas Zehender
+ email : zehender@kde.org
+**************************************************************************
+
+**************************************************************************
+* *
+* 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. *
+* *
+**************************************************************************/
+
+
+#ifndef PMMATRIX_H
+#define PMMATRIX_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "pmmath.h"
+#include "math.h"
+
+#include <qstring.h>
+
+#include <GL/gl.h>
+
+class PMVector;
+
+/**
+ * 4x4 matrix for transformations with homogenous coordinates
+ *
+ * Optimized for OpenGL.
+ */
+class PMMatrix
+{
+public:
+ /**
+ * Creates a zero matrix
+ */
+ PMMatrix( );
+ /**
+ * Deletes the matrix
+ */
+ ~PMMatrix( );
+ /**
+ * Assigns m to the matrix
+ */
+ PMMatrix& operator= ( const PMMatrix& m );
+ /**
+ * Creates an identity matrix
+ */
+ static PMMatrix identity( );
+ /**
+ * Creates a matrix for translation.
+ */
+ static PMMatrix translation( double x, double y, double z );
+ /**
+ * Creates a matrix for rotations. Rotation first around the x, then y
+ * and then around the z axis.
+ *
+ * x, y and z in rad
+ */
+ static PMMatrix rotation( double x, double y, double z );
+ /**
+ * Creates a matrix for rotation around the direction n with angle a.
+ *
+ * a in rad.
+ */
+ static PMMatrix rotation( const PMVector& n, double a );
+ /**
+ * Creates a viewing matrix.
+ *
+ * The viewpoint is specified by the parameter eye. The parameter
+ * lookAt specifies any point along the line of sight. The up vector
+ * indicate which direction is up.
+ */
+ static PMMatrix viewTransformation( const PMVector& eye,
+ const PMVector& lookAt,
+ const PMVector& up );
+ /**
+ * Backwards calculate the rotations from the matrix
+ */
+ void toRotation( double* x, double* y, double* z );
+
+ /**
+ * Creates a matrix for scale.
+ */
+ static PMMatrix scale( double x, double y, double z );
+ /**
+ * Returns the current gl modelview matrix
+ */
+ static PMMatrix modelviewMatrix( );
+
+ /**
+ * Returns a pointer to the column (!) at position index.
+ * That means matrix[i][j] is the element at column i and row j*/
+ GLdouble* operator[] ( int index ) { return &( m_elements[index*4] ); }
+ /**
+ * Returns a pointer to the column (!) at position index.
+ * That means matrix[i][j] is the element at column i and row j*/
+ const GLdouble* operator[] ( int index ) const
+ { return &(m_elements[index*4]); }
+ /**
+ * Returns true if an inverse matrix can be calculated
+ */
+ bool canBuildInverse( ) const { return ! approxZero( det( ) ); }
+ /**
+ * Returns the inverse matrix if possible, otherwise a identity matrix
+ */
+ PMMatrix inverse( ) const;
+ /**
+ * Returns the determinant of the matrix
+ */
+ double det( ) const;
+ /**
+ * Multiplies m to the matrix from the right side
+ */
+ PMMatrix& operator*= ( const PMMatrix& m );
+ /**
+ * Multiplies each element with d
+ */
+ PMMatrix& operator*= ( const double d );
+ /**
+ * Divides each element by d
+ */
+ PMMatrix& operator/= ( const double d );
+
+ /**
+ * Returns a matrix with negated elements
+ */
+ friend PMMatrix operator- ( const PMMatrix& m );
+ /**
+ * Multiplies m2 with m1 from the right side (m1*m2)*/
+ friend PMMatrix operator* ( const PMMatrix& m1, const PMMatrix& m2 );
+ /**
+ * Multiplies d to all elements
+ */
+ friend PMMatrix operator* ( const PMMatrix& m, const double d );
+ /**
+ * Multiplies d to all elements
+ */
+ friend PMMatrix operator* ( const GLdouble d, const PMMatrix& m );
+ /**
+ * Divides all elements by d
+ */
+ friend PMMatrix operator/ ( const PMMatrix& m, const double d );
+
+ /**
+ * Only for tests
+ */
+ void testOutput( );
+ /**
+ * Returns a pointer to the data. Can be used in glMultMatrixd
+ */
+ const GLdouble* data( ) const { return m_elements; }
+
+ /**
+ * Returns a string for xml output
+ */
+ QString serializeXML( ) const;
+ /**
+ * loads the vector data from the xml string
+ */
+ bool loadXML( const QString& str );
+private:
+ /**
+ * Exchanges two rows
+ */
+ void exchangeRows( int r1, int r2 );
+ /**
+ * Finds a row with not zero element in column index. Begins to
+ * search in row at position index. Used for det() and inverse()
+ *
+ * Returns -1 if all rows are zero in that column
+ */
+ int notNullElementRow( const int index ) const;
+
+ GLdouble m_elements[16];
+};
+
+#endif