2014-02-10 09:10:30 +08:00
/*************************************************************************/
2020-03-28 20:19:05 +08:00
/* physics_server_3d.h */
2014-02-10 09:10:30 +08:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
2017-08-27 20:16:55 +08:00
/* https://godotengine.org */
2014-02-10 09:10:30 +08:00
/*************************************************************************/
2021-01-02 03:13:46 +08:00
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 09:10:30 +08: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 07:50:27 +08:00
2014-02-10 09:10:30 +08:00
# ifndef PHYSICS_SERVER_H
# define PHYSICS_SERVER_H
2020-11-08 06:33:38 +08:00
# include "core/io/resource.h"
# include "core/object/class_db.h"
2014-02-10 09:10:30 +08:00
2020-03-28 02:21:27 +08:00
class PhysicsDirectSpaceState3D ;
2014-02-10 09:10:30 +08:00
2020-03-28 02:21:27 +08:00
class PhysicsDirectBodyState3D : public Object {
GDCLASS ( PhysicsDirectBodyState3D , Object ) ;
2017-03-05 23:44:50 +08:00
2014-02-10 09:10:30 +08:00
protected :
static void _bind_methods ( ) ;
2017-03-05 23:44:50 +08:00
public :
virtual Vector3 get_total_gravity ( ) const = 0 ;
2021-01-28 14:34:26 +08:00
virtual real_t get_total_angular_damp ( ) const = 0 ;
virtual real_t get_total_linear_damp ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual Vector3 get_center_of_mass ( ) const = 0 ;
virtual Basis get_principal_inertia_axes ( ) const = 0 ;
2021-01-28 14:34:26 +08:00
virtual real_t get_inverse_mass ( ) const = 0 ; // get the mass
2017-03-05 23:44:50 +08:00
virtual Vector3 get_inverse_inertia ( ) const = 0 ; // get density of this body space
virtual Basis get_inverse_inertia_tensor ( ) const = 0 ; // get density of this body space
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void set_linear_velocity ( const Vector3 & p_velocity ) = 0 ;
virtual Vector3 get_linear_velocity ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void set_angular_velocity ( const Vector3 & p_velocity ) = 0 ;
virtual Vector3 get_angular_velocity ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2020-10-17 13:08:21 +08:00
virtual void set_transform ( const Transform3D & p_transform ) = 0 ;
virtual Transform3D get_transform ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2021-08-10 03:14:24 +08:00
virtual Vector3 get_velocity_at_local_position ( const Vector3 & p_position ) const = 0 ;
2018-02-17 00:48:07 +08:00
virtual void add_central_force ( const Vector3 & p_force ) = 0 ;
2020-03-26 12:23:34 +08:00
virtual void add_force ( const Vector3 & p_force , const Vector3 & p_position = Vector3 ( ) ) = 0 ;
2018-02-17 00:48:07 +08:00
virtual void add_torque ( const Vector3 & p_torque ) = 0 ;
2020-03-26 12:23:34 +08:00
virtual void apply_central_impulse ( const Vector3 & p_impulse ) = 0 ;
virtual void apply_impulse ( const Vector3 & p_impulse , const Vector3 & p_position = Vector3 ( ) ) = 0 ;
virtual void apply_torque_impulse ( const Vector3 & p_impulse ) = 0 ;
2014-02-10 09:10:30 +08:00
2020-04-12 20:39:49 +08:00
virtual void set_sleep_state ( bool p_sleep ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual bool is_sleeping ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual int get_contact_count ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-09-10 21:37:49 +08:00
virtual Vector3 get_contact_local_position ( int p_contact_idx ) const = 0 ;
2017-03-05 23:44:50 +08:00
virtual Vector3 get_contact_local_normal ( int p_contact_idx ) const = 0 ;
2021-01-28 14:34:26 +08:00
virtual real_t get_contact_impulse ( int p_contact_idx ) const = 0 ;
2017-03-05 23:44:50 +08:00
virtual int get_contact_local_shape ( int p_contact_idx ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual RID get_contact_collider ( int p_contact_idx ) const = 0 ;
2017-09-10 21:37:49 +08:00
virtual Vector3 get_contact_collider_position ( int p_contact_idx ) const = 0 ;
2017-03-05 23:44:50 +08: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 21:37:49 +08:00
virtual Vector3 get_contact_collider_velocity_at_position ( int p_contact_idx ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual real_t get_step ( ) const = 0 ;
2014-02-10 09:10:30 +08:00
virtual void integrate_forces ( ) ;
2020-03-28 02:21:27 +08:00
virtual PhysicsDirectSpaceState3D * get_space_state ( ) = 0 ;
2014-02-10 09:10:30 +08:00
2020-03-28 02:21:27 +08:00
PhysicsDirectBodyState3D ( ) ;
2014-02-10 09:10:30 +08:00
} ;
2021-06-05 00:03:15 +08:00
class PhysicsShapeQueryParameters3D : public RefCounted {
GDCLASS ( PhysicsShapeQueryParameters3D , RefCounted ) ;
2020-03-28 02:21:27 +08:00
friend class PhysicsDirectSpaceState3D ;
2017-08-28 03:07:15 +08:00
2020-01-28 03:04:16 +08:00
RES shape_ref ;
2014-09-03 10:13:40 +08:00
RID shape ;
2020-10-17 13:08:21 +08:00
Transform3D transform ;
2021-08-31 07:29:16 +08:00
real_t margin = 0.0 ;
2014-09-03 10:13:40 +08:00
Set < RID > exclude ;
2021-08-31 07:29:16 +08:00
uint32_t collision_mask = UINT32_MAX ;
2017-03-05 23:44:50 +08:00
2021-08-31 07:29:16 +08:00
bool collide_with_bodies = true ;
bool collide_with_areas = false ;
2018-08-22 02:30:41 +08:00
2014-09-03 10:13:40 +08:00
protected :
static void _bind_methods ( ) ;
2017-03-05 23:44:50 +08:00
public :
2020-01-28 03:04:16 +08:00
void set_shape ( const RES & p_shape_ref ) ;
RES get_shape ( ) const ;
2017-03-05 23:44:50 +08:00
void set_shape_rid ( const RID & p_shape ) ;
2014-09-03 10:13:40 +08:00
RID get_shape_rid ( ) const ;
2020-10-17 13:08:21 +08:00
void set_transform ( const Transform3D & p_transform ) ;
Transform3D get_transform ( ) const ;
2014-09-03 10:13:40 +08:00
2021-01-28 14:34:26 +08:00
void set_margin ( real_t p_margin ) ;
real_t get_margin ( ) const ;
2014-09-03 10:13:40 +08:00
2021-04-30 23:19:04 +08:00
void set_collision_mask ( uint32_t p_collision_mask ) ;
uint32_t get_collision_mask ( ) const ;
2014-09-03 10:13:40 +08:00
2017-03-05 23:44:50 +08:00
void set_exclude ( const Vector < RID > & p_exclude ) ;
2014-09-03 10:13:40 +08:00
Vector < RID > get_exclude ( ) const ;
2018-08-22 02:30:41 +08:00
void set_collide_with_bodies ( bool p_enable ) ;
bool is_collide_with_bodies_enabled ( ) const ;
void set_collide_with_areas ( bool p_enable ) ;
bool is_collide_with_areas_enabled ( ) const ;
2014-09-03 10:13:40 +08:00
} ;
2020-03-28 02:21:27 +08:00
class PhysicsDirectSpaceState3D : public Object {
GDCLASS ( PhysicsDirectSpaceState3D , Object ) ;
2014-02-10 09:10:30 +08:00
2014-09-15 22:33:30 +08:00
private :
2021-08-31 07:29:16 +08:00
Dictionary _intersect_ray ( const Vector3 & p_from , const Vector3 & p_to , const Vector < RID > & p_exclude = Vector < RID > ( ) , uint32_t p_collision_mask = UINT32_MAX , bool p_collide_with_bodies = true , bool p_collide_with_areas = false ) ;
2020-03-28 02:21:27 +08:00
Array _intersect_shape ( const Ref < PhysicsShapeQueryParameters3D > & p_shape_query , int p_max_results = 32 ) ;
Array _cast_motion ( const Ref < PhysicsShapeQueryParameters3D > & p_shape_query , const Vector3 & p_motion ) ;
Array _collide_shape ( const Ref < PhysicsShapeQueryParameters3D > & p_shape_query , int p_max_results = 32 ) ;
Dictionary _get_rest_info ( const Ref < PhysicsShapeQueryParameters3D > & p_shape_query ) ;
2014-09-15 22:33:30 +08:00
protected :
static void _bind_methods ( ) ;
public :
2017-07-15 12:23:10 +08:00
struct ShapeResult {
2014-02-10 09:10:30 +08:00
RID rid ;
ObjectID collider_id ;
2021-06-08 01:46:24 +08:00
Object * collider = nullptr ;
int shape = 0 ;
2014-02-10 09:10:30 +08:00
} ;
2021-08-31 07:29:16 +08: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 ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-07-15 12:23:10 +08:00
struct RayResult {
Vector3 position ;
Vector3 normal ;
2014-02-10 09:10:30 +08:00
RID rid ;
ObjectID collider_id ;
2021-06-08 01:46:24 +08:00
Object * collider = nullptr ;
int shape = 0 ;
2014-02-10 09:10:30 +08:00
} ;
2021-08-31 07:29:16 +08:00
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 ) = 0 ;
2017-07-15 12:23:10 +08:00
2021-08-31 07:29:16 +08:00
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 ) = 0 ;
2014-09-03 10:13:40 +08:00
struct ShapeRestInfo {
Vector3 point ;
Vector3 normal ;
RID rid ;
ObjectID collider_id ;
2021-06-08 01:46:24 +08:00
int shape = 0 ;
2014-09-03 10:13:40 +08:00
Vector3 linear_velocity ; //velocity at contact point
} ;
2021-08-31 07:29:16 +08:00
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 ) = 0 ;
2014-09-03 10:13:40 +08:00
2021-08-31 07:29:16 +08:00
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 ) = 0 ;
2014-09-03 10:13:40 +08:00
2021-08-31 07:29:16 +08:00
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 ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-07-15 12:23:10 +08:00
virtual Vector3 get_closest_point_to_object_volume ( RID p_object , const Vector3 p_point ) const = 0 ;
2020-03-28 02:21:27 +08:00
PhysicsDirectSpaceState3D ( ) ;
2014-02-10 09:10:30 +08:00
} ;
2021-03-12 11:33:46 +08:00
class RenderingServerHandler {
public :
virtual void set_vertex ( int p_vertex_id , const void * p_vector3 ) = 0 ;
virtual void set_normal ( int p_vertex_id , const void * p_vector3 ) = 0 ;
virtual void set_aabb ( const AABB & p_aabb ) = 0 ;
virtual ~ RenderingServerHandler ( ) { }
} ;
2021-07-03 09:03:44 +08:00
class PhysicsTestMotionResult3D ;
2020-03-28 02:21:27 +08:00
class PhysicsServer3D : public Object {
GDCLASS ( PhysicsServer3D , Object ) ;
2014-02-10 09:10:30 +08:00
2020-03-28 02:21:27 +08:00
static PhysicsServer3D * singleton ;
2014-09-15 22:33:30 +08:00
2021-08-19 23:28:04 +08:00
virtual bool _body_test_motion ( RID p_body , const Transform3D & p_from , const Vector3 & p_motion , real_t p_margin = 0.001 , const Ref < PhysicsTestMotionResult3D > & p_result = Ref < PhysicsTestMotionResult3D > ( ) , bool p_collide_separation_ray = false , const Vector < RID > & p_exclude = Vector < RID > ( ) ) ;
2021-07-03 09:03:44 +08:00
2014-02-10 09:10:30 +08:00
protected :
static void _bind_methods ( ) ;
public :
2020-03-28 02:21:27 +08:00
static PhysicsServer3D * get_singleton ( ) ;
2014-02-10 09:10:30 +08:00
enum ShapeType {
2021-09-15 01:52:35 +08:00
SHAPE_WORLD_BOUNDARY , ///< plane:"plane"
2021-08-20 02:21:56 +08:00
SHAPE_SEPARATION_RAY , ///< float:"length"
2014-02-10 09:10:30 +08:00
SHAPE_SPHERE , ///< float:"radius"
SHAPE_BOX , ///< vec3:"extents"
SHAPE_CAPSULE , ///< dict( float:"radius", float:"height"):capsule
2018-06-13 06:53:28 +08:00
SHAPE_CYLINDER , ///< dict( float:"radius", float:"height"):cylinder
2014-02-10 09:10:30 +08:00
SHAPE_CONVEX_POLYGON , ///< array of planes:"planes"
SHAPE_CONCAVE_POLYGON , ///< vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array)
SHAPE_HEIGHTMAP , ///< dict( int:"width", int:"depth",float:"cell_size", float_array:"heights"
2021-03-12 11:33:46 +08:00
SHAPE_SOFT_BODY , ///< Used internally, can't be created from the physics server.
2014-02-10 09:10:30 +08:00
SHAPE_CUSTOM , ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
} ;
2021-02-10 00:19:03 +08:00
RID shape_create ( ShapeType p_shape ) ;
2021-09-15 01:52:35 +08:00
virtual RID world_boundary_shape_create ( ) = 0 ;
2021-08-20 02:21:56 +08:00
virtual RID separation_ray_shape_create ( ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual RID sphere_shape_create ( ) = 0 ;
virtual RID box_shape_create ( ) = 0 ;
virtual RID capsule_shape_create ( ) = 0 ;
virtual RID cylinder_shape_create ( ) = 0 ;
virtual RID convex_polygon_shape_create ( ) = 0 ;
virtual RID concave_polygon_shape_create ( ) = 0 ;
virtual RID heightmap_shape_create ( ) = 0 ;
virtual RID custom_shape_create ( ) = 0 ;
2017-03-05 23:44:50 +08: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 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual ShapeType shape_get_type ( RID p_shape ) const = 0 ;
virtual Variant shape_get_data ( RID p_shape ) const = 0 ;
2018-07-10 20:50:14 +08:00
virtual void shape_set_margin ( RID p_shape , real_t p_margin ) = 0 ;
virtual real_t shape_get_margin ( RID p_shape ) const = 0 ;
2017-03-05 23:44:50 +08:00
virtual real_t shape_get_custom_solver_bias ( RID p_shape ) const = 0 ;
2014-02-10 09:10:30 +08:00
/* SPACE API */
2017-03-05 23:44:50 +08:00
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 ;
2014-02-10 09:10:30 +08:00
enum SpaceParameter {
SPACE_PARAM_CONTACT_RECYCLE_RADIUS ,
SPACE_PARAM_CONTACT_MAX_SEPARATION ,
SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION ,
2017-07-08 23:12:18 +08:00
SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_THRESHOLD ,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_THRESHOLD ,
2014-02-10 09:10:30 +08:00
SPACE_PARAM_BODY_TIME_TO_SLEEP ,
SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO ,
SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS ,
2019-02-17 00:45:01 +08:00
SPACE_PARAM_TEST_MOTION_MIN_CONTACT_DEPTH
2014-02-10 09:10:30 +08:00
} ;
2017-03-05 23:44:50 +08: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 ;
2014-02-10 09:10:30 +08:00
2017-09-29 23:33:30 +08:00
// this function only works on physics process, errors and returns null otherwise
2020-03-28 02:21:27 +08:00
virtual PhysicsDirectSpaceState3D * space_get_direct_state ( RID p_space ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void space_set_debug_contacts ( RID p_space , int p_max_contacts ) = 0 ;
virtual Vector < Vector3 > space_get_contacts ( RID p_space ) const = 0 ;
virtual int space_get_contact_count ( RID p_space ) const = 0 ;
2014-02-10 09:10:30 +08:00
//missing space parameters
/* AREA API */
//missing attenuation? missing better override?
enum AreaParameter {
AREA_PARAM_GRAVITY ,
AREA_PARAM_GRAVITY_VECTOR ,
AREA_PARAM_GRAVITY_IS_POINT ,
2015-03-19 22:10:07 +08:00
AREA_PARAM_GRAVITY_DISTANCE_SCALE ,
2014-02-10 09:10:30 +08:00
AREA_PARAM_GRAVITY_POINT_ATTENUATION ,
2015-08-31 05:57:17 +08:00
AREA_PARAM_LINEAR_DAMP ,
AREA_PARAM_ANGULAR_DAMP ,
2021-07-20 12:23:32 +08:00
AREA_PARAM_PRIORITY ,
AREA_PARAM_WIND_FORCE_MAGNITUDE ,
AREA_PARAM_WIND_SOURCE ,
AREA_PARAM_WIND_DIRECTION ,
AREA_PARAM_WIND_ATTENUATION_FACTOR ,
2014-02-10 09:10:30 +08:00
} ;
2017-03-05 23:44:50 +08:00
virtual RID area_create ( ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_space ( RID p_area , RID p_space ) = 0 ;
virtual RID area_get_space ( RID p_area ) const = 0 ;
2014-02-10 09:10:30 +08:00
enum AreaSpaceOverrideMode {
AREA_SPACE_OVERRIDE_DISABLED ,
AREA_SPACE_OVERRIDE_COMBINE ,
2015-12-14 09:56:11 +08:00
AREA_SPACE_OVERRIDE_COMBINE_REPLACE ,
2014-02-10 09:10:30 +08:00
AREA_SPACE_OVERRIDE_REPLACE ,
2015-12-14 09:56:11 +08:00
AREA_SPACE_OVERRIDE_REPLACE_COMBINE
2014-02-10 09:10:30 +08:00
} ;
2017-03-05 23:44:50 +08:00
virtual void area_set_space_override_mode ( RID p_area , AreaSpaceOverrideMode p_mode ) = 0 ;
virtual AreaSpaceOverrideMode area_get_space_override_mode ( RID p_area ) const = 0 ;
2014-02-10 09:10:30 +08:00
2020-10-17 13:08:21 +08:00
virtual void area_add_shape ( RID p_area , RID p_shape , const Transform3D & p_transform = Transform3D ( ) , bool p_disabled = false ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual void area_set_shape ( RID p_area , int p_shape_idx , RID p_shape ) = 0 ;
2020-10-17 13:08:21 +08:00
virtual void area_set_shape_transform ( RID p_area , int p_shape_idx , const Transform3D & p_transform ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08: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 ;
2020-10-17 13:08:21 +08:00
virtual Transform3D area_get_shape_transform ( RID p_area , int p_shape_idx ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_remove_shape ( RID p_area , int p_shape_idx ) = 0 ;
virtual void area_clear_shapes ( RID p_area ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-07-15 12:23:10 +08:00
virtual void area_set_shape_disabled ( RID p_area , int p_shape_idx , bool p_disabled ) = 0 ;
2019-05-09 17:21:49 +08:00
virtual void area_attach_object_instance_id ( RID p_area , ObjectID p_id ) = 0 ;
2017-08-07 18:17:31 +08:00
virtual ObjectID area_get_object_instance_id ( RID p_area ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_param ( RID p_area , AreaParameter p_param , const Variant & p_value ) = 0 ;
2020-10-17 13:08:21 +08:00
virtual void area_set_transform ( RID p_area , const Transform3D & p_transform ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual Variant area_get_param ( RID p_parea , AreaParameter p_param ) const = 0 ;
2020-10-17 13:08:21 +08:00
virtual Transform3D area_get_transform ( RID p_area ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_collision_mask ( RID p_area , uint32_t p_mask ) = 0 ;
2017-06-13 23:45:01 +08:00
virtual void area_set_collision_layer ( RID p_area , uint32_t p_layer ) = 0 ;
2016-04-10 02:54:09 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_monitorable ( RID p_area , bool p_monitorable ) = 0 ;
2015-06-13 02:52:21 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_monitor_callback ( RID p_area , Object * p_receiver , const StringName & p_method ) = 0 ;
virtual void area_set_area_monitor_callback ( RID p_area , Object * p_receiver , const StringName & p_method ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void area_set_ray_pickable ( RID p_area , bool p_enable ) = 0 ;
2014-09-15 22:33:30 +08:00
2014-02-10 09:10:30 +08:00
/* BODY API */
//missing ccd?
enum BodyMode {
BODY_MODE_STATIC ,
2014-02-19 22:57:14 +08:00
BODY_MODE_KINEMATIC ,
2021-05-20 09:15:07 +08:00
BODY_MODE_DYNAMIC ,
BODY_MODE_DYNAMIC_LOCKED ,
2014-02-10 09:10:30 +08:00
} ;
2021-02-10 00:19:03 +08:00
virtual RID body_create ( ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_space ( RID p_body , RID p_space ) = 0 ;
virtual RID body_get_space ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_mode ( RID p_body , BodyMode p_mode ) = 0 ;
virtual BodyMode body_get_mode ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
2020-10-17 13:08:21 +08:00
virtual void body_add_shape ( RID p_body , RID p_shape , const Transform3D & p_transform = Transform3D ( ) , bool p_disabled = false ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual void body_set_shape ( RID p_body , int p_shape_idx , RID p_shape ) = 0 ;
2020-10-17 13:08:21 +08:00
virtual void body_set_shape_transform ( RID p_body , int p_shape_idx , const Transform3D & p_transform ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08: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 ;
2020-10-17 13:08:21 +08:00
virtual Transform3D body_get_shape_transform ( RID p_body , int p_shape_idx ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_remove_shape ( RID p_body , int p_shape_idx ) = 0 ;
virtual void body_clear_shapes ( RID p_body ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-07-15 12:23:10 +08:00
virtual void body_set_shape_disabled ( RID p_body , int p_shape_idx , bool p_disabled ) = 0 ;
2020-02-13 01:24:06 +08: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 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_enable_continuous_collision_detection ( RID p_body , bool p_enable ) = 0 ;
virtual bool body_is_continuous_collision_detection_enabled ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-06-13 23:45:01 +08: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-09-03 10:13:40 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_collision_mask ( RID p_body , uint32_t p_mask ) = 0 ;
2017-06-13 23:45:01 +08:00
virtual uint32_t body_get_collision_mask ( RID p_body ) const = 0 ;
2016-04-10 02:54:09 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_user_flags ( RID p_body , uint32_t p_flags ) = 0 ;
2017-06-13 23:45:01 +08:00
virtual uint32_t body_get_user_flags ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
// common body variables
enum BodyParameter {
BODY_PARAM_BOUNCE ,
BODY_PARAM_FRICTION ,
BODY_PARAM_MASS , ///< unused for static, always infinite
2021-06-11 08:37:19 +08:00
BODY_PARAM_INERTIA ,
BODY_PARAM_CENTER_OF_MASS ,
2015-08-31 05:57:17 +08:00
BODY_PARAM_GRAVITY_SCALE ,
BODY_PARAM_LINEAR_DAMP ,
BODY_PARAM_ANGULAR_DAMP ,
2014-02-10 09:10:30 +08:00
BODY_PARAM_MAX ,
} ;
2021-06-11 08:37:19 +08: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 ;
2014-02-10 09:10:30 +08:00
//state
enum BodyState {
BODY_STATE_TRANSFORM ,
BODY_STATE_LINEAR_VELOCITY ,
BODY_STATE_ANGULAR_VELOCITY ,
BODY_STATE_SLEEPING ,
2016-03-09 07:00:52 +08:00
BODY_STATE_CAN_SLEEP
2014-02-10 09:10:30 +08:00
} ;
2017-03-05 23:44:50 +08: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 ;
2014-02-10 09:10:30 +08:00
//do something about it
2017-03-05 23:44:50 +08:00
virtual void body_set_applied_force ( RID p_body , const Vector3 & p_force ) = 0 ;
virtual Vector3 body_get_applied_force ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_applied_torque ( RID p_body , const Vector3 & p_torque ) = 0 ;
virtual Vector3 body_get_applied_torque ( RID p_body ) const = 0 ;
2014-02-10 09:10:30 +08:00
2018-07-24 15:49:12 +08:00
virtual void body_add_central_force ( RID p_body , const Vector3 & p_force ) = 0 ;
2020-03-26 12:23:34 +08:00
virtual void body_add_force ( RID p_body , const Vector3 & p_force , const Vector3 & p_position = Vector3 ( ) ) = 0 ;
2018-07-24 15:49:12 +08:00
virtual void body_add_torque ( RID p_body , const Vector3 & p_torque ) = 0 ;
virtual void body_apply_central_impulse ( RID p_body , const Vector3 & p_impulse ) = 0 ;
2020-03-26 12:23:34 +08:00
virtual void body_apply_impulse ( RID p_body , const Vector3 & p_impulse , const Vector3 & p_position = Vector3 ( ) ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual void body_apply_torque_impulse ( RID p_body , const Vector3 & p_impulse ) = 0 ;
virtual void body_set_axis_velocity ( RID p_body , const Vector3 & p_axis_velocity ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-12-11 00:21:14 +08:00
enum BodyAxis {
BODY_AXIS_LINEAR_X = 1 < < 0 ,
BODY_AXIS_LINEAR_Y = 1 < < 1 ,
BODY_AXIS_LINEAR_Z = 1 < < 2 ,
BODY_AXIS_ANGULAR_X = 1 < < 3 ,
BODY_AXIS_ANGULAR_Y = 1 < < 4 ,
BODY_AXIS_ANGULAR_Z = 1 < < 5
} ;
virtual void body_set_axis_lock ( RID p_body , BodyAxis p_axis , bool p_lock ) = 0 ;
virtual bool body_is_axis_locked ( RID p_body , BodyAxis p_axis ) const = 0 ;
2014-05-14 12:22:15 +08:00
2014-02-10 09:10:30 +08:00
//fix
2017-03-05 23:44:50 +08:00
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 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
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 ;
2014-02-10 09:10:30 +08:00
//missing remove
2021-01-28 14:34:26 +08: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 09:10:30 +08:00
2017-03-05 23:44:50 +08: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 ;
2014-02-10 09:10:30 +08:00
2021-06-05 07:09:41 +08:00
// Callback for C++ use only.
typedef void ( * BodyStateCallback ) ( void * p_instance , PhysicsDirectBodyState3D * p_state ) ;
virtual void body_set_state_sync_callback ( RID p_body , void * p_instance , BodyStateCallback p_callback ) = 0 ;
2021-03-30 14:22:23 +08:00
virtual void body_set_force_integration_callback ( RID p_body , const Callable & p_callable , const Variant & p_udata = Variant ( ) ) = 0 ;
2014-10-03 11:10:51 +08:00
2017-03-05 23:44:50 +08:00
virtual void body_set_ray_pickable ( RID p_body , bool p_enable ) = 0 ;
2014-10-03 11:10:51 +08:00
2017-09-29 23:33:30 +08:00
// this function only works on physics process, errors and returns null otherwise
2020-03-28 02:21:27 +08:00
virtual PhysicsDirectBodyState3D * body_get_direct_state ( RID p_body ) = 0 ;
2017-09-29 23:33:30 +08:00
2017-07-15 12:23:10 +08:00
struct MotionResult {
2021-08-13 06:41:40 +08:00
Vector3 travel ;
2017-07-15 12:23:10 +08:00
Vector3 remainder ;
Vector3 collision_point ;
Vector3 collision_normal ;
Vector3 collider_velocity ;
2021-06-25 10:25:26 +08:00
real_t collision_depth = 0.0 ;
real_t collision_safe_fraction = 0.0 ;
real_t collision_unsafe_fraction = 0.0 ;
2021-05-20 09:14:33 +08:00
int collision_local_shape = 0 ;
2017-07-15 12:23:10 +08:00
ObjectID collider_id ;
RID collider ;
2021-05-20 09:14:33 +08:00
int collider_shape = 0 ;
2017-07-15 12:23:10 +08:00
Variant collider_metadata ;
2021-08-13 06:41:40 +08:00
real_t get_angle ( Vector3 p_up_direction ) const {
return Math : : acos ( collision_normal . dot ( p_up_direction ) ) ;
}
2017-07-15 12:23:10 +08:00
} ;
2021-08-19 23:28:04 +08:00
virtual bool body_test_motion ( RID p_body , const Transform3D & p_from , const Vector3 & p_motion , real_t p_margin = 0.001 , MotionResult * r_result = nullptr , bool p_collide_separation_ray = false , const Set < RID > & p_exclude = Set < RID > ( ) ) = 0 ;
2018-08-15 01:20:48 +08:00
2017-11-21 08:36:32 +08:00
/* SOFT BODY */
2021-02-10 00:19:03 +08:00
virtual RID soft_body_create ( ) = 0 ;
2017-11-21 08:36:32 +08:00
2021-03-12 11:33:46 +08:00
virtual void soft_body_update_rendering_server ( RID p_body , RenderingServerHandler * p_rendering_server_handler ) = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_space ( RID p_body , RID p_space ) = 0 ;
virtual RID soft_body_get_space ( RID p_body ) const = 0 ;
virtual void soft_body_set_mesh ( RID p_body , const REF & p_mesh ) = 0 ;
2021-03-12 11:33:46 +08:00
virtual AABB soft_body_get_bounds ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_collision_layer ( RID p_body , uint32_t p_layer ) = 0 ;
virtual uint32_t soft_body_get_collision_layer ( RID p_body ) const = 0 ;
virtual void soft_body_set_collision_mask ( RID p_body , uint32_t p_mask ) = 0 ;
virtual uint32_t soft_body_get_collision_mask ( RID p_body ) const = 0 ;
virtual void soft_body_add_collision_exception ( RID p_body , RID p_body_b ) = 0 ;
virtual void soft_body_remove_collision_exception ( RID p_body , RID p_body_b ) = 0 ;
virtual void soft_body_get_collision_exceptions ( RID p_body , List < RID > * p_exceptions ) = 0 ;
virtual void soft_body_set_state ( RID p_body , BodyState p_state , const Variant & p_variant ) = 0 ;
virtual Variant soft_body_get_state ( RID p_body , BodyState p_state ) const = 0 ;
2020-10-17 13:08:21 +08:00
virtual void soft_body_set_transform ( RID p_body , const Transform3D & p_transform ) = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_ray_pickable ( RID p_body , bool p_enable ) = 0 ;
virtual void soft_body_set_simulation_precision ( RID p_body , int p_simulation_precision ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual int soft_body_get_simulation_precision ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_total_mass ( RID p_body , real_t p_total_mass ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t soft_body_get_total_mass ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_linear_stiffness ( RID p_body , real_t p_stiffness ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t soft_body_get_linear_stiffness ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_pressure_coefficient ( RID p_body , real_t p_pressure_coefficient ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t soft_body_get_pressure_coefficient ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_damping_coefficient ( RID p_body , real_t p_damping_coefficient ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t soft_body_get_damping_coefficient ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_set_drag_coefficient ( RID p_body , real_t p_drag_coefficient ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t soft_body_get_drag_coefficient ( RID p_body ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_move_point ( RID p_body , int p_point_index , const Vector3 & p_global_position ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual Vector3 soft_body_get_point_global_position ( RID p_body , int p_point_index ) const = 0 ;
2017-11-21 08:36:32 +08:00
virtual void soft_body_remove_all_pinned_points ( RID p_body ) = 0 ;
virtual void soft_body_pin_point ( RID p_body , int p_point_index , bool p_pin ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual bool soft_body_is_point_pinned ( RID p_body , int p_point_index ) const = 0 ;
2017-11-21 08:36:32 +08:00
2014-02-10 09:10:30 +08:00
/* JOINT API */
2014-09-15 22:33:30 +08:00
enum JointType {
2021-02-10 00:19:03 +08:00
JOINT_TYPE_PIN ,
JOINT_TYPE_HINGE ,
JOINT_TYPE_SLIDER ,
JOINT_TYPE_CONE_TWIST ,
JOINT_TYPE_6DOF ,
JOINT_TYPE_MAX ,
2014-09-15 22:33:30 +08:00
} ;
2021-02-10 00:19:03 +08:00
virtual RID joint_create ( ) = 0 ;
virtual void joint_clear ( RID p_joint ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual JointType joint_get_type ( RID p_joint ) const = 0 ;
2014-09-15 22:33:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void joint_set_solver_priority ( RID p_joint , int p_priority ) = 0 ;
virtual int joint_get_solver_priority ( RID p_joint ) const = 0 ;
2014-09-15 22:33:30 +08:00
2018-02-06 01:20:26 +08: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-10 00:19:03 +08:00
virtual void joint_make_pin ( RID p_joint , RID p_body_A , const Vector3 & p_local_A , RID p_body_B , const Vector3 & p_local_B ) = 0 ;
2014-09-15 22:33:30 +08:00
enum PinJointParam {
PIN_JOINT_BIAS ,
PIN_JOINT_DAMPING ,
PIN_JOINT_IMPULSE_CLAMP
} ;
2021-01-28 14:34:26 +08:00
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 ;
2014-09-15 22:33:30 +08:00
2017-08-07 18:17:31 +08:00
virtual void pin_joint_set_local_a ( RID p_joint , const Vector3 & p_A ) = 0 ;
virtual Vector3 pin_joint_get_local_a ( RID p_joint ) const = 0 ;
2014-09-15 22:33:30 +08:00
2017-08-07 18:17:31 +08:00
virtual void pin_joint_set_local_b ( RID p_joint , const Vector3 & p_B ) = 0 ;
virtual Vector3 pin_joint_get_local_b ( RID p_joint ) const = 0 ;
2014-09-15 22:33:30 +08:00
enum HingeJointParam {
HINGE_JOINT_BIAS ,
HINGE_JOINT_LIMIT_UPPER ,
HINGE_JOINT_LIMIT_LOWER ,
HINGE_JOINT_LIMIT_BIAS ,
HINGE_JOINT_LIMIT_SOFTNESS ,
HINGE_JOINT_LIMIT_RELAXATION ,
HINGE_JOINT_MOTOR_TARGET_VELOCITY ,
HINGE_JOINT_MOTOR_MAX_IMPULSE ,
HINGE_JOINT_MAX
} ;
enum HingeJointFlag {
HINGE_JOINT_FLAG_USE_LIMIT ,
HINGE_JOINT_FLAG_ENABLE_MOTOR ,
HINGE_JOINT_FLAG_MAX
} ;
2020-10-17 13:08:21 +08:00
virtual void joint_make_hinge ( RID p_joint , RID p_body_A , const Transform3D & p_hinge_A , RID p_body_B , const Transform3D & p_hinge_B ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual void joint_make_hinge_simple ( RID p_joint , RID p_body_A , const Vector3 & p_pivot_A , const Vector3 & p_axis_A , RID p_body_B , const Vector3 & p_pivot_B , const Vector3 & p_axis_B ) = 0 ;
2014-09-15 22:33:30 +08:00
2021-01-28 14:34:26 +08:00
virtual void hinge_joint_set_param ( RID p_joint , HingeJointParam p_param , real_t p_value ) = 0 ;
virtual real_t hinge_joint_get_param ( RID p_joint , HingeJointParam p_param ) const = 0 ;
2014-09-15 22:33:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void hinge_joint_set_flag ( RID p_joint , HingeJointFlag p_flag , bool p_value ) = 0 ;
virtual bool hinge_joint_get_flag ( RID p_joint , HingeJointFlag p_flag ) const = 0 ;
2014-09-15 22:33:30 +08:00
enum SliderJointParam {
SLIDER_JOINT_LINEAR_LIMIT_UPPER ,
SLIDER_JOINT_LINEAR_LIMIT_LOWER ,
SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS ,
SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION ,
SLIDER_JOINT_LINEAR_LIMIT_DAMPING ,
SLIDER_JOINT_LINEAR_MOTION_SOFTNESS ,
SLIDER_JOINT_LINEAR_MOTION_RESTITUTION ,
SLIDER_JOINT_LINEAR_MOTION_DAMPING ,
SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS ,
SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION ,
SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING ,
SLIDER_JOINT_ANGULAR_LIMIT_UPPER ,
SLIDER_JOINT_ANGULAR_LIMIT_LOWER ,
SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS ,
SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION ,
SLIDER_JOINT_ANGULAR_LIMIT_DAMPING ,
SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS ,
SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION ,
SLIDER_JOINT_ANGULAR_MOTION_DAMPING ,
SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS ,
SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION ,
SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING ,
SLIDER_JOINT_MAX
} ;
2020-10-17 13:08:21 +08:00
virtual void joint_make_slider ( RID p_joint , RID p_body_A , const Transform3D & p_local_frame_A , RID p_body_B , const Transform3D & p_local_frame_B ) = 0 ; //reference frame is A
2014-09-15 22:33:30 +08:00
2021-01-28 14:34:26 +08:00
virtual void slider_joint_set_param ( RID p_joint , SliderJointParam p_param , real_t p_value ) = 0 ;
virtual real_t slider_joint_get_param ( RID p_joint , SliderJointParam p_param ) const = 0 ;
2014-09-15 22:33:30 +08:00
enum ConeTwistJointParam {
CONE_TWIST_JOINT_SWING_SPAN ,
CONE_TWIST_JOINT_TWIST_SPAN ,
CONE_TWIST_JOINT_BIAS ,
CONE_TWIST_JOINT_SOFTNESS ,
CONE_TWIST_JOINT_RELAXATION ,
CONE_TWIST_MAX
} ;
2020-10-17 13:08:21 +08:00
virtual void joint_make_cone_twist ( RID p_joint , RID p_body_A , const Transform3D & p_local_frame_A , RID p_body_B , const Transform3D & p_local_frame_B ) = 0 ; //reference frame is A
2014-09-15 22:33:30 +08:00
2021-01-28 14:34:26 +08:00
virtual void cone_twist_joint_set_param ( RID p_joint , ConeTwistJointParam p_param , real_t p_value ) = 0 ;
virtual real_t cone_twist_joint_get_param ( RID p_joint , ConeTwistJointParam p_param ) const = 0 ;
2014-09-15 22:33:30 +08:00
enum G6DOFJointAxisParam {
G6DOF_JOINT_LINEAR_LOWER_LIMIT ,
G6DOF_JOINT_LINEAR_UPPER_LIMIT ,
G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS ,
G6DOF_JOINT_LINEAR_RESTITUTION ,
G6DOF_JOINT_LINEAR_DAMPING ,
2018-03-16 20:07:52 +08:00
G6DOF_JOINT_LINEAR_MOTOR_TARGET_VELOCITY ,
G6DOF_JOINT_LINEAR_MOTOR_FORCE_LIMIT ,
2018-11-09 19:58:57 +08:00
G6DOF_JOINT_LINEAR_SPRING_STIFFNESS ,
G6DOF_JOINT_LINEAR_SPRING_DAMPING ,
G6DOF_JOINT_LINEAR_SPRING_EQUILIBRIUM_POINT ,
2014-09-15 22:33:30 +08:00
G6DOF_JOINT_ANGULAR_LOWER_LIMIT ,
G6DOF_JOINT_ANGULAR_UPPER_LIMIT ,
G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS ,
G6DOF_JOINT_ANGULAR_DAMPING ,
G6DOF_JOINT_ANGULAR_RESTITUTION ,
G6DOF_JOINT_ANGULAR_FORCE_LIMIT ,
G6DOF_JOINT_ANGULAR_ERP ,
G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY ,
G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT ,
2018-11-09 19:58:57 +08:00
G6DOF_JOINT_ANGULAR_SPRING_STIFFNESS ,
G6DOF_JOINT_ANGULAR_SPRING_DAMPING ,
G6DOF_JOINT_ANGULAR_SPRING_EQUILIBRIUM_POINT ,
2014-09-15 22:33:30 +08:00
G6DOF_JOINT_MAX
} ;
enum G6DOFJointAxisFlag {
G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT ,
G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT ,
2018-11-09 19:58:57 +08:00
G6DOF_JOINT_FLAG_ENABLE_ANGULAR_SPRING ,
G6DOF_JOINT_FLAG_ENABLE_LINEAR_SPRING ,
2014-09-15 22:33:30 +08:00
G6DOF_JOINT_FLAG_ENABLE_MOTOR ,
2018-03-16 20:07:52 +08:00
G6DOF_JOINT_FLAG_ENABLE_LINEAR_MOTOR ,
2014-09-15 22:33:30 +08:00
G6DOF_JOINT_FLAG_MAX
} ;
2020-10-17 13:08:21 +08:00
virtual void joint_make_generic_6dof ( RID p_joint , RID p_body_A , const Transform3D & p_local_frame_A , RID p_body_B , const Transform3D & p_local_frame_B ) = 0 ; //reference frame is A
2014-09-15 22:33:30 +08:00
2021-01-28 14:34:26 +08:00
virtual void generic_6dof_joint_set_param ( RID p_joint , Vector3 : : Axis , G6DOFJointAxisParam p_param , real_t p_value ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual real_t generic_6dof_joint_get_param ( RID p_joint , Vector3 : : Axis , G6DOFJointAxisParam p_param ) const = 0 ;
2014-09-15 22:33:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void generic_6dof_joint_set_flag ( RID p_joint , Vector3 : : Axis , G6DOFJointAxisFlag p_flag , bool p_enable ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual bool generic_6dof_joint_get_flag ( RID p_joint , Vector3 : : Axis , G6DOFJointAxisFlag p_flag ) const = 0 ;
2014-09-15 22:33:30 +08:00
2014-02-10 09:10:30 +08:00
/* QUERY API */
enum AreaBodyStatus {
AREA_BODY_ADDED ,
AREA_BODY_REMOVED
} ;
/* MISC */
2017-03-05 23:44:50 +08:00
virtual void free ( RID p_rid ) = 0 ;
2014-02-10 09:10:30 +08:00
2017-03-05 23:44:50 +08:00
virtual void set_active ( bool p_active ) = 0 ;
virtual void init ( ) = 0 ;
2021-01-28 14:34:26 +08:00
virtual void step ( real_t p_step ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual void sync ( ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual void flush_queries ( ) = 0 ;
2021-02-10 00:19:03 +08:00
virtual void end_sync ( ) = 0 ;
2017-03-05 23:44:50 +08:00
virtual void finish ( ) = 0 ;
2014-02-10 09:10:30 +08:00
2018-11-16 19:49:26 +08:00
virtual bool is_flushing_queries ( ) const = 0 ;
2021-07-08 01:09:15 +08:00
virtual void set_collision_iterations ( int p_iterations ) = 0 ;
2014-09-03 10:13:40 +08:00
enum ProcessInfo {
INFO_ACTIVE_OBJECTS ,
INFO_COLLISION_PAIRS ,
INFO_ISLAND_COUNT
} ;
2017-03-05 23:44:50 +08:00
virtual int get_process_info ( ProcessInfo p_info ) = 0 ;
2014-09-03 10:13:40 +08:00
2020-03-28 02:21:27 +08:00
PhysicsServer3D ( ) ;
~ PhysicsServer3D ( ) ;
2014-02-10 09:10:30 +08:00
} ;
2021-07-03 09:03:44 +08:00
class PhysicsTestMotionResult3D : public RefCounted {
GDCLASS ( PhysicsTestMotionResult3D , RefCounted ) ;
PhysicsServer3D : : MotionResult result ;
friend class PhysicsServer3D ;
protected :
static void _bind_methods ( ) ;
public :
PhysicsServer3D : : MotionResult * get_result_ptr ( ) const { return const_cast < PhysicsServer3D : : MotionResult * > ( & result ) ; }
2021-08-13 06:41:40 +08:00
Vector3 get_travel ( ) const ;
Vector3 get_remainder ( ) const ;
2021-07-03 09:03:44 +08:00
Vector3 get_collision_point ( ) const ;
Vector3 get_collision_normal ( ) const ;
Vector3 get_collider_velocity ( ) const ;
ObjectID get_collider_id ( ) const ;
RID get_collider_rid ( ) const ;
Object * get_collider ( ) const ;
int get_collider_shape ( ) const ;
real_t get_collision_depth ( ) const ;
real_t get_collision_safe_fraction ( ) const ;
real_t get_collision_unsafe_fraction ( ) const ;
} ;
2020-03-28 02:21:27 +08:00
typedef PhysicsServer3D * ( * CreatePhysicsServer3DCallback ) ( ) ;
2017-10-21 19:02:06 +08:00
2020-03-28 02:21:27 +08:00
class PhysicsServer3DManager {
2017-10-21 19:02:06 +08:00
struct ClassInfo {
String name ;
2020-05-12 23:01:17 +08:00
CreatePhysicsServer3DCallback create_callback = nullptr ;
2017-10-21 19:02:06 +08:00
2020-05-12 23:01:17 +08:00
ClassInfo ( ) { }
2017-10-21 19:02:06 +08:00
2020-03-28 02:21:27 +08:00
ClassInfo ( String p_name , CreatePhysicsServer3DCallback p_create_callback ) :
2017-12-07 04:36:34 +08:00
name ( p_name ) ,
create_callback ( p_create_callback ) { }
2017-10-21 19:02:06 +08:00
2017-12-07 04:36:34 +08:00
ClassInfo ( const ClassInfo & p_ci ) :
name ( p_ci . name ) ,
create_callback ( p_ci . create_callback ) { }
2019-03-02 20:32:29 +08:00
2020-09-04 16:18:19 +08:00
ClassInfo & operator = ( const ClassInfo & p_ci ) {
2019-03-02 20:32:29 +08:00
name = p_ci . name ;
create_callback = p_ci . create_callback ;
return * this ;
}
2017-10-21 19:02:06 +08:00
} ;
static Vector < ClassInfo > physics_servers ;
static int default_server_id ;
static int default_server_priority ;
public :
static const String setting_property_name ;
private :
static void on_servers_changed ( ) ;
public :
2020-03-28 02:21:27 +08:00
static void register_server ( const String & p_name , CreatePhysicsServer3DCallback p_creat_callback ) ;
2017-10-21 19:02:06 +08:00
static void set_default_server ( const String & p_name , int p_priority = 0 ) ;
static int find_server_id ( const String & p_name ) ;
static int get_servers_count ( ) ;
static String get_server_name ( int p_id ) ;
2020-03-28 02:21:27 +08:00
static PhysicsServer3D * new_default_server ( ) ;
static PhysicsServer3D * new_server ( const String & p_name ) ;
2017-10-21 19:02:06 +08:00
} ;
2020-03-28 02:21:27 +08:00
VARIANT_ENUM_CAST ( PhysicsServer3D : : ShapeType ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : SpaceParameter ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : AreaParameter ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : AreaSpaceOverrideMode ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : BodyMode ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : BodyParameter ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : BodyState ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : BodyAxis ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : PinJointParam ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : JointType ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : HingeJointParam ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : HingeJointFlag ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : SliderJointParam ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : ConeTwistJointParam ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : G6DOFJointAxisParam ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : G6DOFJointAxisFlag ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : AreaBodyStatus ) ;
VARIANT_ENUM_CAST ( PhysicsServer3D : : ProcessInfo ) ;
2014-02-10 09:10:30 +08:00
# endif