2014-08-08 11:16:33 +08:00
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +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-07-09 01:23:11 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-08 11:16:33 +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 11:16:33 +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 11:16:33 +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_RAY_H_
|
|
|
|
#define __AX_RAY_H_
|
2014-08-08 11:16:33 +08:00
|
|
|
|
|
|
|
#include "math/CCMath.h"
|
2014-08-29 15:39:52 +08:00
|
|
|
#include "3d/CCAABB.h"
|
|
|
|
#include "3d/CCOBB.h"
|
2014-12-16 16:34:35 +08:00
|
|
|
#include "3d/CCPlane.h"
|
2014-08-08 11:16:33 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2014-08-08 11:16:33 +08:00
|
|
|
|
2015-03-20 17:20:22 +08:00
|
|
|
/**
|
2015-03-27 14:10:41 +08:00
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Ray is a line with one end. usually use it to check intersects with some object,such as Plane, OBB, AABB
|
2015-03-28 15:11:51 +08:00
|
|
|
* @js NA
|
2015-03-20 17:20:22 +08:00
|
|
|
**/
|
2022-07-15 19:17:01 +08:00
|
|
|
class AX_DLL Ray
|
2014-08-08 11:16:33 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-03-30 15:47:47 +08:00
|
|
|
*
|
|
|
|
* @lua new
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
|
|
|
Ray();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor.
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
|
|
|
Ray(const Ray& ray);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-08 11:16:33 +08:00
|
|
|
/**
|
|
|
|
* Constructs a new ray initialized to the specified values.
|
|
|
|
*
|
|
|
|
* @param origin The ray's origin.
|
|
|
|
* @param direction The ray's direction.
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
|
|
|
Ray(const Vec3& origin, const Vec3& direction);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor.
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua NA
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
|
|
|
~Ray();
|
|
|
|
|
|
|
|
/**
|
2015-01-20 10:46:00 +08:00
|
|
|
* Check whether this ray intersects with the specified AABB.
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
2015-01-16 13:23:03 +08:00
|
|
|
bool intersects(const AABB& aabb, float* distance = nullptr) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-08 11:16:33 +08:00
|
|
|
/**
|
2015-01-20 10:46:00 +08:00
|
|
|
* Check whether this ray intersects with the specified OBB.
|
2014-08-08 11:16:33 +08:00
|
|
|
*/
|
2015-01-16 13:23:03 +08:00
|
|
|
bool intersects(const OBB& obb, float* distance = nullptr) const;
|
2014-08-08 11:16:33 +08:00
|
|
|
|
2014-12-16 16:34:35 +08:00
|
|
|
float dist(const Plane& plane) const;
|
2014-12-19 10:25:59 +08:00
|
|
|
Vec3 intersects(const Plane& plane) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-08-08 11:16:33 +08:00
|
|
|
/**
|
|
|
|
* Sets this ray to the specified values.
|
|
|
|
*
|
|
|
|
* @param origin The ray's origin.
|
|
|
|
* @param direction The ray's direction.
|
|
|
|
*/
|
|
|
|
void set(const Vec3& origin, const Vec3& direction);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transforms this ray by the given transformation matrix.
|
|
|
|
*
|
|
|
|
* @param matrix The transformation matrix to transform by.
|
|
|
|
*/
|
|
|
|
void transform(const Mat4& matrix);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Vec3 _origin; // The ray origin position.
|
|
|
|
Vec3 _direction; // The ray direction vector.
|
2014-08-08 11:16:33 +08:00
|
|
|
};
|
|
|
|
|
2015-04-01 10:23:53 +08:00
|
|
|
// end of 3d group
|
2015-03-27 14:10:41 +08:00
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2014-08-08 11:16:33 +08:00
|
|
|
|
|
|
|
#endif
|