Skip to content

Commit

Permalink
doc and update fps example
Browse files Browse the repository at this point in the history
  • Loading branch information
schteppe committed Feb 16, 2013
1 parent bdfb481 commit 123ce91
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 7 deletions.
32 changes: 29 additions & 3 deletions build/cannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -4914,20 +4914,40 @@ CANNON.ContactGenerator = function(){
*/
CANNON.Equation = function(bi,bj,minForce,maxForce){
this.id = -1;

/**
* @property float minForce
* @memberof CANNON.Equation
*/
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;

/**
* @property float maxForce
* @memberof CANNON.Equation
*/
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;

/**
* @property CANNON.Body bi
* @memberof CANNON.Equation
*/
this.bi = bi;

/**
* @property CANNON.Body bj
* @memberof CANNON.Equation
*/
this.bj = bj;

/**
* @property float k
* @property float stiffness
* @brief Corresponds to spring stiffness. Makes constraints stiffer, but harder to solve.
* @memberof CANNON.Equation
*/
this.stiffness = 1e7;

/**
* @property float d
* @property float regularizationTime
* @brief Similar to damping. Represents the number of timesteps needed to stabilize the constraint.
* @memberof CANNON.Equation
*/
Expand Down Expand Up @@ -4963,13 +4983,19 @@ CANNON.Equation = function(bi,bj,minForce,maxForce){
};
CANNON.Equation.prototype.constructor = CANNON.Equation;

/**
* @method updateSpookParams
* @brief Recalculates a,b,eps.
* @memberof CANNON.Equation
*/
CANNON.Equation.prototype.updateSpookParams = function(h){
var d = this.regularizationTime,
k = this.stiffness;
this.a = 4.0 / (h * (1 + 4 * d));
this.b = (4.0 * d) / (1 + 4 * d);
this.eps = 4.0 / (h * h * k * (1 + 4 * d));
};/**
};
/**
* @class CANNON.ContactEquation
* @brief Contact/non-penetration constraint equation
* @author schteppe
Expand Down
2 changes: 0 additions & 2 deletions demos/compound.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@
world.gravity.set(0,0,-30);
world.broadphase = new CANNON.NaiveBroadphase();
world.solver.iterations = 10;
world.solver.k = 1e8;
world.solver.d = 3;

// ground plane
var groundShape = new CANNON.Plane();
Expand Down
5 changes: 4 additions & 1 deletion examples/threejs_fps.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@
world.quatNormalizeFast = false;

var solver = new CANNON.GSSolver();
solver.setSpookParams(1e9,4);

world.defaultContactMaterial.contactEquationStiffness = 1e9;
world.defaultContactMaterial.contactEquationRegularizationTime = 4;

solver.iterations = 7;
solver.tolerance = 0.1;
var split = true;
Expand Down
27 changes: 26 additions & 1 deletion src/constraints/Equation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,29 @@
*/
CANNON.Equation = function(bi,bj,minForce,maxForce){
this.id = -1;

/**
* @property float minForce
* @memberof CANNON.Equation
*/
this.minForce = typeof(minForce)=="undefined" ? -1e6 : minForce;

/**
* @property float maxForce
* @memberof CANNON.Equation
*/
this.maxForce = typeof(maxForce)=="undefined" ? 1e6 : maxForce;

/**
* @property CANNON.Body bi
* @memberof CANNON.Equation
*/
this.bi = bi;

/**
* @property CANNON.Body bj
* @memberof CANNON.Equation
*/
this.bj = bj;

/**
Expand Down Expand Up @@ -60,10 +80,15 @@ CANNON.Equation = function(bi,bj,minForce,maxForce){
};
CANNON.Equation.prototype.constructor = CANNON.Equation;

/**
* @method updateSpookParams
* @brief Recalculates a,b,eps.
* @memberof CANNON.Equation
*/
CANNON.Equation.prototype.updateSpookParams = function(h){
var d = this.regularizationTime,
k = this.stiffness;
this.a = 4.0 / (h * (1 + 4 * d));
this.b = (4.0 * d) / (1 + 4 * d);
this.eps = 4.0 / (h * h * k * (1 + 4 * d));
};
};

0 comments on commit 123ce91

Please sign in to comment.