float3 OpenSteer::SteerLibrary:: steerForTargetSpeed (const AbstractVehicle& v, const float targetSpeed) { const float mf = v.maxForce (); const float speedError = targetSpeed - v.speed (); return float3_scalar_multiply(make_float3(v.forward ()), clip (speedError, -mf, +mf)); }
OpenSteer::Vec3 OpenSteer::Obstacle::PathIntersection:: steerToAvoidIfNeeded (const AbstractVehicle& vehicle, const float minTimeToCollision) const { // if nearby intersection found, steer away from it, otherwise no steering const float minDistanceToCollision = minTimeToCollision * vehicle.speed(); if (intersect && (distance < minDistanceToCollision)) { // compute avoidance steering force: take the component of // steerHint which is lateral (perpendicular to vehicle's // forward direction), set its length to vehicle's maxForce Vec3 lateral = steerHint.perpendicularComponent (vehicle.forward ()); if (lateral == Vec3::zero) lateral = vehicle.side (); return lateral.normalize () * vehicle.maxForce (); } else { return Vec3::zero; } }