30 #include "BulletDynamics/Dynamics/btRigidBody.h"
37 double dampingCoefficient,
40 coefK, dampingCoefficient, pretension),
42 anchor1(anchors.front()),
43 anchor2(anchors.back())
54 std::cout <<
"Destroying tgBulletSpringCable" << std::endl;
70 for (std::size_t i = 0; i < n; i++)
83 throw std::invalid_argument(
"dt is not positive!");
86 calculateAndApplyForce(dt);
90 void tgBulletSpringCable::calculateAndApplyForce(
double dt)
92 btVector3 force(0.0, 0.0, 0.0);
93 double magnitude = 0.0;
94 const btVector3 dist =
98 const double currLength = dist.length();
99 const btVector3 unitVector = dist / currLength;
109 if (abs(magnitude) * 1.0 < abs(
m_damping))
112 (
m_damping > 0.0 ? magnitude * 1.0 : -magnitude * 1.0);
118 std::cout <<
"Length: " << dist.length() <<
" rl: " << m_restLength <<std::endl;
123 force = unitVector * magnitude;
131 m_prevLength = currLength;
145 const btVector3 dist =
147 return dist.length();
153 tension = (tension < 0.0) ? 0.0 : tension;
159 return tgCast::constFilter<tgBulletSpringCableAnchor, const tgSpringCableAnchor>(
m_anchors);
162 bool tgBulletSpringCable::invariant(
void)
const
166 m_prevLength >= 0.0 &&
167 m_restLength >= 0.0 &&
virtual const double getActualLength() const
virtual void step(double dt)
tgBulletSpringCable(const std::vector< tgBulletSpringCableAnchor * > &anchors, double coefK, double dampingCoefficient, double pretension=0.0)
virtual ~tgBulletSpringCable()
virtual const std::vector< const tgSpringCableAnchor * > getAnchors() const
Utility class for class casting and filtering collections by type.
const double m_dampingCoefficient
virtual btVector3 getWorldPosition() const
tgBulletSpringCableAnchor *const anchor2
btRigidBody *const attachedBody
virtual const double getTension() const
std::vector< tgBulletSpringCableAnchor * > m_anchors
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
Definitions of classes tgBulletSpringCable $Id$.
tgBulletSpringCableAnchor *const anchor1
virtual btVector3 getRelativePosition() const