From 3adbeb65ac031e36bd0062364381d8cbe2e57a5b Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Mon, 15 Feb 2010 23:27:35 +0000 Subject: [PATCH] git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@280 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- .../engine/ConstraintSolver.cpp | 76 +++++++++++++++++++ .../reactphysics3d/engine/ConstraintSolver.h | 48 ++++++++++++ sources/reactphysics3d/engine/PhysicsEngine.h | 1 - 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 sources/reactphysics3d/engine/ConstraintSolver.cpp create mode 100644 sources/reactphysics3d/engine/ConstraintSolver.h diff --git a/sources/reactphysics3d/engine/ConstraintSolver.cpp b/sources/reactphysics3d/engine/ConstraintSolver.cpp new file mode 100644 index 00000000..f897de9a --- /dev/null +++ b/sources/reactphysics3d/engine/ConstraintSolver.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** +* Copyright (C) 2009 Daniel Chappuis * +**************************************************************************** +* This file is part of ReactPhysics3D. * +* * +* ReactPhysics3D is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Lesser General Public License as published * +* by the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* ReactPhysics3D is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +// Libraries +#include "ConstraintSolver.h" + +// Constructor +ConstraintSolver::ConstraintSolver() { + +} + +// Destructor +ConstraintSolver~ConstraintSolver() { + +} + +// Allocate all the matrices needed to solve the LCP problem +void ConstraintSolver::allocate(std::vector& constraints, double dt) { + std::vector activeConstraints; + unsigned int sizeJacobian = 0; + unsigned int nbAuxiliaryVars = 0; + + // For each constraint + for (unsigned int i=0; iisActive()) { + activeConstraints.push_back(constraints.at(i)); + + // Evaluate the constraint + constraints.at(i)->evaluate(dt); + + // Set the current jacobian index to the constraint + constraints.at(i)->setJacobianIndex(sizeJacobian); + + // Update the size of the jacobian matrix + sizeJacobian += constraints.at(i)->getNbJacobianRows(); + } + } + + // For each active constraint + for (unsigned int i=0; isetAuxiliaryIndex(sizeJacobian + nbAuxiliaryVars); + + // Update the number of auxiliary variables + nbAuxiliaryVars += activeConstraints.at(i)->getNbAuxiliaryVars(); + } + + // TODO : Continue to implement this ... +} + +// Fill in all the matrices needed to solve the LCP problem +void ConstraintSolver::fillInMatrices(std::vector constraints) { + +} + +// Solve the current LCP problem +void ConstraintSolver::solve(std::vector constraints, double dt) { + +} diff --git a/sources/reactphysics3d/engine/ConstraintSolver.h b/sources/reactphysics3d/engine/ConstraintSolver.h new file mode 100644 index 00000000..9c5e9ad4 --- /dev/null +++ b/sources/reactphysics3d/engine/ConstraintSolver.h @@ -0,0 +1,48 @@ +/*************************************************************************** +* Copyright (C) 2009 Daniel Chappuis * +**************************************************************************** +* This file is part of ReactPhysics3D. * +* * +* ReactPhysics3D is free software: you can redistribute it and/or modify * +* it under the terms of the GNU Lesser General Public License as published * +* by the Free Software Foundation, either version 3 of the License, or * +* (at your option) any later version. * +* * +* ReactPhysics3D is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU Lesser General Public License for more details. * +* * +* You should have received a copy of the GNU Lesser General Public License * +* along with ReactPhysics3D. If not, see . * +***************************************************************************/ + +#ifndef CONSTRAINTSOLVER_H +#define CONSTRAINTSOLVER_H + +// Libraries +#include "../constraint/Constraint.h" + +// ReactPhysics3D namespace +namespace reactphysics3d { + + /* ------------------------------------------------------------------- + Class ConstrainSolver : + This class represents the constraint solver. The goal is to + solve A constraint-base LCP problem. + ------------------------------------------------------------------- +*/ +class ConstraintSolver { + protected: + void allocate(std::vector& constraints, double dt); // Allocate all the matrices needed to solve the LCP problem + void fillInMatrices(std::vector constraints); // Fill in all the matrices needed to solve the LCP problem + + public: + ConstraintSolver(); // Constructor + virtual ~ConstraintSolver(); // Destructor + void solve(std::vector& constraints, double dt); // Solve the current LCP problem +}; + +} // End of ReactPhysics3D namespace + +#endif diff --git a/sources/reactphysics3d/engine/PhysicsEngine.h b/sources/reactphysics3d/engine/PhysicsEngine.h index 59ca4836..5e613737 100644 --- a/sources/reactphysics3d/engine/PhysicsEngine.h +++ b/sources/reactphysics3d/engine/PhysicsEngine.h @@ -47,7 +47,6 @@ class PhysicsEngine { public : PhysicsEngine(PhysicsWorld* world, const Time& timeStep) throw (std::invalid_argument); // Constructor - PhysicsEngine(const PhysicsEngine& engine); // Copy-constructor ~PhysicsEngine(); // Destructor void start(); // Start the physics simulation