diff --git a/src/shapes/ConvexPolyhedron.js b/src/shapes/ConvexPolyhedron.js index 841727350..2cd10fd1d 100644 --- a/src/shapes/ConvexPolyhedron.js +++ b/src/shapes/ConvexPolyhedron.js @@ -731,7 +731,7 @@ var tempWorldVertex = new Vec3(); * @param {Vec3} min * @param {Vec3} max */ -ConvexPolyhedron.prototype.calculateWorldAABB = function(pos,quat,min,max){ + ConvexPolyhedron.prototype.calculateWorldAABB = function(pos,quat,min,max){ var n = this.vertices.length, verts = this.vertices; var minx,miny,minz,maxx,maxy,maxz; for(var i=0; i maxx || maxx===undefined){ + } + + if(v.x > maxx || maxx===undefined){ maxx = v.x; } if (v.y < miny || miny===undefined){ miny = v.y; - } else if(v.y > maxy || maxy===undefined){ + } + + if(v.y > maxy || maxy===undefined){ maxy = v.y; } if (v.z < minz || minz===undefined){ minz = v.z; - } else if(v.z > maxz || maxz===undefined){ + } + + if(v.z > maxz || maxz===undefined){ maxz = v.z; } } diff --git a/test/ConvexPolyhedron.js b/test/ConvexPolyhedron.js index fd79be8d2..f2c797e38 100644 --- a/test/ConvexPolyhedron.js +++ b/test/ConvexPolyhedron.js @@ -26,6 +26,41 @@ module.exports = { test.done(); }, + calculateWorldAABBAlwaysDecreasingVertsNoUndefined: function(test) { + var vertices = [ + new Vec3( 4, 4, 4), + new Vec3( 3, 3, 3), + new Vec3( 2, 2, 2), + new Vec3( 1, 1, 1), + new Vec3( 0, 0, 0), + new Vec3(-1,-1,-1), + new Vec3(-2,-2,-2), + new Vec3(-3,-3,-3) + ]; + + var indices = [ + [3,2,1,0], + [4,5,6,7], + [5,4,0,1], + [2,3,7,6], + [0,4,7,3], + [1,2,6,5], + ]; + + var poly = new ConvexPolyhedron(vertices, indices); + var min = new Vec3(); + var max = new Vec3(); + poly.calculateWorldAABB(new Vec3(0, 0, 0), new Quaternion(0, 0, 0, 1), min, max); + + test.notEqual(min.x, undefined); + test.notEqual(max.x, undefined); + test.notEqual(min.y, undefined); + test.notEqual(max.y, undefined); + test.notEqual(min.z, undefined); + test.notEqual(max.z, undefined); + test.done(); + }, + clipFaceAgainstPlane : function(test){ var h = createBoxHull();