Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5211 in orxonox.OLD for trunk/src/lib/math


Ignore:
Timestamp:
Sep 21, 2005, 2:21:41 PM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: valgrind mem-leak-recovered

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/math/curve.cc

    r4836 r5211  
    1 /* 
     1/*
    22   orxonox - the future of 3D-vertical-scrollers
    33
     
    1313   co-programmer: Patrick Boenzli
    1414
    15    ADD: Patrick Boenzli           B-Spline 
    16 
    17 
    18    TODO: 
     15   ADD: Patrick Boenzli           B-Spline
     16
     17
     18   TODO:
    1919     local-Time implementation
    2020     NURBS
    2121     tList implementation
    22      
     22
    2323*/
    2424
     
    3333
    3434
    35 /** 
     35/**
    3636  *  default constructor for a Curve
    3737*/
     
    7171void Curve::addNode(const Vector& newNode, unsigned int insertPosition)
    7272{
    73 
    7473  if (this->nodeCount == 0 || insertPosition > this->nodeCount)
    7574    return addNode(newNode);
     
    8584    {
    8685      while (tmpNode->next->number != insertPosition)
    87         tmpNode= tmpNode->next;
     86        tmpNode= tmpNode->next;
    8887      insNode->next = tmpNode->next;
    8988      tmpNode->next = insNode;
     
    199198      tmpNode->factor = binCoef;
    200199      if (tmpNode =tmpNode->next)
    201         {
    202           binCoef *=(n-k)/(k+1);
    203           ++k;
    204         }
     200        {
     201          binCoef *=(n-k)/(k+1);
     202          ++k;
     203        }
    205204    }
    206205
     
    212211      dirCurve = new BezierCurve(1);
    213212      while(tmpNode->next)
    214         {
    215           Vector tmpVector = (tmpNode->next->position)- (tmpNode->position);
    216           tmpVector.x*=(float)nodeCount;
    217           tmpVector.y*=(float)nodeCount;
    218           tmpVector.z*=(float)nodeCount;
    219           tmpVector.normalize();
    220           this->dirCurve->addNode(tmpVector);
    221           tmpNode = tmpNode->next;
    222         }
     213        {
     214          Vector tmpVector = (tmpNode->next->position)- (tmpNode->position);
     215          tmpVector.x*=(float)nodeCount;
     216          tmpVector.y*=(float)nodeCount;
     217          tmpVector.z*=(float)nodeCount;
     218          tmpVector.normalize();
     219          this->dirCurve->addNode(tmpVector);
     220          tmpNode = tmpNode->next;
     221        }
    223222    }
    224223}
     
    229228 * @return the Position on the Path
    230229*/
    231 Vector BezierCurve::calcPos(float t) 
     230Vector BezierCurve::calcPos(float t)
    232231{
    233232  Vector ret = Vector(0.0,0.0,0.0);
     
    237236      double factor = pow(1.0-t,nodeCount-1);
    238237      while(tmpNode)
    239         {
    240           ret.x += tmpNode->factor * factor * tmpNode->position.x;
    241           ret.y += tmpNode->factor * factor * tmpNode->position.y;
    242           ret.z += tmpNode->factor * factor * tmpNode->position.z;
    243           factor *= t/(1.0-t); // same as pow but much faster.
    244          
    245           tmpNode = tmpNode->next;
    246         }
     238        {
     239          ret.x += tmpNode->factor * factor * tmpNode->position.x;
     240          ret.y += tmpNode->factor * factor * tmpNode->position.y;
     241          ret.z += tmpNode->factor * factor * tmpNode->position.z;
     242          factor *= t/(1.0-t); // same as pow but much faster.
     243
     244          tmpNode = tmpNode->next;
     245        }
    247246    }
    248247  else if (nodeCount == 2)
Note: See TracChangeset for help on using the changeset viewer.