physics_server.h 24 KB

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