From fc7d412264c3cede536746a6f22d1bfbb96f0b59 Mon Sep 17 00:00:00 2001 From: amazingsmash Date: Fri, 21 Sep 2018 12:58:49 +0100 Subject: [PATCH] done --- iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.cpp | 261 +++++++++--------- iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.hpp | 169 ++++++------ .../Commons/Geometry/Matrix44DProvider.cpp | 115 ++++---- .../Commons/Geometry/Matrix44DProvider.hpp | 151 +++++----- .../Commons/Geometry/MutableMatrix44D.cpp | 73 +++++ .../Commons/Geometry/MutableMatrix44D.hpp | 3 + 6 files changed, 412 insertions(+), 360 deletions(-) diff --git a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.cpp b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.cpp index 980eee3a40..c906de2f7c 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.cpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.cpp @@ -10,6 +10,8 @@ #include "IFactory.hpp" +long long Matrix44D::_lastID = 0; + Matrix44D::Matrix44D(double m00, double m10, double m20, double m30, double m01, double m11, double m21, double m31, double m02, double m12, double m22, double m32, @@ -32,18 +34,20 @@ _m23(m23), _m30(m30), _m31(m31), _m32(m32), -_m33(m33) { - _columnMajorFloatArray = NULL; - _columnMajorFloatBuffer = NULL; +_m33(m33), +_id(_lastID++) +{ + _columnMajorFloatArray = NULL; + _columnMajorFloatBuffer = NULL; } Matrix44D::~Matrix44D() { - delete[] _columnMajorFloatArray; - delete _columnMajorFloatBuffer; - + delete[] _columnMajorFloatArray; + delete _columnMajorFloatBuffer; + #ifdef JAVA_CODE - super.dispose(); + super.dispose(); #endif } @@ -66,148 +70,133 @@ _m23(m._m23), _m30(m._m30), _m31(m._m31), _m32(m._m32), -_m33(m._m33) { - _columnMajorFloatArray = NULL; - _columnMajorFloatBuffer = NULL; +_m33(m._m33), +_id(_lastID++) { + _columnMajorFloatArray = NULL; + _columnMajorFloatBuffer = NULL; } Matrix44D* Matrix44D::createMultiplication(const Matrix44D &that) const { - - const double that00 = that._m00; - const double that10 = that._m10; - const double that20 = that._m20; - const double that30 = that._m30; - - const double that01 = that._m01; - const double that11 = that._m11; - const double that21 = that._m21; - const double that31 = that._m31; - - const double that02 = that._m02; - const double that12 = that._m12; - const double that22 = that._m22; - const double that32 = that._m32; - - const double that03 = that._m03; - const double that13 = that._m13; - const double that23 = that._m23; - const double that33 = that._m33; - - //Rows of this X Columns of that - const double m00 = (_m00 * that00) + (_m01 * that10) + (_m02 * that20) + (_m03 * that30); - const double m01 = (_m00 * that01) + (_m01 * that11) + (_m02 * that21) + (_m03 * that31); - const double m02 = (_m00 * that02) + (_m01 * that12) + (_m02 * that22) + (_m03 * that32); - const double m03 = (_m00 * that03) + (_m01 * that13) + (_m02 * that23) + (_m03 * that33); - - const double m10 = (_m10 * that00) + (_m11 * that10) + (_m12 * that20) + (_m13 * that30); - const double m11 = (_m10 * that01) + (_m11 * that11) + (_m12 * that21) + (_m13 * that31); - const double m12 = (_m10 * that02) + (_m11 * that12) + (_m12 * that22) + (_m13 * that32); - const double m13 = (_m10 * that03) + (_m11 * that13) + (_m12 * that23) + (_m13 * that33); - - const double m20 = (_m20 * that00) + (_m21 * that10) + (_m22 * that20) + (_m23 * that30); - const double m21 = (_m20 * that01) + (_m21 * that11) + (_m22 * that21) + (_m23 * that31); - const double m22 = (_m20 * that02) + (_m21 * that12) + (_m22 * that22) + (_m23 * that32); - const double m23 = (_m20 * that03) + (_m21 * that13) + (_m22 * that23) + (_m23 * that33); - - const double m30 = (_m30 * that00) + (_m31 * that10) + (_m32 * that20) + (_m33 * that30); - const double m31 = (_m30 * that01) + (_m31 * that11) + (_m32 * that21) + (_m33 * that31); - const double m32 = (_m30 * that02) + (_m31 * that12) + (_m32 * that22) + (_m33 * that32); - const double m33 = (_m30 * that03) + (_m31 * that13) + (_m32 * that23) + (_m33 * that33); - - return new Matrix44D(m00, m10, m20, m30, - m01, m11, m21, m31, - m02, m12, m22, m32, - m03, m13, m23, m33); + + const double that00 = that._m00; + const double that10 = that._m10; + const double that20 = that._m20; + const double that30 = that._m30; + + const double that01 = that._m01; + const double that11 = that._m11; + const double that21 = that._m21; + const double that31 = that._m31; + + const double that02 = that._m02; + const double that12 = that._m12; + const double that22 = that._m22; + const double that32 = that._m32; + + const double that03 = that._m03; + const double that13 = that._m13; + const double that23 = that._m23; + const double that33 = that._m33; + + //Rows of this X Columns of that + const double m00 = (_m00 * that00) + (_m01 * that10) + (_m02 * that20) + (_m03 * that30); + const double m01 = (_m00 * that01) + (_m01 * that11) + (_m02 * that21) + (_m03 * that31); + const double m02 = (_m00 * that02) + (_m01 * that12) + (_m02 * that22) + (_m03 * that32); + const double m03 = (_m00 * that03) + (_m01 * that13) + (_m02 * that23) + (_m03 * that33); + + const double m10 = (_m10 * that00) + (_m11 * that10) + (_m12 * that20) + (_m13 * that30); + const double m11 = (_m10 * that01) + (_m11 * that11) + (_m12 * that21) + (_m13 * that31); + const double m12 = (_m10 * that02) + (_m11 * that12) + (_m12 * that22) + (_m13 * that32); + const double m13 = (_m10 * that03) + (_m11 * that13) + (_m12 * that23) + (_m13 * that33); + + const double m20 = (_m20 * that00) + (_m21 * that10) + (_m22 * that20) + (_m23 * that30); + const double m21 = (_m20 * that01) + (_m21 * that11) + (_m22 * that21) + (_m23 * that31); + const double m22 = (_m20 * that02) + (_m21 * that12) + (_m22 * that22) + (_m23 * that32); + const double m23 = (_m20 * that03) + (_m21 * that13) + (_m22 * that23) + (_m23 * that33); + + const double m30 = (_m30 * that00) + (_m31 * that10) + (_m32 * that20) + (_m33 * that30); + const double m31 = (_m30 * that01) + (_m31 * that11) + (_m32 * that21) + (_m33 * that31); + const double m32 = (_m30 * that02) + (_m31 * that12) + (_m32 * that22) + (_m33 * that32); + const double m33 = (_m30 * that03) + (_m31 * that13) + (_m32 * that23) + (_m33 * that33); + + return new Matrix44D(m00, m10, m20, m30, + m01, m11, m21, m31, + m02, m12, m22, m32, + m03, m13, m23, m33); } bool Matrix44D::isEquals(const Matrix44D& m) const { - return ( - (_m00 == m._m00) && (_m01 == m._m01) && (_m02 == m._m02) && (_m03 == m._m03) && - (_m10 == m._m10) && (_m11 == m._m11) && (_m12 == m._m12) && (_m13 == m._m13) && - (_m20 == m._m20) && (_m21 == m._m21) && (_m22 == m._m22) && (_m23 == m._m23) && - (_m30 == m._m30) && (_m31 == m._m31) && (_m32 == m._m32) && (_m33 == m._m33) - ); + return ( + (_m00 == m._m00) && (_m01 == m._m01) && (_m02 == m._m02) && (_m03 == m._m03) && + (_m10 == m._m10) && (_m11 == m._m11) && (_m12 == m._m12) && (_m13 == m._m13) && + (_m20 == m._m20) && (_m21 == m._m21) && (_m22 == m._m22) && (_m23 == m._m23) && + (_m30 == m._m30) && (_m31 == m._m31) && (_m32 == m._m32) && (_m33 == m._m33) + ); } const IFloatBuffer* Matrix44D::getColumnMajorFloatBuffer() const { - if (_columnMajorFloatBuffer == NULL) { - _columnMajorFloatBuffer = IFactory::instance()->createFloatBuffer( - (float) _m00, - (float) _m10, - (float) _m20, - (float) _m30, - - (float) _m01, - (float) _m11, - (float) _m21, - (float) _m31, - - (float) _m02, - (float) _m12, - (float) _m22, - (float) _m32, - - (float) _m03, - (float) _m13, - (float) _m23, - (float) _m33 - ); - } - return _columnMajorFloatBuffer; + if (_columnMajorFloatBuffer == NULL) { + _columnMajorFloatBuffer = IFactory::instance()->createFloatBuffer( + (float) _m00, + (float) _m10, + (float) _m20, + (float) _m30, + + (float) _m01, + (float) _m11, + (float) _m21, + (float) _m31, + + (float) _m02, + (float) _m12, + (float) _m22, + (float) _m32, + + (float) _m03, + (float) _m13, + (float) _m23, + (float) _m33 + ); + } + return _columnMajorFloatBuffer; } bool Matrix44D::isScaleMatrix() const { - - return (_m01 == 0 && - _m02 == 0 && - _m03 == 0 && - - _m10 == 0 && - _m12 == 0 && - _m13 == 0 && - - _m20 == 0 && - _m21 == 0 && - _m23 == 0 && - - _m30 == 0 && - _m31 == 0 && - _m32 == 0 && - _m33 == 1.0); - - - // - // return MutableMatrix44D(scale._x, 0, 0, 0, - // 0, scale._y, 0, 0, - // 0, 0, scale._z, 0, - // 0, 0, 0, 1); - + + return (_m01 == 0 && + _m02 == 0 && + _m03 == 0 && + + _m10 == 0 && + _m12 == 0 && + _m13 == 0 && + + _m20 == 0 && + _m21 == 0 && + _m23 == 0 && + + _m30 == 0 && + _m31 == 0 && + _m32 == 0 && + _m33 == 1.0); } bool Matrix44D::isTranslationMatrix() const { - - return (_m00 == 1 && - _m01 == 0 && - _m02 == 0 && - _m03 == 0 && - - _m10 == 0 && - _m11 == 1 && - _m12 == 0 && - _m13 == 0 && - - _m20 == 0 && - _m21 == 0 && - _m22 == 1 && - _m23 == 0 && - - _m33 == 1); - - - -// return MutableMatrix44D(1, 0, 0, 0, -// 0, 1, 0, 0, -// 0, 0, 1, 0, -// x, y, z, 1); - + + return (_m00 == 1 && + _m01 == 0 && + _m02 == 0 && + _m03 == 0 && + + _m10 == 0 && + _m11 == 1 && + _m12 == 0 && + _m13 == 0 && + + _m20 == 0 && + _m21 == 0 && + _m22 == 1 && + _m23 == 0 && + + _m33 == 1); } diff --git a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.hpp b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.hpp index e535b283f7..867d6013ef 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.hpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44D.hpp @@ -15,90 +15,101 @@ class Matrix44D: public RCObject { private: - ~Matrix44D(); - + ~Matrix44D(); + + static long long _lastID; + public: - - //_m23 -> row 2, column 3 - const double _m00; - const double _m01; - const double _m02; - const double _m03; - const double _m10; - const double _m11; - const double _m12; - const double _m13; - const double _m20; - const double _m21; - const double _m22; - const double _m23; - const double _m30; - const double _m31; - const double _m32; - const double _m33; - - mutable float* _columnMajorFloatArray; - mutable IFloatBuffer* _columnMajorFloatBuffer; - - explicit Matrix44D(const Matrix44D& m); - - Matrix44D(double m00, double m10, double m20, double m30, - double m01, double m11, double m21, double m31, - double m02, double m12, double m22, double m32, - double m03, double m13, double m23, double m33); - - - Matrix44D* createMultiplication(const Matrix44D &that) const; - + + const long long _id; //Sequential, incremental ID + + //_m23 -> row 2, column 3 + const double _m00; + const double _m01; + const double _m02; + const double _m03; + const double _m10; + const double _m11; + const double _m12; + const double _m13; + const double _m20; + const double _m21; + const double _m22; + const double _m23; + const double _m30; + const double _m31; + const double _m32; + const double _m33; + + mutable float* _columnMajorFloatArray; + mutable IFloatBuffer* _columnMajorFloatBuffer; + + explicit Matrix44D(const Matrix44D& m); + + Matrix44D(double m00, double m10, double m20, double m30, + double m01, double m11, double m21, double m31, + double m02, double m12, double m22, double m32, + double m03, double m13, double m23, double m33); + + Matrix44D* createMultiplication(const Matrix44D &that) const; + #ifdef C_CODE - float* getColumnMajorFloatArray() const + float* getColumnMajorFloatArray() const #else - float[] getColumnMajorFloatArray() const + float[] getColumnMajorFloatArray() const #endif - { - if (_columnMajorFloatArray == NULL) { - _columnMajorFloatArray = new float[16]; - - _columnMajorFloatArray[ 0] = (float) _m00; - _columnMajorFloatArray[ 1] = (float) _m10; - _columnMajorFloatArray[ 2] = (float) _m20; - _columnMajorFloatArray[ 3] = (float) _m30; - - _columnMajorFloatArray[ 4] = (float) _m01; - _columnMajorFloatArray[ 5] = (float) _m11; - _columnMajorFloatArray[ 6] = (float) _m21; - _columnMajorFloatArray[ 7] = (float) _m31; - - _columnMajorFloatArray[ 8] = (float) _m02; - _columnMajorFloatArray[ 9] = (float) _m12; - _columnMajorFloatArray[10] = (float) _m22; - _columnMajorFloatArray[11] = (float) _m32; - - _columnMajorFloatArray[12] = (float) _m03; - _columnMajorFloatArray[13] = (float) _m13; - _columnMajorFloatArray[14] = (float) _m23; - _columnMajorFloatArray[15] = (float) _m33; + { + if (_columnMajorFloatArray == NULL) { + _columnMajorFloatArray = new float[16]; + + _columnMajorFloatArray[ 0] = (float) _m00; + _columnMajorFloatArray[ 1] = (float) _m10; + _columnMajorFloatArray[ 2] = (float) _m20; + _columnMajorFloatArray[ 3] = (float) _m30; + + _columnMajorFloatArray[ 4] = (float) _m01; + _columnMajorFloatArray[ 5] = (float) _m11; + _columnMajorFloatArray[ 6] = (float) _m21; + _columnMajorFloatArray[ 7] = (float) _m31; + + _columnMajorFloatArray[ 8] = (float) _m02; + _columnMajorFloatArray[ 9] = (float) _m12; + _columnMajorFloatArray[10] = (float) _m22; + _columnMajorFloatArray[11] = (float) _m32; + + _columnMajorFloatArray[12] = (float) _m03; + _columnMajorFloatArray[13] = (float) _m13; + _columnMajorFloatArray[14] = (float) _m23; + _columnMajorFloatArray[15] = (float) _m33; + } + + return _columnMajorFloatArray; } - - return _columnMajorFloatArray; - } - - const IFloatBuffer* getColumnMajorFloatBuffer() const; - - bool isEquals(const Matrix44D& m) const; - - static Matrix44D* createIdentity() { - return new Matrix44D(1, 0, 0, 0, - 0, 1, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1); - } - - - bool isScaleMatrix() const; - - bool isTranslationMatrix() const; - + + const IFloatBuffer* getColumnMajorFloatBuffer() const; + + bool isEquals(const Matrix44D& m) const; + + static Matrix44D* createIdentity() { + return new Matrix44D(1, 0, 0, 0, + 0, 1, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1); + } + + static Matrix44D* createScaleMatrix(double scaleX, + double scaleY, + double scaleZ) { + return new Matrix44D(scaleX, 0, 0, 0, + 0, scaleY, 0, 0, + 0, 0, scaleZ, 0, + 0, 0, 0, 1); + } + + bool isScaleMatrix() const; + + bool isTranslationMatrix() const; + }; #endif /* defined(__G3MiOSSDK__Matrix44D__) */ diff --git a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.cpp b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.cpp index 52260e3d55..97cd41456a 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.cpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.cpp @@ -8,94 +8,75 @@ #include "Matrix44DProvider.hpp" #include "ILogger.hpp" - -void Matrix44DMultiplicationHolder::pullMatrixes() const { - for (int j = 0; j < _matricesSize; j++) { - const Matrix44D* newMatrix = _providers[j]->getMatrix(); - - if (newMatrix != _matrices[j]) { - if (_matrices[j] != NULL) { - _matrices[j]->_release(); - } - - _matrices[j] = newMatrix; - _matrices[j]->_retain(); - } - } -} +#include "MutableMatrix44D.hpp" Matrix44DMultiplicationHolder::Matrix44DMultiplicationHolder(const Matrix44DProvider* providers[], size_t matricesSize): _matricesSize(matricesSize), -_modelview(NULL) +_result(NULL) { #ifdef C_CODE - _matrices = new const Matrix44D*[_matricesSize]; - _providers = new const Matrix44DProvider*[_matricesSize]; + _providers = new const Matrix44DProvider*[_matricesSize]; #endif #ifdef JAVA_CODE - _matrices = new Matrix44D[_matricesSize]; - _providers = new Matrix44DProvider[_matricesSize]; + _providers = new Matrix44DProvider[_matricesSize]; #endif - for (int i = 0; i < _matricesSize; i++) { - _matrices[i] = NULL; - _providers[i] = providers[i]; - _providers[i]->_retain(); - } - - pullMatrixes(); + for (int i = 0; i < _matricesSize; i++) { + _providers[i] = providers[i]; + _providers[i]->_retain(); + } } Matrix44DMultiplicationHolder::~Matrix44DMultiplicationHolder() { - for (int j = 0; j < _matricesSize; j++) { - if (_matrices[j] != NULL) { - _matrices[j]->_release(); + for (int j = 0; j < _matricesSize; j++) { + _providers[j]->_release(); } - _providers[j]->_release(); - } - + #ifdef C_CODE - delete[] _matrices; - delete[] _providers; + delete[] _providers; #endif - - if (_modelview != NULL) { - _modelview->_release(); - } - + + if (_result != NULL) { + _result->_release(); + } + #ifdef JAVA_CODE - super.dispose(); + super.dispose(); #endif } Matrix44D* Matrix44DMultiplicationHolder::getMatrix() const { - if (_modelview != NULL) { + long long newSumID = 0; + const Matrix44D* matrices[_matricesSize]; for (int i = 0; i < _matricesSize; i++) { - const Matrix44D* m = _providers[i]->getMatrix(); - if (m == NULL) { - ILogger::instance()->logError("Modelview multiplication failure"); - } - - if (_matrices[i] != m) { - //If one matrix differs we have to raplace all matrixes on Holders and recalculate modelview - _modelview->_release();//NEW MODELVIEW NEEDED - _modelview = NULL; - - pullMatrixes(); - break; - } + matrices[i] = _providers[i]->getMatrix(); + if (matrices[i] != NULL){ + newSumID += matrices[i]->_id; + } else{ + ILogger::instance()->logWarning("Provider returned NULL matrix."); + } } - } - - if (_modelview == NULL) { - _modelview = new Matrix44D(*_matrices[0]); - for (int i = 1; i < _matricesSize; i++) { - const Matrix44D* m2 = _matrices[i]; - Matrix44D* m3 = _modelview->createMultiplication(*m2); - _modelview->_release(); - _modelview = m3; + + if (newSumID != _sumMatrixIDs || _result == NULL){ + if (_result != NULL){ + _result->_release(); + _result = NULL; + } + + MutableMatrix44D m = MutableMatrix44D::identity(); + for (int i = 0; i < _matricesSize; i++) { + const Matrix44D* m1 = matrices[i]; + if (m1 != NULL){ + m.copyValueOfMultiplicationWithMatrix44D(m, *m1); + } + } + + _result = m.asMatrix44D(); + _result->_retain(); + _sumMatrixIDs = newSumID; + } + if (_result == NULL){ + THROW_EXCEPTION("Provider returned NULL matrix."); } - } - - return _modelview; + return _result; } diff --git a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.hpp b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.hpp index b91abf2826..3984d75836 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.hpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/Matrix44DProvider.hpp @@ -11,122 +11,117 @@ #include "RCObject.hpp" #include "Matrix44D.hpp" -//#include "ILogger.hpp" #include "ErrorHandling.hpp" #include class Matrix44DProvider: public RCObject { protected: - virtual ~Matrix44DProvider() { + virtual ~Matrix44DProvider() { #ifdef JAVA_CODE - super.dispose(); + super.dispose(); #endif - } - + } + public: - virtual const Matrix44D* getMatrix() const = 0; + virtual const Matrix44D* getMatrix() const = 0; }; class Matrix44DHolder: public Matrix44DProvider { private: #ifdef C_CODE - const Matrix44D* _matrix; + const Matrix44D* _matrix; #endif #ifdef JAVA_CODE - private Matrix44D _matrix; + private Matrix44D _matrix; #endif - - ~Matrix44DHolder() { - _matrix->_release(); - + + ~Matrix44DHolder() { + _matrix->_release(); + #ifdef JAVA_CODE - super.dispose(); + super.dispose(); #endif - } - + } + public: - Matrix44DHolder(const Matrix44D* matrix) : - _matrix(matrix) - { - if (matrix == NULL) { - THROW_EXCEPTION("Setting NULL in Matrix44D Holder"); + Matrix44DHolder(const Matrix44D* matrix):_matrix(matrix) { + if (matrix == NULL) { + THROW_EXCEPTION("Setting NULL in Matrix44D Holder"); + } + _matrix->_retain(); } - _matrix->_retain(); - } - - void setMatrix(const Matrix44D* matrix) { - if (matrix == NULL) { - THROW_EXCEPTION("Setting NULL in Matrix44D Holder"); + + void setMatrix(const Matrix44D* matrix) { + if (matrix == NULL) { + THROW_EXCEPTION("Setting NULL in Matrix44D Holder"); + } + + if (matrix != _matrix) { + if (_matrix != NULL) { + _matrix->_release(); + } + _matrix = matrix; + _matrix->_retain(); + } } - - if (matrix != _matrix) { - if (_matrix != NULL) { - _matrix->_release(); - } - _matrix = matrix; - _matrix->_retain(); + + const Matrix44D* getMatrix() const { + return _matrix; } - } - - const Matrix44D* getMatrix() const { - return _matrix; - } }; class Matrix44DMultiplicationHolder : public Matrix44DProvider { private: - const Matrix44D** _matrices; - const Matrix44DProvider** _providers; - const size_t _matricesSize; - mutable Matrix44D* _modelview; - - void pullMatrixes() const; - - ~Matrix44DMultiplicationHolder(); - + mutable long long _sumMatrixIDs; + const Matrix44DProvider** _providers; + const size_t _matricesSize; + mutable Matrix44D* _result; + + ~Matrix44DMultiplicationHolder(); + public: - Matrix44DMultiplicationHolder(const Matrix44DProvider* providers[], - size_t matricesSize); - - Matrix44D* getMatrix() const; - + Matrix44DMultiplicationHolder(const Matrix44DProvider* providers[], + size_t matricesSize); + + Matrix44D* getMatrix() const; + }; class Matrix44DMultiplicationHolderBuilder { private: - std::vector _providers; - + std::vector _providers; + public: - ~Matrix44DMultiplicationHolderBuilder() { - const size_t providersSize = _providers.size(); - for (size_t i = 0; i < providersSize; i++) { - _providers[i]->_release(); + ~Matrix44DMultiplicationHolderBuilder() { + const size_t providersSize = _providers.size(); + for (size_t i = 0; i < providersSize; i++) { + _providers[i]->_release(); + } } - } - - size_t size() const { - return _providers.size(); - } - - void add(const Matrix44DProvider* provider) { - _providers.push_back(provider); - provider->_retain(); - } - - Matrix44DMultiplicationHolder* create() const { - const size_t providersSize = _providers.size(); - const Matrix44DProvider* ps[providersSize]; - for (size_t i = 0; i < providersSize; i++) { - ps[i] = _providers[i]; + + size_t size() const { + return _providers.size(); } - - return new Matrix44DMultiplicationHolder(ps, providersSize); - } - + + void add(const Matrix44DProvider* provider) { + _providers.push_back(provider); + provider->_retain(); + } + + Matrix44DMultiplicationHolder* create() const { + const size_t providersSize = _providers.size(); + const Matrix44DProvider* ps[providersSize]; + for (size_t i = 0; i < providersSize; i++) { + ps[i] = _providers[i]; + } + + return new Matrix44DMultiplicationHolder(ps, providersSize); + } + }; #endif diff --git a/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.cpp b/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.cpp index 0fa3d9457b..7728467146 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.cpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.cpp @@ -144,6 +144,79 @@ MutableMatrix44D::~MutableMatrix44D() { } } + +void MutableMatrix44D::copyValueOfMultiplicationWithMatrix44D(const MutableMatrix44D& m1, + const Matrix44D& m2) { + + const double m1_00 = m1._m00; + const double m1_10 = m1._m10; + const double m1_20 = m1._m20; + const double m1_30 = m1._m30; + + const double m1_01 = m1._m01; + const double m1_11 = m1._m11; + const double m1_21 = m1._m21; + const double m1_31 = m1._m31; + + const double m1_02 = m1._m02; + const double m1_12 = m1._m12; + const double m1_22 = m1._m22; + const double m1_32 = m1._m32; + + const double m1_03 = m1._m03; + const double m1_13 = m1._m13; + const double m1_23 = m1._m23; + const double m1_33 = m1._m33; + + + const double m2_00 = m2._m00; + const double m2_10 = m2._m10; + const double m2_20 = m2._m20; + const double m2_30 = m2._m30; + + const double m2_01 = m2._m01; + const double m2_11 = m2._m11; + const double m2_21 = m2._m21; + const double m2_31 = m2._m31; + + const double m2_02 = m2._m02; + const double m2_12 = m2._m12; + const double m2_22 = m2._m22; + const double m2_32 = m2._m32; + + const double m2_03 = m2._m03; + const double m2_13 = m2._m13; + const double m2_23 = m2._m23; + const double m2_33 = m2._m33; + + + //Rows of m1_ X Columns of m2_ + _m00 = (m1_00 * m2_00) + (m1_01 * m2_10) + (m1_02 * m2_20) + (m1_03 * m2_30); + _m01 = (m1_00 * m2_01) + (m1_01 * m2_11) + (m1_02 * m2_21) + (m1_03 * m2_31); + _m02 = (m1_00 * m2_02) + (m1_01 * m2_12) + (m1_02 * m2_22) + (m1_03 * m2_32); + _m03 = (m1_00 * m2_03) + (m1_01 * m2_13) + (m1_02 * m2_23) + (m1_03 * m2_33); + + _m10 = (m1_10 * m2_00) + (m1_11 * m2_10) + (m1_12 * m2_20) + (m1_13 * m2_30); + _m11 = (m1_10 * m2_01) + (m1_11 * m2_11) + (m1_12 * m2_21) + (m1_13 * m2_31); + _m12 = (m1_10 * m2_02) + (m1_11 * m2_12) + (m1_12 * m2_22) + (m1_13 * m2_32); + _m13 = (m1_10 * m2_03) + (m1_11 * m2_13) + (m1_12 * m2_23) + (m1_13 * m2_33); + + _m20 = (m1_20 * m2_00) + (m1_21 * m2_10) + (m1_22 * m2_20) + (m1_23 * m2_30); + _m21 = (m1_20 * m2_01) + (m1_21 * m2_11) + (m1_22 * m2_21) + (m1_23 * m2_31); + _m22 = (m1_20 * m2_02) + (m1_21 * m2_12) + (m1_22 * m2_22) + (m1_23 * m2_32); + _m23 = (m1_20 * m2_03) + (m1_21 * m2_13) + (m1_22 * m2_23) + (m1_23 * m2_33); + + _m30 = (m1_30 * m2_00) + (m1_31 * m2_10) + (m1_32 * m2_20) + (m1_33 * m2_30); + _m31 = (m1_30 * m2_01) + (m1_31 * m2_11) + (m1_32 * m2_21) + (m1_33 * m2_31); + _m32 = (m1_30 * m2_02) + (m1_31 * m2_12) + (m1_32 * m2_22) + (m1_33 * m2_32); + _m33 = (m1_30 * m2_03) + (m1_31 * m2_13) + (m1_32 * m2_23) + (m1_33 * m2_33); + + if (_matrix44D != NULL) { + _matrix44D->_release(); + _matrix44D = NULL; + } +} + void MutableMatrix44D::copyValueOfMultiplication(const MutableMatrix44D& m1, const MutableMatrix44D& m2) { const double m1_00 = m1._m00; diff --git a/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.hpp b/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.hpp index 33cce9654a..5c9e1a77ea 100644 --- a/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.hpp +++ b/iOS/G3MiOSSDK/Commons/Geometry/MutableMatrix44D.hpp @@ -146,6 +146,9 @@ class MutableMatrix44D { #endif void copyValueOfMultiplication(const MutableMatrix44D& m1, const MutableMatrix44D& m2); + +void copyValueOfMultiplicationWithMatrix44D(const MutableMatrix44D& m1, + const Matrix44D& m2); MutableMatrix44D multiply(const MutableMatrix44D& that) const;