btHinge2Constraint.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Bullet Continuous Collision Detection and Physics Library, http://bulletphysics.org
  3. Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
  4. This software is provided 'as-is', without any express or implied warranty.
  5. In no event will the authors be held liable for any damages arising from the use of this software.
  6. Permission is granted to anyone to use this software for any purpose,
  7. including commercial applications, and to alter it and redistribute it freely,
  8. subject to the following restrictions:
  9. 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  10. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  11. 3. This notice may not be removed or altered from any source distribution.
  12. */
  13. #ifndef BT_HINGE2_CONSTRAINT_H
  14. #define BT_HINGE2_CONSTRAINT_H
  15. #include "bullet/LinearMath/btVector3.h"
  16. #include "btTypedConstraint.h"
  17. #include "btGeneric6DofSpringConstraint.h"
  18. // Constraint similar to ODE Hinge2 Joint
  19. // has 3 degrees of frredom:
  20. // 2 rotational degrees of freedom, similar to Euler rotations around Z (axis 1) and X (axis 2)
  21. // 1 translational (along axis Z) with suspension spring
  22. ATTRIBUTE_ALIGNED16(class) btHinge2Constraint : public btGeneric6DofSpringConstraint
  23. {
  24. protected:
  25. btVector3 m_anchor;
  26. btVector3 m_axis1;
  27. btVector3 m_axis2;
  28. public:
  29. BT_DECLARE_ALIGNED_ALLOCATOR();
  30. // constructor
  31. // anchor, axis1 and axis2 are in world coordinate system
  32. // axis1 must be orthogonal to axis2
  33. btHinge2Constraint(btRigidBody& rbA, btRigidBody& rbB, btVector3& anchor, btVector3& axis1, btVector3& axis2);
  34. // access
  35. const btVector3& getAnchor() { return m_calculatedTransformA.getOrigin(); }
  36. const btVector3& getAnchor2() { return m_calculatedTransformB.getOrigin(); }
  37. const btVector3& getAxis1() { return m_axis1; }
  38. const btVector3& getAxis2() { return m_axis2; }
  39. btScalar getAngle1() { return getAngle(2); }
  40. btScalar getAngle2() { return getAngle(0); }
  41. // limits
  42. void setUpperLimit(btScalar ang1max) { setAngularUpperLimit(btVector3(-1.f, 0.f, ang1max)); }
  43. void setLowerLimit(btScalar ang1min) { setAngularLowerLimit(btVector3( 1.f, 0.f, ang1min)); }
  44. };
  45. #endif // BT_HINGE2_CONSTRAINT_H