Skip to content

Commit

Permalink
removed superfluous method World.prototype.setGlobalEquationParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Jul 6, 2015
1 parent 3583a79 commit 69d494b
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
81 changes: 33 additions & 48 deletions src/world/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -1159,65 +1159,33 @@ World.prototype.hitTest = function(worldPoint,bodies,precision){
};

/**
* Sets the Equation parameters for all constraints and contact materials.
* @method setGlobalEquationParameters
* @param {object} [parameters]
* @param {Number} [parameters.relaxation]
* @param {Number} [parameters.stiffness]
* @deprecated To be removed. Use setGlobalStiffness and setGlobalRelaxation instead.
* Set the stiffness for all equations and contact materials.
* @method setGlobalStiffness
* @param {Number} stiffness
*/
World.prototype.setGlobalEquationParameters = function(parameters){
parameters = parameters || {};
World.prototype.setGlobalStiffness = function(stiffness){

// Set for all constraints
for(var i=0; i !== this.constraints.length; i++){
var c = this.constraints[i];
var constraints = this.constraints;
for(var i=0; i !== constraints.length; i++){
var c = constraints[i];
for(var j=0; j !== c.equations.length; j++){
var eq = c.equations[j];
if(typeof(parameters.stiffness) !== "undefined"){
eq.stiffness = parameters.stiffness;
}
if(typeof(parameters.relaxation) !== "undefined"){
eq.relaxation = parameters.relaxation;
}
eq.stiffness = stiffness;
eq.needsUpdate = true;
}
}

// Set for all contact materials
for(var i=0; i !== this.contactMaterials.length; i++){
var c = this.contactMaterials[i];
if(typeof(parameters.stiffness) !== "undefined"){
c.stiffness = parameters.stiffness;
c.frictionStiffness = parameters.stiffness;
}
if(typeof(parameters.relaxation) !== "undefined"){
c.relaxation = parameters.relaxation;
c.frictionRelaxation = parameters.relaxation;
}
var contactMaterials = this.contactMaterials;
for(var i=0; i !== contactMaterials.length; i++){
var c = contactMaterials[i];
c.stiffness = c.frictionStiffness = stiffness;
}

// Set for default contact material
var c = this.defaultContactMaterial;
if(typeof(parameters.stiffness) !== "undefined"){
c.stiffness = parameters.stiffness;
c.frictionStiffness = parameters.stiffness;
}
if(typeof(parameters.relaxation) !== "undefined"){
c.relaxation = parameters.relaxation;
c.frictionRelaxation = parameters.relaxation;
}
};

/**
* Set the stiffness for all equations and contact materials.
* @method setGlobalStiffness
* @param {Number} stiffness
*/
World.prototype.setGlobalStiffness = function(stiffness){
this.setGlobalEquationParameters({
stiffness: stiffness
});
c.stiffness = c.frictionStiffness = stiffness;
};

/**
Expand All @@ -1226,9 +1194,26 @@ World.prototype.setGlobalStiffness = function(stiffness){
* @param {Number} relaxation
*/
World.prototype.setGlobalRelaxation = function(relaxation){
this.setGlobalEquationParameters({
relaxation: relaxation
});

// Set for all constraints
for(var i=0; i !== this.constraints.length; i++){
var c = this.constraints[i];
for(var j=0; j !== c.equations.length; j++){
var eq = c.equations[j];
eq.relaxation = relaxation;
eq.needsUpdate = true;
}
}

// Set for all contact materials
for(var i=0; i !== this.contactMaterials.length; i++){
var c = this.contactMaterials[i];
c.relaxation = c.frictionRelaxation = relaxation;
}

// Set for default contact material
var c = this.defaultContactMaterial;
c.relaxation = c.frictionRelaxation = relaxation;
};

var tmpAABB = new AABB();
Expand Down
14 changes: 14 additions & 0 deletions test/world/World.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,20 @@ exports.runNarrowphase = function(test){
test.done();
};

exports.setGlobalStiffness = function(test){
var world = new World();
world.setGlobalStiffness(123);
test.equal(world.defaultContactMaterial.stiffness, 123);
test.done();
};

exports.setGlobalRelaxation = function(test){
var world = new World();
world.setGlobalRelaxation(123);
test.equal(world.defaultContactMaterial.relaxation, 123);
test.done();
};

exports.step = function(test){
// STUB
test.done();
Expand Down

0 comments on commit 69d494b

Please sign in to comment.