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

87 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-10-14 12:32:53 +02:00
/**
* Physics Solver Superset
* @param id
2016-10-31 09:30:03 +01:00
* @param engine GameLib.D3.Engine
2016-10-14 12:32:53 +02:00
* @param solverType
2016-10-31 09:30:03 +01:00
* @param name
2016-10-14 12:32:53 +02:00
* @param iterations
* @param tolerance
* @constructor
*/
2016-10-31 09:30:03 +01:00
GameLib.D3.Solver = function(
2016-10-14 12:32:53 +02:00
id,
2016-10-31 09:30:03 +01:00
engine,
2016-10-14 12:32:53 +02:00
solverType,
2016-10-31 09:30:03 +01:00
name,
2016-10-14 12:32:53 +02:00
iterations,
tolerance
) {
this.id = id;
2016-10-31 09:30:03 +01:00
this.engine = engine;
this.engine.isNotCannonThrow();
if (typeof solverType == 'undefined') {
solverType = GameLib.D3.Solver.GS_SOLVER;
}
this.solverType = solverType;
2016-10-14 12:32:53 +02:00
if (typeof name == 'undefined') {
2016-10-31 09:30:03 +01:00
if (this.solverType == GameLib.D3.Solver.SPLIT_SOLVER) {
2016-10-14 12:32:53 +02:00
name = 'split solver';
2016-10-31 09:30:03 +01:00
} else if (this.solverType == GameLib.D3.Solver.GS_SOLVER) {
2016-10-14 12:32:53 +02:00
name = 'gs solver';
} else {
name = 'unknown solver';
}
}
this.name = name;
2016-10-31 09:30:03 +01:00
if (typeof iterations == 'undefined') {
iterations = 10;
}
2016-10-14 12:32:53 +02:00
this.iterations = iterations;
2016-10-31 09:30:03 +01:00
if (typeof tolerance == 'undefined') {
tolerance = 1e-7;
}
2016-10-14 12:32:53 +02:00
this.tolerance = tolerance;
2016-10-31 09:30:03 +01:00
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;
2016-10-14 12:32:53 +02:00
};
2016-12-09 20:32:09 +01:00
GameLib.D3.Solver.prototype.toApiSolver = function() {
return null;
};
2016-10-14 12:32:53 +02:00
/**
* Solver Types
* @type {number}
*/
2016-10-31 09:30:03 +01:00
GameLib.D3.Solver.SPLIT_SOLVER = 0x1;
GameLib.D3.Solver.GS_SOLVER = 0x2;