r3-legacy/bak/game-lib-d3-solver.js

87 lines
1.9 KiB
JavaScript

/**
* Physics Solver Superset
* @param id
* @param engine GameLib.D3.Engine
* @param solverType
* @param name
* @param iterations
* @param tolerance
* @constructor
*/
GameLib.D3.Solver = function(
id,
engine,
solverType,
name,
iterations,
tolerance
) {
this.id = id;
this.engine = engine;
this.engine.isNotCannonThrow();
if (typeof solverType == 'undefined') {
solverType = GameLib.D3.Solver.GS_SOLVER;
}
this.solverType = solverType;
if (typeof name == 'undefined') {
if (this.solverType == GameLib.D3.Solver.SPLIT_SOLVER) {
name = 'split solver';
} else if (this.solverType == GameLib.D3.Solver.GS_SOLVER) {
name = 'gs solver';
} else {
name = 'unknown solver';
}
}
this.name = name;
if (typeof iterations == 'undefined') {
iterations = 10;
}
this.iterations = iterations;
if (typeof tolerance == 'undefined') {
tolerance = 1e-7;
}
this.tolerance = tolerance;
this.instance = this.createInstance();
this.instance.tolerance = tolerance;
this.instance.iterations = iterations;
};
/**
* Creates a custom solver instance
* @returns {*}
*/
GameLib.D3.Solver.prototype.createInstance = function(){
var instance = null;
if (this.solverType == GameLib.D3.Solver.SPLIT_SOLVER) {
instance = new this.engine.instance.SplitSolver();
} else if (this.solverType == GameLib.D3.Solver.GS_SOLVER) {
instance = new this.engine.instance.GSSolver();
} else {
console.warn('Unsupported solver type: ' + this.solverType);
throw new Error('Unsupported solver type: ' + this.solverType);
}
return instance;
};
GameLib.D3.Solver.prototype.toApiSolver = function() {
return null;
};
/**
* Solver Types
* @type {number}
*/
GameLib.D3.Solver.SPLIT_SOLVER = 0x1;
GameLib.D3.Solver.GS_SOLVER = 0x2;