Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3321 in orxonox.OLD for orxonox


Ignore:
Timestamp:
Jan 3, 2005, 12:25:49 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: derivation-curve implemented.

Location:
orxonox/branches/parenting/src
Files:
3 edited

Legend:

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

    r3320 r3321  
    5050BezierCurve::BezierCurve (void)
    5151{
    52   nodeCount = 0;
    53   firstNode = new PathNode;
    54   currentNode = firstNode;
     52  this->derivation = 0;
     53  dirCurve = new BezierCurve(1);
     54  this->init();
     55}
    5556
    56   firstNode->position = Vector (.0, .0, .0);
    57   firstNode->number = 0;
    58   firstNode->next = 0; // not sure if this really points to NULL!!
    59 
    60   return;
     57/**
     58   \brief Creates a new BezierCurve-Derivation-Curve
     59*/
     60BezierCurve::BezierCurve (int derivation)
     61{
     62  this->derivation = derivation;
     63  dirCurve=NULL;
     64  this->init();
    6165}
    6266
     
    7680      delete tmpNode;
    7781    }
     82  if (dirCurve)
     83    delete dirCurve;
     84}
     85
     86/**
     87   \brief Initializes a BezierCurve
     88*/
     89void BezierCurve::init(void)
     90{
     91  nodeCount = 0;
     92  firstNode = new PathNode;
     93  currentNode = firstNode;
     94
     95  firstNode->position = Vector (.0, .0, .0);
     96  firstNode->number = 0;
     97  firstNode->next = 0; // not sure if this really points to NULL!!
     98
     99  return;
    78100}
    79101
     
    85107  PathNode* tmpNode = firstNode;
    86108
     109  // rebuilding the Curve itself
    87110  int k=0;
    88111  int binCoef = 1;
     
    96119      tmpNode->factor = binCoef;
    97120      tmpNode = tmpNode->next;
     121    }
     122
     123  // rebuilding the Derivation curve
     124  if(this->derivation == 0)
     125    {
     126      tmpNode = firstNode;
     127      delete dirCurve;
     128      dirCurve = new BezierCurve(1);
     129      while(tmpNode->next)
     130        {
     131          Vector tmpVector = (tmpNode->next->position)- (tmpNode->position);
     132          tmpVector.x*=(float)nodeCount;
     133          tmpVector.y*=(float)nodeCount;
     134          tmpVector.z*=(float)nodeCount;
     135          tmpVector.normalize();
     136          this->dirCurve->addNode(tmpVector);
     137          tmpNode = tmpNode->next;
     138        }
    98139    }
    99140}
     
    134175Vector BezierCurve::calcDir (float t)
    135176{
    136   PathNode* tmpNode = firstNode;
    137   BezierCurve* tmpCurve = new BezierCurve();
    138   Vector ret;
    139   Vector tmpVector;
    140 
    141   while (tmpNode->next != 0)
    142     {
    143       tmpVector = (tmpNode->next->position)- (tmpNode->position);
    144       tmpVector.x*=(float)nodeCount;
    145       tmpVector.y*=(float)nodeCount;
    146       tmpVector.z*=(float)nodeCount;
    147 
    148       tmpCurve->addNode(tmpVector);
    149       tmpNode = tmpNode->next;
    150     }
    151   ret = tmpCurve->calcPos(t);
    152   ret.normalize();
    153 
    154   return ret;
     177  return static_cast<BezierCurve*>(dirCurve)->calcPos(t);
    155178}
    156179
  • orxonox/branches/parenting/src/curve.h

    r3320 r3321  
    2020  Vector curvePoint;     //!< The point on the Cureve at a local Time.
    2121  float localTime;       //!< If the time of one point is asked more than once the programm will not calculate it again.
     22  Curve* dirCurve;       //!< The derivation-curve of this Curve.
     23  int derivation;        //!< Which derivation of a Curve is this.
    2224
    2325  //! Handles the curve-points (dynamic List)
     
    5254 public:
    5355  BezierCurve(void);
     56  BezierCurve(int derivation);
    5457  ~BezierCurve(void);
     58  void init(void);
    5559
    5660  Vector calcPos(float t);
  • orxonox/branches/parenting/src/world.cc

    r3319 r3321  
    159159            testCurve->addNode(Vector(20, 0,10));
    160160            testCurve->addNode(Vector(50, 7,-5));
     161            testCurve->addNode(Vector(60, -20,0));
     162            testCurve->addNode(Vector(60, 10,0));
    161163           
    162164            this->nullParent = NullParent::getInstance ();
     
    448450  for(float i=0.0; i<1; i+=.01)
    449451    {
     452      printf("%f %f %f\n",testCurve->calcDir(i).x,testCurve->calcDir(i).y,testCurve->calcDir(i).z);
    450453      glVertex3f(testCurve->calcPos(i).x, testCurve->calcPos(i).y, testCurve->calcPos(i).z);
     454      glVertex3f(testCurve->calcPos(i).x+testCurve->calcDir(i).x, testCurve->calcPos(i).y+testCurve->calcDir(i).y, testCurve->calcPos(i).z+testCurve->calcDir(i).z);
    451455    }
    452456  glEnd();
Note: See TracChangeset for help on using the changeset viewer.