Constraint.pkg 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. $#include "Constraint.h"
  2. /// Supported constraint types.
  3. enum ConstraintType
  4. {
  5. CONSTRAINT_POINT = 0,
  6. CONSTRAINT_HINGE,
  7. CONSTRAINT_SLIDER,
  8. CONSTRAINT_CONETWIST
  9. };
  10. /// Physics constraint component. Connects two rigid bodies together, or one rigid body to a static point.
  11. class Constraint : public Component
  12. {
  13. public:
  14. /// Set constraint type and recreate the constraint.
  15. void SetConstraintType(ConstraintType type);
  16. /// Set other body to connect to. Set to null to connect to the static world.
  17. void SetOtherBody(RigidBody* body);
  18. /// Set constraint position relative to own body.
  19. void SetPosition(const Vector3& position);
  20. /// Set constraint rotation relative to own body.
  21. void SetRotation(const Quaternion& rotation);
  22. /// Set constraint rotation relative to own body by specifying the axis.
  23. void SetAxis(const Vector3& axis);
  24. /// Set constraint position relative to the other body. If connected to the static world, is a world-space position.
  25. void SetOtherPosition(const Vector3& position);
  26. /// Set constraint rotation relative to the other body. If connected to the static world, is a world-space rotation.
  27. void SetOtherRotation(const Quaternion& rotation);
  28. /// Set constraint rotation relative to the other body by specifying the axis.
  29. void SetOtherAxis(const Vector3& axis);
  30. /// Set constraint world-space position. Resets both own and other body relative position, ie. zeroes the constraint error.
  31. void SetWorldPosition(const Vector3& position);
  32. /// Set high limit. Interpretation is constraint type specific.
  33. void SetHighLimit(const Vector2& limit);
  34. /// Set low limit. Interpretation is constraint type specific.
  35. void SetLowLimit(const Vector2& limit);
  36. /// Set constraint error reduction parameter. Zero = leave to default.
  37. void SetERP(float erp);
  38. /// Set constraint force mixing parameter. Zero = leave to default.
  39. void SetCFM(float cfm);
  40. /// Set whether to disable collisions between connected bodies.
  41. void SetDisableCollision(bool disable);
  42. /// Return physics world.
  43. PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
  44. /// Return constraint type.
  45. ConstraintType GetConstraintType() const { return constraintType_; }
  46. /// Return rigid body in own scene node.
  47. RigidBody* GetOwnBody() const { return ownBody_; }
  48. /// Return the other rigid body. May be null if connected to the static world.
  49. RigidBody* GetOtherBody() const { return otherBody_; }
  50. /// Return constraint position relative to own body.
  51. const Vector3& GetPosition() const { return position_; }
  52. /// Return constraint rotation relative to own body.
  53. const Quaternion& GetRotation() const { return rotation_; }
  54. /// Return constraint position relative to other body.
  55. const Vector3& GetOtherPosition() const { return otherPosition_; }
  56. /// Return constraint rotation relative to other body.
  57. const Quaternion& GetOtherRotation() const { return otherRotation_; }
  58. /// Return constraint world position, calculated from own body.
  59. Vector3 GetWorldPosition() const;
  60. /// Return high limit.
  61. const Vector2& GetHighLimit() const { return highLimit_; }
  62. /// Return low limit.
  63. const Vector2& GetLowLimit() const { return lowLimit_; }
  64. /// Return constraint error reduction parameter.
  65. float GetERP() const { return erp_; }
  66. /// Return constraint force mixing parameter.
  67. float GetCFM() const { return cfm_; }
  68. /// Return whether collisions between connected bodies are disabled.
  69. bool GetDisableCollision() const { return disableCollision_; }
  70. /// Release the constraint.
  71. void ReleaseConstraint();
  72. /// Apply constraint frames.
  73. void ApplyFrames();
  74. // Properties:
  75. tolua_property__get_set ConstraintType constraintType;
  76. tolua_property__get_set const Vector3& position;
  77. tolua_property__get_set const Quaternion& rotation;
  78. tolua_property__get_set const Vector3& otherPosition;
  79. tolua_property__get_set const Quaternion& otherRotation;
  80. tolua_property__get_set Vector3 worldPosition;
  81. tolua_property__get_set const Vector2& highLimit;
  82. tolua_property__get_set const Vector2& lowLimit;
  83. tolua_property__get_set float ERP;
  84. tolua_property__get_set float CFM;
  85. tolua_property__get_set bool disableCollision;
  86. tolua_readonly tolua_property__get_set RigidBody* ownBody;
  87. tolua_property__get_set RigidBody* otherBody;
  88. };
  89. ${
  90. #define TOLUA_DISABLE_tolua_get_Constraint_worldPosition
  91. #define tolua_get_Constraint_worldPosition tolua_PhysicsLuaAPI_Constraint_GetWorldPosition00
  92. $}