Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3355 in orxonox.OLD for orxonox/branches/parenting/src/curve.cc


Ignore:
Timestamp:
Jan 6, 2005, 1:52:47 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: :Curve: bezierCurve now can have 0,1,2,3 points. instead of only more than 3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/parenting/src/curve.cc

    r3351 r3355  
    164164   \param t The position on the Curve (0<=t<=1)
    165165   \return the Position on the Path
    166    \todo implement nodeCount 0,1,2,3
    167166*/
    168167Vector BezierCurve::calcPos(float t)
    169168{
    170   if (nodeCount < 4)
    171     {
    172       //    if (verbose >= 1)
    173       //      printf ("Please define at least 4 nodes, until now you have only defined %i.\n", nodeCount);
    174       return Vector(0,0,0);
    175     }
    176   PathNode* tmpNode = firstNode;
    177169  Vector ret = Vector(0.0,0.0,0.0);
    178   double factor = pow(1.0-t,nodeCount-1);
    179   while(tmpNode)
    180     {
    181       ret.x += tmpNode->factor * factor * tmpNode->position.x;
    182       ret.y += tmpNode->factor * factor * tmpNode->position.y;
    183       ret.z += tmpNode->factor * factor * tmpNode->position.z;
    184       factor *= t/(1.0-t); // same as pow but much faster.
    185 
    186       tmpNode = tmpNode->next;
    187     }
     170  if (this->nodeCount >= 3)
     171    {
     172      PathNode* tmpNode = this->firstNode;
     173      double factor = pow(1.0-t,nodeCount-1);
     174      while(tmpNode)
     175        {
     176          ret.x += tmpNode->factor * factor * tmpNode->position.x;
     177          ret.y += tmpNode->factor * factor * tmpNode->position.y;
     178          ret.z += tmpNode->factor * factor * tmpNode->position.z;
     179          factor *= t/(1.0-t); // same as pow but much faster.
     180         
     181          tmpNode = tmpNode->next;
     182        }
     183    }
     184  else if (nodeCount == 2)
     185    {
     186      ret = this->firstNode->position *(1.0-t);
     187      ret = ret + this->firstNode->next->position * t;
     188    }
     189  else if (nodeCount == 1)
     190    ret = this->firstNode->position;
    188191  return ret;
    189192}
Note: See TracChangeset for help on using the changeset viewer.