Skip to content

Commit

Permalink
Added normal to returned collider for mesh collider tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drojdjou committed Apr 13, 2011
1 parent 964ae25 commit 8ab742c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
*.swp
.project
2 changes: 1 addition & 1 deletion src/extras/physics/CollisionUtils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @author drojdjou / http://everyday3d.com/
* @author bartek drozdz / http://everyday3d.com/
*/

THREE.CollisionUtils = {};
Expand Down
15 changes: 11 additions & 4 deletions src/extras/physics/Collisions.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @author drojdjou / http://everyday3d.com/
* @author bartek drozdz / http://everyday3d.com/
*/

THREE.PlaneCollider = function( point, normal ) {
Expand Down Expand Up @@ -38,6 +38,7 @@ THREE.MeshCollider = function( vertices, faces, normals, box ) {

THREE.CollisionSystem = function() {

this.collisionNormal;
this.colliders = [];
this.hits = [];

Expand Down Expand Up @@ -139,8 +140,12 @@ THREE.CollisionSystem.prototype.rayMesh = function( r, me ) {
var p2 = me.vertices[ me.faces[ t + 2 ] ];
var n = me.normals[ me.faces[ i ] ];

d = Math.min(d, this.rayTriangle( rt, p0, p1, p2, n, d ) );

var nd = this.rayTriangle( rt, p0, p1, p2, n, d );

if(nd < d) {
d = nd;
me.normal = this.collisionNormal;
}
}

return d;
Expand Down Expand Up @@ -245,7 +250,9 @@ THREE.CollisionSystem.prototype.rayTriangle = function( ray, p0, p1, p2, n, mind
var gamma = 1 - alpha - beta;
if( !(gamma >= 0) ) return Number.MAX_VALUE;
//console.log("gamma: " + gamma);


this.collisionNormal = n;

return t;

};
Expand Down

0 comments on commit 8ab742c

Please sign in to comment.