physics_server.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. /*************************************************************************/
  2. /* physics_server.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef PHYSICS_SERVER_H
  31. #define PHYSICS_SERVER_H
  32. #include "object.h"
  33. #include "resource.h"
  34. class PhysicsDirectSpaceState;
  35. class PhysicsDirectBodyState : public Object {
  36. OBJ_TYPE(PhysicsDirectBodyState, Object);
  37. protected:
  38. static void _bind_methods();
  39. public:
  40. virtual Vector3 get_total_gravity() const = 0;
  41. virtual float get_total_angular_damp() const = 0;
  42. virtual float get_total_linear_damp() const = 0;
  43. virtual float get_inverse_mass() const = 0; // get the mass
  44. virtual Vector3 get_inverse_inertia() const = 0; // get density of this body space
  45. virtual Matrix3 get_inverse_inertia_tensor() const = 0; // get density of this body space
  46. virtual void set_linear_velocity(const Vector3 &p_velocity) = 0;
  47. virtual Vector3 get_linear_velocity() const = 0;
  48. virtual void set_angular_velocity(const Vector3 &p_velocity) = 0;
  49. virtual Vector3 get_angular_velocity() const = 0;
  50. virtual void set_transform(const Transform &p_transform) = 0;
  51. virtual Transform get_transform() const = 0;
  52. virtual void add_force(const Vector3 &p_force, const Vector3 &p_pos) = 0;
  53. virtual void apply_impulse(const Vector3 &p_pos, const Vector3 &p_j) = 0;
  54. virtual void set_sleep_state(bool p_enable) = 0;
  55. virtual bool is_sleeping() const = 0;
  56. virtual int get_contact_count() const = 0;
  57. virtual Vector3 get_contact_local_pos(int p_contact_idx) const = 0;
  58. virtual Vector3 get_contact_local_normal(int p_contact_idx) const = 0;
  59. virtual int get_contact_local_shape(int p_contact_idx) const = 0;
  60. virtual RID get_contact_collider(int p_contact_idx) const = 0;
  61. virtual Vector3 get_contact_collider_pos(int p_contact_idx) const = 0;
  62. virtual ObjectID get_contact_collider_id(int p_contact_idx) const = 0;
  63. virtual Object *get_contact_collider_object(int p_contact_idx) const;
  64. virtual int get_contact_collider_shape(int p_contact_idx) const = 0;
  65. virtual Vector3 get_contact_collider_velocity_at_pos(int p_contact_idx) const = 0;
  66. virtual real_t get_step() const = 0;
  67. virtual void integrate_forces();
  68. virtual PhysicsDirectSpaceState *get_space_state() = 0;
  69. PhysicsDirectBodyState();
  70. };
  71. class PhysicsShapeQueryResult;
  72. class PhysicsShapeQueryParameters : public Reference {
  73. OBJ_TYPE(PhysicsShapeQueryParameters, Reference);
  74. friend class PhysicsDirectSpaceState;
  75. RID shape;
  76. Transform transform;
  77. float margin;
  78. Set<RID> exclude;
  79. uint32_t layer_mask;
  80. uint32_t object_type_mask;
  81. protected:
  82. static void _bind_methods();
  83. public:
  84. void set_shape(const RES &p_shape);
  85. void set_shape_rid(const RID &p_shape);
  86. RID get_shape_rid() const;
  87. void set_transform(const Transform &p_transform);
  88. Transform get_transform() const;
  89. void set_margin(float p_margin);
  90. float get_margin() const;
  91. void set_layer_mask(int p_layer_mask);
  92. int get_layer_mask() const;
  93. void set_object_type_mask(int p_object_type_mask);
  94. int get_object_type_mask() const;
  95. void set_exclude(const Vector<RID> &p_exclude);
  96. Vector<RID> get_exclude() const;
  97. PhysicsShapeQueryParameters();
  98. };
  99. class PhysicsDirectSpaceState : public Object {
  100. OBJ_TYPE(PhysicsDirectSpaceState, Object);
  101. // Variant _intersect_ray(const Vector3& p_from, const Vector3& p_to,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_collision_mask=0);
  102. // Variant _intersect_shape(const RID& p_shape, const Transform& p_xform,int p_result_max=64,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_collision_mask=0);
  103. public:
  104. enum ObjectTypeMask {
  105. TYPE_MASK_STATIC_BODY = 1 << 0,
  106. TYPE_MASK_KINEMATIC_BODY = 1 << 1,
  107. TYPE_MASK_RIGID_BODY = 1 << 2,
  108. TYPE_MASK_CHARACTER_BODY = 1 << 3,
  109. TYPE_MASK_AREA = 1 << 4,
  110. TYPE_MASK_COLLISION = TYPE_MASK_STATIC_BODY | TYPE_MASK_CHARACTER_BODY | TYPE_MASK_KINEMATIC_BODY | TYPE_MASK_RIGID_BODY
  111. };
  112. private:
  113. Dictionary _intersect_ray(const Vector3 &p_from, const Vector3 &p_to, const Vector<RID> &p_exclude = Vector<RID>(), uint32_t p_layers = 0, uint32_t p_object_type_mask = TYPE_MASK_COLLISION);
  114. Array _intersect_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results = 32);
  115. Array _cast_motion(const Ref<PhysicsShapeQueryParameters> &p_shape_query, const Vector3 &p_motion);
  116. Array _collide_shape(const Ref<PhysicsShapeQueryParameters> &p_shape_query, int p_max_results = 32);
  117. Dictionary _get_rest_info(const Ref<PhysicsShapeQueryParameters> &p_shape_query);
  118. protected:
  119. static void _bind_methods();
  120. public:
  121. struct RayResult {
  122. Vector3 position;
  123. Vector3 normal;
  124. RID rid;
  125. ObjectID collider_id;
  126. Object *collider;
  127. int shape;
  128. };
  129. 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_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION, bool p_pick_ray = false) = 0;
  130. struct ShapeResult {
  131. RID rid;
  132. ObjectID collider_id;
  133. Object *collider;
  134. int shape;
  135. };
  136. virtual int intersect_shape(const RID &p_shape, const Transform &p_xform, float p_margin, ShapeResult *r_results, int p_result_max, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
  137. struct ShapeRestInfo {
  138. Vector3 point;
  139. Vector3 normal;
  140. RID rid;
  141. ObjectID collider_id;
  142. int shape;
  143. Vector3 linear_velocity; //velocity at contact point
  144. };
  145. virtual bool cast_motion(const RID &p_shape, const Transform &p_xform, const Vector3 &p_motion, float p_margin, float &p_closest_safe, float &p_closest_unsafe, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION, ShapeRestInfo *r_info = NULL) = 0;
  146. virtual bool collide_shape(RID p_shape, const Transform &p_shape_xform, float p_margin, Vector3 *r_results, int p_result_max, int &r_result_count, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
  147. virtual bool rest_info(RID p_shape, const Transform &p_shape_xform, float p_margin, ShapeRestInfo *r_info, const Set<RID> &p_exclude = Set<RID>(), uint32_t p_layer_mask = 0xFFFFFFFF, uint32_t p_object_type_mask = TYPE_MASK_COLLISION) = 0;
  148. PhysicsDirectSpaceState();
  149. };
  150. class PhysicsShapeQueryResult : public Reference {
  151. OBJ_TYPE(PhysicsShapeQueryResult, Reference);
  152. Vector<PhysicsDirectSpaceState::ShapeResult> result;
  153. friend class PhysicsDirectSpaceState;
  154. protected:
  155. static void _bind_methods();
  156. public:
  157. int get_result_count() const;
  158. RID get_result_rid(int p_idx) const;
  159. ObjectID get_result_object_id(int p_idx) const;
  160. Object *get_result_object(int p_idx) const;
  161. int get_result_object_shape(int p_idx) const;
  162. PhysicsShapeQueryResult();
  163. };
  164. class PhysicsServer : public Object {
  165. OBJ_TYPE(PhysicsServer, Object);
  166. static PhysicsServer *singleton;
  167. protected:
  168. static void _bind_methods();
  169. public:
  170. static PhysicsServer *get_singleton();
  171. enum ShapeType {
  172. SHAPE_PLANE, ///< plane:"plane"
  173. SHAPE_RAY, ///< float:"length"
  174. SHAPE_SPHERE, ///< float:"radius"
  175. SHAPE_BOX, ///< vec3:"extents"
  176. SHAPE_CAPSULE, ///< dict( float:"radius", float:"height"):capsule
  177. SHAPE_CONVEX_POLYGON, ///< array of planes:"planes"
  178. SHAPE_CONCAVE_POLYGON, ///< vector3 array:"triangles" , or Dictionary with "indices" (int array) and "triangles" (Vector3 array)
  179. SHAPE_HEIGHTMAP, ///< dict( int:"width", int:"depth",float:"cell_size", float_array:"heights"
  180. SHAPE_CUSTOM, ///< Server-Implementation based custom shape, calling shape_create() with this value will result in an error
  181. };
  182. virtual RID shape_create(ShapeType p_shape) = 0;
  183. virtual void shape_set_data(RID p_shape, const Variant &p_data) = 0;
  184. virtual void shape_set_custom_solver_bias(RID p_shape, real_t p_bias) = 0;
  185. virtual ShapeType shape_get_type(RID p_shape) const = 0;
  186. virtual Variant shape_get_data(RID p_shape) const = 0;
  187. virtual real_t shape_get_custom_solver_bias(RID p_shape) const = 0;
  188. /* SPACE API */
  189. virtual RID space_create() = 0;
  190. virtual void space_set_active(RID p_space, bool p_active) = 0;
  191. virtual bool space_is_active(RID p_space) const = 0;
  192. enum SpaceParameter {
  193. SPACE_PARAM_CONTACT_RECYCLE_RADIUS,
  194. SPACE_PARAM_CONTACT_MAX_SEPARATION,
  195. SPACE_PARAM_BODY_MAX_ALLOWED_PENETRATION,
  196. SPACE_PARAM_BODY_LINEAR_VELOCITY_SLEEP_TRESHOLD,
  197. SPACE_PARAM_BODY_ANGULAR_VELOCITY_SLEEP_TRESHOLD,
  198. SPACE_PARAM_BODY_TIME_TO_SLEEP,
  199. SPACE_PARAM_BODY_ANGULAR_VELOCITY_DAMP_RATIO,
  200. SPACE_PARAM_CONSTRAINT_DEFAULT_BIAS,
  201. };
  202. virtual void space_set_param(RID p_space, SpaceParameter p_param, real_t p_value) = 0;
  203. virtual real_t space_get_param(RID p_space, SpaceParameter p_param) const = 0;
  204. // this function only works on fixed process, errors and returns null otherwise
  205. virtual PhysicsDirectSpaceState *space_get_direct_state(RID p_space) = 0;
  206. virtual void space_set_debug_contacts(RID p_space, int p_max_contacts) = 0;
  207. virtual Vector<Vector3> space_get_contacts(RID p_space) const = 0;
  208. virtual int space_get_contact_count(RID p_space) const = 0;
  209. //missing space parameters
  210. /* AREA API */
  211. //missing attenuation? missing better override?
  212. enum AreaParameter {
  213. AREA_PARAM_GRAVITY,
  214. AREA_PARAM_GRAVITY_VECTOR,
  215. AREA_PARAM_GRAVITY_IS_POINT,
  216. AREA_PARAM_GRAVITY_DISTANCE_SCALE,
  217. AREA_PARAM_GRAVITY_POINT_ATTENUATION,
  218. AREA_PARAM_LINEAR_DAMP,
  219. AREA_PARAM_ANGULAR_DAMP,
  220. AREA_PARAM_PRIORITY
  221. };
  222. virtual RID area_create() = 0;
  223. virtual void area_set_space(RID p_area, RID p_space) = 0;
  224. virtual RID area_get_space(RID p_area) const = 0;
  225. enum AreaSpaceOverrideMode {
  226. AREA_SPACE_OVERRIDE_DISABLED,
  227. AREA_SPACE_OVERRIDE_COMBINE,
  228. AREA_SPACE_OVERRIDE_COMBINE_REPLACE,
  229. AREA_SPACE_OVERRIDE_REPLACE,
  230. AREA_SPACE_OVERRIDE_REPLACE_COMBINE
  231. };
  232. virtual void area_set_space_override_mode(RID p_area, AreaSpaceOverrideMode p_mode) = 0;
  233. virtual AreaSpaceOverrideMode area_get_space_override_mode(RID p_area) const = 0;
  234. virtual void area_add_shape(RID p_area, RID p_shape, const Transform &p_transform = Transform()) = 0;
  235. virtual void area_set_shape(RID p_area, int p_shape_idx, RID p_shape) = 0;
  236. virtual void area_set_shape_transform(RID p_area, int p_shape_idx, const Transform &p_transform) = 0;
  237. virtual int area_get_shape_count(RID p_area) const = 0;
  238. virtual RID area_get_shape(RID p_area, int p_shape_idx) const = 0;
  239. virtual Transform area_get_shape_transform(RID p_area, int p_shape_idx) const = 0;
  240. virtual void area_remove_shape(RID p_area, int p_shape_idx) = 0;
  241. virtual void area_clear_shapes(RID p_area) = 0;
  242. virtual void area_attach_object_instance_ID(RID p_area, ObjectID p_ID) = 0;
  243. virtual ObjectID area_get_object_instance_ID(RID p_area) const = 0;
  244. virtual void area_set_param(RID p_area, AreaParameter p_param, const Variant &p_value) = 0;
  245. virtual void area_set_transform(RID p_area, const Transform &p_transform) = 0;
  246. virtual Variant area_get_param(RID p_parea, AreaParameter p_param) const = 0;
  247. virtual Transform area_get_transform(RID p_area) const = 0;
  248. virtual void area_set_collision_mask(RID p_area, uint32_t p_mask) = 0;
  249. virtual void area_set_layer_mask(RID p_area, uint32_t p_mask) = 0;
  250. virtual void area_set_monitorable(RID p_area, bool p_monitorable) = 0;
  251. virtual void area_set_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0;
  252. virtual void area_set_area_monitor_callback(RID p_area, Object *p_receiver, const StringName &p_method) = 0;
  253. virtual void area_set_ray_pickable(RID p_area, bool p_enable) = 0;
  254. virtual bool area_is_ray_pickable(RID p_area) const = 0;
  255. /* BODY API */
  256. //missing ccd?
  257. enum BodyMode {
  258. BODY_MODE_STATIC,
  259. BODY_MODE_KINEMATIC,
  260. BODY_MODE_RIGID,
  261. //BODY_MODE_SOFT
  262. BODY_MODE_CHARACTER
  263. };
  264. virtual RID body_create(BodyMode p_mode = BODY_MODE_RIGID, bool p_init_sleeping = false) = 0;
  265. virtual void body_set_space(RID p_body, RID p_space) = 0;
  266. virtual RID body_get_space(RID p_body) const = 0;
  267. virtual void body_set_mode(RID p_body, BodyMode p_mode) = 0;
  268. virtual BodyMode body_get_mode(RID p_body) const = 0;
  269. virtual void body_add_shape(RID p_body, RID p_shape, const Transform &p_transform = Transform()) = 0;
  270. virtual void body_set_shape(RID p_body, int p_shape_idx, RID p_shape) = 0;
  271. virtual void body_set_shape_transform(RID p_body, int p_shape_idx, const Transform &p_transform) = 0;
  272. virtual int body_get_shape_count(RID p_body) const = 0;
  273. virtual RID body_get_shape(RID p_body, int p_shape_idx) const = 0;
  274. virtual Transform body_get_shape_transform(RID p_body, int p_shape_idx) const = 0;
  275. virtual void body_set_shape_as_trigger(RID p_body, int p_shape_idx, bool p_enable) = 0;
  276. virtual bool body_is_shape_set_as_trigger(RID p_body, int p_shape_idx) const = 0;
  277. virtual void body_remove_shape(RID p_body, int p_shape_idx) = 0;
  278. virtual void body_clear_shapes(RID p_body) = 0;
  279. virtual void body_attach_object_instance_ID(RID p_body, uint32_t p_ID) = 0;
  280. virtual uint32_t body_get_object_instance_ID(RID p_body) const = 0;
  281. virtual void body_set_enable_continuous_collision_detection(RID p_body, bool p_enable) = 0;
  282. virtual bool body_is_continuous_collision_detection_enabled(RID p_body) const = 0;
  283. virtual void body_set_layer_mask(RID p_body, uint32_t p_mask) = 0;
  284. virtual uint32_t body_get_layer_mask(RID p_body, uint32_t p_mask) const = 0;
  285. virtual void body_set_collision_mask(RID p_body, uint32_t p_mask) = 0;
  286. virtual uint32_t body_get_collision_mask(RID p_body, uint32_t p_mask) const = 0;
  287. virtual void body_set_user_flags(RID p_body, uint32_t p_flags) = 0;
  288. virtual uint32_t body_get_user_flags(RID p_body, uint32_t p_flags) const = 0;
  289. // common body variables
  290. enum BodyParameter {
  291. BODY_PARAM_BOUNCE,
  292. BODY_PARAM_FRICTION,
  293. BODY_PARAM_MASS, ///< unused for static, always infinite
  294. BODY_PARAM_GRAVITY_SCALE,
  295. BODY_PARAM_LINEAR_DAMP,
  296. BODY_PARAM_ANGULAR_DAMP,
  297. BODY_PARAM_MAX,
  298. };
  299. virtual void body_set_param(RID p_body, BodyParameter p_param, float p_value) = 0;
  300. virtual float body_get_param(RID p_body, BodyParameter p_param) const = 0;
  301. //state
  302. enum BodyState {
  303. BODY_STATE_TRANSFORM,
  304. BODY_STATE_LINEAR_VELOCITY,
  305. BODY_STATE_ANGULAR_VELOCITY,
  306. BODY_STATE_SLEEPING,
  307. BODY_STATE_CAN_SLEEP
  308. };
  309. virtual void body_set_state(RID p_body, BodyState p_state, const Variant &p_variant) = 0;
  310. virtual Variant body_get_state(RID p_body, BodyState p_state) const = 0;
  311. //do something about it
  312. virtual void body_set_applied_force(RID p_body, const Vector3 &p_force) = 0;
  313. virtual Vector3 body_get_applied_force(RID p_body) const = 0;
  314. virtual void body_set_applied_torque(RID p_body, const Vector3 &p_torque) = 0;
  315. virtual Vector3 body_get_applied_torque(RID p_body) const = 0;
  316. virtual void body_apply_impulse(RID p_body, const Vector3 &p_pos, const Vector3 &p_impulse) = 0;
  317. virtual void body_set_axis_velocity(RID p_body, const Vector3 &p_axis_velocity) = 0;
  318. enum BodyAxisLock {
  319. BODY_AXIS_LOCK_DISABLED,
  320. BODY_AXIS_LOCK_X,
  321. BODY_AXIS_LOCK_Y,
  322. BODY_AXIS_LOCK_Z,
  323. };
  324. virtual void body_set_axis_lock(RID p_body, BodyAxisLock p_lock) = 0;
  325. virtual BodyAxisLock body_get_axis_lock(RID p_body) const = 0;
  326. //fix
  327. virtual void body_add_collision_exception(RID p_body, RID p_body_b) = 0;
  328. virtual void body_remove_collision_exception(RID p_body, RID p_body_b) = 0;
  329. virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions) = 0;
  330. virtual void body_set_max_contacts_reported(RID p_body, int p_contacts) = 0;
  331. virtual int body_get_max_contacts_reported(RID p_body) const = 0;
  332. //missing remove
  333. virtual void body_set_contacts_reported_depth_treshold(RID p_body, float p_treshold) = 0;
  334. virtual float body_get_contacts_reported_depth_treshold(RID p_body) const = 0;
  335. virtual void body_set_omit_force_integration(RID p_body, bool p_omit) = 0;
  336. virtual bool body_is_omitting_force_integration(RID p_body) const = 0;
  337. virtual void body_set_force_integration_callback(RID p_body, Object *p_receiver, const StringName &p_method, const Variant &p_udata = Variant()) = 0;
  338. virtual void body_set_ray_pickable(RID p_body, bool p_enable) = 0;
  339. virtual bool body_is_ray_pickable(RID p_body) const = 0;
  340. /* JOINT API */
  341. enum JointType {
  342. JOINT_PIN,
  343. JOINT_HINGE,
  344. JOINT_SLIDER,
  345. JOINT_CONE_TWIST,
  346. JOINT_6DOF
  347. };
  348. virtual JointType joint_get_type(RID p_joint) const = 0;
  349. virtual void joint_set_solver_priority(RID p_joint, int p_priority) = 0;
  350. virtual int joint_get_solver_priority(RID p_joint) const = 0;
  351. virtual RID joint_create_pin(RID p_body_A, const Vector3 &p_local_A, RID p_body_B, const Vector3 &p_local_B) = 0;
  352. enum PinJointParam {
  353. PIN_JOINT_BIAS,
  354. PIN_JOINT_DAMPING,
  355. PIN_JOINT_IMPULSE_CLAMP
  356. };
  357. virtual void pin_joint_set_param(RID p_joint, PinJointParam p_param, float p_value) = 0;
  358. virtual float pin_joint_get_param(RID p_joint, PinJointParam p_param) const = 0;
  359. virtual void pin_joint_set_local_A(RID p_joint, const Vector3 &p_A) = 0;
  360. virtual Vector3 pin_joint_get_local_A(RID p_joint) const = 0;
  361. virtual void pin_joint_set_local_B(RID p_joint, const Vector3 &p_B) = 0;
  362. virtual Vector3 pin_joint_get_local_B(RID p_joint) const = 0;
  363. enum HingeJointParam {
  364. HINGE_JOINT_BIAS,
  365. HINGE_JOINT_LIMIT_UPPER,
  366. HINGE_JOINT_LIMIT_LOWER,
  367. HINGE_JOINT_LIMIT_BIAS,
  368. HINGE_JOINT_LIMIT_SOFTNESS,
  369. HINGE_JOINT_LIMIT_RELAXATION,
  370. HINGE_JOINT_MOTOR_TARGET_VELOCITY,
  371. HINGE_JOINT_MOTOR_MAX_IMPULSE,
  372. HINGE_JOINT_MAX
  373. };
  374. enum HingeJointFlag {
  375. HINGE_JOINT_FLAG_USE_LIMIT,
  376. HINGE_JOINT_FLAG_ENABLE_MOTOR,
  377. HINGE_JOINT_FLAG_MAX
  378. };
  379. virtual RID joint_create_hinge(RID p_body_A, const Transform &p_hinge_A, RID p_body_B, const Transform &p_hinge_B) = 0;
  380. virtual RID joint_create_hinge_simple(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;
  381. virtual void hinge_joint_set_param(RID p_joint, HingeJointParam p_param, float p_value) = 0;
  382. virtual float hinge_joint_get_param(RID p_joint, HingeJointParam p_param) const = 0;
  383. virtual void hinge_joint_set_flag(RID p_joint, HingeJointFlag p_flag, bool p_value) = 0;
  384. virtual bool hinge_joint_get_flag(RID p_joint, HingeJointFlag p_flag) const = 0;
  385. enum SliderJointParam {
  386. SLIDER_JOINT_LINEAR_LIMIT_UPPER,
  387. SLIDER_JOINT_LINEAR_LIMIT_LOWER,
  388. SLIDER_JOINT_LINEAR_LIMIT_SOFTNESS,
  389. SLIDER_JOINT_LINEAR_LIMIT_RESTITUTION,
  390. SLIDER_JOINT_LINEAR_LIMIT_DAMPING,
  391. SLIDER_JOINT_LINEAR_MOTION_SOFTNESS,
  392. SLIDER_JOINT_LINEAR_MOTION_RESTITUTION,
  393. SLIDER_JOINT_LINEAR_MOTION_DAMPING,
  394. SLIDER_JOINT_LINEAR_ORTHOGONAL_SOFTNESS,
  395. SLIDER_JOINT_LINEAR_ORTHOGONAL_RESTITUTION,
  396. SLIDER_JOINT_LINEAR_ORTHOGONAL_DAMPING,
  397. SLIDER_JOINT_ANGULAR_LIMIT_UPPER,
  398. SLIDER_JOINT_ANGULAR_LIMIT_LOWER,
  399. SLIDER_JOINT_ANGULAR_LIMIT_SOFTNESS,
  400. SLIDER_JOINT_ANGULAR_LIMIT_RESTITUTION,
  401. SLIDER_JOINT_ANGULAR_LIMIT_DAMPING,
  402. SLIDER_JOINT_ANGULAR_MOTION_SOFTNESS,
  403. SLIDER_JOINT_ANGULAR_MOTION_RESTITUTION,
  404. SLIDER_JOINT_ANGULAR_MOTION_DAMPING,
  405. SLIDER_JOINT_ANGULAR_ORTHOGONAL_SOFTNESS,
  406. SLIDER_JOINT_ANGULAR_ORTHOGONAL_RESTITUTION,
  407. SLIDER_JOINT_ANGULAR_ORTHOGONAL_DAMPING,
  408. SLIDER_JOINT_MAX
  409. };
  410. virtual RID joint_create_slider(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) = 0; //reference frame is A
  411. virtual void slider_joint_set_param(RID p_joint, SliderJointParam p_param, float p_value) = 0;
  412. virtual float slider_joint_get_param(RID p_joint, SliderJointParam p_param) const = 0;
  413. enum ConeTwistJointParam {
  414. CONE_TWIST_JOINT_SWING_SPAN,
  415. CONE_TWIST_JOINT_TWIST_SPAN,
  416. CONE_TWIST_JOINT_BIAS,
  417. CONE_TWIST_JOINT_SOFTNESS,
  418. CONE_TWIST_JOINT_RELAXATION,
  419. CONE_TWIST_MAX
  420. };
  421. virtual RID joint_create_cone_twist(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) = 0; //reference frame is A
  422. virtual void cone_twist_joint_set_param(RID p_joint, ConeTwistJointParam p_param, float p_value) = 0;
  423. virtual float cone_twist_joint_get_param(RID p_joint, ConeTwistJointParam p_param) const = 0;
  424. enum G6DOFJointAxisParam {
  425. G6DOF_JOINT_LINEAR_LOWER_LIMIT,
  426. G6DOF_JOINT_LINEAR_UPPER_LIMIT,
  427. G6DOF_JOINT_LINEAR_LIMIT_SOFTNESS,
  428. G6DOF_JOINT_LINEAR_RESTITUTION,
  429. G6DOF_JOINT_LINEAR_DAMPING,
  430. G6DOF_JOINT_ANGULAR_LOWER_LIMIT,
  431. G6DOF_JOINT_ANGULAR_UPPER_LIMIT,
  432. G6DOF_JOINT_ANGULAR_LIMIT_SOFTNESS,
  433. G6DOF_JOINT_ANGULAR_DAMPING,
  434. G6DOF_JOINT_ANGULAR_RESTITUTION,
  435. G6DOF_JOINT_ANGULAR_FORCE_LIMIT,
  436. G6DOF_JOINT_ANGULAR_ERP,
  437. G6DOF_JOINT_ANGULAR_MOTOR_TARGET_VELOCITY,
  438. G6DOF_JOINT_ANGULAR_MOTOR_FORCE_LIMIT,
  439. G6DOF_JOINT_MAX
  440. };
  441. enum G6DOFJointAxisFlag {
  442. G6DOF_JOINT_FLAG_ENABLE_LINEAR_LIMIT,
  443. G6DOF_JOINT_FLAG_ENABLE_ANGULAR_LIMIT,
  444. G6DOF_JOINT_FLAG_ENABLE_MOTOR,
  445. G6DOF_JOINT_FLAG_MAX
  446. };
  447. virtual RID joint_create_generic_6dof(RID p_body_A, const Transform &p_local_frame_A, RID p_body_B, const Transform &p_local_frame_B) = 0; //reference frame is A
  448. virtual void generic_6dof_joint_set_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param, float p_value) = 0;
  449. virtual float generic_6dof_joint_get_param(RID p_joint, Vector3::Axis, G6DOFJointAxisParam p_param) = 0;
  450. virtual void generic_6dof_joint_set_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag, bool p_enable) = 0;
  451. virtual bool generic_6dof_joint_get_flag(RID p_joint, Vector3::Axis, G6DOFJointAxisFlag p_flag) = 0;
  452. #if 0
  453. enum JointType {
  454. JOINT_PIN,
  455. JOINT_GROOVE,
  456. JOINT_DAMPED_SPRING
  457. };
  458. enum JointParam {
  459. JOINT_PARAM_BIAS,
  460. JOINT_PARAM_MAX_BIAS,
  461. JOINT_PARAM_MAX_FORCE,
  462. };
  463. virtual void joint_set_param(RID p_joint, JointParam p_param, real_t p_value)=0;
  464. virtual real_t joint_get_param(RID p_joint,JointParam p_param) const=0;
  465. virtual RID pin_joint_create(const Vector3& p_anchor,RID p_body_a,RID p_body_b=RID())=0;
  466. virtual RID groove_joint_create(const Vector3& p_a_groove1,const Vector3& p_a_groove2, const Vector3& p_b_anchor, RID p_body_a,RID p_body_b)=0;
  467. virtual RID damped_spring_joint_create(const Vector3& p_anchor_a,const Vector3& p_anchor_b,RID p_body_a,RID p_body_b=RID())=0;
  468. enum DampedStringParam {
  469. DAMPED_STRING_REST_LENGTH,
  470. DAMPED_STRING_STIFFNESS,
  471. DAMPED_STRING_DAMPING
  472. };
  473. virtual void damped_string_joint_set_param(RID p_joint, DampedStringParam p_param, real_t p_value)=0;
  474. virtual real_t damped_string_joint_get_param(RID p_joint, DampedStringParam p_param) const=0;
  475. virtual JointType joint_get_type(RID p_joint) const=0;
  476. #endif
  477. /* QUERY API */
  478. enum AreaBodyStatus {
  479. AREA_BODY_ADDED,
  480. AREA_BODY_REMOVED
  481. };
  482. /* MISC */
  483. virtual void free(RID p_rid) = 0;
  484. virtual void set_active(bool p_active) = 0;
  485. virtual void init() = 0;
  486. virtual void step(float p_step) = 0;
  487. virtual void sync() = 0;
  488. virtual void flush_queries() = 0;
  489. virtual void finish() = 0;
  490. enum ProcessInfo {
  491. INFO_ACTIVE_OBJECTS,
  492. INFO_COLLISION_PAIRS,
  493. INFO_ISLAND_COUNT
  494. };
  495. virtual int get_process_info(ProcessInfo p_info) = 0;
  496. PhysicsServer();
  497. ~PhysicsServer();
  498. };
  499. VARIANT_ENUM_CAST(PhysicsServer::ShapeType);
  500. VARIANT_ENUM_CAST(PhysicsServer::SpaceParameter);
  501. VARIANT_ENUM_CAST(PhysicsServer::AreaParameter);
  502. VARIANT_ENUM_CAST(PhysicsServer::AreaSpaceOverrideMode);
  503. VARIANT_ENUM_CAST(PhysicsServer::BodyMode);
  504. VARIANT_ENUM_CAST(PhysicsServer::BodyParameter);
  505. VARIANT_ENUM_CAST(PhysicsServer::BodyState);
  506. VARIANT_ENUM_CAST(PhysicsServer::BodyAxisLock);
  507. VARIANT_ENUM_CAST(PhysicsServer::PinJointParam);
  508. VARIANT_ENUM_CAST(PhysicsServer::JointType);
  509. VARIANT_ENUM_CAST(PhysicsServer::HingeJointParam);
  510. VARIANT_ENUM_CAST(PhysicsServer::HingeJointFlag);
  511. VARIANT_ENUM_CAST(PhysicsServer::SliderJointParam);
  512. VARIANT_ENUM_CAST(PhysicsServer::ConeTwistJointParam);
  513. VARIANT_ENUM_CAST(PhysicsServer::G6DOFJointAxisParam);
  514. VARIANT_ENUM_CAST(PhysicsServer::G6DOFJointAxisFlag);
  515. //VARIANT_ENUM_CAST( PhysicsServer::ObjectType );
  516. VARIANT_ENUM_CAST(PhysicsServer::AreaBodyStatus);
  517. VARIANT_ENUM_CAST(PhysicsServer::ProcessInfo);
  518. #endif