godot_shape_3d.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. /**************************************************************************/
  2. /* godot_shape_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef GODOT_SHAPE_3D_H
  31. #define GODOT_SHAPE_3D_H
  32. #include "core/math/geometry_3d.h"
  33. #include "core/templates/local_vector.h"
  34. #include "servers/physics_server_3d.h"
  35. class GodotShape3D;
  36. class GodotShapeOwner3D {
  37. public:
  38. virtual void _shape_changed() = 0;
  39. virtual void remove_shape(GodotShape3D *p_shape) = 0;
  40. virtual ~GodotShapeOwner3D() {}
  41. };
  42. class GodotShape3D {
  43. RID self;
  44. AABB aabb;
  45. bool configured = false;
  46. real_t custom_bias = 0.0;
  47. HashMap<GodotShapeOwner3D *, int> owners;
  48. protected:
  49. void configure(const AABB &p_aabb);
  50. public:
  51. enum FeatureType {
  52. FEATURE_POINT,
  53. FEATURE_EDGE,
  54. FEATURE_FACE,
  55. FEATURE_CIRCLE,
  56. };
  57. virtual real_t get_volume() const { return aabb.get_volume(); }
  58. _FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
  59. _FORCE_INLINE_ RID get_self() const { return self; }
  60. virtual PhysicsServer3D::ShapeType get_type() const = 0;
  61. _FORCE_INLINE_ const AABB &get_aabb() const { return aabb; }
  62. _FORCE_INLINE_ bool is_configured() const { return configured; }
  63. virtual bool is_concave() const { return false; }
  64. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const = 0;
  65. virtual Vector3 get_support(const Vector3 &p_normal) const;
  66. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const = 0;
  67. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const = 0;
  68. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const = 0;
  69. virtual bool intersect_point(const Vector3 &p_point) const = 0;
  70. virtual Vector3 get_moment_of_inertia(real_t p_mass) const = 0;
  71. virtual void set_data(const Variant &p_data) = 0;
  72. virtual Variant get_data() const = 0;
  73. _FORCE_INLINE_ void set_custom_bias(real_t p_bias) { custom_bias = p_bias; }
  74. _FORCE_INLINE_ real_t get_custom_bias() const { return custom_bias; }
  75. void add_owner(GodotShapeOwner3D *p_owner);
  76. void remove_owner(GodotShapeOwner3D *p_owner);
  77. bool is_owner(GodotShapeOwner3D *p_owner) const;
  78. const HashMap<GodotShapeOwner3D *, int> &get_owners() const;
  79. GodotShape3D() {}
  80. virtual ~GodotShape3D();
  81. };
  82. class GodotConcaveShape3D : public GodotShape3D {
  83. public:
  84. virtual bool is_concave() const override { return true; }
  85. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
  86. // Returns true to stop the query.
  87. typedef bool (*QueryCallback)(void *p_userdata, GodotShape3D *p_convex);
  88. virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata, bool p_invert_backface_collision) const = 0;
  89. GodotConcaveShape3D() {}
  90. };
  91. class GodotWorldBoundaryShape3D : public GodotShape3D {
  92. Plane plane;
  93. void _setup(const Plane &p_plane);
  94. public:
  95. Plane get_plane() const;
  96. virtual real_t get_volume() const override { return INFINITY; }
  97. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_WORLD_BOUNDARY; }
  98. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  99. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  100. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
  101. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  102. virtual bool intersect_point(const Vector3 &p_point) const override;
  103. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  104. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  105. virtual void set_data(const Variant &p_data) override;
  106. virtual Variant get_data() const override;
  107. GodotWorldBoundaryShape3D();
  108. };
  109. class GodotSeparationRayShape3D : public GodotShape3D {
  110. real_t length = 1.0;
  111. bool slide_on_slope = false;
  112. void _setup(real_t p_length, bool p_slide_on_slope);
  113. public:
  114. real_t get_length() const;
  115. bool get_slide_on_slope() const;
  116. virtual real_t get_volume() const override { return 0.0; }
  117. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SEPARATION_RAY; }
  118. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  119. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  120. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  121. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  122. virtual bool intersect_point(const Vector3 &p_point) const override;
  123. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  124. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  125. virtual void set_data(const Variant &p_data) override;
  126. virtual Variant get_data() const override;
  127. GodotSeparationRayShape3D();
  128. };
  129. class GodotSphereShape3D : public GodotShape3D {
  130. real_t radius = 0.0;
  131. void _setup(real_t p_radius);
  132. public:
  133. real_t get_radius() const;
  134. virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
  135. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_SPHERE; }
  136. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  137. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  138. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  139. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  140. virtual bool intersect_point(const Vector3 &p_point) const override;
  141. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  142. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  143. virtual void set_data(const Variant &p_data) override;
  144. virtual Variant get_data() const override;
  145. GodotSphereShape3D();
  146. };
  147. class GodotBoxShape3D : public GodotShape3D {
  148. Vector3 half_extents;
  149. void _setup(const Vector3 &p_half_extents);
  150. public:
  151. _FORCE_INLINE_ Vector3 get_half_extents() const { return half_extents; }
  152. virtual real_t get_volume() const override { return 8 * half_extents.x * half_extents.y * half_extents.z; }
  153. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_BOX; }
  154. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  155. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  156. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  157. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  158. virtual bool intersect_point(const Vector3 &p_point) const override;
  159. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  160. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  161. virtual void set_data(const Variant &p_data) override;
  162. virtual Variant get_data() const override;
  163. GodotBoxShape3D();
  164. };
  165. class GodotCapsuleShape3D : public GodotShape3D {
  166. real_t height = 0.0;
  167. real_t radius = 0.0;
  168. void _setup(real_t p_height, real_t p_radius);
  169. public:
  170. _FORCE_INLINE_ real_t get_height() const { return height; }
  171. _FORCE_INLINE_ real_t get_radius() const { return radius; }
  172. virtual real_t get_volume() const override { return 4.0 / 3.0 * Math_PI * radius * radius * radius + (height - radius * 2.0) * Math_PI * radius * radius; }
  173. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CAPSULE; }
  174. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  175. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  176. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  177. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  178. virtual bool intersect_point(const Vector3 &p_point) const override;
  179. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  180. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  181. virtual void set_data(const Variant &p_data) override;
  182. virtual Variant get_data() const override;
  183. GodotCapsuleShape3D();
  184. };
  185. class GodotCylinderShape3D : public GodotShape3D {
  186. real_t height = 0.0;
  187. real_t radius = 0.0;
  188. void _setup(real_t p_height, real_t p_radius);
  189. public:
  190. _FORCE_INLINE_ real_t get_height() const { return height; }
  191. _FORCE_INLINE_ real_t get_radius() const { return radius; }
  192. virtual real_t get_volume() const override { return height * Math_PI * radius * radius; }
  193. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CYLINDER; }
  194. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  195. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  196. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  197. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  198. virtual bool intersect_point(const Vector3 &p_point) const override;
  199. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  200. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  201. virtual void set_data(const Variant &p_data) override;
  202. virtual Variant get_data() const override;
  203. GodotCylinderShape3D();
  204. };
  205. struct GodotConvexPolygonShape3D : public GodotShape3D {
  206. Geometry3D::MeshData mesh;
  207. LocalVector<int> extreme_vertices;
  208. LocalVector<LocalVector<int>> vertex_neighbors;
  209. void _setup(const Vector<Vector3> &p_vertices);
  210. public:
  211. const Geometry3D::MeshData &get_mesh() const { return mesh; }
  212. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
  213. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  214. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  215. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  216. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  217. virtual bool intersect_point(const Vector3 &p_point) const override;
  218. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  219. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  220. virtual void set_data(const Variant &p_data) override;
  221. virtual Variant get_data() const override;
  222. GodotConvexPolygonShape3D();
  223. };
  224. struct _Volume_BVH;
  225. struct GodotFaceShape3D;
  226. struct GodotConcavePolygonShape3D : public GodotConcaveShape3D {
  227. // always a trimesh
  228. struct Face {
  229. Vector3 normal;
  230. int indices[3] = {};
  231. };
  232. Vector<Face> faces;
  233. Vector<Vector3> vertices;
  234. struct BVH {
  235. AABB aabb;
  236. int left = 0;
  237. int right = 0;
  238. int face_index = 0;
  239. };
  240. Vector<BVH> bvh;
  241. struct _CullParams {
  242. AABB aabb;
  243. QueryCallback callback = nullptr;
  244. void *userdata = nullptr;
  245. const Face *faces = nullptr;
  246. const Vector3 *vertices = nullptr;
  247. const BVH *bvh = nullptr;
  248. GodotFaceShape3D *face = nullptr;
  249. };
  250. struct _SegmentCullParams {
  251. Vector3 from;
  252. Vector3 to;
  253. Vector3 dir;
  254. const Face *faces = nullptr;
  255. const Vector3 *vertices = nullptr;
  256. const BVH *bvh = nullptr;
  257. GodotFaceShape3D *face = nullptr;
  258. Vector3 result;
  259. Vector3 normal;
  260. int face_index = -1;
  261. real_t min_d = 1e20;
  262. int collisions = 0;
  263. };
  264. bool backface_collision = false;
  265. void _cull_segment(int p_idx, _SegmentCullParams *p_params) const;
  266. bool _cull(int p_idx, _CullParams *p_params) const;
  267. void _fill_bvh(_Volume_BVH *p_bvh_tree, BVH *p_bvh_array, int &p_idx);
  268. void _setup(const Vector<Vector3> &p_faces, bool p_backface_collision);
  269. public:
  270. Vector<Vector3> get_faces() const;
  271. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
  272. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  273. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  274. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  275. virtual bool intersect_point(const Vector3 &p_point) const override;
  276. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  277. virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata, bool p_invert_backface_collision) const override;
  278. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  279. virtual void set_data(const Variant &p_data) override;
  280. virtual Variant get_data() const override;
  281. GodotConcavePolygonShape3D();
  282. };
  283. struct GodotHeightMapShape3D : public GodotConcaveShape3D {
  284. Vector<real_t> heights;
  285. int width = 0;
  286. int depth = 0;
  287. Vector3 local_origin;
  288. // Accelerator.
  289. struct Range {
  290. real_t min = 0.0;
  291. real_t max = 0.0;
  292. };
  293. LocalVector<Range> bounds_grid;
  294. int bounds_grid_width = 0;
  295. int bounds_grid_depth = 0;
  296. static const int BOUNDS_CHUNK_SIZE = 16;
  297. _FORCE_INLINE_ const Range &_get_bounds_chunk(int p_x, int p_z) const {
  298. return bounds_grid[(p_z * bounds_grid_width) + p_x];
  299. }
  300. _FORCE_INLINE_ real_t _get_height(int p_x, int p_z) const {
  301. return heights[(p_z * width) + p_x];
  302. }
  303. _FORCE_INLINE_ void _get_point(int p_x, int p_z, Vector3 &r_point) const {
  304. r_point.x = p_x - 0.5 * (width - 1.0);
  305. r_point.y = _get_height(p_x, p_z);
  306. r_point.z = p_z - 0.5 * (depth - 1.0);
  307. }
  308. void _get_cell(const Vector3 &p_point, int &r_x, int &r_y, int &r_z) const;
  309. void _build_accelerator();
  310. template <typename ProcessFunction>
  311. bool _intersect_grid_segment(ProcessFunction &p_process, const Vector3 &p_begin, const Vector3 &p_end, int p_width, int p_depth, const Vector3 &offset, Vector3 &r_point, Vector3 &r_normal) const;
  312. void _setup(const Vector<real_t> &p_heights, int p_width, int p_depth, real_t p_min_height, real_t p_max_height);
  313. public:
  314. Vector<real_t> get_heights() const;
  315. int get_width() const;
  316. int get_depth() const;
  317. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_HEIGHTMAP; }
  318. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  319. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  320. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  321. virtual bool intersect_point(const Vector3 &p_point) const override;
  322. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  323. virtual void cull(const AABB &p_local_aabb, QueryCallback p_callback, void *p_userdata, bool p_invert_backface_collision) const override;
  324. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  325. virtual void set_data(const Variant &p_data) override;
  326. virtual Variant get_data() const override;
  327. GodotHeightMapShape3D();
  328. };
  329. //used internally
  330. struct GodotFaceShape3D : public GodotShape3D {
  331. Vector3 normal; //cache
  332. Vector3 vertex[3];
  333. bool backface_collision = false;
  334. bool invert_backface_collision = false;
  335. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
  336. const Vector3 &get_vertex(int p_idx) const { return vertex[p_idx]; }
  337. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override;
  338. virtual Vector3 get_support(const Vector3 &p_normal) const override;
  339. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override;
  340. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override;
  341. virtual bool intersect_point(const Vector3 &p_point) const override;
  342. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override;
  343. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override;
  344. virtual void set_data(const Variant &p_data) override {}
  345. virtual Variant get_data() const override { return Variant(); }
  346. GodotFaceShape3D();
  347. };
  348. struct GodotMotionShape3D : public GodotShape3D {
  349. GodotShape3D *shape = nullptr;
  350. Vector3 motion;
  351. virtual PhysicsServer3D::ShapeType get_type() const override { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
  352. virtual void project_range(const Vector3 &p_normal, const Transform3D &p_transform, real_t &r_min, real_t &r_max) const override {
  353. Vector3 cast = p_transform.basis.xform(motion);
  354. real_t mina, maxa;
  355. real_t minb, maxb;
  356. Transform3D ofsb = p_transform;
  357. ofsb.origin += cast;
  358. shape->project_range(p_normal, p_transform, mina, maxa);
  359. shape->project_range(p_normal, ofsb, minb, maxb);
  360. r_min = MIN(mina, minb);
  361. r_max = MAX(maxa, maxb);
  362. }
  363. virtual Vector3 get_support(const Vector3 &p_normal) const override {
  364. Vector3 support = shape->get_support(p_normal);
  365. if (p_normal.dot(motion) > 0) {
  366. support += motion;
  367. }
  368. return support;
  369. }
  370. virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount, FeatureType &r_type) const override { r_amount = 0; }
  371. virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal, int &r_face_index, bool p_hit_back_faces) const override { return false; }
  372. virtual bool intersect_point(const Vector3 &p_point) const override { return false; }
  373. virtual Vector3 get_closest_point_to(const Vector3 &p_point) const override { return p_point; }
  374. virtual Vector3 get_moment_of_inertia(real_t p_mass) const override { return Vector3(); }
  375. virtual void set_data(const Variant &p_data) override {}
  376. virtual Variant get_data() const override { return Variant(); }
  377. GodotMotionShape3D() { configure(AABB()); }
  378. };
  379. #endif // GODOT_SHAPE_3D_H