author | insilmaril |
Fri Mar 05 20:16:46 2010 +0000 (2010-03-05) | |
branch | release-1-12-maintained |
changeset 80 | 5c5b4464b24f |
permissions | -rw-r--r-- |
insilmaril@47 | 1 |
#include "animpoint.h" |
insilmaril@47 | 2 |
|
insilmaril@47 | 3 |
#include <math.h> |
insilmaril@47 | 4 |
|
insilmaril@47 | 5 |
AnimPoint::AnimPoint() |
insilmaril@47 | 6 |
{ |
insilmaril@47 | 7 |
init(); |
insilmaril@47 | 8 |
} |
insilmaril@47 | 9 |
|
insilmaril@47 | 10 |
void AnimPoint::operator= ( const AnimPoint & other ) |
insilmaril@47 | 11 |
{ |
insilmaril@47 | 12 |
copy (other); |
insilmaril@47 | 13 |
} |
insilmaril@47 | 14 |
|
insilmaril@47 | 15 |
void AnimPoint::operator= ( const QPointF & other ) |
insilmaril@47 | 16 |
{ |
insilmaril@47 | 17 |
init(); |
insilmaril@47 | 18 |
setX (other.x() ); |
insilmaril@47 | 19 |
setY (other.x() ); |
insilmaril@47 | 20 |
} |
insilmaril@47 | 21 |
|
insilmaril@47 | 22 |
bool AnimPoint::operator== ( const QPointF& other ) |
insilmaril@47 | 23 |
{ |
insilmaril@47 | 24 |
QPointF p( x(),y()); |
insilmaril@47 | 25 |
return p == other; |
insilmaril@47 | 26 |
} |
insilmaril@47 | 27 |
|
insilmaril@47 | 28 |
bool AnimPoint::operator== ( AnimPoint other ) |
insilmaril@47 | 29 |
{ |
insilmaril@47 | 30 |
if (rx() != other.rx() ) return false; |
insilmaril@47 | 31 |
if (ry() != other.ry() ) return false; |
insilmaril@47 | 32 |
if (startPos != other.startPos) return false; |
insilmaril@47 | 33 |
if (destPos != other.destPos) return false; |
insilmaril@47 | 34 |
if (animated != other.animated ) return false; |
insilmaril@47 | 35 |
|
insilmaril@47 | 36 |
return true; |
insilmaril@47 | 37 |
} |
insilmaril@47 | 38 |
|
insilmaril@47 | 39 |
void AnimPoint::init () |
insilmaril@47 | 40 |
{ |
insilmaril@47 | 41 |
animated=false; |
insilmaril@47 | 42 |
n=0; |
insilmaril@47 | 43 |
startPos=QPointF(0,0); |
insilmaril@47 | 44 |
destPos=QPointF(0,0); |
insilmaril@47 | 45 |
vector=QPointF(0,0); |
insilmaril@47 | 46 |
animTicks=10; |
insilmaril@47 | 47 |
} |
insilmaril@47 | 48 |
|
insilmaril@47 | 49 |
void AnimPoint::copy (AnimPoint other) |
insilmaril@47 | 50 |
{ |
insilmaril@47 | 51 |
setX (other.x() ); |
insilmaril@47 | 52 |
setY (other.x() ); |
insilmaril@47 | 53 |
startPos=other.startPos; |
insilmaril@47 | 54 |
destPos=other.destPos; |
insilmaril@47 | 55 |
vector=other.vector; |
insilmaril@47 | 56 |
animated=other.animated; |
insilmaril@47 | 57 |
n=other.n; |
insilmaril@47 | 58 |
animTicks=other.animTicks; |
insilmaril@47 | 59 |
} |
insilmaril@47 | 60 |
|
insilmaril@47 | 61 |
void AnimPoint::setStart(const QPointF &p) |
insilmaril@47 | 62 |
{ |
insilmaril@47 | 63 |
startPos=p; |
insilmaril@47 | 64 |
initVector(); |
insilmaril@47 | 65 |
} |
insilmaril@47 | 66 |
|
insilmaril@47 | 67 |
QPointF AnimPoint::getStart() |
insilmaril@47 | 68 |
{ |
insilmaril@47 | 69 |
return startPos; |
insilmaril@47 | 70 |
} |
insilmaril@47 | 71 |
|
insilmaril@47 | 72 |
|
insilmaril@47 | 73 |
void AnimPoint::setDest(const QPointF &p) |
insilmaril@47 | 74 |
{ |
insilmaril@47 | 75 |
destPos=p; |
insilmaril@47 | 76 |
initVector(); |
insilmaril@47 | 77 |
} |
insilmaril@47 | 78 |
|
insilmaril@47 | 79 |
QPointF AnimPoint::getDest() |
insilmaril@47 | 80 |
{ |
insilmaril@47 | 81 |
return destPos; |
insilmaril@47 | 82 |
} |
insilmaril@47 | 83 |
|
insilmaril@47 | 84 |
void AnimPoint::setTicks (const uint &t) |
insilmaril@47 | 85 |
{ |
insilmaril@47 | 86 |
animTicks=t; |
insilmaril@47 | 87 |
} |
insilmaril@47 | 88 |
|
insilmaril@47 | 89 |
uint AnimPoint::getTicks() |
insilmaril@47 | 90 |
{ |
insilmaril@47 | 91 |
return animTicks; |
insilmaril@47 | 92 |
} |
insilmaril@47 | 93 |
|
insilmaril@47 | 94 |
void AnimPoint::setAnimated(bool b) |
insilmaril@47 | 95 |
{ |
insilmaril@47 | 96 |
animated=b; |
insilmaril@47 | 97 |
if (b) n=0; |
insilmaril@47 | 98 |
} |
insilmaril@47 | 99 |
|
insilmaril@47 | 100 |
bool AnimPoint::isAnimated() |
insilmaril@47 | 101 |
{ |
insilmaril@47 | 102 |
return animated; |
insilmaril@47 | 103 |
} |
insilmaril@47 | 104 |
|
insilmaril@47 | 105 |
bool AnimPoint::animate() |
insilmaril@47 | 106 |
{ |
insilmaril@47 | 107 |
if (!animated) return animated; |
insilmaril@47 | 108 |
n++; |
insilmaril@47 | 109 |
if (n>animTicks) |
insilmaril@47 | 110 |
{ |
insilmaril@47 | 111 |
vector=QPointF(0,0); |
insilmaril@47 | 112 |
animated=false; |
insilmaril@47 | 113 |
return animated; |
insilmaril@47 | 114 |
} |
insilmaril@47 | 115 |
|
insilmaril@47 | 116 |
// Some math slow down the movement |
insilmaril@47 | 117 |
qreal f=1-n/animTicks; |
insilmaril@47 | 118 |
qreal ff=1-f*f*f; |
insilmaril@47 | 119 |
setX (startPos.x() + vector.x()*ff ); |
insilmaril@47 | 120 |
setY (startPos.y() + vector.y()*ff ); |
insilmaril@47 | 121 |
|
insilmaril@47 | 122 |
return animated; |
insilmaril@47 | 123 |
} |
insilmaril@47 | 124 |
|
insilmaril@47 | 125 |
void AnimPoint::initVector() |
insilmaril@47 | 126 |
{ |
insilmaril@47 | 127 |
vector.setX (destPos.x()-startPos.x() ); |
insilmaril@47 | 128 |
vector.setY (destPos.y()-startPos.y() ); |
insilmaril@47 | 129 |
} |
insilmaril@47 | 130 |
|
insilmaril@47 | 131 |