BsDistanceJoint.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsJoint.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Physics
  9. * @{
  10. */
  11. struct DISTANCE_JOINT_DESC;
  12. /** A joint that maintains an upper or lower (or both) bound on the distance between two bodies. */
  13. class BS_CORE_EXPORT DistanceJoint : public Joint
  14. {
  15. public:
  16. /** Controls distance joint options. */
  17. enum class Flag
  18. {
  19. MinDistance = 0x1, /** Enables minimum distance limit. */
  20. MaxDistance = 0x2, /** Enables maximum distance limit. */
  21. Spring = 0x4 /** Enables spring when maintaining limits. */
  22. };
  23. public:
  24. DistanceJoint(const DISTANCE_JOINT_DESC& desc) { }
  25. virtual ~DistanceJoint() { }
  26. /** Returns the current distance between the two joint bodies. */
  27. virtual float getDistance() const = 0;
  28. /**
  29. * Returns the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
  30. * distance flag in order for this limit to be applied.
  31. */
  32. virtual float getMinDistance() const = 0;
  33. /**
  34. * Sets the minimum distance the bodies are allowed to be at, they will get no closer. You must enable min
  35. * distance flag in order for this limit to be applied.
  36. */
  37. virtual void setMinDistance(float value) = 0;
  38. /**
  39. * Returns the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
  40. * distance flag in order for this limit to be applied.
  41. */
  42. virtual float getMaxDistance() const = 0;
  43. /**
  44. * Sets the maximum distance the bodies are allowed to be at, they will get no further. You must enable max
  45. * distance flag in order for this limit to be applied.
  46. */
  47. virtual void setMaxDistance(float value) = 0;
  48. /**
  49. * Returns the error tolerance of the joint at which the joint becomes active. This value slightly extends the
  50. * lower and upper limit.
  51. */
  52. virtual float getTolerance() const = 0;
  53. /**
  54. * Sets the error tolerance of the joint at which the joint becomes active. This value slightly extends the
  55. * lower and upper limit.
  56. */
  57. virtual void setTolerance(float value) = 0;
  58. /**
  59. * Returns a spring that controls how the joint responds when a limit is reached. You must enable the spring flag
  60. * on the joint in order for this to be recognized.
  61. *
  62. * @see Spring
  63. */
  64. virtual Spring getSpring() const = 0;
  65. /**
  66. * Sets a spring that controls how the joint responds when a limit is reached. You must enable the spring flag on
  67. * the joint in order for this to be recognized.
  68. *
  69. * @see Spring
  70. */
  71. virtual void setSpring(const Spring& value) = 0;
  72. /** Enables or disables a flag that controls joint behaviour. */
  73. virtual void setFlag(Flag flag, bool enabled) = 0;
  74. /** Checks whether a certain joint flag is enabled. */
  75. virtual bool hasFlag(Flag flag) const = 0;
  76. /** Creates a new distance joint. */
  77. static SPtr<DistanceJoint> create(const DISTANCE_JOINT_DESC& desc);
  78. };
  79. /** Structure used for initializing a new DistanceJoint. */
  80. struct DISTANCE_JOINT_DESC : JOINT_DESC
  81. {
  82. float minDistance = 0.0f;
  83. float maxDistance = 0.0f;
  84. float tolerance = 0.25f;
  85. Spring spring;
  86. DistanceJoint::Flag flag = (DistanceJoint::Flag)0;
  87. };
  88. /** @} */
  89. }