cannon
Version:
A lightweight 3D physics engine written in JavaScript.
60 lines (53 loc) • 1.09 kB
JavaScript
module.exports = Solver;
/**
* Constraint equation solver base class.
* @class Solver
* @constructor
* @author schteppe / https://github.com/schteppe
*/
function Solver(){
/**
* All equations to be solved
* @property {Array} equations
*/
this.equations = [];
}
/**
* Should be implemented in subclasses!
* @method solve
* @param {Number} dt
* @param {World} world
*/
Solver.prototype.solve = function(dt,world){
// Should return the number of iterations done!
return 0;
};
/**
* Add an equation
* @method addEquation
* @param {Equation} eq
*/
Solver.prototype.addEquation = function(eq){
if (eq.enabled) {
this.equations.push(eq);
}
};
/**
* Remove an equation
* @method removeEquation
* @param {Equation} eq
*/
Solver.prototype.removeEquation = function(eq){
var eqs = this.equations;
var i = eqs.indexOf(eq);
if(i !== -1){
eqs.splice(i,1);
}
};
/**
* Add all equations
* @method removeAllEquations
*/
Solver.prototype.removeAllEquations = function(){
this.equations.length = 0;
};