Skip to content

Commit

Permalink
3rdparty: bullet3: remove getters/setters from btMatrixX
Browse files Browse the repository at this point in the history
  • Loading branch information
dbartolini committed Jan 31, 2025
1 parent a0b4a05 commit c840f9c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ void btMultiBodyMLCPConstraintSolver::createMLCPFastRigidBody(const btContactSol
if (1)
{
// add cfm to the diagonal of m_A
for (int i = 0; i < m_A.rows(); ++i)
for (int i = 0; i < m_A.m_rows; ++i)
{
m_A.setElem(i, i, m_A(i, i) + infoGlobal.m_globalCfm / infoGlobal.m_timeStep);
}
Expand Down Expand Up @@ -628,7 +628,7 @@ void btMultiBodyMLCPConstraintSolver::createMLCPFastMultiBody(const btContactSol
}

// Add CFM to the diagonal of m_A
for (int i = 0; i < m_multiBodyA.rows(); ++i)
for (int i = 0; i < m_multiBodyA.m_rows; ++i)
{
m_multiBodyA.setElem(i, i, m_multiBodyA(i, i) + infoGlobal.m_globalCfm / infoGlobal.m_timeStep);
}
Expand Down Expand Up @@ -658,7 +658,7 @@ bool btMultiBodyMLCPConstraintSolver::solveMLCP(const btContactSolverInfo& infoG
{
bool result = true;

if (m_A.rows() != 0)
if (m_A.m_rows != 0)
{
// If using split impulse, we solve 2 separate (M)LCPs
if (infoGlobal.m_splitImpulse)
Expand All @@ -680,7 +680,7 @@ bool btMultiBodyMLCPConstraintSolver::solveMLCP(const btContactSolverInfo& infoG
if (!result)
return false;

if (m_multiBodyA.rows() != 0)
if (m_multiBodyA.m_rows != 0)
{
result = m_solver->solveMLCP(m_multiBodyA, m_multiBodyB, m_multiBodyX, m_multiBodyLo, m_multiBodyHi, m_multiBodyLimitDependencies, infoGlobal.m_numIterations);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Code was converted for the Bullet Continuous Collision Detection and Physics Lib
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,
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.
Expand Down Expand Up @@ -228,7 +228,7 @@ int btLemkeAlgorithm::findLexicographicMinimum(const btMatrixXu& A, const int& p
bool firstRow = true;
btScalar currentMin = 0.0;

int dim = A.rows();
int dim = A.m_rows;

for (int row = 0; row < dim; row++)
{
Expand Down Expand Up @@ -323,11 +323,11 @@ void btLemkeAlgorithm::GaussJordanEliminationStep(btMatrixXu& A, int pivotRowInd
cout << A << std::endl;
#endif

for (int i = 0; i < A.rows(); i++)
for (int i = 0; i < A.m_rows; i++)
{
if (i != pivotRowIndex)
{
for (int j = 0; j < A.cols(); j++)
for (int j = 0; j < A.m_cols; j++)
{
if (j != pivotColumnIndex)
{
Expand All @@ -342,15 +342,15 @@ void btLemkeAlgorithm::GaussJordanEliminationStep(btMatrixXu& A, int pivotRowInd
#ifdef BT_DEBUG_OSTREAM
cout << A << std::endl;
#endif //BT_DEBUG_OSTREAM
for (int i = 0; i < A.cols(); i++)
for (int i = 0; i < A.m_cols; i++)
{
A.mulElem(pivotRowIndex, i, -a);
}
#ifdef BT_DEBUG_OSTREAM
cout << A << std::endl;
#endif //#ifdef BT_DEBUG_OSTREAM

for (int i = 0; i < A.rows(); i++)
for (int i = 0; i < A.m_rows; i++)
{
if (i != pivotRowIndex)
{
Expand Down
12 changes: 6 additions & 6 deletions 3rdparty/bullet3/src/BulletDynamics/MLCPSolvers/btMLCPSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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,
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.
Expand Down Expand Up @@ -117,7 +117,7 @@ bool btMLCPSolver::solveMLCP(const btContactSolverInfo& infoGlobal)
{
bool result = true;

if (m_A.rows() == 0)
if (m_A.m_rows == 0)
return true;

//if using split impulse, we solve 2 separate (M)LCPs
Expand Down Expand Up @@ -421,7 +421,7 @@ void btMLCPSolver::createMLCPFast(const btContactSolverInfo& infoGlobal)
if (1)
{
// add cfm to the diagonal of m_A
for (int i = 0; i < m_A.rows(); ++i)
for (int i = 0; i < m_A.m_rows; ++i)
{
m_A.setElem(i, i, m_A(i, i) + infoGlobal.m_globalCfm / infoGlobal.m_timeStep);
}
Expand Down Expand Up @@ -547,7 +547,7 @@ void btMLCPSolver::createMLCP(const btContactSolverInfo& infoGlobal)
if (1)
{
// add cfm to the diagonal of m_A
for (int i = 0; i < m_A.rows(); ++i)
for (int i = 0; i < m_A.m_rows; ++i)
{
m_A.setElem(i, i, m_A(i, i) + infoGlobal.m_globalCfm / infoGlobal.m_timeStep);
}
Expand All @@ -572,7 +572,7 @@ btScalar btMLCPSolver::solveGroupCacheFriendlyIterations(btCollisionObject** bod
bool result = true;
{
BT_PROFILE("solveMLCP");
// printf("m_A(%d,%d)\n", m_A.rows(),m_A.cols());
// printf("m_A(%d,%d)\n", m_A.m_rows,m_A.m_cols);
result = solveMLCP(infoGlobal);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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,
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.
Expand Down Expand Up @@ -34,15 +34,15 @@ class btSolveProjectedGaussSeidel : public btMLCPSolverInterface

virtual bool solveMLCP(const btMatrixXu& A, const btVectorXu& b, btVectorXu& x, const btVectorXu& lo, const btVectorXu& hi, const btAlignedObjectArray<int>& limitDependency, int numIterations, bool useSparsity = true)
{
if (!A.rows())
if (!A.m_rows)
return true;
//the A matrix is sparse, so compute the non-zero elements
A.rowComputeNonZeroElements();

//A is a m-n matrix, m rows, n columns
btAssert(A.rows() == b.rows());
btAssert(A.m_rows == b.rows());

int i, j, numRows = A.rows();
int i, j, numRows = A.m_rows;

btScalar delta;

Expand Down
61 changes: 27 additions & 34 deletions 3rdparty/bullet3/src/LinearMath/btMatrixX.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ 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,
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.
Expand Down Expand Up @@ -196,14 +196,7 @@ struct btMatrixX
m_storage.resize(rows * cols);
}
}
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)
{
Expand Down Expand Up @@ -243,15 +236,15 @@ struct btMatrixX
void copyLowerToUpperTriangle()
{
int count = 0;
for (int row = 0; row < rows(); row++)
for (int row = 0; row < m_rows; row++)
{
for (int col = 0; col < row; col++)
{
setElem(col, row, (*this)(row, col));
count++;
}
}
//printf("copyLowerToUpperTriangle copied %d elements out of %dx%d=%d\n", count,rows(),cols(),cols()*rows());
//printf("copyLowerToUpperTriangle copied %d elements out of %dx%d=%d\n", count,m_rows,m_cols,m_cols*m_rows);
}

const T& operator()(int row, int col) const
Expand All @@ -275,10 +268,10 @@ struct btMatrixX

void setIdentity()
{
btAssert(rows() == cols());
btAssert(m_rows == m_cols);

setZero();
for (int row = 0; row < rows(); row++)
for (int row = 0; row < m_rows; row++)
{
setElem(row, row, 1);
}
Expand All @@ -287,10 +280,10 @@ struct btMatrixX
void printMatrix(const char* msg) const
{
printf("%s ---------------------\n", msg);
for (int i = 0; i < rows(); i++)
for (int i = 0; i < m_rows; i++)
{
printf("\n");
for (int j = 0; j < cols(); j++)
for (int j = 0; j < m_cols; j++)
{
printf("%2.1f\t", (*this)(i, j));
}
Expand All @@ -300,11 +293,11 @@ struct btMatrixX

void rowComputeNonZeroElements() const
{
m_rowNonZeroElements1.resize(rows());
for (int i = 0; i < rows(); i++)
m_rowNonZeroElements1.resize(m_rows);
for (int i = 0; i < m_rows; i++)
{
m_rowNonZeroElements1[i].resize(0);
for (int j = 0; j < cols(); j++)
for (int j = 0; j < m_cols; j++)
{
if ((*this)(i, j) != 0.f)
{
Expand Down Expand Up @@ -333,20 +326,20 @@ struct btMatrixX
btMatrixX operator*(const btMatrixX& other)
{
//btMatrixX*btMatrixX implementation, brute force
btAssert(cols() == other.rows());
btAssert(m_cols == other.m_rows);

btMatrixX res(rows(), other.cols());
btMatrixX res(m_rows, other.m_cols);
res.setZero();
// BT_PROFILE("btMatrixX mul");
for (int i = 0; i < rows(); ++i)
for (int i = 0; i < m_rows; ++i)
{
{
for (int j = 0; j < other.cols(); ++j)
for (int j = 0; j < other.m_cols; ++j)
{
T dotProd = 0;
{
{
int c = cols();
int c = m_cols;

for (int k = 0; k < c; k++)
{
Expand Down Expand Up @@ -428,11 +421,11 @@ struct btMatrixX

void setSubMatrix(int rowstart, int colstart, int rowend, int colend, const btMatrixX& block)
{
btAssert(rowend + 1 - rowstart == block.rows());
btAssert(colend + 1 - colstart == block.cols());
for (int row = 0; row < block.rows(); row++)
btAssert(rowend + 1 - rowstart == block.m_rows);
btAssert(colend + 1 - colstart == block.m_cols);
for (int row = 0; row < block.m_rows; row++)
{
for (int col = 0; col < block.cols(); col++)
for (int col = 0; col < block.m_cols; col++)
{
setElem(rowstart + row, colstart + col, block(row, col));
}
Expand All @@ -453,9 +446,9 @@ struct btMatrixX

btMatrixX negative()
{
btMatrixX neg(rows(), cols());
for (int i = 0; i < rows(); i++)
for (int j = 0; j < cols(); j++)
btMatrixX neg(m_rows, m_cols);
for (int i = 0; i < m_rows; i++)
for (int j = 0; j < m_cols; j++)
{
T v = (*this)(i, j);
neg.setElem(i, j, -v);
Expand All @@ -476,13 +469,13 @@ std::ostream& operator<<(std::ostream& os, const btMatrixX<T>& mat)
{
os << " [";
//printf("%s ---------------------\n",msg);
for (int i = 0; i < mat.rows(); i++)
for (int i = 0; i < mat.m_rows; i++)
{
for (int j = 0; j < mat.cols(); j++)
for (int j = 0; j < mat.m_cols; j++)
{
os << std::setw(12) << mat(i, j);
}
if (i != mat.rows() - 1)
if (i != mat.m_rows - 1)
os << std::endl
<< " ";
}
Expand Down

0 comments on commit c840f9c

Please sign in to comment.