Skip to content

Commit

Permalink
Adding Sweep and Prune broadphase
Browse files Browse the repository at this point in the history
  • Loading branch information
chandlerprall committed Jun 22, 2015
1 parent 01e5ba0 commit ce5944a
Show file tree
Hide file tree
Showing 9 changed files with 925 additions and 53 deletions.
481 changes: 458 additions & 23 deletions build/goblin.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions build/goblin.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/js/exampleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ window.exampleUtils = (function(){
};

var startGoblin = function() {
exampleUtils.world = world = new Goblin.World( new Goblin.BasicBroadphase(), new Goblin.NarrowPhase(), new Goblin.IterativeSolver() );
exampleUtils.world = world = new Goblin.World( new Goblin.SAPBroadphase(), new Goblin.NarrowPhase(), new Goblin.IterativeSolver() );
exampleUtils.world.addListener(
'stepStart',
displayContacts
Expand Down
3 changes: 2 additions & 1 deletion examples/raytracer.html
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
color = new Goblin.Vector3();

return function() {
//var x = 726, y = 63;
for ( var i = 0; i < 30 && y < height; i++ && y++ ) {
for ( var x = 0; x < width; x++ ) {
// Unproject pixel
Expand All @@ -337,7 +338,7 @@
canvas_data.data[data_offset + 1] = color.y * 255;
canvas_data.data[data_offset + 2] = color.z * 255;
canvas_data.data[data_offset + 3] = 255;
}
}
}

ctx.putImageData( canvas_data, 0, 0 );
Expand Down
2 changes: 1 addition & 1 deletion src/classes/AABB.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Goblin.AABB.prototype.testRayIntersect = (function(){
tmin, tmax,
ood, t1, t2;

return function( start, end ) {
return function AABB_testRayIntersect( start, end ) {
tmin = 0;

direction.subtractVectors( end, start );
Expand Down
28 changes: 8 additions & 20 deletions src/classes/BroadPhases/BasicBroadphase.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Goblin.BasicBroadphase = function() {
this.bodies = [];

/**
* Array of all (current) collision pairs between the broadphase's bodies
* Array of all (current) collision pairs between the broadphases' bodies
*
* @property collision_pairs
* @type {Array}
Expand All @@ -26,7 +26,7 @@ Goblin.BasicBroadphase = function() {
* Adds a body to the broadphase for contact checking
*
* @method addBody
* @param body {MassPoint|RigidBody} body to add to the broadphase contact checking
* @param body {RigidBody} body to add to the broadphase contact checking
*/
Goblin.BasicBroadphase.prototype.addBody = function( body ) {
this.bodies.push( body );
Expand All @@ -36,7 +36,7 @@ Goblin.BasicBroadphase.prototype.addBody = function( body ) {
* Removes a body from the broadphase contact checking
*
* @method removeBody
* @param body {MassPoint|RigidBody} body to remove from the broadphase contact checking
* @param body {RigidBody} body to remove from the broadphase contact checking
*/
Goblin.BasicBroadphase.prototype.removeBody = function( body ) {
var i,
Expand All @@ -54,9 +54,9 @@ Goblin.BasicBroadphase.prototype.removeBody = function( body ) {
* Checks all collision objects to find any which are possibly in contact
* resulting contact pairs are held in the object's `collision_pairs` property
*
* @method predictContactPairs
* @method update
*/
Goblin.BasicBroadphase.prototype.predictContactPairs = function() {
Goblin.BasicBroadphase.prototype.update = function() {
var i, j,
object_a, object_b,
bodies_count = this.bodies.length;
Expand Down Expand Up @@ -110,15 +110,15 @@ Goblin.BasicBroadphase.prototype.predictContactPairs = function() {
}
}

if ( this.mightIntersect( object_a, object_b ) ) {
this.collision_pairs.push( [ object_a, object_b ] );
if ( object_a.aabb.intersects( object_b.aabb ) ) {
this.collision_pairs.push( [ object_b, object_a ] );
}
}
}
};

/**
* Returns an of objects the given body may be colliding with
* Returns an array of objects the given body may be colliding with
*
* @method intersectsWith
* @param object_a {RigidBody}
Expand All @@ -145,18 +145,6 @@ Goblin.BasicBroadphase.prototype.intersectsWith = function( object_a ) {
return intersections;
};

/**
* Determines whether two objects may be colliding
*
* @method mightIntersect
* @param object_a {RigidBody}
* @param object_b {RigidBody}
* @returns {Boolean}
*/
Goblin.BasicBroadphase.prototype.mightIntersect = function( object_a, object_b ) {
return object_a.aabb.intersects( object_b.aabb );
};

/**
* Checks if a ray segment intersects with objects in the world
*
Expand Down
Loading

0 comments on commit ce5944a

Please sign in to comment.