2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-03-28 13:19:05 +01:00
|
|
|
/* shape_3d_sw.h */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
#ifndef SHAPE_SW_H
|
|
|
|
#define SHAPE_SW_H
|
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/geometry.h"
|
2020-03-27 19:21:27 +01:00
|
|
|
#include "servers/physics_server_3d.h"
|
2014-09-03 04:13:40 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
SHAPE_LINE, ///< plane:"plane"
|
2017-02-14 00:25:05 +01:00
|
|
|
SHAPE_SEGMENT, ///< real_t:"length"
|
|
|
|
SHAPE_CIRCLE, ///< real_t:"radius"
|
2014-09-03 04:13:40 +02:00
|
|
|
SHAPE_RECTANGLE, ///< vec3:"extents"
|
|
|
|
SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
|
|
|
|
SHAPE_CONCAVE_POLYGON, ///< Vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array)
|
|
|
|
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class Shape3DSW;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class ShapeOwner3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
public:
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void _shape_changed() = 0;
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual void remove_shape(Shape3DSW *p_shape) = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual ~ShapeOwner3DSW() {}
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
RID self;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2014-09-03 04:13:40 +02:00
|
|
|
bool configured;
|
|
|
|
real_t custom_bias;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
Map<ShapeOwner3DSW *, int> owners;
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
protected:
|
2017-11-17 03:09:00 +01:00
|
|
|
void configure(const AABB &p_aabb);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum {
|
2017-03-05 16:44:50 +01:00
|
|
|
MAX_SUPPORTS = 8
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual real_t get_area() const { return aabb.get_area(); }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
|
|
|
|
_FORCE_INLINE_ RID get_self() const { return self; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
_FORCE_INLINE_ AABB get_aabb() const { return aabb; }
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ bool is_configured() const { return configured; }
|
|
|
|
|
|
|
|
virtual bool is_concave() const { return false; }
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const = 0;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const = 0;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const = 0;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data) = 0;
|
|
|
|
virtual Variant get_data() const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
_FORCE_INLINE_ void set_custom_bias(real_t p_bias) { custom_bias = p_bias; }
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ real_t get_custom_bias() const { return custom_bias; }
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
void add_owner(ShapeOwner3DSW *p_owner);
|
|
|
|
void remove_owner(ShapeOwner3DSW *p_owner);
|
|
|
|
bool is_owner(ShapeOwner3DSW *p_owner) const;
|
|
|
|
const Map<ShapeOwner3DSW *, int> &get_owners() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
Shape3DSW();
|
|
|
|
virtual ~Shape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class ConcaveShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
public:
|
|
|
|
virtual bool is_concave() const { return true; }
|
2020-03-27 19:21:27 +01:00
|
|
|
typedef void (*Callback)(void *p_userdata, Shape3DSW *p_convex);
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const { r_amount = 0; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
virtual void cull(const AABB &p_local_aabb, Callback p_callback, void *p_userdata) const = 0;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
ConcaveShape3DSW() {}
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class PlaneShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
Plane plane;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Plane &p_plane);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
Plane get_plane() const;
|
|
|
|
|
2017-02-06 23:44:22 +01:00
|
|
|
virtual real_t get_area() const { return Math_INF; }
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_PLANE; }
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const { r_amount = 0; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
PlaneShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class RayShape3DSW : public Shape3DSW {
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t length;
|
2018-02-19 20:59:57 +01:00
|
|
|
bool slips_on_slope;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2018-02-19 20:59:57 +01:00
|
|
|
void _setup(real_t p_length, bool p_slips_on_slope);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t get_length() const;
|
2018-02-19 20:59:57 +01:00
|
|
|
bool get_slips_on_slope() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2016-12-31 15:39:25 +01:00
|
|
|
virtual real_t get_area() const { return 0.0; }
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_RAY; }
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
RayShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class SphereShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
real_t radius;
|
|
|
|
|
|
|
|
void _setup(real_t p_radius);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
real_t get_radius() const;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual real_t get_area() const { return 4.0 / 3.0 * Math_PI * radius * radius * radius; }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_SPHERE; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
SphereShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class BoxShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 half_extents;
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Vector3 &p_half_extents);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-09-03 04:13:40 +02:00
|
|
|
_FORCE_INLINE_ Vector3 get_half_extents() const { return half_extents; }
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual real_t get_area() const { return 8 * half_extents.x * half_extents.y * half_extents.z; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_BOX; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
BoxShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class CapsuleShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
real_t height;
|
|
|
|
real_t radius;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(real_t p_height, real_t p_radius);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
_FORCE_INLINE_ real_t get_height() const { return height; }
|
|
|
|
_FORCE_INLINE_ real_t get_radius() const { return radius; }
|
|
|
|
|
2018-03-22 03:58:40 +01:00
|
|
|
virtual real_t get_area() const { return 4.0 / 3.0 * Math_PI * radius * radius * radius + height * Math_PI * radius * radius; }
|
2016-12-31 15:39:25 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_CAPSULE; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
CapsuleShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
struct ConvexPolygonShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
Geometry::MeshData mesh;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _setup(const Vector<Vector3> &p_vertices);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
|
|
|
const Geometry::MeshData &get_mesh() const { return mesh; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
ConvexPolygonShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _VolumeSW_BVH;
|
2020-03-27 19:21:27 +01:00
|
|
|
struct FaceShape3DSW;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
struct ConcavePolygonShape3DSW : public ConcaveShape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
// always a trimesh
|
|
|
|
|
|
|
|
struct Face {
|
|
|
|
Vector3 normal;
|
|
|
|
int indices[3];
|
|
|
|
};
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Face> faces;
|
|
|
|
Vector<Vector3> vertices;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
struct BVH {
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2014-09-03 04:13:40 +02:00
|
|
|
int left;
|
|
|
|
int right;
|
|
|
|
|
|
|
|
int face_index;
|
|
|
|
};
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<BVH> bvh;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
|
|
|
struct _CullParams {
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2014-09-03 04:13:40 +02:00
|
|
|
Callback callback;
|
|
|
|
void *userdata;
|
|
|
|
const Face *faces;
|
|
|
|
const Vector3 *vertices;
|
|
|
|
const BVH *bvh;
|
2020-03-27 19:21:27 +01:00
|
|
|
FaceShape3DSW *face;
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _SegmentCullParams {
|
|
|
|
Vector3 from;
|
|
|
|
Vector3 to;
|
|
|
|
const Face *faces;
|
|
|
|
const Vector3 *vertices;
|
|
|
|
const BVH *bvh;
|
|
|
|
Vector3 dir;
|
|
|
|
|
|
|
|
Vector3 result;
|
|
|
|
Vector3 normal;
|
|
|
|
real_t min_d;
|
|
|
|
int collisions;
|
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _cull_segment(int p_idx, _SegmentCullParams *p_params) const;
|
|
|
|
void _cull(int p_idx, _CullParams *p_params) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void _fill_bvh(_VolumeSW_BVH *p_bvh_tree, BVH *p_bvh_array, int &p_idx);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void _setup(Vector<Vector3> p_faces);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> get_faces() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
virtual void cull(const AABB &p_local_aabb, Callback p_callback, void *p_userdata) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
ConcavePolygonShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
struct HeightMapShape3DSW : public ConcaveShape3DSW {
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<real_t> heights;
|
2014-09-03 04:13:40 +02:00
|
|
|
int width;
|
|
|
|
int depth;
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t cell_size;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//void _cull_segment(int p_idx,_SegmentCullParams *p_params) const;
|
|
|
|
//void _cull(int p_idx,_CullParams *p_params) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
void _setup(Vector<real_t> p_heights, int p_width, int p_depth, real_t p_cell_size);
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<real_t> get_heights() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
int get_width() const;
|
|
|
|
int get_depth() const;
|
2017-02-14 00:25:05 +01:00
|
|
|
real_t get_cell_size() const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_HEIGHTMAP; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
virtual Vector3 get_support(const Vector3 &p_normal) const;
|
2017-08-11 21:10:05 +02:00
|
|
|
virtual bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_point, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2017-11-17 03:09:00 +01:00
|
|
|
virtual void cull(const AABB &p_local_aabb, Callback p_callback, void *p_userdata) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
virtual Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data);
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
HeightMapShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//used internally
|
2020-03-27 19:21:27 +01:00
|
|
|
struct FaceShape3DSW : public Shape3DSW {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 normal; //cache
|
|
|
|
Vector3 vertex[3];
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_CONCAVE_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Vector3 &get_vertex(int p_idx) const { return vertex[p_idx]; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const;
|
|
|
|
Vector3 get_support(const Vector3 &p_normal) const;
|
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const;
|
|
|
|
bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const;
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const;
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
Vector3 get_moment_of_inertia(real_t p_mass) const;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data) {}
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const { return Variant(); }
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
FaceShape3DSW();
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
struct MotionShape3DSW : public Shape3DSW {
|
|
|
|
Shape3DSW *shape;
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 motion;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsServer3D::ShapeType get_type() const { return PhysicsServer3D::SHAPE_CONVEX_POLYGON; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
void project_range(const Vector3 &p_normal, const Transform &p_transform, real_t &r_min, real_t &r_max) const {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 cast = p_transform.basis.xform(motion);
|
2017-03-05 16:44:50 +01:00
|
|
|
real_t mina, maxa;
|
|
|
|
real_t minb, maxb;
|
2014-09-03 04:13:40 +02:00
|
|
|
Transform ofsb = p_transform;
|
2017-03-05 16:44:50 +01:00
|
|
|
ofsb.origin += cast;
|
|
|
|
shape->project_range(p_normal, p_transform, mina, maxa);
|
|
|
|
shape->project_range(p_normal, ofsb, minb, maxb);
|
|
|
|
r_min = MIN(mina, minb);
|
|
|
|
r_max = MAX(maxa, maxb);
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 get_support(const Vector3 &p_normal) const {
|
2014-09-03 04:13:40 +02:00
|
|
|
Vector3 support = shape->get_support(p_normal);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_normal.dot(motion) > 0) {
|
|
|
|
support += motion;
|
2014-09-03 04:13:40 +02:00
|
|
|
}
|
|
|
|
return support;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void get_supports(const Vector3 &p_normal, int p_max, Vector3 *r_supports, int &r_amount) const { r_amount = 0; }
|
|
|
|
bool intersect_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 &r_result, Vector3 &r_normal) const { return false; }
|
2017-07-15 06:23:10 +02:00
|
|
|
virtual bool intersect_point(const Vector3 &p_point) const { return false; }
|
|
|
|
virtual Vector3 get_closest_point_to(const Vector3 &p_point) const { return p_point; }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-02-14 00:25:05 +01:00
|
|
|
Vector3 get_moment_of_inertia(real_t p_mass) const { return Vector3(); }
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
virtual void set_data(const Variant &p_data) {}
|
2014-09-03 04:13:40 +02:00
|
|
|
virtual Variant get_data() const { return Variant(); }
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
MotionShape3DSW() { configure(AABB()); }
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
#endif // SHAPE_SW_H
|