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