Skip to content

Commit

Permalink
added support for multichannel sound + sound volume based on speed on…
Browse files Browse the repository at this point in the history
… impact
  • Loading branch information
jeromeetienne committed Dec 8, 2011
1 parent c2537cd commit 8ad57e5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ <h3>Ouch no WebGL :(</h3>

<script>
jQuery(function(){
// TODO use the threex.embedded for that

// prevent default actions for arrow keys
// - required if this window.document is embedded in another page as an iframe
// - it prevent the hosting page to scroll when you use arrows in the game page
Expand Down
6 changes: 5 additions & 1 deletion js/marble.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ Marble.Marble.prototype.init = function(opts)
// - used to have a single contact notification when 2 marbles are in contact
if( this._marbleId >= otherBody._marbleId ) return;
//console.log("marlbe", this._marbleId, "collide with", otherBody._marbleId)
soundPool.get('marbleContact').play();
var volume = this.separatingVelocity(otherBody) * 0.8 / Marble.tileSize;
volume = Math.min(volume, 1.0);
soundPool.get('marbleContact').play({
volume : volume
});
});

// apply friction
Expand Down
2 changes: 1 addition & 1 deletion js/pageGameLife.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Marble.PageGameLife.prototype._render = function()

// FIXME this should be INSIDE webgl renderer... bug
renderer.context.depthMask( true );

// actually display the scene in the Dom element
renderer.render( scene, gameLevel.camera().object() );
}
26 changes: 26 additions & 0 deletions vendor/microphysics.js/codeflow/physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,32 @@
this.pz + (this.z - this.pz)*u,
]
},
separatingVelocity: function(other){
var b1 = this, b2 = other;

var x = b1.x - b2.x;
var y = b1.y - b2.y;
var z = b1.z - b2.z;
var l = sqrt(x*x + y*y + z*z);
var xn = x/l;
var yn = y/l;
var zn = z/l;

var v1 = b1.getVelocity();
var v2 = b2.getVelocity();

var vrx = v1[0] - v2[0];
var vry = v1[1] - v2[1];
var vrz = v1[2] - v2[2];

var vdotn = vrx*xn + vry*yn + vrz*zn;
var xs = vrx*vdotn;
var ys = vry*vdotn;
var zs = vrz*vdotn;
var speed = sqrt(xs*xs + ys*ys + zs*zs);

return speed;
},
collide: function(other, restitute){
switch(other.type){
case AABB:
Expand Down

0 comments on commit 8ad57e5

Please sign in to comment.