void AutomationPattern::saveSettings( QDomDocument & _doc, QDomElement & _this ) { _this.setAttribute( "pos", startPosition() ); _this.setAttribute( "len", length() ); _this.setAttribute( "name", name() ); _this.setAttribute( "prog", QString::number( progressionType() ) ); _this.setAttribute( "tens", QString::number( getTension() ) ); _this.setAttribute( "mute", QString::number( isMuted() ) ); for( timeMap::const_iterator it = m_timeMap.begin(); it != m_timeMap.end(); ++it ) { QDomElement element = _doc.createElement( "time" ); element.setAttribute( "pos", it.key() ); element.setAttribute( "value", it.value() ); _this.appendChild( element ); } for( objectVector::const_iterator it = m_objects.begin(); it != m_objects.end(); ++it ) { if( *it ) { QDomElement element = _doc.createElement( "object" ); element.setAttribute( "id", ProjectJournal::idToSave( ( *it )->id() ) ); _this.appendChild( element ); } } }
void SplineCardinal<Point>::toHermite(SplineHermite<Point>& s) const { //copy times s.copyTimeBase(*this); s.getPoint(0)=getPoint(0); int numSegments = getNumSegments(); if(numSegments > 0) { s.getTangentOut(0)=(getPoint(1)-getPoint(0))*getTension(0); for(int i=1;i<numSegments;i++) { s.getPoint(i)=getPoint(i); s.getTangentIn(i)=s.getTangentOut(i)=(getPoint(i+1)-getPoint(i-1))*getTension(i); } s.getTangentIn(numSegments)=(getPoint(numSegments)-getPoint(numSegments-1))*getTension(numSegments); } s.getTangentIn(0) = Zero; s.getTangentOut(numSegments) = Zero; }
void tgBulletContactSpringCable::calculateAndApplyForce(double dt) { #ifndef BT_NO_PROFILE BT_PROFILE("calculateAndApplyForce"); #endif //BT_NO_PROFILE const double tension = getTension(); const double currLength = getActualLength(); const double deltaStretch = currLength - m_prevLength; m_velocity = deltaStretch / dt; m_damping = m_dampingCoefficient * m_velocity; if (btFabs(tension) * 1.0 < btFabs(m_damping)) { m_damping = (m_damping > 0.0 ? tension * 1.0 : -tension * 1.0); } const double magnitude = tension + m_damping; // Apply forces std::size_t n = m_anchors.size(); for (std::size_t i = 0; i < n; i++) { btVector3 force = btVector3 (0.0, 0.0, 0.0); if (i == 0) { btVector3 direction = m_anchors[i + 1]->getWorldPosition() - m_anchors[i]->getWorldPosition(); force = direction.normalize() * magnitude; } // Will likely only be true for the last anchor else if (m_anchors[i]->sliding == false) { btVector3 direction = m_anchors[i]->getWorldPosition() - m_anchors[i - 1]->getWorldPosition(); force = -direction.normalize() * magnitude; } else if (i < n - 1) { // Already normalized btVector3 direction = m_anchors[i]->getContactNormal(); // Get normal to string btVector3 back = m_anchors[i - 1]->getWorldPosition(); btVector3 current = m_anchors[i]->getWorldPosition(); btVector3 forward = m_anchors[i + 1]->getWorldPosition(); btVector3 first = (forward - current); btVector3 second = (back - current); btVector3 forceDir = first.normalize() + second.normalize(); // For sliding anchors, just figuring out directions for now force = magnitude * forceDir; } else { throw std::runtime_error("tgBulletContactSpringCable: First or last anchor is a sliding constraint!!"); } m_anchors[i]->force = force; } btVector3 totalForce(0.0, 0.0, 0.0); for (std::size_t i = 0; i < n; i++) { btRigidBody* body = m_anchors[i]->attachedBody; btVector3 contactPoint = m_anchors[i]->getRelativePosition(); body->activate(); totalForce += m_anchors[i]->force; btVector3 impulse = m_anchors[i]->force* dt; body->applyImpulse(impulse, contactPoint); } if (!totalForce.fuzzyZero()) { std::cout << "Total Force Error! " << totalForce << std::endl; throw std::runtime_error("Total force did not sum to zero!"); } // Finished calculating, so can store things m_prevLength = currLength; }