/* Bullet Continuous Collision Detection and Physics Library Copyright (c) 2003-2013 Erwin Coumans http://bulletphysics.org This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ ///original version written by Erwin Coumans, October 2013 #ifndef BT_MATRIX_X_H #define BT_MATRIX_X_H #include "LinearMath/btQuickprof.h" #include "LinearMath/btAlignedObjectArray.h" class btIntSortPredicate { public: bool operator() ( const int& a, const int& b ) const { return a < b; } }; template struct btMatrixX { int m_rows; int m_cols; int m_operations; int m_resizeOperations; int m_setElemOperations; btAlignedObjectArray m_storage; btAlignedObjectArray< btAlignedObjectArray > m_rowNonZeroElements1; btAlignedObjectArray< btAlignedObjectArray > m_colNonZeroElements; T* getBufferPointerWritable() { return m_storage.size() ? &m_storage[0] : 0; } const T* getBufferPointer() const { return m_storage.size() ? &m_storage[0] : 0; } btMatrixX() :m_rows(0), m_cols(0), m_operations(0), m_resizeOperations(0), m_setElemOperations(0) { } btMatrixX(int rows,int cols) :m_rows(rows), m_cols(cols), m_operations(0), m_resizeOperations(0), m_setElemOperations(0) { resize(rows,cols); } void resize(int rows, int cols) { m_resizeOperations++; m_rows = rows; m_cols = cols; { BT_PROFILE("m_storage.resize"); m_storage.resize(rows*cols); } clearSparseInfo(); } int cols() const { return m_cols; } int rows() const { return m_rows; } ///we don't want this read/write operator(), because we cannot keep track of non-zero elements, use setElem instead /*T& operator() (int row,int col) { return m_storage[col*m_rows+row]; } */ void addElem(int row,int col, T val) { if (val) { if (m_storage[col+row*m_cols]==0.f) { setElem(row,col,val); } else { m_storage[row*m_cols+col] += val; } } } void copyLowerToUpperTriangle() { int count=0; for (int row=0;row0 && numRowsOther>0 && B && C); const btScalar *bb = B; for ( int i = 0;i struct btVectorX { btAlignedObjectArray m_storage; btVectorX() { } btVectorX(int numRows) { m_storage.resize(numRows); } void resize(int rows) { m_storage.resize(rows); } int cols() const { return 1; } int rows() const { return m_storage.size(); } int size() const { return rows(); } void setZero() { // for (int i=0;i void setElem(btMatrixX& mat, int row, int col, T val) { mat.setElem(row,col,val); } */ typedef btMatrixX btMatrixXf; typedef btVectorX btVectorXf; typedef btMatrixX btMatrixXd; typedef btVectorX btVectorXd; inline void setElem(btMatrixXd& mat, int row, int col, double val) { mat.setElem(row,col,val); } inline void setElem(btMatrixXf& mat, int row, int col, float val) { mat.setElem(row,col,val); } #ifdef BT_USE_DOUBLE_PRECISION #define btVectorXu btVectorXd #define btMatrixXu btMatrixXd #else #define btVectorXu btVectorXf #define btMatrixXu btMatrixXf #endif //BT_USE_DOUBLE_PRECISION #endif//BT_MATRIX_H_H