diff -r 1973a58f3900 -r d0086df58648 animpoint.cpp --- a/animpoint.cpp Thu Apr 10 19:56:11 2008 +0000 +++ b/animpoint.cpp Mon May 05 13:46:42 2008 +0000 @@ -1,5 +1,7 @@ #include "animpoint.h" +#include + AnimPoint::AnimPoint() { init(); @@ -27,6 +29,8 @@ { if (rx() != other.rx() ) return false; if (ry() != other.ry() ) return false; + if (startPos != other.startPos) return false; + if (destPos != other.destPos) return false; if (animated != other.animated ) return false; return true; @@ -35,24 +39,62 @@ void AnimPoint::init () { animated=false; + n=0; + startPos=QPointF(0,0); + destPos=QPointF(0,0); + vector=QPointF(0,0); + animTicks=10; } void AnimPoint::copy (AnimPoint other) { setX (other.x() ); setY (other.x() ); + startPos=other.startPos; + destPos=other.destPos; + vector=other.vector; animated=other.animated; + n=other.n; + animTicks=other.animTicks; +} + +void AnimPoint::setStart(const QPointF &p) +{ + startPos=p; + initVector(); +} + +QPointF AnimPoint::getStart() +{ + return startPos; } void AnimPoint::setDest(const QPointF &p) { destPos=p; + initVector(); +} + +QPointF AnimPoint::getDest() +{ + return destPos; +} + +void AnimPoint::setTicks (const uint &t) +{ + animTicks=t; +} + +uint AnimPoint::getTicks() +{ + return animTicks; } void AnimPoint::setAnimated(bool b) { animated=b; + if (b) n=0; } bool AnimPoint::isAnimated() @@ -60,11 +102,30 @@ return animated; } -void AnimPoint::animate() +bool AnimPoint::animate() { - setX (x()+1); - setY (y()+1); + if (!animated) return animated; + n++; + if (n>animTicks) + { + vector=QPointF(0,0); + animated=false; + return animated; + } + + setX (startPos.x() + vector.x()*sqrt(n/animTicks) ); + setY (startPos.y() + vector.y()*sqrt(n/animTicks) ); + /* + setX (startPos.x() + vector.x()*(n/animTicks) ); + setY (startPos.y() + vector.y()*(n/animTicks) ); + */ + return animated; } +void AnimPoint::initVector() +{ + vector.setX (destPos.x()-startPos.x() ); + vector.setY (destPos.y()-startPos.y() ); +}