2015-10-08 18:00:40 +00:00
|
|
|
/*************************************************************************/
|
2020-03-28 12:19:05 +00:00
|
|
|
/* space_3d_sw.h */
|
2015-10-08 18:00:40 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:16:55 +00:00
|
|
|
/* https://godotengine.org */
|
2015-10-08 18:00:40 +00:00
|
|
|
/*************************************************************************/
|
2021-01-01 19:13:46 +00:00
|
|
|
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
|
2015-10-08 18:00:40 +00: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-04 23:50:27 +00:00
|
|
|
|
2015-10-08 18:00:40 +00:00
|
|
|
#ifndef SPACE_SW_H
|
|
|
|
#define SPACE_SW_H
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
#include "area_3d_sw.h"
|
|
|
|
#include "area_pair_3d_sw.h"
|
|
|
|
#include "body_3d_sw.h"
|
|
|
|
#include "body_pair_3d_sw.h"
|
|
|
|
#include "broad_phase_3d_sw.h"
|
|
|
|
#include "collision_object_3d_sw.h"
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/config/project_settings.h"
|
|
|
|
#include "core/templates/hash_map.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/typedefs.h"
|
2021-03-12 03:33:46 +00:00
|
|
|
#include "soft_body_3d_sw.h"
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
class PhysicsDirectSpaceState3DSW : public PhysicsDirectSpaceState3D {
|
|
|
|
GDCLASS(PhysicsDirectSpaceState3DSW, PhysicsDirectSpaceState3D);
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2020-03-27 18:21:27 +00:00
|
|
|
Space3DSW *space;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-08-30 23:29:16 +00:00
|
|
|
virtual int intersect_point(const Vector3 &p_point, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override;
|
|
|
|
virtual bool intersect_ray(const Vector3 &p_from, const Vector3 &p_to, RayResult &r_result, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, bool p_pick_ray = false) override;
|
|
|
|
virtual int intersect_shape(const RID &p_shape, const Transform3D &p_xform, real_t p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override;
|
|
|
|
virtual bool cast_motion(const RID &p_shape, const Transform3D &p_xform, const Vector3 &p_motion, real_t p_margin, real_t &p_closest_safe, real_t &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false, ShapeRestInfo *r_info = nullptr) override;
|
|
|
|
virtual bool collide_shape(RID p_shape, const Transform3D &p_shape_xform, real_t p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override;
|
|
|
|
virtual bool rest_info(RID p_shape, const Transform3D &p_shape_xform, real_t p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_collision_mask = UINT32_MAX, bool p_collide_with_bodies = true, bool p_collide_with_areas = false) override;
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Vector3 get_closest_point_to_object_volume(RID p_object, const Vector3 p_point) const override;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
PhysicsDirectSpaceState3DSW();
|
2015-10-08 18:00:40 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
class Space3DSW {
|
2016-05-22 00:18:16 +00:00
|
|
|
public:
|
|
|
|
enum ElapsedTime {
|
|
|
|
ELAPSED_TIME_INTEGRATE_FORCES,
|
|
|
|
ELAPSED_TIME_GENERATE_ISLANDS,
|
|
|
|
ELAPSED_TIME_SETUP_CONSTRAINTS,
|
|
|
|
ELAPSED_TIME_SOLVE_CONSTRAINTS,
|
|
|
|
ELAPSED_TIME_INTEGRATE_VELOCITIES,
|
|
|
|
ELAPSED_TIME_MAX
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
private:
|
2021-09-14 09:01:49 +00:00
|
|
|
uint64_t elapsed_time[ELAPSED_TIME_MAX] = {};
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
PhysicsDirectSpaceState3DSW *direct_access;
|
2015-10-08 18:00:40 +00:00
|
|
|
RID self;
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
BroadPhase3DSW *broadphase;
|
|
|
|
SelfList<Body3DSW>::List active_list;
|
2021-06-11 00:37:19 +00:00
|
|
|
SelfList<Body3DSW>::List mass_properties_update_list;
|
2020-03-27 18:21:27 +00:00
|
|
|
SelfList<Body3DSW>::List state_query_list;
|
|
|
|
SelfList<Area3DSW>::List monitor_query_list;
|
|
|
|
SelfList<Area3DSW>::List area_moved_list;
|
2021-03-12 03:33:46 +00:00
|
|
|
SelfList<SoftBody3DSW>::List active_soft_body_list;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
static void *_broadphase_pair(CollisionObject3DSW *A, int p_subindex_A, CollisionObject3DSW *B, int p_subindex_B, void *p_self);
|
|
|
|
static void _broadphase_unpair(CollisionObject3DSW *A, int p_subindex_A, CollisionObject3DSW *B, int p_subindex_B, void *p_data, void *p_self);
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
Set<CollisionObject3DSW *> objects;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-09-14 09:01:49 +00:00
|
|
|
Area3DSW *area = nullptr;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-09-14 09:01:49 +00:00
|
|
|
real_t contact_recycle_radius = 0.01;
|
|
|
|
real_t contact_max_separation = 0.05;
|
|
|
|
real_t contact_max_allowed_penetration = 0.01;
|
|
|
|
real_t constraint_bias = 0.01;
|
|
|
|
real_t test_motion_min_contact_depth = 0.00001;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
|
|
|
enum {
|
2017-03-05 15:44:50 +00:00
|
|
|
INTERSECTION_QUERY_MAX = 2048
|
2015-10-08 18:00:40 +00:00
|
|
|
};
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
CollisionObject3DSW *intersection_query_results[INTERSECTION_QUERY_MAX];
|
2015-10-08 18:00:40 +00:00
|
|
|
int intersection_query_subindex_results[INTERSECTION_QUERY_MAX];
|
|
|
|
|
2017-02-13 23:25:05 +00:00
|
|
|
real_t body_linear_velocity_sleep_threshold;
|
|
|
|
real_t body_angular_velocity_sleep_threshold;
|
|
|
|
real_t body_time_to_sleep;
|
|
|
|
real_t body_angular_velocity_damp_ratio;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-09-14 09:01:49 +00:00
|
|
|
bool locked = false;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-06-04 23:09:41 +00:00
|
|
|
real_t last_step = 0.001;
|
|
|
|
|
2021-09-14 09:01:49 +00:00
|
|
|
int island_count = 0;
|
|
|
|
int active_objects = 0;
|
|
|
|
int collision_pairs = 0;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
|
|
|
RID static_global_body;
|
|
|
|
|
|
|
|
Vector<Vector3> contact_debug;
|
2021-09-14 09:01:49 +00:00
|
|
|
int contact_debug_count = 0;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
friend class PhysicsDirectSpaceState3DSW;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
int _cull_aabb_for_body(Body3DSW *p_body, const AABB &p_aabb);
|
2017-07-15 04:23:10 +00:00
|
|
|
|
2015-10-08 18:00:40 +00:00
|
|
|
public:
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void set_self(const RID &p_self) { self = p_self; }
|
2015-10-08 18:00:40 +00:00
|
|
|
_FORCE_INLINE_ RID get_self() const { return self; }
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void set_default_area(Area3DSW *p_area) { area = p_area; }
|
|
|
|
Area3DSW *get_default_area() const { return area; }
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
const SelfList<Body3DSW>::List &get_active_body_list() const;
|
|
|
|
void body_add_to_active_list(SelfList<Body3DSW> *p_body);
|
|
|
|
void body_remove_from_active_list(SelfList<Body3DSW> *p_body);
|
2021-06-11 00:37:19 +00:00
|
|
|
void body_add_to_mass_properties_update_list(SelfList<Body3DSW> *p_body);
|
|
|
|
void body_remove_from_mass_properties_update_list(SelfList<Body3DSW> *p_body);
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void body_add_to_state_query_list(SelfList<Body3DSW> *p_body);
|
|
|
|
void body_remove_from_state_query_list(SelfList<Body3DSW> *p_body);
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void area_add_to_monitor_query_list(SelfList<Area3DSW> *p_area);
|
|
|
|
void area_remove_from_monitor_query_list(SelfList<Area3DSW> *p_area);
|
|
|
|
void area_add_to_moved_list(SelfList<Area3DSW> *p_area);
|
|
|
|
void area_remove_from_moved_list(SelfList<Area3DSW> *p_area);
|
|
|
|
const SelfList<Area3DSW>::List &get_moved_area_list() const;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-03-12 03:33:46 +00:00
|
|
|
const SelfList<SoftBody3DSW>::List &get_active_soft_body_list() const;
|
|
|
|
void soft_body_add_to_active_list(SelfList<SoftBody3DSW> *p_soft_body);
|
|
|
|
void soft_body_remove_from_active_list(SelfList<SoftBody3DSW> *p_soft_body);
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
BroadPhase3DSW *get_broadphase();
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void add_object(CollisionObject3DSW *p_object);
|
|
|
|
void remove_object(CollisionObject3DSW *p_object);
|
|
|
|
const Set<CollisionObject3DSW *> &get_objects() const;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
|
|
|
_FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; }
|
|
|
|
_FORCE_INLINE_ real_t get_contact_max_separation() const { return contact_max_separation; }
|
|
|
|
_FORCE_INLINE_ real_t get_contact_max_allowed_penetration() const { return contact_max_allowed_penetration; }
|
|
|
|
_FORCE_INLINE_ real_t get_constraint_bias() const { return constraint_bias; }
|
2017-07-08 15:12:18 +00:00
|
|
|
_FORCE_INLINE_ real_t get_body_linear_velocity_sleep_threshold() const { return body_linear_velocity_sleep_threshold; }
|
|
|
|
_FORCE_INLINE_ real_t get_body_angular_velocity_sleep_threshold() const { return body_angular_velocity_sleep_threshold; }
|
2015-10-08 18:00:40 +00:00
|
|
|
_FORCE_INLINE_ real_t get_body_time_to_sleep() const { return body_time_to_sleep; }
|
|
|
|
_FORCE_INLINE_ real_t get_body_angular_velocity_damp_ratio() const { return body_angular_velocity_damp_ratio; }
|
|
|
|
|
|
|
|
void update();
|
|
|
|
void setup();
|
|
|
|
void call_queries();
|
|
|
|
|
|
|
|
bool is_locked() const;
|
|
|
|
void lock();
|
|
|
|
void unlock();
|
|
|
|
|
2021-06-04 23:09:41 +00:00
|
|
|
real_t get_last_step() const { return last_step; }
|
|
|
|
void set_last_step(real_t p_step) { last_step = p_step; }
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
void set_param(PhysicsServer3D::SpaceParameter p_param, real_t p_value);
|
|
|
|
real_t get_param(PhysicsServer3D::SpaceParameter p_param) const;
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_island_count(int p_island_count) { island_count = p_island_count; }
|
2015-10-08 18:00:40 +00:00
|
|
|
int get_island_count() const { return island_count; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_active_objects(int p_active_objects) { active_objects = p_active_objects; }
|
2015-10-08 18:00:40 +00:00
|
|
|
int get_active_objects() const { return active_objects; }
|
|
|
|
|
|
|
|
int get_collision_pairs() const { return collision_pairs; }
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
PhysicsDirectSpaceState3DSW *get_direct_state();
|
2015-10-08 18:00:40 +00:00
|
|
|
|
|
|
|
void set_debug_contacts(int p_amount) { contact_debug.resize(p_amount); }
|
2020-12-15 12:04:21 +00:00
|
|
|
_FORCE_INLINE_ bool is_debugging_contacts() const { return !contact_debug.is_empty(); }
|
2017-03-05 15:44:50 +00:00
|
|
|
_FORCE_INLINE_ void add_debug_contact(const Vector3 &p_contact) {
|
2020-05-14 14:41:43 +00:00
|
|
|
if (contact_debug_count < contact_debug.size()) {
|
2020-05-10 10:56:01 +00:00
|
|
|
contact_debug.write[contact_debug_count++] = p_contact;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
}
|
2015-10-08 18:00:40 +00:00
|
|
|
_FORCE_INLINE_ Vector<Vector3> get_debug_contacts() { return contact_debug; }
|
|
|
|
_FORCE_INLINE_ int get_debug_contact_count() { return contact_debug_count; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_static_global_body(RID p_body) { static_global_body = p_body; }
|
2015-10-08 18:00:40 +00:00
|
|
|
RID get_static_global_body() { return static_global_body; }
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void set_elapsed_time(ElapsedTime p_time, uint64_t p_msec) { elapsed_time[p_time] = p_msec; }
|
2016-05-22 00:18:16 +00:00
|
|
|
uint64_t get_elapsed_time(ElapsedTime p_time) const { return elapsed_time[p_time]; }
|
2015-10-08 18:00:40 +00:00
|
|
|
|
2021-08-30 18:49:09 +00:00
|
|
|
bool test_body_motion(Body3DSW *p_body, const Transform3D &p_from, const Vector3 &p_motion, real_t p_margin, PhysicsServer3D::MotionResult *r_result, int p_max_collisions = 1, bool p_collide_separation_ray = false, const Set<RID> &p_exclude = Set<RID>());
|
2017-07-15 04:23:10 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
Space3DSW();
|
|
|
|
~Space3DSW();
|
2015-10-08 18:00:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SPACE__SW_H
|