space_sw.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*************************************************************************/
  2. /* space_sw.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 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 SPACE_SW_H
  30. #define SPACE_SW_H
  31. #include "typedefs.h"
  32. #include "hash_map.h"
  33. #include "body_sw.h"
  34. #include "area_sw.h"
  35. #include "body_pair_sw.h"
  36. #include "area_pair_sw.h"
  37. #include "broad_phase_sw.h"
  38. #include "collision_object_sw.h"
  39. class PhysicsDirectSpaceStateSW : public PhysicsDirectSpaceState {
  40. OBJ_TYPE( PhysicsDirectSpaceStateSW, PhysicsDirectSpaceState );
  41. public:
  42. SpaceSW *space;
  43. bool intersect_ray(const Vector3& p_from, const Vector3& p_to,RayResult &r_result,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0);
  44. int intersect_shape(const RID& p_shape, const Transform& p_xform,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0);
  45. PhysicsDirectSpaceStateSW();
  46. };
  47. class SpaceSW {
  48. PhysicsDirectSpaceStateSW *direct_access;
  49. RID self;
  50. BroadPhaseSW *broadphase;
  51. SelfList<BodySW>::List active_list;
  52. SelfList<BodySW>::List inertia_update_list;
  53. SelfList<BodySW>::List state_query_list;
  54. SelfList<AreaSW>::List monitor_query_list;
  55. SelfList<AreaSW>::List area_moved_list;
  56. static void* _broadphase_pair(CollisionObjectSW *A,int p_subindex_A,CollisionObjectSW *B,int p_subindex_B,void *p_self);
  57. static void _broadphase_unpair(CollisionObjectSW *A,int p_subindex_A,CollisionObjectSW *B,int p_subindex_B,void *p_data,void *p_self);
  58. Set<CollisionObjectSW*> objects;
  59. AreaSW *area;
  60. real_t contact_recycle_radius;
  61. real_t contact_max_separation;
  62. real_t contact_max_allowed_penetration;
  63. real_t constraint_bias;
  64. enum {
  65. INTERSECTION_QUERY_MAX=2048
  66. };
  67. CollisionObjectSW *intersection_query_results[INTERSECTION_QUERY_MAX];
  68. int intersection_query_subindex_results[INTERSECTION_QUERY_MAX];
  69. float body_linear_velocity_sleep_threshold;
  70. float body_angular_velocity_sleep_threshold;
  71. float body_time_to_sleep;
  72. float body_angular_velocity_damp_ratio;
  73. bool locked;
  74. friend class PhysicsDirectSpaceStateSW;
  75. public:
  76. _FORCE_INLINE_ void set_self(const RID& p_self) { self=p_self; }
  77. _FORCE_INLINE_ RID get_self() const { return self; }
  78. void set_default_area(AreaSW *p_area) { area=p_area; }
  79. AreaSW *get_default_area() const { return area; }
  80. const SelfList<BodySW>::List& get_active_body_list() const;
  81. void body_add_to_active_list(SelfList<BodySW>* p_body);
  82. void body_remove_from_active_list(SelfList<BodySW>* p_body);
  83. void body_add_to_inertia_update_list(SelfList<BodySW>* p_body);
  84. void body_remove_from_inertia_update_list(SelfList<BodySW>* p_body);
  85. void body_add_to_state_query_list(SelfList<BodySW>* p_body);
  86. void body_remove_from_state_query_list(SelfList<BodySW>* p_body);
  87. void area_add_to_monitor_query_list(SelfList<AreaSW>* p_area);
  88. void area_remove_from_monitor_query_list(SelfList<AreaSW>* p_area);
  89. void area_add_to_moved_list(SelfList<AreaSW>* p_area);
  90. void area_remove_from_moved_list(SelfList<AreaSW>* p_area);
  91. const SelfList<AreaSW>::List& get_moved_area_list() const;
  92. BroadPhaseSW *get_broadphase();
  93. void add_object(CollisionObjectSW *p_object);
  94. void remove_object(CollisionObjectSW *p_object);
  95. const Set<CollisionObjectSW*> &get_objects() const;
  96. _FORCE_INLINE_ real_t get_contact_recycle_radius() const { return contact_recycle_radius; }
  97. _FORCE_INLINE_ real_t get_contact_max_separation() const { return contact_max_separation; }
  98. _FORCE_INLINE_ real_t get_contact_max_allowed_penetration() const { return contact_max_allowed_penetration; }
  99. _FORCE_INLINE_ real_t get_constraint_bias() const { return constraint_bias; }
  100. _FORCE_INLINE_ real_t get_body_linear_velocity_sleep_treshold() const { return body_linear_velocity_sleep_threshold; }
  101. _FORCE_INLINE_ real_t get_body_angular_velocity_sleep_treshold() const { return body_angular_velocity_sleep_threshold; }
  102. _FORCE_INLINE_ real_t get_body_time_to_sleep() const { return body_time_to_sleep; }
  103. _FORCE_INLINE_ real_t get_body_angular_velocity_damp_ratio() const { return body_angular_velocity_damp_ratio; }
  104. void update();
  105. void setup();
  106. void call_queries();
  107. bool is_locked() const;
  108. void lock();
  109. void unlock();
  110. void set_param(PhysicsServer::SpaceParameter p_param, real_t p_value);
  111. real_t get_param(PhysicsServer::SpaceParameter p_param) const;
  112. PhysicsDirectSpaceStateSW *get_direct_state();
  113. SpaceSW();
  114. ~SpaceSW();
  115. };
  116. #endif // SPACE__SW_H