NTRT Simulator  Version: Master
 All Classes Namespaces Files Functions Variables Typedefs Friends Pages
tgBulletUnidirComprSpr Class Reference

#include <tgBulletUnidirComprSpr.h>

Inheritance diagram for tgBulletUnidirComprSpr:
Collaboration diagram for tgBulletUnidirComprSpr:

Public Member Functions

 tgBulletUnidirComprSpr (const std::vector< tgBulletSpringCableAnchor * > &anchors, bool isFreeEndAttached, double coefK, double coefD, double restLength, btVector3 *direction)
 
virtual ~tgBulletUnidirComprSpr ()
 
virtual void step (double dt)
 
virtual const double getCurrentAnchorDistanceAlongDirection () const
 
virtual const double getCurrentSpringLength () const
 
virtual const btVector3 getSpringEndpoint () const
 
virtual const double getSpringForce () const
 
virtual const btVector3 * getDirection () const
 
virtual const double getCurrentAnchorDistance () const
 
virtual const btVector3 getAnchorDirectionUnitVector () const
 
virtual const double getCoefK () const
 
virtual const double getCoefD () const
 
virtual const double getVelocity () const
 
virtual const double getDampingForce () const
 
virtual const double getRestLength () const
 
virtual const bool isFreeEndAttached () const
 
virtual const std::vector
< const tgSpringCableAnchor * > 
getAnchors () const
 

Protected Member Functions

virtual void calculateAndApplyForce (double dt)
 

Protected Attributes

btVector3 * m_direction
 
std::vector
< tgBulletSpringCableAnchor * > 
m_anchors
 
tgBulletSpringCableAnchor *const anchor1
 
tgBulletSpringCableAnchor *const anchor2
 
double m_dampingForce
 
double m_velocity
 
bool m_isFreeEndAttached
 
const double m_coefK
 
const double m_coefD
 
double m_restLength
 
double m_prevLength
 

Detailed Description

This class defines the passive dynamics of a compression spring system, with damping, in the Bullet physics engine. It extends tgBulletCompressionSpring, and changes the way that forces are applied: instead of calculating and applying force along the vector between the two anchor points, it only calculates/applies force along one of the axes: X, Y or Z. So for example, if it's only in Z, one anchor could move around in X or Y and the applied force wouldn't change. Here, we use "Unidir" to mean "Unidirectional."

Definition at line 60 of file tgBulletUnidirComprSpr.h.

Constructor & Destructor Documentation

tgBulletUnidirComprSpr::tgBulletUnidirComprSpr ( const std::vector< tgBulletSpringCableAnchor * > &  anchors,
bool  isFreeEndAttached,
double  coefK,
double  coefD,
double  restLength,
btVector3 *  direction 
)

The only constructor. Takes a list of anchors, a flag controlling attached-ness of the free end of the spring, a coefficient of stiffness, a coefficent of damping, rest length of the spring, and a btVector3 in one of the X, Y, or Z directions.

Parameters
[in]anchors- a list of this spring cable's attachements
[in]isFreeEndAttached- boolean flag. If no, the spring only provides compression force. If yes, the spring is "attached" to both anchors, and provides a tension force too when the distance between anchors is greater than rest length.
[in]coefK- the stiffness of the spring. Must be positive
[in]dampingCoefficient- the damping in the spring. Must be non-negative.
[in]restLength- the length of the compression spring when unloaded.
[in]direction- the direction of the force to be applied, a btVector3. the current version will only support (1,0,0), (0,1,0), or (0,0,1), or the negatives of those vectors. NOTE that if the To anchor is in the negative direction with respect to the From anchor, then direction should be NEGATIVE. NOTE that although direction is a pointer, it is not deleted in this class or any of the other related classes in core. That is because it's stored in the const Config struct of an application: it's only created once, not dynamically, so it's only deleted at the very end of the application (NOT during any individual setups or teardowns.)

The main constructor for this class In comparison to the tgSpringCable vs. tgBulletSpringCable class inheritance, there is no need for the tgCast here, since the same type of anchor is used in both tgBulletCompressionSpring and tgBulletUnidirComprSpr.

Definition at line 43 of file tgBulletUnidirComprSpr.cpp.

tgBulletUnidirComprSpr::~tgBulletUnidirComprSpr ( )
virtual

The virtual destructor. Deletes all of the anchors including anchor1 and anchor2

Definition at line 83 of file tgBulletUnidirComprSpr.cpp.

Member Function Documentation

void tgBulletUnidirComprSpr::calculateAndApplyForce ( double  dt)
protectedvirtual

Calculates the current forces that need to be applied to the rigid bodies, and applies them to the bodies of anchor1 and anchor2 Need to re-declare it here so it can be redefined in this child class.

This is the method that does the heavy lifting in this class. Called by step, it calculates what force the spring is experiencing, and applies that force to the rigid bodies it connects to.

Reimplemented from tgBulletCompressionSpring.

Definition at line 229 of file tgBulletUnidirComprSpr.cpp.

Here is the caller graph for this function:

const btVector3 tgBulletCompressionSpring::getAnchorDirectionUnitVector ( ) const
virtualinherited

Return the unit vector in the direction of this spring

Returns the unit vector in the direction of this spring.

Definition at line 181 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const std::vector< const tgSpringCableAnchor * > tgBulletCompressionSpring::getAnchors ( ) const
virtualinherited

Returns a const vector of const anchors. Currently casts from tgBulletSpringCableAnchors, which makes it impossible to return a reference

Todo:
figure out how to cast and pass by reference

Definition at line 296 of file tgBulletCompressionSpring.cpp.

Here is the caller graph for this function:

virtual const double tgBulletCompressionSpring::getCoefD ( ) const
inlinevirtualinherited

Get the coefficent of damping

Definition at line 124 of file tgBulletCompressionSpring.h.

Here is the caller graph for this function:

virtual const double tgBulletCompressionSpring::getCoefK ( ) const
inlinevirtualinherited

Get the coefficent of stiffness

Definition at line 116 of file tgBulletCompressionSpring.h.

Here is the caller graph for this function:

const double tgBulletCompressionSpring::getCurrentAnchorDistance ( ) const
virtualinherited

Finds the distance between anchor1 and anchor2, and returns the length between them

Returns the distance between the two anchors. This is similar to the getActualLength function in tgBulletSpringCable.

Definition at line 139 of file tgBulletCompressionSpring.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const double tgBulletUnidirComprSpr::getCurrentAnchorDistanceAlongDirection ( ) const
virtual

Returns the distance between anchors along the vector m_direction. This function just calculates the dot product between m_direction and getCurrentAnchorDistance from the parent class.

Dot getCurrentAnchorDistance with m_direction.

Definition at line 124 of file tgBulletUnidirComprSpr.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

const double tgBulletUnidirComprSpr::getCurrentSpringLength ( ) const
virtual

Returns either restLength or the length of the spring along the single direction, depending on isFreeEndAttached.

Returns the current length of the spring. If isFreeEndAttached, this can be either greater or less than m_restLength. If not, then spring can only exist in compression (less than m_restLength). This only calculates the distance in the stated direction.

Reimplemented from tgBulletCompressionSpring.

Definition at line 142 of file tgBulletUnidirComprSpr.cpp.

virtual const double tgBulletCompressionSpring::getDampingForce ( ) const
inlinevirtualinherited

Get the last value of the damping force

Definition at line 140 of file tgBulletCompressionSpring.h.

virtual const btVector3* tgBulletUnidirComprSpr::getDirection ( ) const
inlinevirtual

Return the direction of applied force for this spring

Definition at line 138 of file tgBulletUnidirComprSpr.h.

virtual const double tgBulletCompressionSpring::getRestLength ( ) const
inlinevirtualinherited

Get the rest length of the spring (we're using these accessor functions per C++ style guidelines.)

Definition at line 149 of file tgBulletCompressionSpring.h.

const btVector3 tgBulletUnidirComprSpr::getSpringEndpoint ( ) const
virtual

Return the location of the free end of the spring. This is used, in particular, for rendering. See tgBulletRenderer.

Returns the location of the endpoint of the spring in space. The renderer uses this to draw lines more easily.

Reimplemented from tgBulletCompressionSpring.

Definition at line 174 of file tgBulletUnidirComprSpr.cpp.

const double tgBulletUnidirComprSpr::getSpringForce ( ) const
virtual

Returns the force currently in the spring, either compression only (e.g., a positive force only if isFreeEndAttached is false), or potentially either + or - force (if isFreeEndAttached == true).

Returns the current force in the spring. If ~isFreeEndAttached, this is zero if the distance between anchors is larger than restLength. Note that this does NOT include the force due to the damper, since that force is only temporary and isn't reallyt "the force in the spring" per se.

Reimplemented from tgBulletCompressionSpring.

Definition at line 194 of file tgBulletUnidirComprSpr.cpp.

Here is the caller graph for this function:

virtual const double tgBulletCompressionSpring::getVelocity ( ) const
inlinevirtualinherited

Get the last change in length / time

Definition at line 132 of file tgBulletCompressionSpring.h.

virtual const bool tgBulletCompressionSpring::isFreeEndAttached ( ) const
inlinevirtualinherited

Return the boolean: is the free end attached?

Definition at line 157 of file tgBulletCompressionSpring.h.

void tgBulletUnidirComprSpr::step ( double  dt)
virtual

Updates this object. Calls calculateAndApplyForce(dt)

Parameters
[in]dt,mustbe positive

Reimplemented from tgBulletCompressionSpring.

Definition at line 91 of file tgBulletUnidirComprSpr.cpp.

Here is the call graph for this function:

Member Data Documentation

tgBulletSpringCableAnchor* const tgBulletCompressionSpring::anchor1
protectedinherited

The first attachement point for this spring cable. Storing it seperately makes a number of functions easier

Definition at line 186 of file tgBulletCompressionSpring.h.

tgBulletSpringCableAnchor* const tgBulletCompressionSpring::anchor2
protectedinherited

The other permanent attachment for this spring cable.

Definition at line 191 of file tgBulletCompressionSpring.h.

std::vector<tgBulletSpringCableAnchor*> tgBulletCompressionSpring::m_anchors
protectedinherited

The list of contact points. tgBulletSpringCable typically has two whereas tgBulletContactSpringCable will have more. Needs to be stored here for consistent rendering. Vector has the convienence of tgCast functions, and we used to need a random iterator to sort

Definition at line 180 of file tgBulletCompressionSpring.h.

const double tgBulletCompressionSpring::m_coefD
protectedinherited

The damping coefficient. Units of mass / sec. Must be non-negative

Definition at line 222 of file tgBulletCompressionSpring.h.

const double tgBulletCompressionSpring::m_coefK
protectedinherited

The stiffness coefficient Units of mass / sec ^2 Must be positive

Definition at line 215 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_dampingForce
protectedinherited

The force in the spring due to damping, at the last update step. Stored so we can get it without passing a dt

Definition at line 197 of file tgBulletCompressionSpring.h.

btVector3* tgBulletUnidirComprSpr::m_direction
protected

Direction of the force that this spring will apply A constant pointer to a constant direction.

Definition at line 149 of file tgBulletUnidirComprSpr.h.

bool tgBulletCompressionSpring::m_isFreeEndAttached
protectedinherited

Boolean flag controlling the application of either tension forces or not.

Definition at line 208 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_prevLength
protectedinherited

The previous actual length of the spring. Used when calculating force and velocity

Definition at line 233 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_restLength
protectedinherited

The rest length of the spring. Must be non negative

Definition at line 227 of file tgBulletCompressionSpring.h.

double tgBulletCompressionSpring::m_velocity
protectedinherited

The velocity of the spring tip at the last update step. Stored so we can get it without passing a dt

Definition at line 203 of file tgBulletCompressionSpring.h.


The documentation for this class was generated from the following files: