Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3015 in orxonox.OLD for orxonox/branches/bezierTrack/src


Ignore:
Timestamp:
Nov 27, 2004, 5:38:19 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/bezierCurve: better algorithm

Location:
orxonox/branches/bezierTrack/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/bezierTrack/src/track.cc

    r3014 r3015  
    6666{
    6767  return curve.calcPos (t);
     68}
     69Vector Track::getDir (float t)
     70{
     71  return curve.calcDir (t);
    6872}
    6973
  • orxonox/branches/bezierTrack/src/track.h

    r3014 r3015  
    3939 
    4040  Vector getPos(float t);
     41  Vector getDir (float t);
     42
    4143 
    4244  virtual void post_enter (WorldEntity* entity);        // handle coordinate transition in here !!! (when dist < 0 or dist > lasttracklenght)
  • orxonox/branches/bezierTrack/src/vector.cc

    r3010 r3015  
    912912  PathNode* tmpNode = firstNode;
    913913   
    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-1; 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       }
     914  Vector ret = Vector(0.0,0.0,0.0);
     915  double factor;
     916 
     917  for (int k=0; k < nodeCount; k++)
     918    {
     919      factor = ncr (nodeCount, k);
     920     
     921      for (int j=0; j<nodeCount-k; j++)
     922        factor*=(1-t);
     923      for (int j=0; j<k; j++)
     924        factor*=t;
     925      ret.x += factor * tmpNode->position.x;
     926      ret.y += factor * tmpNode->position.y;
     927      ret.z += factor * tmpNode->position.z;
     928   
     929    tmpNode = tmpNode->next;
    939930    }
    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;
     931  return ret;
    947932}
    948933
     
    964949  return curvePoint;
    965950}
     951
     952
     953int BezierCurve::ncr(int n, int i)
     954{
     955  int ret = 1;
     956  for (int k=1; k<=n; k++)
     957    ret*=k;
     958  for (int k=1; k<=i; k++)
     959    ret/=k;
     960  for (int k=1; k<=n-i; k++)
     961    ret/=k;
     962
     963  return ret;
     964}
  • orxonox/branches/bezierTrack/src/vector.h

    r3010 r3015  
    173173  PathNode* currentNode;
    174174
     175  int ncr(int n, int i);
     176
    175177 public:
    176178  BezierCurve (void);
Note: See TracChangeset for help on using the changeset viewer.