2017-11-04 20:52:59 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* shape_bullet.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2018-01-05 00:50:27 +01:00
|
|
|
/* https://godotengine.org */
|
2017-11-04 20:52:59 +01:00
|
|
|
/*************************************************************************/
|
2022-01-03 21:27:34 +01:00
|
|
|
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
|
2017-11-04 20:52:59 +01: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: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* 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 SHAPE_BULLET_H
|
|
|
|
#define SHAPE_BULLET_H
|
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
#include "core/math/geometry_3d.h"
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/variant/variant.h"
|
2017-11-04 20:52:59 +01:00
|
|
|
#include "rid_bullet.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/physics_server_3d.h"
|
2017-11-04 20:52:59 +01:00
|
|
|
|
2018-01-05 00:50:27 +01:00
|
|
|
#include <LinearMath/btAlignedObjectArray.h>
|
|
|
|
#include <LinearMath/btScalar.h>
|
|
|
|
#include <LinearMath/btVector3.h>
|
|
|
|
|
2017-11-04 20:52:59 +01:00
|
|
|
class ShapeBullet;
|
|
|
|
class btCollisionShape;
|
|
|
|
class ShapeOwnerBullet;
|
|
|
|
class btBvhTriangleMeshShape;
|
|
|
|
|
|
|
|
class ShapeBullet : public RIDBullet {
|
|
|
|
Map<ShapeOwnerBullet *, int> owners;
|
2020-05-12 17:01:17 +02:00
|
|
|
real_t margin = 0.04;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// return self
|
|
|
|
btCollisionShape *prepare(btCollisionShape *p_btShape) const;
|
|
|
|
void notifyShapeChanged();
|
|
|
|
|
|
|
|
public:
|
|
|
|
ShapeBullet();
|
|
|
|
virtual ~ShapeBullet();
|
|
|
|
|
2018-07-10 14:50:14 +02:00
|
|
|
btCollisionShape *create_bt_shape(const Vector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0) = 0;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
void add_owner(ShapeOwnerBullet *p_owner);
|
|
|
|
void remove_owner(ShapeOwnerBullet *p_owner, bool p_permanentlyFromThisBody = false);
|
|
|
|
bool is_owner(ShapeOwnerBullet *p_owner) const;
|
|
|
|
const Map<ShapeOwnerBullet *, int> &get_owners() const;
|
|
|
|
|
2018-07-10 14:50:14 +02:00
|
|
|
void set_margin(real_t p_margin);
|
|
|
|
real_t get_margin() const;
|
|
|
|
|
2017-11-04 20:52:59 +01:00
|
|
|
/// Setup the shape
|
|
|
|
virtual void set_data(const Variant &p_data) = 0;
|
|
|
|
virtual Variant get_data() const = 0;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const = 0;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
static class btEmptyShape *create_shape_empty();
|
2021-09-14 19:52:35 +02:00
|
|
|
static class btStaticPlaneShape *create_shape_world_boundary(const btVector3 &planeNormal, btScalar planeConstant);
|
2017-11-04 20:52:59 +01:00
|
|
|
static class btSphereShape *create_shape_sphere(btScalar radius);
|
|
|
|
static class btBoxShape *create_shape_box(const btVector3 &boxHalfExtents);
|
2020-02-23 19:41:31 +01:00
|
|
|
static class btCapsuleShape *create_shape_capsule(btScalar radius, btScalar height);
|
2018-06-13 00:53:28 +02:00
|
|
|
static class btCylinderShape *create_shape_cylinder(btScalar radius, btScalar height);
|
2017-11-04 20:52:59 +01:00
|
|
|
/// IMPORTANT: Remember to delete the shape interface by calling: delete my_shape->getMeshInterface();
|
|
|
|
static class btConvexPointCloudShape *create_shape_convex(btAlignedObjectArray<btVector3> &p_vertices, const btVector3 &p_local_scaling = btVector3(1, 1, 1));
|
|
|
|
static class btScaledBvhTriangleMeshShape *create_shape_concave(btBvhTriangleMeshShape *p_mesh_shape, const btVector3 &p_local_scaling = btVector3(1, 1, 1));
|
2021-03-25 02:49:04 +01:00
|
|
|
static class btHeightfieldTerrainShape *create_shape_height_field(Vector<float> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height);
|
2018-02-19 20:59:57 +01:00
|
|
|
static class btRayShape *create_shape_ray(real_t p_length, bool p_slips_on_slope);
|
2017-11-04 20:52:59 +01:00
|
|
|
};
|
|
|
|
|
2021-09-14 19:52:35 +02:00
|
|
|
class WorldBoundaryShapeBullet : public ShapeBullet {
|
2017-11-04 20:52:59 +01:00
|
|
|
Plane plane;
|
|
|
|
|
|
|
|
public:
|
2021-09-14 19:52:35 +02:00
|
|
|
WorldBoundaryShapeBullet();
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(const Plane &p_plane);
|
|
|
|
};
|
|
|
|
|
|
|
|
class SphereShapeBullet : public ShapeBullet {
|
2022-01-31 18:42:32 +01:00
|
|
|
real_t radius = 0.0;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
SphereShapeBullet();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ real_t get_radius() { return radius; }
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(real_t p_radius);
|
|
|
|
};
|
|
|
|
|
|
|
|
class BoxShapeBullet : public ShapeBullet {
|
|
|
|
btVector3 half_extents;
|
|
|
|
|
|
|
|
public:
|
|
|
|
BoxShapeBullet();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ const btVector3 &get_half_extents() { return half_extents; }
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(const Vector3 &p_half_extents);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CapsuleShapeBullet : public ShapeBullet {
|
2022-01-31 18:42:32 +01:00
|
|
|
real_t height = 0.0;
|
|
|
|
real_t radius = 0.0;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
CapsuleShapeBullet();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ real_t get_height() { return height; }
|
|
|
|
_FORCE_INLINE_ real_t get_radius() { return radius; }
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(real_t p_height, real_t p_radius);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CylinderShapeBullet : public ShapeBullet {
|
2022-01-31 18:42:32 +01:00
|
|
|
real_t height = 0.0;
|
|
|
|
real_t radius = 0.0;
|
2018-06-13 00:53:28 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
CylinderShapeBullet();
|
|
|
|
|
|
|
|
_FORCE_INLINE_ real_t get_height() { return height; }
|
|
|
|
_FORCE_INLINE_ real_t get_radius() { return radius; }
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_margin = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(real_t p_height, real_t p_radius);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConvexPolygonShapeBullet : public ShapeBullet {
|
|
|
|
public:
|
|
|
|
btAlignedObjectArray<btVector3> vertices;
|
|
|
|
|
|
|
|
ConvexPolygonShapeBullet();
|
|
|
|
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
void get_vertices(Vector<Vector3> &out_vertices);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setup(const Vector<Vector3> &p_vertices);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ConcavePolygonShapeBullet : public ShapeBullet {
|
2020-05-12 17:01:17 +02:00
|
|
|
class btBvhTriangleMeshShape *meshShape = nullptr;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
public:
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> faces;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
ConcavePolygonShapeBullet();
|
|
|
|
virtual ~ConcavePolygonShapeBullet();
|
|
|
|
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
2020-02-17 22:06:54 +01:00
|
|
|
void setup(Vector<Vector3> p_faces);
|
2017-11-04 20:52:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class HeightMapShapeBullet : public ShapeBullet {
|
|
|
|
public:
|
2021-03-25 02:49:04 +01:00
|
|
|
Vector<float> heights;
|
2021-02-08 10:57:18 +01:00
|
|
|
int width = 0;
|
|
|
|
int depth = 0;
|
|
|
|
real_t min_height = 0.0;
|
|
|
|
real_t max_height = 0.0;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
HeightMapShapeBullet();
|
|
|
|
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
2021-03-25 02:49:04 +01:00
|
|
|
void setup(Vector<float> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height);
|
2017-11-04 20:52:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class RayShapeBullet : public ShapeBullet {
|
|
|
|
public:
|
2021-02-08 10:57:18 +01:00
|
|
|
real_t length = 1.0;
|
2020-05-12 17:01:17 +02:00
|
|
|
bool slips_on_slope = false;
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
RayShapeBullet();
|
|
|
|
|
|
|
|
virtual void set_data(const Variant &p_data);
|
|
|
|
virtual Variant get_data() const;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const;
|
2020-10-08 12:22:59 +02:00
|
|
|
virtual btCollisionShape *create_bt_shape(const btVector3 &p_implicit_scale, real_t p_extra_edge = 0);
|
2017-11-04 20:52:59 +01:00
|
|
|
|
|
|
|
private:
|
2018-02-19 20:59:57 +01:00
|
|
|
void setup(real_t p_length, bool p_slips_on_slope);
|
2017-11-04 20:52:59 +01:00
|
|
|
};
|
2022-01-04 20:26:22 +01:00
|
|
|
|
|
|
|
#endif // SHAPE_BULLET_H
|