32 #include "BulletDynamics/Dynamics/btRigidBody.h"
41 bool isFreeEndAttached,
47 m_isFreeEndAttached(isFreeEndAttached),
50 m_restLength(restLength),
52 anchor1(anchors.front()),
53 anchor2(anchors.back())
65 throw std::invalid_argument(
"Rest length for a compression spring must be postive.");
72 std::cout <<
"Location of the starting and ending point of the two anchors:" << std::endl;
73 std::cout <<
"Anchor1: (" << anchor1pos.x() <<
", ";
74 std::cout << anchor1pos.y() <<
", ";
75 std::cout << anchor1pos.z() <<
")" << std::endl;
76 std::cout <<
"Anchor2: (" << anchor2pos.x() <<
", ";
77 std::cout << anchor2pos.y() <<
", ";
78 std::cout << anchor2pos.z() <<
")" << std::endl;
90 std::cout <<
"Destroying tgBulletCompressionSpring" << std::endl;
106 for (std::size_t i = 0; i < n; i++)
120 throw std::invalid_argument(
"dt is not positive!");
129 throw std::runtime_error(
"Compression spring has negative length, simulation stopping. Increase your stiffness coefficient. TO-DO: implement a 'hard stop' inside the step method of tgBulletCompressionSpring instead of crashing the simulator.");
141 const btVector3 dist =
143 return dist.length();
165 springLength = currAnchorDist;
171 springLength = currAnchorDist;
185 const btVector3 dist =
193 const btVector3 unitVector = - dist / dist.length();
225 std::cout <<
"getCoefK: " <<
getCoefK() <<
" getCurrentSpringLength(): "
236 assert(springForce >= 0.0);
250 btVector3 force(0.0, 0.0, 0.0);
262 const double changeInDeltaX = currLength -
m_prevLength;
273 std::cout <<
"SpringForce: " << magnitude <<
" DampingForce: " <<
m_dampingForce <<std::endl;
280 force = unitVector * magnitude;
283 m_prevLength = currLength;
298 return tgCast::constFilter<tgBulletSpringCableAnchor, const tgSpringCableAnchor>(
m_anchors);
302 bool tgBulletCompressionSpring::invariant(
void)
const
virtual ~tgBulletCompressionSpring()
virtual void step(double dt)
virtual const double getSpringForce() const
tgBulletSpringCableAnchor *const anchor1
virtual const bool isFreeEndAttached() const
Utility class for class casting and filtering collections by type.
tgBulletCompressionSpring(const std::vector< tgBulletSpringCableAnchor * > &anchors, bool isFreeEndAttached, double coefK, double coefD, double restLength)
virtual btVector3 getWorldPosition() const
btRigidBody *const attachedBody
virtual const btVector3 getSpringEndpoint() const
tgBulletSpringCableAnchor *const anchor2
Definitions of class tgBulletCompressionSpring.
std::vector< tgBulletSpringCableAnchor * > m_anchors
virtual const double getCoefK() const
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
virtual const double getCurrentSpringLength() const
virtual const double getCoefD() const
virtual const std::vector< const tgSpringCableAnchor * > getAnchors() const
virtual void calculateAndApplyForce(double dt)
virtual const btVector3 getAnchorDirectionUnitVector() const
virtual const double getCurrentAnchorDistance() const
virtual const double getRestLength() const
virtual btVector3 getRelativePosition() const