2 Copyright (c) 2006 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2006 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
16 #define QUINTIC_SIGMOID
18 double Movement::sigmoid(double t
) {
20 return -2 * pow(t
- 0.5, 3) + 1.5 * t
- 0.25;
22 return 6 * pow(t
- 0.5, 5) - 5 * pow(t
, 3) + 7.5 * t
* t
- 15 * 0.125 * t
+ 3.0 / 16;
26 double Movement::half_sigmoid(double t
) {
27 // use the second half of the sigmoid parameterization
28 return sigmoid(0.5 * (t
+ 1));
31 LinearMovement::LinearMovement(const QPoint
& from
, const QPoint
& to
, bool /*rotate*/)
33 , m_velocity(to
- from
) { }
35 QPoint
LinearMovement::pos(double t
) const {
36 return m_from
+ m_velocity
* t
;
39 LMovement::LMovement(const QPoint
& from
, const QPoint
& to
, bool rotate
)
41 , m_velocity(to
- from
)
43 if (abs(static_cast<double>(m_velocity
.x())) >=
44 abs(static_cast<double>(m_velocity
.y()))) {
45 m_x
= LMovement::nonlinear
;
46 m_y
= LMovement::linear
;
49 m_y
= LMovement::nonlinear
;
50 m_x
= LMovement::linear
;
54 double LMovement::nonlinear(double t
) {
55 return (exp( (double)(3 * t
) ) - 1) / (exp( (double)3 ) - 1);
58 QPoint
LMovement::pos(double t
) const {
59 return m_from
+ QPoint(
60 static_cast<int>(m_velocity
.x() * m_x(t
)),
61 static_cast<int>(m_velocity
.y() * m_y(t
)));
64 double LMovement::rotation(double t
) const {
68 double r
= (1.0-cos(t
*M_PI
))*M_PI
;
69 return m_velocity
.x() >= 0 ? r
: -r
;