1 /** 2 Copyright (c) 2008-2010 Ricardo Quesada 3 Copyright (c) 2011-2012 cocos2d-x.org 4 Copyright (c) 2013-2014 Chukong Technologies Inc. 5 Copyright (c) 2008, Luke Benstead. 6 All rights reserved. 7 8 Redistribution and use in source and binary forms, with or without modification, 9 are permitted provided that the following conditions are met: 10 11 Redistributions of source code must retain the above copyright notice, 12 this list of conditions and the following disclaimer. 13 Redistributions in binary form must reproduce the above copyright notice, 14 this list of conditions and the following disclaimer in the documentation 15 and/or other materials provided with the distribution. 16 17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 /** 30 * A struture that represents an axis-aligned 31 * bounding box. 32 */ 33 cc.kmAABB = function (min, max) { 34 /** The max corner of the box */ 35 this.min = min || new cc.kmVec3(); 36 /** The min corner of the box */ 37 this.max = max || new cc.kmVec3(); 38 }; 39 40 /** 41 * Returns KM_TRUE if point is in the specified AABB, returns 42 * KM_FALSE otherwise. 43 */ 44 cc.kmAABBContainsPoint = function (pPoint, pBox) { 45 if (pPoint.x >= pBox.min.x && pPoint.x <= pBox.max.x && 46 pPoint.y >= pBox.min.y && pPoint.y <= pBox.max.y && 47 pPoint.z >= pBox.min.z && pPoint.z <= pBox.max.z) { 48 return cc.KM_TRUE; 49 } 50 return cc.KM_FALSE; 51 }; 52 53 /** 54 * Assigns pIn to pOut, returns pOut. 55 */ 56 cc.kmAABBAssign = function (pOut, pIn) { 57 cc.kmVec3Assign(pOut.min, pIn.min); 58 cc.kmVec3Assign(pOut.max, pIn.max); 59 return pOut; 60 }; 61 62 /** 63 * Scales pIn by s, stores the resulting AABB in pOut. Returns pOut 64 */ 65 cc.kmAABBScale = function (pOut, pIn, s) { 66 cc.log("cc.kmAABBScale hasn't been supported."); 67 }; 68 69