Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jan 6, 2005, 3:03:54 AM (19 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: fixed major flaw in BezierCurve-calculation. before all BezierCurves started in the Origin. Now they are realy bezier-curves.

File:
1 edited

Legend:

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

    r3330 r3348  
    2424#include "curve.h"
    2525#include "matrix.h"
     26#include "debug.h"
    2627
    2728#include <math.h>
     
    113114
    114115  // rebuilding the Curve itself
    115   int k=0;
    116   int binCoef = 1;
    117   while(tmpNode)
    118     {
    119       if (k+1 < nodeCount-k)
    120         binCoef *=(nodeCount-k)/(k+1);
    121       else
    122         binCoef /= (k+1)/(nodeCount-k);
    123       ++k;
     116  float k=0;
     117  float n = nodeCount -1;
     118  float binCoef = 1;
     119  printf("n=%f\n", n);
     120  while(tmpNode)
     121    {
    124122      tmpNode->factor = binCoef;
    125       tmpNode = tmpNode->next;
     123      printf("bincoef: %f\n", binCoef);
     124      if (tmpNode =tmpNode->next)
     125        {
     126          binCoef *=(n-k)/(k+1);
     127          ++k;
     128        }
    126129    }
    127130
     
    149152   \param t The position on the Curve (0<=t<=1)
    150153   \return the Position on the Path
     154   \todo implement nodeCount 0,1,2,3
    151155*/
    152156Vector BezierCurve::calcPos(float t)
    153157{
    154   if (nodeCount <=4)
     158  if (nodeCount < 4)
    155159    {
    156160      //    if (verbose >= 1)
     
    160164  PathNode* tmpNode = firstNode;
    161165  Vector ret = Vector(0.0,0.0,0.0);
    162   float factor = 1.0*pow(1.0-t,nodeCount);
    163   while(tmpNode)
    164     {
    165       factor *= t/(1.0-t); // same as pow but much faster.
     166  double factor = pow(1.0-t,nodeCount-1);
     167  while(tmpNode)
     168    {
    166169      ret.x += tmpNode->factor * factor * tmpNode->position.x;
    167170      ret.y += tmpNode->factor * factor * tmpNode->position.y;
    168171      ret.z += tmpNode->factor * factor * tmpNode->position.z;
     172      factor *= t/(1.0-t); // same as pow but much faster.
    169173
    170174      tmpNode = tmpNode->next;
Note: See TracChangeset for help on using the changeset viewer.