axmol/core/3d/CCAABB.h

129 lines
3.4 KiB
C
Raw Normal View History

2014-08-08 00:00:58 +08:00
/****************************************************************************
Copyright (c) 2014-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2021-12-25 10:04:45 +08:00
2022-08-08 18:02:17 +08:00
https://axys1.github.io/
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
2022-07-15 19:17:01 +08:00
#ifndef __AX_AABB_H__
#define __AX_AABB_H__
2014-08-08 00:00:58 +08:00
#include "base/ccMacros.h"
#include "math/CCMath.h"
NS_AX_BEGIN
2014-08-08 00:00:58 +08:00
2015-03-27 14:10:41 +08:00
/**
* @addtogroup _3d
* @{
*/
2015-03-20 17:20:22 +08:00
/**
2015-09-09 11:37:41 +08:00
* Axis Aligned Bounding Box (AABB), usually calculate some rough but fast collision detection.
2015-03-20 17:20:22 +08:00
*/
2022-07-15 19:17:01 +08:00
class AX_DLL AABB
2014-08-08 00:00:58 +08:00
{
public:
/**
* Constructor.
2015-03-30 15:47:47 +08:00
* @lua new
2014-08-08 00:00:58 +08:00
*/
AABB();
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
/**
* Constructor.
2015-03-30 15:47:47 +08:00
* @lua new
2014-08-08 00:00:58 +08:00
*/
AABB(const Vec3& min, const Vec3& max);
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
/**
* Gets the center point of the bounding box.
*/
Vec3 getCenter();
/* Near face, specified counter-clockwise looking towards the origin from the positive z-axis.
* verts[0] : left top front
* verts[1] : left bottom front
* verts[2] : right bottom front
* verts[3] : right top front
*
* Far face, specified counter-clockwise looking towards the origin from the negative z-axis.
* verts[4] : right top back
* verts[5] : right bottom back
* verts[6] : left bottom back
* verts[7] : left top back
*/
2021-12-25 10:04:45 +08:00
void getCorners(Vec3* dst) const;
2014-08-08 00:00:58 +08:00
/**
* Tests whether this bounding box intersects the specified bounding object.
*/
bool intersects(const AABB& aabb) const;
/**
* check whether the point is in.
*/
bool containPoint(const Vec3& point) const;
/**
* Sets this bounding box to the smallest bounding box
* that contains both this bounding object and the specified bounding box.
*/
void merge(const AABB& box);
/**
* Sets this bounding box to the specified values.
*/
void set(const Vec3& min, const Vec3& max);
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
/**
2015-03-20 17:20:22 +08:00
* Reset min and max value.If you invoke this method, isEmpty() shall return true.
2014-08-08 00:00:58 +08:00
*/
void reset();
2021-12-25 10:04:45 +08:00
2015-03-20 17:20:22 +08:00
/**
* check the AABB object is empty(reset).
*/
2014-08-18 17:02:13 +08:00
bool isEmpty() const;
2014-08-08 00:00:58 +08:00
/**
* update the _min and _max from the given point.
*/
void updateMinMax(const Vec3* point, ssize_t num);
2021-12-25 10:04:45 +08:00
2014-08-08 00:00:58 +08:00
/**
* Transforms the bounding box by the given transformation matrix.
*/
2014-08-11 10:40:34 +08:00
void transform(const Mat4& mat);
2014-08-08 00:00:58 +08:00
public:
Vec3 _min;
Vec3 _max;
};
2015-04-01 10:23:53 +08:00
// end of 3d group
2015-03-27 14:10:41 +08:00
/// @}
NS_AX_END
2014-08-08 00:00:58 +08:00
#endif