void AccelerateAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime) { // basic physics // v = a t // d = v t // d = 1/2 a t^2 // delta_d = 1/2 a t^2 - 1/2 a (t-delta_t)^2 : 6 *, 2 - // alternate forms (thanks to wolfram alpha) // delta_d = -1/2 a delta_t (delta_t - 2 t) : 4 *, 1 - (using this one) // delta_d = a delta_t t - (a delta_t^2)/2 : 4 *, 1 /, 1 - // delta_d = 1/2 a delta_t (2 t - delta_t) : 4 *, 1 - elapsedTime += deltaTime; double delta_t = deltaTime.realSeconds(); double t = elapsedTime.realSeconds(); Point position = target->position(); currentSpeed = t * yPixelsPerSecondSquared; if( (useMaxSpeed && (currentSpeed <= maxSpd)) || (!useMaxSpeed)) { position.y() += -.5 * yPixelsPerSecondSquared * delta_t * (delta_t - 2 * t); } else { position.y() += maxSpd *delta_t; } position.x() += -.5 * xPixelsPerSecondSquared * delta_t * (delta_t - 2 * t); target->setPosition(position); }