Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3151 in orxonox.OLD for orxonox/branches/dave/src/vector.cc


Ignore:
Timestamp:
Dec 11, 2004, 5:26:18 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/dave: src of trunk copied into branches/dave/src

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/dave/src/vector.cc

    r2860 r3151  
    843843  return (n.dot(p) + k);
    844844}
     845
     846
     847/**
     848   \brief Creates a new BezierCurve
     849*/
     850BezierCurve::BezierCurve (void)
     851{
     852  nodeCount = 0;
     853  firstNode = new PathNode;
     854  currentNode = firstNode;
     855
     856  firstNode->position = Vector (.0, .0, .0);
     857  firstNode->number = 0;
     858  firstNode->next = 0; // not sure if this really points to NULL!!
     859
     860  return;
     861}
     862
     863/**
     864   \brief Deletes a BezierCurve.
     865   It does this by freeing all the space taken over from the nodes
     866*/
     867BezierCurve::~BezierCurve (void)
     868{
     869  PathNode* tmpNode;
     870  currentNode = firstNode;
     871  while (tmpNode != 0)
     872    {
     873      tmpNode = currentNode;
     874      currentNode = currentNode->next;
     875      delete tmpNode;
     876    }
     877}
     878
     879/**
     880   \brief adds a new Node to the bezier Curve
     881   \param newNode a Vector to the position of the new node
     882*/
     883void BezierCurve::addNode(const Vector& newNode)
     884{
     885  PathNode* tmpNode;
     886  if (nodeCount == 0 )
     887    tmpNode = firstNode;
     888  else
     889    {
     890      tmpNode = new PathNode;
     891      currentNode = currentNode->next = tmpNode;
     892    }
     893  tmpNode->position = newNode;
     894  tmpNode->next = 0; // not sure if this really points to NULL!!
     895  tmpNode->number = (++nodeCount);
     896  return;
     897}
     898
     899/**
     900   \brief calculates the Position on the curve
     901   \param t The position on the Curve (0<=t<=1)
     902   \return the Position on the Path
     903*/
     904Vector BezierCurve::calcPos(float t)
     905{
     906  if (nodeCount <=4)
     907    {
     908      //      if (verbose >= 1)
     909      //      printf ("Please define at least 4 nodes, until now you have only defined %i.\n", nodeCount);
     910      curvePoint = Vector(0,0,0);
     911    }
     912  PathNode* tmpNode = firstNode;
     913   
     914  int k,kn,nn,nkn;
     915  double blend,muk,munk;
     916  Vector b = Vector(0.0,0.0,0.0);
     917 
     918  muk = 1;
     919  munk = pow(1-t,(double)nodeCount);
     920 
     921  for (k=0; k<=nodeCount; k++) {
     922    nn = nodeCount;
     923    kn = k;
     924    nkn = nodeCount - k;
     925    blend = muk * munk;
     926    muk *= t;
     927    munk /= (1-t);
     928    while (nn >= 1) {
     929      blend *= nn;
     930      nn--;
     931      if (kn > 1) {
     932        blend /= (double)kn;
     933        kn--;
     934      }
     935      if (nkn > 1) {
     936        blend /= (double)nkn;
     937        nkn--;
     938      }
     939    }
     940    b.x += tmpNode->position.x * blend;
     941    b.y += tmpNode->position.y * blend;
     942    b.z += tmpNode->position.z * blend;
     943
     944    tmpNode = tmpNode->next;
     945  }
     946  return b;
     947}
     948
     949Vector BezierCurve::calcDirection (float t)
     950{
     951  double diff = .00000000001;
     952 
     953  Vector diffV = ((calcPos(t+diff) - calcPos(t))/diff);
     954  diffV.normalize();
     955  return diffV;
     956}
     957
     958/**
     959  \brief returns the Position of the point calculated on the Curve
     960  \return a Vector to the calculated position
     961*/
     962Vector BezierCurve::getPos() const
     963{
     964  return curvePoint;
     965}
Note: See TracChangeset for help on using the changeset viewer.