32 #include "BulletDynamics/Dynamics/btRigidBody.h"
44 const std::vector<tgBulletSpringCableAnchor*>& anchors,
45 bool isFreeEndAttached,
49 btVector3 * direction) :
51 m_direction(direction)
59 std::cout <<
"tgBulletUnidirComprSpr constructor, ";
60 std::cout <<
"direction is: ";
71 double dotproduct =
m_direction->dot( btVector3(1,1,1) );
74 if( fabs(dotproduct) != 1.0 ){
75 std::cout <<
"Error: m_direction is not a unit vector. Its dot product" <<
76 " with (1,1,1) is " << dotproduct << std::endl;
77 throw std::invalid_argument(
"Direction must be a unit vector.");
86 std::cout <<
"Destroying tgBulletUnidirComprSpr..." << std::endl;
95 throw std::invalid_argument(
"dt is not positive!");
104 std::cout <<
"WARNING! UNIDIRECTIONAL COMPRESSION SPRING IS "
105 <<
"LESS THAN ZERO LENGTH. YOUR SIMULATION MAY BE INACCURATE FOR "
106 <<
"ANY TIMESTEPS WHEN THIS MESSAGE APPEARS. " << std::endl;
108 << std::endl << std::endl;
127 const btVector3 dist =
132 double currAnchDistAlongDir = dist.dot( (*
getDirection()) );
133 return currAnchDistAlongDir;
158 springLength = currAnchorDistAlongDir;
164 springLength = currAnchorDistAlongDir;
202 std::cout <<
"getCoefK: " <<
getCoefK() <<
" getCurrentSpringLength(): "
209 std::cout <<
"Called getSpringForce "
210 <<
"inside tgBulletUnidirComprSpr" << std::endl;
219 assert(springForce >= 0.0);
233 btVector3 force(0.0, 0.0, 0.0);
251 const double changeInDeltaX = currLength -
m_prevLength;
261 std::cout <<
"tgBulletUnidirComprSpr::calculateAndApplyForce " << std::endl;
263 std::cout <<
"SpringForce: " << magnitude <<
" DampingForce: " <<
m_dampingForce <<std::endl;
270 force = unitVector * magnitude;
273 m_prevLength = currLength;
290 bool tgBulletUnidirComprSpr::invariant(
void)
const
296 std::cout <<
"WARNING! UNIDIRECTIONAL COMPRESSION SPRING IS "
297 <<
"LESS THAN ZERO LENGTH. YOUR SIMULATION MAY BE INACCURATE FOR "
298 <<
"ANY TIMESTEPS WHEN THIS MESSAGE APPEARS. " << std::endl;
Definitions of class tgBulletUnidirComprSpr, a version of tgBulletCompressionSpring that only applies...
virtual ~tgBulletUnidirComprSpr()
virtual const btVector3 getSpringEndpoint() const
virtual void calculateAndApplyForce(double dt)
tgBulletSpringCableAnchor *const anchor1
virtual const bool isFreeEndAttached() const
Utility class for class casting and filtering collections by type.
virtual const double getCurrentAnchorDistanceAlongDirection() const
virtual btVector3 getWorldPosition() const
btRigidBody *const attachedBody
tgBulletUnidirComprSpr(const std::vector< tgBulletSpringCableAnchor * > &anchors, bool isFreeEndAttached, double coefK, double coefD, double restLength, btVector3 *direction)
tgBulletSpringCableAnchor *const anchor2
virtual const double getCurrentSpringLength() const
virtual const double getSpringForce() const
std::vector< tgBulletSpringCableAnchor * > m_anchors
virtual const double getCoefK() const
Definitions of class tgBulletSpringCableAnchor, formerly muscleAnchor.
virtual const double getCoefD() const
virtual void step(double dt)
virtual const btVector3 * getDirection() const
virtual const double getRestLength() const
virtual btVector3 getRelativePosition() const