aabb.js 2.3 KB

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