From 3a13c0ebd6b6a272a666411c61fae46b27764a02 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Wed, 14 Apr 2010 21:53:06 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@308 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../engine/ConstraintSolver.cpp | 15 +++++- .../reactphysics3d/engine/ConstraintSolver.h | 2 +- sources/reactphysics3d/mathematics/Matrix.cpp | 21 ++++++++ sources/reactphysics3d/mathematics/Matrix.h | 54 ++++++++++--------- sources/reactphysics3d/mathematics/Vector.h | 1 + sources/reactphysics3d/mathematics/Vector3D.h | 1 + 6 files changed, 65 insertions(+), 29 deletions(-) diff --git a/sources/reactphysics3d/engine/ConstraintSolver.cpp b/sources/reactphysics3d/engine/ConstraintSolver.cpp index 0403d86c..9bb9399f 100644 --- a/sources/reactphysics3d/engine/ConstraintSolver.cpp +++ b/sources/reactphysics3d/engine/ConstraintSolver.cpp @@ -164,12 +164,23 @@ void ConstraintSolver::freeMemory() { // Compute the vector b void ConstraintSolver::computeVectorB() { - // TODO : Implement this method ... + } // Compute the matrix B_sp void ConstraintSolver::computeMatrixB_sp() { - // TODO : Implement this method ... + unsigned int indexBody1; + unsigned int indexBody2; + + // For each constraint + for (unsigned int j = 0; j constraintBodies; // Bodies that are implied in some constraint unsigned int nbBodies; // Current number of bodies in the physics world std::map bodyNumberMapping; // Map a body pointer with its index number - Body** bodyMapping; // 2-dimensional array that contains the mapping of body reference + Body*** bodyMapping; // 2-dimensional array that contains the mapping of body reference // in the J_sp and B_sp matrices. For instance the cell bodyMapping[i][j] contains // the integer index of the body that correspond to the 1x6 J_ij matrix in the // J_sp matrix. A integer body index refers to its index in the "bodies" std::vector diff --git a/sources/reactphysics3d/mathematics/Matrix.cpp b/sources/reactphysics3d/mathematics/Matrix.cpp index 6a7699ea..ff85812e 100644 --- a/sources/reactphysics3d/mathematics/Matrix.cpp +++ b/sources/reactphysics3d/mathematics/Matrix.cpp @@ -266,6 +266,27 @@ double Matrix::getTrace() const throw(MathematicsException) { } +// Return a sub matrix of size of the current matrix +Matrix Matrix::getSubMatrix(unsigned int i, unsigned int j, + unsigned int sizeRows, unsigned int sizeColumns) const throw(std::invalid_argument) { + // Check the arguments + if (i<0 || j<0 || i+sizeRows >= nbRow || j+sizeColumns >= nbColumn) { + // Throw an exception + throw std::invalid_argument("Error : The arguments are out of matrix bounds"); + } + + // Compute the sub-matrix + Matrix resultMatrix(sizeRows, sizeColumns); + for (unsigned int k=0; k #include + // ReactPhysics3D namespace namespace reactphysics3d { diff --git a/sources/reactphysics3d/mathematics/Vector3D.h b/sources/reactphysics3d/mathematics/Vector3D.h index 691ab8d2..029624c3 100644 --- a/sources/reactphysics3d/mathematics/Vector3D.h +++ b/sources/reactphysics3d/mathematics/Vector3D.h @@ -26,6 +26,7 @@ #include "exceptions.h" #include "mathematics_functions.h" + // ReactPhysics3D namespace namespace reactphysics3d {