2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +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
|
|
|
|
2019-11-23 20:27:39 +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
|
|
|
|
2019-11-23 20:27:39 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __PHYSICS_3D_SHAPE_H__
|
|
|
|
#define __PHYSICS_3D_SHAPE_H__
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "base/Ref.h"
|
|
|
|
#include "base/Config.h"
|
|
|
|
#include "math/Math.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#if AX_USE_3D_PHYSICS
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if (AX_ENABLE_BULLET_INTEGRATION)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
class btCollisionShape;
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup _3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Create a physical shape(box, sphere, cylinder, capsule, convexhull, mesh and heightfield)
|
|
|
|
*/
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_DLL Physics3DShape : public Ref
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class ShapeType
|
|
|
|
{
|
|
|
|
UNKNOWN = 0,
|
|
|
|
BOX,
|
|
|
|
SPHERE,
|
|
|
|
CYLINDER,
|
|
|
|
CAPSULE,
|
|
|
|
CONVEX,
|
|
|
|
MESH,
|
|
|
|
HEIGHT_FIELD,
|
|
|
|
COMPOUND
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* get shape type
|
|
|
|
*/
|
|
|
|
virtual ShapeType getShapeType() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* create box shape
|
|
|
|
* @param extent The extent of sphere.
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static Physics3DShape* createBox(const ax::Vec3& extent);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* create sphere shape
|
|
|
|
* @param radius The radius of sphere.
|
|
|
|
*/
|
|
|
|
static Physics3DShape* createSphere(float radius);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* create cylinder shape
|
|
|
|
* @param radius The radius of cylinder.
|
|
|
|
* @param height The height.
|
|
|
|
*/
|
|
|
|
static Physics3DShape* createCylinder(float radius, float height);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* create capsule shape
|
|
|
|
* @param radius The radius of capsule.
|
|
|
|
* @param height The height (cylinder part).
|
|
|
|
*/
|
|
|
|
static Physics3DShape* createCapsule(float radius, float height);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create convex hull
|
|
|
|
* @param points The vertices of convex hull
|
|
|
|
* @param numPoints The number of vertices.
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static Physics3DShape* createConvexHull(const ax::Vec3* points, int numPoints);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create mesh
|
|
|
|
* @param triangles The pointer of triangle list
|
|
|
|
* @param numTriangles The number of triangles.
|
|
|
|
*/
|
2022-08-08 18:02:17 +08:00
|
|
|
static Physics3DShape* createMesh(const ax::Vec3* triangles, int numTriangles);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create heightfield
|
|
|
|
* @param heightStickWidth The Width of heightfield
|
|
|
|
* @param heightStickLength The Length of heightfield.
|
|
|
|
* @param heightfieldData The Data of heightfield.
|
|
|
|
* @param minHeight The minHeight of heightfield.
|
|
|
|
* @param maxHeight The maxHeight of heightfield.
|
|
|
|
* @param flipQuadEdges if flip QuadEdges
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DShape* createHeightfield(int heightStickWidth,
|
|
|
|
int heightStickLength,
|
|
|
|
const void* heightfieldData,
|
|
|
|
float heightScale,
|
|
|
|
float minHeight,
|
|
|
|
float maxHeight,
|
|
|
|
bool useFloatDatam,
|
|
|
|
bool flipQuadEdges,
|
|
|
|
bool useDiamondSubdivision = false);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* create Compound Shape
|
|
|
|
* @param shapes The list of child shape
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static Physics3DShape* createCompoundShape(const std::vector<std::pair<Physics3DShape*, Mat4>>& shapes);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if AX_ENABLE_BULLET_INTEGRATION
|
2019-11-23 20:27:39 +08:00
|
|
|
btCollisionShape* getbtShape() const { return _btShape; }
|
2021-12-25 10:04:45 +08:00
|
|
|
# endif
|
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
Physics3DShape();
|
2019-11-23 20:27:39 +08:00
|
|
|
~Physics3DShape();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
bool initBox(const ax::Vec3& ext);
|
2019-11-23 20:27:39 +08:00
|
|
|
bool initSphere(float radius);
|
|
|
|
bool initCylinder(float radius, float height);
|
|
|
|
bool initCapsule(float radius, float height);
|
2022-08-08 18:02:17 +08:00
|
|
|
bool initConvexHull(const ax::Vec3* points, int numPoints);
|
|
|
|
bool initMesh(const ax::Vec3* triangles, int numTriangles);
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initHeightfield(int heightStickWidth,
|
|
|
|
int heightStickLength,
|
|
|
|
const void* heightfieldData,
|
|
|
|
float heightScale,
|
|
|
|
float minHeight,
|
|
|
|
float maxHeight,
|
|
|
|
bool useFloatDatam,
|
|
|
|
bool flipQuadEdges,
|
|
|
|
bool useDiamondSubdivision);
|
|
|
|
bool initCompoundShape(const std::vector<std::pair<Physics3DShape*, Mat4>>& shapes);
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
ShapeType _shapeType; // shape type
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# if (AX_ENABLE_BULLET_INTEGRATION)
|
2021-12-25 10:04:45 +08:00
|
|
|
btCollisionShape* _btShape;
|
|
|
|
unsigned char* _heightfieldData;
|
|
|
|
std::vector<Physics3DShape*> _compoundChildShapes;
|
|
|
|
# endif
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// end of 3d group
|
|
|
|
/// @}
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
# endif // AX_ENABLE_BULLET_INTEGRATION
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#endif // AX_USE_3D_PHYSICS
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __PHYSICS_3D_SHAPE_H__
|