Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3000 in orxonox.OLD for orxonox/trunk/src


Ignore:
Timestamp:
Nov 26, 2004, 8:12:33 PM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: added a Benzier-Class: testing it with the new track-system

Location:
orxonox/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/vector.cc

    r2816 r3000  
    843843  return (n.dot(p) + k);
    844844}
     845
     846
     847/**
     848   \brief Creates a new BenzierCurve
     849*/
     850BenzierCurve::BenzierCurve (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 BenzierCurve.
     865   It does this by freeing all the space taken over from the nodes
     866*/
     867BenzierCurve::~BenzierCurve (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 benzier Curve
     881   \param newNode a Vector to the position of the new node
     882*/
     883void BenzierCurve::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 (and does not return) the Position on the curve
     901   \param t The position on the Curve (0<=t<=1)
     902*/
     903void BenzierCurve::calcPos(float t)
     904{
     905  if (nodeCount <=4)
     906    {
     907      //      if (verbose >= 1)
     908      //      printf ("Please define at least 4 nodes, until now you have only defined %i.\n", nodeCount);
     909      curvePoint = Vector(0,0,0);
     910    }
     911  PathNode* tmpNode = firstNode;
     912   
     913  int k,kn,nn,nkn;
     914  double blend,muk,munk;
     915  Vector b = Vector(0.0,0.0,0.0);
     916 
     917  muk = 1;
     918  munk = pow(1-t,(double)nodeCount);
     919 
     920  for (k=0; k<=nodeCount; k++) {
     921    nn = nodeCount;
     922    kn = k;
     923    nkn = nodeCount - k;
     924    blend = muk * munk;
     925    muk *= t;
     926    munk /= (1-t);
     927    while (nn >= 1) {
     928      blend *= nn;
     929      nn--;
     930      if (kn > 1) {
     931        blend /= (double)kn;
     932        kn--;
     933      }
     934      if (nkn > 1) {
     935        blend /= (double)nkn;
     936        nkn--;
     937      }
     938    }
     939    b.x += tmpNode->position.x * blend;
     940    b.y += tmpNode->position.y * blend;
     941    b.z += tmpNode->position.z * blend;
     942
     943    tmpNode = tmpNode->next;
     944  }
     945  curvePoint = b;
     946  return;
     947}
     948
     949/**
     950  \brief returns the Position of the point calculated on the Curve
     951  \return a Vector to the calculated position
     952*/
     953Vector BenzierCurve::getPos() const
     954{
     955  return curvePoint;
     956}
     957
     958/**
     959  \brief returns the position of the point on the Curve at position t
     960  \param t The position on the Curve (0<=t<=1)
     961  \return a Vector to the calculated position
     962*/
     963Vector BenzierCurve::getPos(float t)
     964{
     965  calcPos(t);
     966  return curvePoint;
     967}
  • orxonox/trunk/src/vector.h

    r2551 r3000  
    149149};
    150150
     151
     152
     153//! Benzier Curve
     154/**
     155   Class to handle benzier curves in 3-dimesnsional space
     156   
     157   needed for  the Tracking system in OrxOnoX.
     158*/
     159class BenzierCurve
     160{
     161 private:
     162  int nodeCount;
     163  Vector curvePoint;
     164 
     165  struct PathNode
     166  {
     167    int number;
     168    Vector position;
     169    PathNode* next;
     170  };
     171
     172  PathNode* firstNode;
     173  PathNode* currentNode;
     174
     175 public:
     176  BenzierCurve (void);
     177  ~BenzierCurve (void);
     178  void addNode (const Vector& newNode);
     179  void calcPos (float t);
     180 
     181  Vector getPos () const;
     182  Vector getPos (float t);
     183};
     184
     185
     186
    151187#endif
Note: See TracChangeset for help on using the changeset viewer.