Added normal to returned collider for mesh collider tests

This commit is contained in:
Bartek Drozdz
2011-04-13 12:16:13 +02:00
parent 964ae25886
commit 8ab742ca2c
3 changed files with 13 additions and 5 deletions
+1
View File
@@ -1,2 +1,3 @@
.DS_Store
*.swp
.project
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* @author drojdjou / http://everyday3d.com/
* @author bartek drozdz / http://everyday3d.com/
*/
THREE.CollisionUtils = {};
+9 -2
View File
@@ -1,5 +1,5 @@
/**
* @author drojdjou / http://everyday3d.com/
* @author bartek drozdz / http://everyday3d.com/
*/
THREE.PlaneCollider = function( point, normal ) {
@@ -38,6 +38,7 @@ THREE.MeshCollider = function( vertices, faces, normals, box ) {
THREE.CollisionSystem = function() {
this.collisionNormal;
this.colliders = [];
this.hits = [];
@@ -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;
@@ -246,6 +251,8 @@ THREE.CollisionSystem.prototype.rayTriangle = function( ray, p0, p1, p2, n, mind
if( !(gamma >= 0) ) return Number.MAX_VALUE;
//console.log("gamma: " + gamma);
this.collisionNormal = n;
return t;
};