void OpenSteer::SimpleVehicle::applyBrakingForce (const float rate, const float deltaTime) { const float rawBraking = speed () * rate; const float clipBraking = ((rawBraking < maxForce ()) ? rawBraking : maxForce ()); setSpeed (speed () - (clipBraking * deltaTime)); }
// Will be called from subclasses, as is virtual function //---------------------------------------------------------------------------------------------------------------------- void Muscle::toXml(ci::XmlTree& muscle) { // XMLTree muscle provided by subclass //ci::XmlTree muscle("Muscle", ""); muscle.setAttribute("Name", getName()); muscle.setAttribute("IsFlexor", isFlexor()); muscle.setAttribute("IsMono", isMonoArticulate()); ci::XmlTree attach("Attachment",""); attach.setAttribute("Origin", getOrigin()); attach.setAttribute("Insertion", getInsertion()); muscle.push_back(attach); double Fmax = getForceMax(); ci::XmlTree maxForce("MaxIsoForce", toString(Fmax)); muscle.push_back(maxForce); double Vmax = getVelocityMax(); ci::XmlTree maxVel("MaxVelocity", toString(Vmax)); muscle.push_back(maxVel); ci::XmlTree length("Length",""); length.setAttribute("Optimal", getOptimalLength()); length.setAttribute("Min", m_lengthMin); length.setAttribute("Max", m_lengthMax); muscle.push_back(length); ci::XmlTree hillParams("HillParameters",""); hillParams.setAttribute("Shortening", m_hillSh); hillParams.setAttribute("Lengthening", m_hillLn); hillParams.setAttribute("Asymptote", m_hillMax); hillParams.setAttribute("Slope", m_hillSlope); muscle.push_back(hillParams); }
// reset state void LowSpeedTurn::reset(){ // reset vehicle state SimpleVehicle::reset(); // speed along Forward direction. speed(startSpeed); // initial position along X axis position(startX, 0, 0); // steering force clip magnitude maxForce(0.3f); // velocity clip magnitude maxSpeed(1.5f); // for next instance: step starting location startX += 2; // for next instance: step speed startSpeed += 0.15f; // 15 seconds and 150 points along the trail setTrailParameters(15, 150); clearTrailHistory(); // prevent long streaks due to teleportation // load the mesh Mesh = getMesh_VehicleDisk(); Box = Mesh.getBoundingbox(); setScale(irr::core::vector3df(2.0, 1.0, 2.0)); // disable lighting Material.Lighting = false; }
void OpenSteer::SimpleVehicle::annotationVelocityAcceleration (float maxLengthA, float maxLengthV) { const float desat = 0.4f; const float aScale = maxLengthA / maxForce (); const float vScale = maxLengthV / maxSpeed (); const Vec3& p = position(); const Vec3 aColor (desat, desat, 1); // bluish const Vec3 vColor ( 1, desat, 1); // pinkish annotationLine (p, p + (velocity () * vScale), vColor); annotationLine (p, p + (_smoothedAcceleration * aScale), aColor); }
void OpenSteer::SimpleVehicle::applySteeringForce (const Vec3& force, const float elapsedTime) { const Vec3 adjustedForce = adjustRawSteeringForce (force, elapsedTime); // enforce limit on magnitude of steering force const Vec3 clippedForce = adjustedForce.truncateLength (maxForce ()); // compute acceleration and velocity Vec3 newAcceleration = (clippedForce / mass()); Vec3 newVelocity = velocity(); // damp out abrupt changes and oscillations in steering acceleration // (rate is proportional to time step, then clipped into useful range) if (elapsedTime > 0) { const float smoothRate = clip (9 * elapsedTime, 0.15f, 0.4f); blendIntoAccumulator (smoothRate, newAcceleration, _smoothedAcceleration); } // Euler integrate (per frame) acceleration into velocity newVelocity += _smoothedAcceleration * elapsedTime; // enforce speed limit newVelocity = newVelocity.truncateLength (maxSpeed ()); // update Speed setSpeed (newVelocity.length()); // Euler integrate (per frame) velocity into position setPosition (position() + (newVelocity * elapsedTime)); // regenerate local space (by default: align vehicle's forward axis with // new velocity, but this behavior may be overridden by derived classes.) regenerateLocalSpace (newVelocity, elapsedTime); // maintain path curvature information measurePathCurvature (elapsedTime); // running average of recent positions blendIntoAccumulator (elapsedTime * 0.06f, // QQQ position (), _smoothedPosition); }