2023-01-05 13:25:55 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* physics_server_2d.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#ifndef PHYSICS_SERVER_2D_H
|
|
|
|
#define PHYSICS_SERVER_2D_H
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-11-07 23:33:38 +01:00
|
|
|
#include "core/io/resource.h"
|
|
|
|
#include "core/object/class_db.h"
|
2021-06-04 18:03:15 +02:00
|
|
|
#include "core/object/ref_counted.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class PhysicsDirectSpaceState2D;
|
2022-08-05 20:35:08 +02:00
|
|
|
template <typename T>
|
|
|
|
class TypedArray;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class PhysicsDirectBodyState2D : public Object {
|
|
|
|
GDCLASS(PhysicsDirectBodyState2D, Object);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual Vector2 get_total_gravity() const = 0; // get gravity vector working on this body space/area
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual real_t get_total_linear_damp() const = 0; // get density of this body space/area
|
|
|
|
virtual real_t get_total_angular_damp() const = 0; // get density of this body space/area
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-06-11 02:37:19 +02:00
|
|
|
virtual Vector2 get_center_of_mass() const = 0;
|
2021-10-22 20:56:00 +02:00
|
|
|
virtual Vector2 get_center_of_mass_local() const = 0;
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual real_t get_inverse_mass() const = 0; // get the mass
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual real_t get_inverse_inertia() const = 0; // get density of this body space
|
|
|
|
|
|
|
|
virtual void set_linear_velocity(const Vector2 &p_velocity) = 0;
|
|
|
|
virtual Vector2 get_linear_velocity() const = 0;
|
|
|
|
|
|
|
|
virtual void set_angular_velocity(real_t p_velocity) = 0;
|
|
|
|
virtual real_t get_angular_velocity() const = 0;
|
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual void set_transform(const Transform2D &p_transform) = 0;
|
|
|
|
virtual Transform2D get_transform() const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-08-09 21:14:24 +02:00
|
|
|
virtual Vector2 get_velocity_at_local_position(const Vector2 &p_position) const = 0;
|
|
|
|
|
2018-07-24 09:49:12 +02:00
|
|
|
virtual void apply_central_impulse(const Vector2 &p_impulse) = 0;
|
|
|
|
virtual void apply_torque_impulse(real_t p_torque) = 0;
|
2020-03-26 05:23:34 +01:00
|
|
|
virtual void apply_impulse(const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
2018-07-24 09:49:12 +02:00
|
|
|
|
2021-12-08 02:09:54 +01:00
|
|
|
virtual void apply_central_force(const Vector2 &p_force) = 0;
|
|
|
|
virtual void apply_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
|
|
|
virtual void apply_torque(real_t p_torque) = 0;
|
|
|
|
|
|
|
|
virtual void add_constant_central_force(const Vector2 &p_force) = 0;
|
|
|
|
virtual void add_constant_force(const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
|
|
|
virtual void add_constant_torque(real_t p_torque) = 0;
|
|
|
|
|
|
|
|
virtual void set_constant_force(const Vector2 &p_force) = 0;
|
|
|
|
virtual Vector2 get_constant_force() const = 0;
|
|
|
|
|
|
|
|
virtual void set_constant_torque(real_t p_torque) = 0;
|
|
|
|
virtual real_t get_constant_torque() const = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void set_sleep_state(bool p_enable) = 0;
|
|
|
|
virtual bool is_sleeping() const = 0;
|
|
|
|
|
|
|
|
virtual int get_contact_count() const = 0;
|
|
|
|
|
2017-09-10 15:37:49 +02:00
|
|
|
virtual Vector2 get_contact_local_position(int p_contact_idx) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual Vector2 get_contact_local_normal(int p_contact_idx) const = 0;
|
|
|
|
virtual int get_contact_local_shape(int p_contact_idx) const = 0;
|
|
|
|
|
|
|
|
virtual RID get_contact_collider(int p_contact_idx) const = 0;
|
2017-09-10 15:37:49 +02:00
|
|
|
virtual Vector2 get_contact_collider_position(int p_contact_idx) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
|
|
|
|
virtual Object *get_contact_collider_object(int p_contact_idx) const;
|
|
|
|
virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
|
2017-09-10 15:37:49 +02:00
|
|
|
virtual Vector2 get_contact_collider_velocity_at_position(int p_contact_idx) const = 0;
|
2023-01-10 23:28:02 +01:00
|
|
|
virtual Vector2 get_contact_impulse(int p_contact_idx) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual real_t get_step() const = 0;
|
|
|
|
virtual void integrate_forces();
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsDirectSpaceState2D *get_space_state() = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
PhysicsDirectBodyState2D();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
class PhysicsRayQueryParameters2D;
|
|
|
|
class PhysicsPointQueryParameters2D;
|
|
|
|
class PhysicsShapeQueryParameters2D;
|
2014-09-03 04:13:40 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class PhysicsDirectSpaceState2D : public Object {
|
|
|
|
GDCLASS(PhysicsDirectSpaceState2D, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
Dictionary _intersect_ray(const Ref<PhysicsRayQueryParameters2D> &p_ray_query);
|
2022-08-05 20:35:08 +02:00
|
|
|
TypedArray<Dictionary> _intersect_point(const Ref<PhysicsPointQueryParameters2D> &p_point_query, int p_max_results = 32);
|
|
|
|
TypedArray<Dictionary> _intersect_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32);
|
|
|
|
Vector<real_t> _cast_motion(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query);
|
2023-03-23 15:59:41 +01:00
|
|
|
TypedArray<Vector2> _collide_shape(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query, int p_max_results = 32);
|
2020-03-27 19:21:27 +01:00
|
|
|
Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters2D> &p_shape_query);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2021-11-02 02:00:58 +01:00
|
|
|
struct RayParameters {
|
|
|
|
Vector2 from;
|
|
|
|
Vector2 to;
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<RID> exclude;
|
2021-11-02 02:00:58 +01:00
|
|
|
uint32_t collision_mask = UINT32_MAX;
|
|
|
|
|
|
|
|
bool collide_with_bodies = true;
|
|
|
|
bool collide_with_areas = false;
|
2021-11-10 23:57:11 +01:00
|
|
|
|
|
|
|
bool hit_from_inside = false;
|
2021-11-02 02:00:58 +01:00
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
struct RayResult {
|
|
|
|
Vector2 position;
|
|
|
|
Vector2 normal;
|
|
|
|
RID rid;
|
|
|
|
ObjectID collider_id;
|
2021-06-07 19:46:24 +02:00
|
|
|
Object *collider = nullptr;
|
|
|
|
int shape = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
virtual bool intersect_ray(const RayParameters &p_parameters, RayResult &r_result) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
struct ShapeResult {
|
|
|
|
RID rid;
|
|
|
|
ObjectID collider_id;
|
2021-06-07 19:46:24 +02:00
|
|
|
Object *collider = nullptr;
|
|
|
|
int shape = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
struct PointParameters {
|
|
|
|
Vector2 position;
|
|
|
|
ObjectID canvas_instance_id;
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<RID> exclude;
|
2021-11-02 02:00:58 +01:00
|
|
|
uint32_t collision_mask = UINT32_MAX;
|
|
|
|
|
|
|
|
bool collide_with_bodies = true;
|
|
|
|
bool collide_with_areas = false;
|
2015-03-22 05:46:18 +01:00
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
bool pick_point = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual int intersect_point(const PointParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
|
2014-02-23 00:28:19 +01:00
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
struct ShapeParameters {
|
|
|
|
RID shape_rid;
|
|
|
|
Transform2D transform;
|
|
|
|
Vector2 motion;
|
|
|
|
real_t margin = 0.0;
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<RID> exclude;
|
2021-11-02 02:00:58 +01:00
|
|
|
uint32_t collision_mask = UINT32_MAX;
|
2014-02-19 15:57:14 +01:00
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
bool collide_with_bodies = true;
|
|
|
|
bool collide_with_areas = false;
|
|
|
|
};
|
2014-02-23 00:28:19 +01:00
|
|
|
|
|
|
|
struct ShapeRestInfo {
|
2014-02-19 15:57:14 +01:00
|
|
|
Vector2 point;
|
|
|
|
Vector2 normal;
|
|
|
|
RID rid;
|
|
|
|
ObjectID collider_id;
|
2021-06-07 19:46:24 +02:00
|
|
|
int shape = 0;
|
2021-11-02 02:00:58 +01:00
|
|
|
Vector2 linear_velocity; // Velocity at contact point.
|
2014-02-19 15:57:14 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
virtual int intersect_shape(const ShapeParameters &p_parameters, ShapeResult *r_results, int p_result_max) = 0;
|
|
|
|
virtual bool cast_motion(const ShapeParameters &p_parameters, real_t &p_closest_safe, real_t &p_closest_unsafe) = 0;
|
|
|
|
virtual bool collide_shape(const ShapeParameters &p_parameters, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
|
|
|
|
virtual bool rest_info(const ShapeParameters &p_parameters, ShapeRestInfo *r_info) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
PhysicsDirectSpaceState2D();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-09-30 20:28:57 +02:00
|
|
|
class PhysicsTestMotionParameters2D;
|
2020-03-28 13:19:05 +01:00
|
|
|
class PhysicsTestMotionResult2D;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
class PhysicsServer2D : public Object {
|
|
|
|
GDCLASS(PhysicsServer2D, Object);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
static PhysicsServer2D *singleton;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-09-30 20:28:57 +02:00
|
|
|
virtual bool _body_test_motion(RID p_body, const Ref<PhysicsTestMotionParameters2D> &p_parameters, const Ref<PhysicsTestMotionResult2D> &p_result = Ref<PhysicsTestMotionResult2D>());
|
2015-04-20 01:50:55 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2020-03-27 19:21:27 +01:00
|
|
|
static PhysicsServer2D *get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
enum ShapeType {
|
2021-09-14 19:52:35 +02:00
|
|
|
SHAPE_WORLD_BOUNDARY, ///< plane:"plane"
|
2021-08-19 20:21:56 +02:00
|
|
|
SHAPE_SEPARATION_RAY, ///< float:"length"
|
2014-02-10 02:10:30 +01:00
|
|
|
SHAPE_SEGMENT, ///< float:"length"
|
|
|
|
SHAPE_CIRCLE, ///< float:"radius"
|
|
|
|
SHAPE_RECTANGLE, ///< vec3:"extents"
|
|
|
|
SHAPE_CAPSULE,
|
|
|
|
SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
|
|
|
|
SHAPE_CONCAVE_POLYGON, ///< Vector2 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector2 array)
|
|
|
|
SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
|
|
|
|
};
|
|
|
|
|
2021-09-14 19:52:35 +02:00
|
|
|
virtual RID world_boundary_shape_create() = 0;
|
2021-08-19 20:21:56 +02:00
|
|
|
virtual RID separation_ray_shape_create() = 0;
|
2017-11-10 03:34:01 +01:00
|
|
|
virtual RID segment_shape_create() = 0;
|
|
|
|
virtual RID circle_shape_create() = 0;
|
|
|
|
virtual RID rectangle_shape_create() = 0;
|
|
|
|
virtual RID capsule_shape_create() = 0;
|
|
|
|
virtual RID convex_polygon_shape_create() = 0;
|
|
|
|
virtual RID concave_polygon_shape_create() = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
|
|
|
|
virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
|
|
|
|
|
|
|
|
virtual ShapeType shape_get_type(RID p_shape) const = 0;
|
|
|
|
virtual Variant shape_get_data(RID p_shape) const = 0;
|
|
|
|
virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
|
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
//these work well, but should be used from the main thread only
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual bool shape_collide(RID p_shape_A, const Transform2D &p_xform_A, const Vector2 &p_motion_A, RID p_shape_B, const Transform2D &p_xform_B, const Vector2 &p_motion_B, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* SPACE API */
|
|
|
|
|
|
|
|
virtual RID space_create() = 0;
|
|
|
|
virtual void space_set_active(RID p_space, bool p_active) = 0;
|
|
|
|
virtual bool space_is_active(RID p_space) const = 0;
|
|
|
|
|
|
|
|
enum SpaceParameter {
|
|
|
|
SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
|
|
|
|
SPACE_PARAM_CONTACT_MAX_SEPARATION,
|
2021-12-03 18:38:40 +01:00
|
|
|
SPACE_PARAM_CONTACT_MAX_ALLOWED_PENETRATION,
|
|
|
|
SPACE_PARAM_CONTACT_DEFAULT_BIAS,
|
2017-07-08 17:12:18 +02:00
|
|
|
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD,
|
|
|
|
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD,
|
2014-02-10 02:10:30 +01:00
|
|
|
SPACE_PARAM_BODY_TIME_TO_SLEEP,
|
|
|
|
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
|
2021-12-03 18:38:40 +01:00
|
|
|
SPACE_PARAM_SOLVER_ITERATIONS,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
|
|
|
|
virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
|
|
|
|
|
2017-09-29 17:33:30 +02:00
|
|
|
// this function only works on physics process, errors and returns null otherwise
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsDirectSpaceState2D *space_get_direct_state(RID p_space) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-09-20 18:03:46 +02:00
|
|
|
virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
|
|
|
|
virtual Vector<Vector2> space_get_contacts(RID p_space) const = 0;
|
|
|
|
virtual int space_get_contact_count(RID p_space) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
//missing space parameters
|
|
|
|
|
|
|
|
/* AREA API */
|
|
|
|
|
|
|
|
//missing attenuation? missing better override?
|
|
|
|
|
|
|
|
enum AreaParameter {
|
2021-11-05 02:12:00 +01:00
|
|
|
AREA_PARAM_GRAVITY_OVERRIDE_MODE,
|
2014-02-10 02:10:30 +01:00
|
|
|
AREA_PARAM_GRAVITY,
|
|
|
|
AREA_PARAM_GRAVITY_VECTOR,
|
|
|
|
AREA_PARAM_GRAVITY_IS_POINT,
|
2023-01-30 01:11:41 +01:00
|
|
|
AREA_PARAM_GRAVITY_POINT_UNIT_DISTANCE,
|
2021-11-05 02:12:00 +01:00
|
|
|
AREA_PARAM_LINEAR_DAMP_OVERRIDE_MODE,
|
2015-01-05 22:37:12 +01:00
|
|
|
AREA_PARAM_LINEAR_DAMP,
|
2021-11-05 02:12:00 +01:00
|
|
|
AREA_PARAM_ANGULAR_DAMP_OVERRIDE_MODE,
|
2015-01-05 22:37:12 +01:00
|
|
|
AREA_PARAM_ANGULAR_DAMP,
|
2014-02-10 02:10:30 +01:00
|
|
|
AREA_PARAM_PRIORITY
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual RID area_create() = 0;
|
|
|
|
|
|
|
|
virtual void area_set_space(RID p_area, RID p_space) = 0;
|
|
|
|
virtual RID area_get_space(RID p_area) const = 0;
|
|
|
|
|
|
|
|
enum AreaSpaceOverrideMode {
|
|
|
|
AREA_SPACE_OVERRIDE_DISABLED,
|
|
|
|
AREA_SPACE_OVERRIDE_COMBINE,
|
2015-12-14 02:56:11 +01:00
|
|
|
AREA_SPACE_OVERRIDE_COMBINE_REPLACE, // Combines, then discards all subsequent calculations
|
2014-02-10 02:10:30 +01:00
|
|
|
AREA_SPACE_OVERRIDE_REPLACE,
|
2015-12-14 02:56:11 +01:00
|
|
|
AREA_SPACE_OVERRIDE_REPLACE_COMBINE // Discards all previous calculations, then keeps combining
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2019-03-24 10:38:31 +01:00
|
|
|
virtual void area_add_shape(RID p_area, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform2D &p_transform) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual int area_get_shape_count(RID p_area) const = 0;
|
|
|
|
virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual Transform2D area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
|
|
|
|
virtual void area_clear_shapes(RID p_area) = 0;
|
|
|
|
|
2017-06-24 04:30:43 +02:00
|
|
|
virtual void area_set_shape_disabled(RID p_area, int p_shape, bool p_disabled) = 0;
|
|
|
|
|
2019-05-09 11:21:49 +02:00
|
|
|
virtual void area_attach_object_instance_id(RID p_area, ObjectID p_id) = 0;
|
2017-08-07 12:17:31 +02:00
|
|
|
virtual ObjectID area_get_object_instance_id(RID p_area) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-05-09 11:21:49 +02:00
|
|
|
virtual void area_attach_canvas_instance_id(RID p_area, ObjectID p_id) = 0;
|
2018-08-25 00:03:26 +02:00
|
|
|
virtual ObjectID area_get_canvas_instance_id(RID p_area) const = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual void area_set_transform(RID p_area, const Transform2D &p_transform) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual Transform2D area_get_transform(RID p_area) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-13 17:45:01 +02:00
|
|
|
virtual void area_set_collision_layer(RID p_area, uint32_t p_layer) = 0;
|
2022-09-23 08:06:29 +02:00
|
|
|
virtual uint32_t area_get_collision_layer(RID p_area) const = 0;
|
|
|
|
|
|
|
|
virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
|
|
|
|
virtual uint32_t area_get_collision_mask(RID p_area) const = 0;
|
2015-05-03 21:47:21 +02:00
|
|
|
|
2015-03-17 04:45:25 +01:00
|
|
|
virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
|
2015-03-22 05:46:18 +01:00
|
|
|
virtual void area_set_pickable(RID p_area, bool p_pickable) = 0;
|
2015-03-17 04:45:25 +01:00
|
|
|
|
2021-10-31 22:45:58 +01:00
|
|
|
virtual void area_set_monitor_callback(RID p_area, const Callable &p_callback) = 0;
|
|
|
|
virtual void area_set_area_monitor_callback(RID p_area, const Callable &p_callback) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* BODY API */
|
|
|
|
|
|
|
|
//missing ccd?
|
|
|
|
|
|
|
|
enum BodyMode {
|
|
|
|
BODY_MODE_STATIC,
|
2014-02-19 15:57:14 +01:00
|
|
|
BODY_MODE_KINEMATIC,
|
2022-08-25 19:35:52 +02:00
|
|
|
BODY_MODE_RIGID,
|
|
|
|
BODY_MODE_RIGID_LINEAR,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-11-10 03:34:01 +01:00
|
|
|
virtual RID body_create() = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_set_space(RID p_body, RID p_space) = 0;
|
|
|
|
virtual RID body_get_space(RID p_body) const = 0;
|
|
|
|
|
|
|
|
virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
|
2014-02-19 15:57:14 +01:00
|
|
|
virtual BodyMode body_get_mode(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-03-24 10:38:31 +01:00
|
|
|
virtual void body_add_shape(RID p_body, RID p_shape, const Transform2D &p_transform = Transform2D(), bool p_disabled = false) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform2D &p_transform) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual int body_get_shape_count(RID p_body) const = 0;
|
|
|
|
virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual Transform2D body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-24 04:30:43 +02:00
|
|
|
virtual void body_set_shape_disabled(RID p_body, int p_shape, bool p_disabled) = 0;
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual void body_set_shape_as_one_way_collision(RID p_body, int p_shape, bool p_enabled, real_t p_margin = 0) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
|
|
|
|
virtual void body_clear_shapes(RID p_body) = 0;
|
|
|
|
|
2020-02-12 18:24:06 +01:00
|
|
|
virtual void body_attach_object_instance_id(RID p_body, ObjectID p_id) = 0;
|
|
|
|
virtual ObjectID body_get_object_instance_id(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-02-12 18:24:06 +01:00
|
|
|
virtual void body_attach_canvas_instance_id(RID p_body, ObjectID p_id) = 0;
|
|
|
|
virtual ObjectID body_get_canvas_instance_id(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-02-19 15:57:14 +01:00
|
|
|
enum CCDMode {
|
|
|
|
CCD_MODE_DISABLED,
|
|
|
|
CCD_MODE_CAST_RAY,
|
|
|
|
CCD_MODE_CAST_SHAPE,
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void body_set_continuous_collision_detection_mode(RID p_body, CCDMode p_mode) = 0;
|
|
|
|
virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-06-13 17:45:01 +02:00
|
|
|
virtual void body_set_collision_layer(RID p_body, uint32_t p_layer) = 0;
|
|
|
|
virtual uint32_t body_get_collision_layer(RID p_body) const = 0;
|
2014-05-14 06:22:15 +02:00
|
|
|
|
2015-05-03 21:47:21 +02:00
|
|
|
virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
|
2015-05-26 06:05:08 +02:00
|
|
|
virtual uint32_t body_get_collision_mask(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-08-10 18:45:36 +02:00
|
|
|
virtual void body_set_collision_priority(RID p_body, real_t p_priority) = 0;
|
|
|
|
virtual real_t body_get_collision_priority(RID p_body) const = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
// common body variables
|
|
|
|
enum BodyParameter {
|
|
|
|
BODY_PARAM_BOUNCE,
|
|
|
|
BODY_PARAM_FRICTION,
|
|
|
|
BODY_PARAM_MASS, ///< unused for static, always infinite
|
2021-06-11 02:37:19 +02:00
|
|
|
BODY_PARAM_INERTIA,
|
|
|
|
BODY_PARAM_CENTER_OF_MASS,
|
2015-01-05 22:37:12 +01:00
|
|
|
BODY_PARAM_GRAVITY_SCALE,
|
2020-04-14 19:59:53 +02:00
|
|
|
BODY_PARAM_LINEAR_DAMP_MODE,
|
|
|
|
BODY_PARAM_ANGULAR_DAMP_MODE,
|
2015-01-05 22:37:12 +01:00
|
|
|
BODY_PARAM_LINEAR_DAMP,
|
|
|
|
BODY_PARAM_ANGULAR_DAMP,
|
2014-02-10 02:10:30 +01:00
|
|
|
BODY_PARAM_MAX,
|
|
|
|
};
|
|
|
|
|
2020-04-14 19:59:53 +02:00
|
|
|
enum BodyDampMode {
|
|
|
|
BODY_DAMP_MODE_COMBINE,
|
|
|
|
BODY_DAMP_MODE_REPLACE,
|
|
|
|
};
|
|
|
|
|
2021-06-11 02:37:19 +02:00
|
|
|
virtual void body_set_param(RID p_body, BodyParameter p_param, const Variant &p_value) = 0;
|
|
|
|
virtual Variant body_get_param(RID p_body, BodyParameter p_param) const = 0;
|
|
|
|
|
|
|
|
virtual void body_reset_mass_properties(RID p_body) = 0;
|
2017-10-24 18:10:30 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
//state
|
|
|
|
enum BodyState {
|
|
|
|
BODY_STATE_TRANSFORM,
|
|
|
|
BODY_STATE_LINEAR_VELOCITY,
|
|
|
|
BODY_STATE_ANGULAR_VELOCITY,
|
|
|
|
BODY_STATE_SLEEPING,
|
2015-01-05 22:37:12 +01:00
|
|
|
BODY_STATE_CAN_SLEEP,
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
|
|
|
|
virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
|
|
|
|
|
2018-07-24 09:49:12 +02:00
|
|
|
virtual void body_apply_central_impulse(RID p_body, const Vector2 &p_impulse) = 0;
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual void body_apply_torque_impulse(RID p_body, real_t p_torque) = 0;
|
2020-03-26 05:23:34 +01:00
|
|
|
virtual void body_apply_impulse(RID p_body, const Vector2 &p_impulse, const Vector2 &p_position = Vector2()) = 0;
|
2021-12-08 02:09:54 +01:00
|
|
|
|
|
|
|
virtual void body_apply_central_force(RID p_body, const Vector2 &p_force) = 0;
|
|
|
|
virtual void body_apply_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
|
|
|
virtual void body_apply_torque(RID p_body, real_t p_torque) = 0;
|
|
|
|
|
|
|
|
virtual void body_add_constant_central_force(RID p_body, const Vector2 &p_force) = 0;
|
|
|
|
virtual void body_add_constant_force(RID p_body, const Vector2 &p_force, const Vector2 &p_position = Vector2()) = 0;
|
|
|
|
virtual void body_add_constant_torque(RID p_body, real_t p_torque) = 0;
|
|
|
|
|
|
|
|
virtual void body_set_constant_force(RID p_body, const Vector2 &p_force) = 0;
|
|
|
|
virtual Vector2 body_get_constant_force(RID p_body) const = 0;
|
|
|
|
|
|
|
|
virtual void body_set_constant_torque(RID p_body, real_t p_torque) = 0;
|
|
|
|
virtual real_t body_get_constant_torque(RID p_body) const = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void body_set_axis_velocity(RID p_body, const Vector2 &p_axis_velocity) = 0;
|
|
|
|
|
|
|
|
//fix
|
|
|
|
virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
|
|
|
|
virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
|
|
|
|
virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
|
|
|
|
|
|
|
|
virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
|
|
|
|
virtual int body_get_max_contacts_reported(RID p_body) const = 0;
|
|
|
|
|
|
|
|
//missing remove
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual void body_set_contacts_reported_depth_threshold(RID p_body, real_t p_threshold) = 0;
|
|
|
|
virtual real_t body_get_contacts_reported_depth_threshold(RID p_body) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
|
|
|
|
virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
|
|
|
|
|
2022-09-15 14:15:39 +02:00
|
|
|
virtual void body_set_state_sync_callback(RID p_body, const Callable &p_callable) = 0;
|
2021-03-30 08:22:23 +02:00
|
|
|
virtual void body_set_force_integration_callback(RID p_body, const Callable &p_callable, const Variant &p_udata = Variant()) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-11 04:52:51 +01:00
|
|
|
virtual bool body_collide_shape(RID p_body, int p_body_shape, RID p_shape, const Transform2D &p_shape_xform, const Vector2 &p_motion, Vector2 *r_results, int p_result_max, int &r_result_count) = 0;
|
2014-02-19 15:57:14 +01:00
|
|
|
|
2015-03-22 05:46:18 +01:00
|
|
|
virtual void body_set_pickable(RID p_body, bool p_pickable) = 0;
|
|
|
|
|
2017-09-29 17:33:30 +02:00
|
|
|
// this function only works on physics process, errors and returns null otherwise
|
2020-03-27 19:21:27 +01:00
|
|
|
virtual PhysicsDirectBodyState2D *body_get_direct_state(RID p_body) = 0;
|
2017-09-29 17:33:30 +02:00
|
|
|
|
2021-09-30 20:28:57 +02:00
|
|
|
struct MotionParameters {
|
|
|
|
Transform2D from;
|
|
|
|
Vector2 motion;
|
|
|
|
real_t margin = 0.08;
|
|
|
|
bool collide_separation_ray = false;
|
2022-05-19 17:00:06 +02:00
|
|
|
HashSet<RID> exclude_bodies;
|
|
|
|
HashSet<ObjectID> exclude_objects;
|
2022-10-05 22:51:29 +02:00
|
|
|
bool recovery_as_collision = false;
|
2021-09-30 20:28:57 +02:00
|
|
|
|
|
|
|
MotionParameters() {}
|
|
|
|
|
|
|
|
MotionParameters(const Transform2D &p_from, const Vector2 &p_motion, real_t p_margin = 0.08) :
|
|
|
|
from(p_from),
|
|
|
|
motion(p_motion),
|
|
|
|
margin(p_margin) {}
|
|
|
|
};
|
|
|
|
|
2015-04-20 01:50:55 +02:00
|
|
|
struct MotionResult {
|
2021-08-13 00:41:40 +02:00
|
|
|
Vector2 travel;
|
2015-04-20 01:50:55 +02:00
|
|
|
Vector2 remainder;
|
|
|
|
|
|
|
|
Vector2 collision_point;
|
|
|
|
Vector2 collision_normal;
|
|
|
|
Vector2 collider_velocity;
|
2021-06-25 04:25:26 +02:00
|
|
|
real_t collision_depth = 0.0;
|
|
|
|
real_t collision_safe_fraction = 0.0;
|
|
|
|
real_t collision_unsafe_fraction = 0.0;
|
2021-05-20 03:14:33 +02:00
|
|
|
int collision_local_shape = 0;
|
2015-04-20 01:50:55 +02:00
|
|
|
ObjectID collider_id;
|
|
|
|
RID collider;
|
2021-05-20 03:14:33 +02:00
|
|
|
int collider_shape = 0;
|
2021-08-13 00:41:40 +02:00
|
|
|
|
|
|
|
real_t get_angle(Vector2 p_up_direction) const {
|
|
|
|
return Math::acos(collision_normal.dot(p_up_direction));
|
|
|
|
}
|
2015-04-20 01:50:55 +02:00
|
|
|
};
|
|
|
|
|
2021-09-30 20:28:57 +02:00
|
|
|
virtual bool body_test_motion(RID p_body, const MotionParameters &p_parameters, MotionResult *r_result = nullptr) = 0;
|
2018-07-17 01:04:07 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
/* JOINT API */
|
|
|
|
|
2021-02-09 17:19:03 +01:00
|
|
|
virtual RID joint_create() = 0;
|
|
|
|
|
|
|
|
virtual void joint_clear(RID p_joint) = 0;
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
enum JointType {
|
2021-02-09 17:19:03 +01:00
|
|
|
JOINT_TYPE_PIN,
|
|
|
|
JOINT_TYPE_GROOVE,
|
|
|
|
JOINT_TYPE_DAMPED_SPRING,
|
|
|
|
JOINT_TYPE_MAX
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum JointParam {
|
|
|
|
JOINT_PARAM_BIAS,
|
|
|
|
JOINT_PARAM_MAX_BIAS,
|
|
|
|
JOINT_PARAM_MAX_FORCE,
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value) = 0;
|
|
|
|
virtual real_t joint_get_param(RID p_joint, JointParam p_param) const = 0;
|
|
|
|
|
2018-02-05 18:20:26 +01:00
|
|
|
virtual void joint_disable_collisions_between_bodies(RID p_joint, const bool p_disable) = 0;
|
|
|
|
virtual bool joint_is_disabled_collisions_between_bodies(RID p_joint) const = 0;
|
|
|
|
|
2021-02-09 17:19:03 +01:00
|
|
|
virtual void joint_make_pin(RID p_joint, const Vector2 &p_anchor, RID p_body_a, RID p_body_b = RID()) = 0;
|
|
|
|
virtual void joint_make_groove(RID p_joint, const Vector2 &p_a_groove1, const Vector2 &p_a_groove2, const Vector2 &p_b_anchor, RID p_body_a, RID p_body_b) = 0;
|
|
|
|
virtual void joint_make_damped_spring(RID p_joint, const Vector2 &p_anchor_a, const Vector2 &p_anchor_b, RID p_body_a, RID p_body_b = RID()) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-10-10 22:28:05 +02:00
|
|
|
enum PinJointParam {
|
|
|
|
PIN_JOINT_SOFTNESS
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, real_t p_value) = 0;
|
|
|
|
virtual real_t pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
|
|
|
|
|
2020-06-04 18:53:29 +02:00
|
|
|
enum DampedSpringParam {
|
|
|
|
DAMPED_SPRING_REST_LENGTH,
|
|
|
|
DAMPED_SPRING_STIFFNESS,
|
|
|
|
DAMPED_SPRING_DAMPING
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
2020-06-04 18:53:29 +02:00
|
|
|
virtual void damped_spring_joint_set_param(RID p_joint, DampedSpringParam p_param, real_t p_value) = 0;
|
|
|
|
virtual real_t damped_spring_joint_get_param(RID p_joint, DampedSpringParam p_param) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
virtual JointType joint_get_type(RID p_joint) const = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
/* QUERY API */
|
|
|
|
|
|
|
|
enum AreaBodyStatus {
|
|
|
|
AREA_BODY_ADDED,
|
|
|
|
AREA_BODY_REMOVED
|
|
|
|
};
|
|
|
|
|
|
|
|
/* MISC */
|
|
|
|
|
|
|
|
virtual void free(RID p_rid) = 0;
|
|
|
|
|
|
|
|
virtual void set_active(bool p_active) = 0;
|
|
|
|
virtual void init() = 0;
|
2021-01-28 07:34:26 +01:00
|
|
|
virtual void step(real_t p_step) = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void sync() = 0;
|
|
|
|
virtual void flush_queries() = 0;
|
2015-05-26 06:05:08 +02:00
|
|
|
virtual void end_sync() = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
virtual void finish() = 0;
|
|
|
|
|
2018-11-16 12:49:26 +01:00
|
|
|
virtual bool is_flushing_queries() const = 0;
|
|
|
|
|
2014-09-03 04:13:40 +02:00
|
|
|
enum ProcessInfo {
|
|
|
|
INFO_ACTIVE_OBJECTS,
|
|
|
|
INFO_COLLISION_PAIRS,
|
2018-09-26 13:13:56 +02:00
|
|
|
INFO_ISLAND_COUNT
|
2014-09-03 04:13:40 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual int get_process_info(ProcessInfo p_info) = 0;
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
PhysicsServer2D();
|
|
|
|
~PhysicsServer2D();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-11-02 02:00:58 +01:00
|
|
|
class PhysicsRayQueryParameters2D : public RefCounted {
|
|
|
|
GDCLASS(PhysicsRayQueryParameters2D, RefCounted);
|
|
|
|
|
|
|
|
PhysicsDirectSpaceState2D::RayParameters parameters;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2022-08-31 19:24:04 +02:00
|
|
|
static Ref<PhysicsRayQueryParameters2D> create(Vector2 p_from, Vector2 p_to, uint32_t p_mask, const TypedArray<RID> &p_exclude);
|
2021-11-02 02:00:58 +01:00
|
|
|
const PhysicsDirectSpaceState2D::RayParameters &get_parameters() const { return parameters; }
|
|
|
|
|
|
|
|
void set_from(const Vector2 &p_from) { parameters.from = p_from; }
|
|
|
|
const Vector2 &get_from() const { return parameters.from; }
|
|
|
|
|
|
|
|
void set_to(const Vector2 &p_to) { parameters.to = p_to; }
|
|
|
|
const Vector2 &get_to() const { return parameters.to; }
|
|
|
|
|
|
|
|
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
|
|
|
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
|
|
|
|
|
|
|
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
|
|
|
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
|
|
|
|
|
|
|
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
|
|
|
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
|
|
|
|
2021-11-10 23:57:11 +01:00
|
|
|
void set_hit_from_inside(bool p_enable) { parameters.hit_from_inside = p_enable; }
|
|
|
|
bool is_hit_from_inside_enabled() const { return parameters.hit_from_inside; }
|
|
|
|
|
2022-08-31 19:24:04 +02:00
|
|
|
void set_exclude(const TypedArray<RID> &p_exclude);
|
|
|
|
TypedArray<RID> get_exclude() const;
|
2021-11-02 02:00:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsPointQueryParameters2D : public RefCounted {
|
|
|
|
GDCLASS(PhysicsPointQueryParameters2D, RefCounted);
|
|
|
|
|
|
|
|
PhysicsDirectSpaceState2D::PointParameters parameters;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
const PhysicsDirectSpaceState2D::PointParameters &get_parameters() const { return parameters; }
|
|
|
|
|
|
|
|
void set_position(const Vector2 &p_position) { parameters.position = p_position; }
|
|
|
|
const Vector2 &get_position() const { return parameters.position; }
|
|
|
|
|
|
|
|
void set_canvas_instance_id(ObjectID p_canvas_instance_id) { parameters.canvas_instance_id = p_canvas_instance_id; }
|
|
|
|
ObjectID get_canvas_instance_id() const { return parameters.canvas_instance_id; }
|
|
|
|
|
|
|
|
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
|
|
|
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
|
|
|
|
|
|
|
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
|
|
|
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
|
|
|
|
|
|
|
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
|
|
|
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
|
|
|
|
2022-08-31 19:24:04 +02:00
|
|
|
void set_exclude(const TypedArray<RID> &p_exclude);
|
|
|
|
TypedArray<RID> get_exclude() const;
|
2021-11-02 02:00:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class PhysicsShapeQueryParameters2D : public RefCounted {
|
|
|
|
GDCLASS(PhysicsShapeQueryParameters2D, RefCounted);
|
|
|
|
|
|
|
|
PhysicsDirectSpaceState2D::ShapeParameters parameters;
|
|
|
|
|
2022-05-03 01:43:50 +02:00
|
|
|
Ref<Resource> shape_ref;
|
2021-11-02 02:00:58 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
const PhysicsDirectSpaceState2D::ShapeParameters &get_parameters() const { return parameters; }
|
|
|
|
|
2022-05-03 01:43:50 +02:00
|
|
|
void set_shape(const Ref<Resource> &p_shape_ref);
|
|
|
|
Ref<Resource> get_shape() const { return shape_ref; }
|
2021-11-02 02:00:58 +01:00
|
|
|
|
|
|
|
void set_shape_rid(const RID &p_shape);
|
|
|
|
RID get_shape_rid() const { return parameters.shape_rid; }
|
|
|
|
|
|
|
|
void set_transform(const Transform2D &p_transform) { parameters.transform = p_transform; }
|
|
|
|
const Transform2D &get_transform() const { return parameters.transform; }
|
|
|
|
|
|
|
|
void set_motion(const Vector2 &p_motion) { parameters.motion = p_motion; }
|
|
|
|
const Vector2 &get_motion() const { return parameters.motion; }
|
|
|
|
|
|
|
|
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
|
|
|
|
real_t get_margin() const { return parameters.margin; }
|
|
|
|
|
|
|
|
void set_collision_mask(uint32_t p_mask) { parameters.collision_mask = p_mask; }
|
|
|
|
uint32_t get_collision_mask() const { return parameters.collision_mask; }
|
|
|
|
|
|
|
|
void set_collide_with_bodies(bool p_enable) { parameters.collide_with_bodies = p_enable; }
|
|
|
|
bool is_collide_with_bodies_enabled() const { return parameters.collide_with_bodies; }
|
|
|
|
|
|
|
|
void set_collide_with_areas(bool p_enable) { parameters.collide_with_areas = p_enable; }
|
|
|
|
bool is_collide_with_areas_enabled() const { return parameters.collide_with_areas; }
|
|
|
|
|
2022-08-31 19:24:04 +02:00
|
|
|
void set_exclude(const TypedArray<RID> &p_exclude);
|
|
|
|
TypedArray<RID> get_exclude() const;
|
2021-11-02 02:00:58 +01:00
|
|
|
};
|
|
|
|
|
2021-09-30 20:28:57 +02:00
|
|
|
class PhysicsTestMotionParameters2D : public RefCounted {
|
|
|
|
GDCLASS(PhysicsTestMotionParameters2D, RefCounted);
|
|
|
|
|
|
|
|
PhysicsServer2D::MotionParameters parameters;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
const PhysicsServer2D::MotionParameters &get_parameters() const { return parameters; }
|
|
|
|
|
|
|
|
const Transform2D &get_from() const { return parameters.from; }
|
|
|
|
void set_from(const Transform2D &p_from) { parameters.from = p_from; }
|
|
|
|
|
|
|
|
const Vector2 &get_motion() const { return parameters.motion; }
|
|
|
|
void set_motion(const Vector2 &p_motion) { parameters.motion = p_motion; }
|
|
|
|
|
|
|
|
real_t get_margin() const { return parameters.margin; }
|
|
|
|
void set_margin(real_t p_margin) { parameters.margin = p_margin; }
|
|
|
|
|
|
|
|
bool is_collide_separation_ray_enabled() const { return parameters.collide_separation_ray; }
|
|
|
|
void set_collide_separation_ray_enabled(bool p_enabled) { parameters.collide_separation_ray = p_enabled; }
|
|
|
|
|
2022-08-31 19:24:04 +02:00
|
|
|
TypedArray<RID> get_exclude_bodies() const;
|
|
|
|
void set_exclude_bodies(const TypedArray<RID> &p_exclude);
|
2021-09-30 20:05:30 +02:00
|
|
|
|
2022-11-23 18:32:30 +01:00
|
|
|
TypedArray<uint64_t> get_exclude_objects() const;
|
|
|
|
void set_exclude_objects(const TypedArray<uint64_t> &p_exclude);
|
2022-04-28 22:44:09 +02:00
|
|
|
|
|
|
|
bool is_recovery_as_collision_enabled() const { return parameters.recovery_as_collision; }
|
|
|
|
void set_recovery_as_collision_enabled(bool p_enabled) { parameters.recovery_as_collision = p_enabled; }
|
2021-09-30 20:28:57 +02:00
|
|
|
};
|
|
|
|
|
2021-06-04 18:03:15 +02:00
|
|
|
class PhysicsTestMotionResult2D : public RefCounted {
|
|
|
|
GDCLASS(PhysicsTestMotionResult2D, RefCounted);
|
2015-04-20 01:50:55 +02:00
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
PhysicsServer2D::MotionResult result;
|
2015-04-20 01:50:55 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
public:
|
2020-03-27 19:21:27 +01:00
|
|
|
PhysicsServer2D::MotionResult *get_result_ptr() const { return const_cast<PhysicsServer2D::MotionResult *>(&result); }
|
2015-04-20 01:50:55 +02:00
|
|
|
|
2021-08-13 00:41:40 +02:00
|
|
|
Vector2 get_travel() const;
|
|
|
|
Vector2 get_remainder() const;
|
2015-04-20 01:50:55 +02:00
|
|
|
|
|
|
|
Vector2 get_collision_point() const;
|
|
|
|
Vector2 get_collision_normal() const;
|
|
|
|
Vector2 get_collider_velocity() const;
|
|
|
|
ObjectID get_collider_id() const;
|
|
|
|
RID get_collider_rid() const;
|
|
|
|
Object *get_collider() const;
|
|
|
|
int get_collider_shape() const;
|
2021-09-30 20:28:57 +02:00
|
|
|
int get_collision_local_shape() const;
|
2021-06-25 04:25:26 +02:00
|
|
|
real_t get_collision_depth() const;
|
|
|
|
real_t get_collision_safe_fraction() const;
|
|
|
|
real_t get_collision_unsafe_fraction() const;
|
2015-04-20 01:50:55 +02:00
|
|
|
};
|
|
|
|
|
2022-09-06 15:35:33 +02:00
|
|
|
class PhysicsServer2DManager : public Object {
|
|
|
|
GDCLASS(PhysicsServer2DManager, Object);
|
|
|
|
|
|
|
|
static PhysicsServer2DManager *singleton;
|
2017-10-21 13:02:06 +02:00
|
|
|
|
|
|
|
struct ClassInfo {
|
|
|
|
String name;
|
2022-09-06 15:35:33 +02:00
|
|
|
Callable create_callback;
|
2017-10-21 13:02:06 +02:00
|
|
|
|
2020-05-12 17:01:17 +02:00
|
|
|
ClassInfo() {}
|
2017-10-21 13:02:06 +02:00
|
|
|
|
2022-09-06 15:35:33 +02:00
|
|
|
ClassInfo(String p_name, Callable p_create_callback) :
|
2017-12-06 21:36:34 +01:00
|
|
|
name(p_name),
|
|
|
|
create_callback(p_create_callback) {}
|
2017-10-21 13:02:06 +02:00
|
|
|
|
2017-12-06 21:36:34 +01:00
|
|
|
ClassInfo(const ClassInfo &p_ci) :
|
|
|
|
name(p_ci.name),
|
|
|
|
create_callback(p_ci.create_callback) {}
|
2019-03-02 13:32:29 +01:00
|
|
|
|
2021-11-30 15:19:26 +01:00
|
|
|
void operator=(const ClassInfo &p_ci) {
|
2019-03-02 13:32:29 +01:00
|
|
|
name = p_ci.name;
|
|
|
|
create_callback = p_ci.create_callback;
|
|
|
|
}
|
2017-10-21 13:02:06 +02:00
|
|
|
};
|
|
|
|
|
2022-09-06 15:35:33 +02:00
|
|
|
Vector<ClassInfo> physics_2d_servers;
|
|
|
|
int default_server_id = -1;
|
|
|
|
int default_server_priority = -1;
|
|
|
|
|
|
|
|
void on_servers_changed();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2017-10-21 13:02:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
static const String setting_property_name;
|
|
|
|
|
2022-09-06 15:35:33 +02:00
|
|
|
static PhysicsServer2DManager *get_singleton();
|
2017-10-21 13:02:06 +02:00
|
|
|
|
2022-09-06 15:35:33 +02:00
|
|
|
void register_server(const String &p_name, const Callable &p_create_callback);
|
|
|
|
void set_default_server(const String &p_name, int p_priority = 0);
|
|
|
|
int find_server_id(const String &p_name);
|
|
|
|
int get_servers_count();
|
|
|
|
String get_server_name(int p_id);
|
|
|
|
PhysicsServer2D *new_default_server();
|
|
|
|
PhysicsServer2D *new_server(const String &p_name);
|
|
|
|
|
|
|
|
PhysicsServer2DManager();
|
|
|
|
~PhysicsServer2DManager();
|
2017-10-21 13:02:06 +02:00
|
|
|
};
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::ShapeType);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::SpaceParameter);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::AreaParameter);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::AreaSpaceOverrideMode);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::BodyMode);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::BodyParameter);
|
2020-04-14 19:59:53 +02:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::BodyDampMode);
|
2020-03-27 19:21:27 +01:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::BodyState);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::CCDMode);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::JointParam);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::JointType);
|
2022-09-04 10:32:21 +02:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::PinJointParam);
|
2020-06-04 18:53:29 +02:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam);
|
2020-03-27 19:21:27 +01:00
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus);
|
|
|
|
VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-10-18 21:24:30 +02:00
|
|
|
#endif // PHYSICS_SERVER_2D_H
|