physics_server.h 25 KB

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