animpoint.cpp
changeset 688 d0086df58648
parent 461 b0d72eb511c9
child 721 12958f987bcf
     1.1 --- a/animpoint.cpp	Thu Apr 10 19:56:11 2008 +0000
     1.2 +++ b/animpoint.cpp	Mon May 05 13:46:42 2008 +0000
     1.3 @@ -1,5 +1,7 @@
     1.4  #include "animpoint.h"
     1.5  
     1.6 +#include <math.h>
     1.7 +
     1.8  AnimPoint::AnimPoint()
     1.9  {
    1.10  	init();
    1.11 @@ -27,6 +29,8 @@
    1.12  {
    1.13      if (rx() != other.rx() ) return false;
    1.14      if (ry() != other.ry() ) return false;
    1.15 +	if (startPos != other.startPos) return false;
    1.16 +	if (destPos  != other.destPos) return false;
    1.17      if (animated != other.animated ) return false;
    1.18  
    1.19  	return true;
    1.20 @@ -35,24 +39,62 @@
    1.21  void AnimPoint::init ()
    1.22  {
    1.23  	animated=false;
    1.24 +	n=0;
    1.25 +	startPos=QPointF(0,0);
    1.26 +	destPos=QPointF(0,0);
    1.27 +	vector=QPointF(0,0);
    1.28 +	animTicks=10;
    1.29  }
    1.30  
    1.31  void AnimPoint::copy (AnimPoint other)
    1.32  {
    1.33  	setX (other.x() );
    1.34  	setY (other.x() );
    1.35 +	startPos=other.startPos;
    1.36 +	destPos=other.destPos;
    1.37 +	vector=other.vector;
    1.38  	animated=other.animated;
    1.39 +	n=other.n;
    1.40 +	animTicks=other.animTicks;
    1.41 +}
    1.42 +
    1.43 +void AnimPoint::setStart(const QPointF &p)
    1.44 +{
    1.45 +	startPos=p;
    1.46 +	initVector();
    1.47 +}
    1.48 +
    1.49 +QPointF AnimPoint::getStart()
    1.50 +{
    1.51 +	return startPos;
    1.52  }
    1.53  
    1.54  
    1.55  void AnimPoint::setDest(const QPointF &p)
    1.56  {
    1.57  	destPos=p;
    1.58 +	initVector();
    1.59 +}
    1.60 +
    1.61 +QPointF AnimPoint::getDest()
    1.62 +{
    1.63 +	return destPos;
    1.64 +}
    1.65 +
    1.66 +void AnimPoint::setTicks (const uint &t)
    1.67 +{
    1.68 +	animTicks=t;
    1.69 +}
    1.70 +
    1.71 +uint AnimPoint::getTicks()
    1.72 +{
    1.73 +	return animTicks;
    1.74  }
    1.75  
    1.76  void AnimPoint::setAnimated(bool b)
    1.77  {
    1.78  	animated=b;
    1.79 +	if (b) n=0;
    1.80  }
    1.81  
    1.82  bool AnimPoint::isAnimated()
    1.83 @@ -60,11 +102,30 @@
    1.84  	return animated;
    1.85  }
    1.86  
    1.87 -void AnimPoint::animate()
    1.88 +bool AnimPoint::animate()
    1.89  {
    1.90 -	setX (x()+1);
    1.91 -	setY (y()+1);
    1.92 +	if (!animated) return animated;
    1.93 +	n++;
    1.94 +	if (n>animTicks)
    1.95 +	{
    1.96 +		vector=QPointF(0,0);
    1.97 +		animated=false;
    1.98 +		return animated;
    1.99 +	}
   1.100 +
   1.101 +	setX (startPos.x() + vector.x()*sqrt(n/animTicks) );
   1.102 +	setY (startPos.y() + vector.y()*sqrt(n/animTicks) );
   1.103 +	/*
   1.104 +	setX (startPos.x() + vector.x()*(n/animTicks) );
   1.105 +	setY (startPos.y() + vector.y()*(n/animTicks) );
   1.106 +	*/
   1.107 +	return animated;
   1.108  }
   1.109  
   1.110 +void AnimPoint::initVector()
   1.111 +{
   1.112 +	vector.setX (destPos.x()-startPos.x() );
   1.113 +	vector.setY (destPos.y()-startPos.y() );
   1.114 +}
   1.115  
   1.116