@@ -1953,6 +1953,33 @@ function Narrowphase(){
19531953 */
19541954 this . restitution = 0 ;
19551955
1956+ /**
1957+ * The stiffness value to use in the next contact equations.
1958+ * @property {Number } stiffness
1959+ */
1960+ this . stiffness = 1e7 ;
1961+
1962+ /**
1963+ * The stiffness value to use in the next contact equations.
1964+ * @property {Number } stiffness
1965+ */
1966+ this . relaxation = 3 ;
1967+
1968+ /**
1969+ * The stiffness value to use in the next friction equations.
1970+ * @property frictionStiffness
1971+ * @type {Number }
1972+ */
1973+ this . frictionStiffness = 1e7 ;
1974+
1975+ /**
1976+ * The relaxation value to use in the next friction equations.
1977+ * @property frictionRelaxation
1978+ * @type {Number }
1979+ */
1980+ this . frictionRelaxation = 3 ;
1981+
1982+
19561983 // Keep track of the colliding bodies last step
19571984 this . collidingBodiesLastStep = { keys :[ ] } ;
19581985} ;
@@ -2041,6 +2068,8 @@ Narrowphase.prototype.createContactEquation = function(bodyA,bodyB,shapeA,shapeB
20412068 c . shapeB = shapeB ;
20422069 c . restitution = this . restitution ;
20432070 c . firstImpact = ! this . collidedLastStep ( bodyA , bodyB ) ;
2071+ c . stiffness = this . stiffness ;
2072+ c . relaxation = this . relaxation ;
20442073 c . enabled = true ;
20452074
20462075 if ( bodyA . allowSleep && ( bodyA . motionState == Body . DYNAMIC ) && ! ( bodyB . motionState == Body . STATIC || bodyB . sleepState === Body . SLEEPY ) )
@@ -2068,6 +2097,8 @@ Narrowphase.prototype.createFrictionEquation = function(bodyA,bodyB,shapeA,shape
20682097 c . frictionCoefficient = this . frictionCoefficient ;
20692098 c . relativeVelocity = this . surfaceVelocity ;
20702099 c . enabled = true ;
2100+ c . frictionStiffness = this . frictionStiffness ;
2101+ c . frictionRelaxation = this . frictionRelaxation ;
20712102 return c ;
20722103} ;
20732104
@@ -5439,8 +5470,8 @@ ContactEquation.prototype.computeB = function(a,b,h){
54395470 Gq = 0 ;
54405471 GW = ( 1 / b ) * ( 1 + this . restitution ) * this . computeGW ( ) ;
54415472 } else {
5442- GW = this . computeGW ( ) ;
54435473 Gq = vec2 . dot ( n , penetrationVec ) ;
5474+ GW = this . computeGW ( ) ;
54445475 }
54455476
54465477 var GiMf = this . computeGiMf ( ) ;
@@ -6946,9 +6977,19 @@ function Body(options){
69466977 this . wlambda = 0 ;
69476978
69486979 /**
6949- * The angle of the body
6980+ * The angle of the body, in radians.
69506981 * @property angle
69516982 * @type {number }
6983+ * @example
6984+ * // The angle property is not normalized to the interval 0 to 2*pi, it can be any value.
6985+ * // If you need a value between 0 and 2*pi, use the following function to normalize it.
6986+ * function normalizeAngle(angle){
6987+ * angle = angle % (2*Math.PI);
6988+ * if(angle < 0){
6989+ * angle += (2*Math.PI);
6990+ * }
6991+ * return angle;
6992+ * }
69526993 */
69536994 this . angle = options . angle || 0 ;
69546995
@@ -8803,7 +8844,7 @@ GSSolver.prototype.solve = function(h,world){
88038844 lambda = this . lambda ;
88048845 if ( ! useGlobalParams ) {
88058846 for ( var i = 0 , c ; c = equations [ i ] ; i ++ ) {
8806- if ( h !== c . h ) c . updateSpookParams ( h ) ;
8847+ c . updateSpookParams ( h ) ;
88078848 Bs [ i ] = c . computeB ( c . a , c . b , h ) ;
88088849 invCs [ i ] = c . computeInvC ( c . eps ) ;
88098850 }
@@ -9465,6 +9506,10 @@ function World(options){
94659506 */
94669507 this . defaultRestitution = 0.0 ;
94679508
9509+ this . defaultMaterial = new Material ( ) ;
9510+
9511+ this . defaultContactMaterial = new ContactMaterial ( this . defaultMaterial , this . defaultMaterial ) ;
9512+
94689513 /**
94699514 * For keeping track of what time step size we used last step
94709515 * @property lastTimeStep
@@ -9863,20 +9908,26 @@ World.prototype.internalStep = function(dt){
98639908 xj = bj . shapeOffsets [ l ] ,
98649909 aj = bj . shapeAngles [ l ] ;
98659910
9911+ /*
98669912 var mu = this.defaultFriction,
98679913 restitution = this.defaultRestitution,
98689914 surfaceVelocity = 0;
9915+ */
98699916
9917+ var cm = this . defaultContactMaterial ;
98709918 if ( si . material && sj . material ) {
9871- var cm = this . getContactMaterial ( si . material , sj . material ) ;
9872- if ( cm ) {
9919+ var tmp = this . getContactMaterial ( si . material , sj . material ) ;
9920+ if ( tmp ) {
9921+ cm = tmp ;
9922+ /*
98739923 mu = cm.friction;
98749924 restitution = cm.restitution;
98759925 surfaceVelocity = cm.surfaceVelocity;
9926+ */
98769927 }
98779928 }
98789929
9879- this . runNarrowphase ( np , bi , si , xi , ai , bj , sj , xj , aj , mu , restitution , surfaceVelocity , glen ) ;
9930+ this . runNarrowphase ( np , bi , si , xi , ai , bj , sj , xj , aj , cm , glen ) ;
98809931 }
98819932 }
98829933 }
@@ -10031,7 +10082,7 @@ World.integrateBody = function(body,dt){
1003110082 * @param {Number } aj
1003210083 * @param {Number } mu
1003310084 */
10034- World . prototype . runNarrowphase = function ( np , bi , si , xi , ai , bj , sj , xj , aj , mu , restitution , surfaceVelocity , glen ) {
10085+ World . prototype . runNarrowphase = function ( np , bi , si , xi , ai , bj , sj , xj , aj , cm , glen ) { /* mu,restitution,surfaceVelocity */
1003510086
1003610087 if ( ! ( ( si . collisionGroup & sj . collisionMask ) !== 0 && ( sj . collisionGroup & si . collisionMask ) !== 0 ) )
1003710088 return ;
@@ -10051,18 +10102,22 @@ World.prototype.runNarrowphase = function(np,bi,si,xi,ai,bj,sj,xj,aj,mu,restitut
1005110102 var ajw = aj + bj . angle ;
1005210103
1005310104 // Run narrowphase
10054- np . enableFriction = mu > 0 ;
10055- np . frictionCoefficient = mu ;
10105+ np . enableFriction = cm . friction > 0 ;
10106+ np . frictionCoefficient = cm . friction ;
1005610107 var reducedMass ;
1005710108 if ( bi . motionState == Body . STATIC || bi . motionState == Body . KINEMATIC )
1005810109 reducedMass = bj . mass ;
1005910110 else if ( bj . motionState == Body . STATIC || bj . motionState == Body . KINEMATIC )
1006010111 reducedMass = bi . mass ;
1006110112 else
1006210113 reducedMass = ( bi . mass * bj . mass ) / ( bi . mass + bj . mass ) ;
10063- np . slipForce = mu * glen * reducedMass ;
10064- np . restitution = restitution ;
10065- np . surfaceVelocity = surfaceVelocity ;
10114+ np . slipForce = cm . friction * glen * reducedMass ;
10115+ np . restitution = cm . restitution ;
10116+ np . surfaceVelocity = cm . surfaceVelocity ;
10117+ np . frictionStiffness = cm . frictionStiffness ;
10118+ np . frictionRelaxation = cm . frictionRelaxation ;
10119+ np . stiffness = cm . stiffness ;
10120+ np . relaxation = cm . relaxation ;
1006610121
1006710122 var resolver = np [ si . type | sj . type ] ,
1006810123 numContacts = 0 ;
0 commit comments