body_pair_2d_sw.h 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*************************************************************************/
  2. /* body_pair_2d_sw.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 BODY_PAIR_2D_SW_H
  31. #define BODY_PAIR_2D_SW_H
  32. #include "body_2d_sw.h"
  33. #include "constraint_2d_sw.h"
  34. class BodyPair2DSW : public Constraint2DSW {
  35. enum {
  36. MAX_CONTACTS = 2
  37. };
  38. union {
  39. struct {
  40. Body2DSW *A;
  41. Body2DSW *B;
  42. };
  43. Body2DSW *_arr[2];
  44. };
  45. int shape_A;
  46. int shape_B;
  47. Space2DSW *space;
  48. struct Contact {
  49. Vector2 position;
  50. Vector2 normal;
  51. Vector2 local_A, local_B;
  52. real_t acc_normal_impulse; // accumulated normal impulse (Pn)
  53. real_t acc_tangent_impulse; // accumulated tangent impulse (Pt)
  54. real_t acc_bias_impulse; // accumulated normal impulse for position bias (Pnb)
  55. real_t mass_normal, mass_tangent;
  56. real_t bias;
  57. real_t depth;
  58. bool active;
  59. Vector2 rA, rB;
  60. bool reused;
  61. real_t bounce;
  62. };
  63. Vector2 offset_B; //use local A coordinates to avoid numerical issues on collision detection
  64. Vector2 sep_axis;
  65. Contact contacts[MAX_CONTACTS];
  66. int contact_count;
  67. bool collided;
  68. bool oneway_disabled;
  69. int cc;
  70. bool _test_ccd(real_t p_step, Body2DSW *p_A, int p_shape_A, const Transform2D &p_xform_A, Body2DSW *p_B, int p_shape_B, const Transform2D &p_xform_B, bool p_swap_result = false);
  71. void _validate_contacts();
  72. static void _add_contact(const Vector2 &p_point_A, const Vector2 &p_point_B, void *p_self);
  73. _FORCE_INLINE_ void _contact_added_callback(const Vector2 &p_point_A, const Vector2 &p_point_B);
  74. public:
  75. bool setup(real_t p_step);
  76. void solve(real_t p_step);
  77. BodyPair2DSW(Body2DSW *p_A, int p_shape_A, Body2DSW *p_B, int p_shape_B);
  78. ~BodyPair2DSW();
  79. };
  80. #endif // BODY_PAIR_2D_SW_H