Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jan 3, 2005, 6:57:01 PM (19 years ago)
Author:
bensch
Message:

orxonox/branches/parenting: added Class UPointCurve. It is so Bad, I can't even believe it myself… you can see the behaviour of this curve in this revision. have fun

File:
1 edited

Legend:

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

    r3322 r3327  
    2323
    2424#include "curve.h"
     25#include "matrix.h"
    2526
    2627#include <math.h>
    2728#include <stdio.h>
     29
    2830
    2931/**
     
    4547
    4648
     49///////////////////////////////////
     50/// Bezier Curve //////////////////
     51///////////////////////////////////
     52
    4753/**
    4854   \brief Creates a new BezierCurve
     
    7076   It does this by freeing all the space taken over from the nodes
    7177*/
    72 BezierCurve::~BezierCurve (void)
     78BezierCurve::~BezierCurve(void)
    7379{
    7480  PathNode* tmpNode;
     
    197203  return curvePoint;
    198204}
     205
     206
     207
     208///////////////////////////////////
     209//// Uniform Point curve  /////////
     210///////////////////////////////////
     211/**
     212   \brief Creates a new UPointCurve
     213*/
     214UPointCurve::UPointCurve (void)
     215{
     216  this->derivation = 0;
     217  dirCurve = new UPointCurve(1);
     218  this->init();
     219}
     220
     221/**
     222   \brief Creates a new UPointCurve-Derivation-Curve of deriavation'th degree
     223*/
     224UPointCurve::UPointCurve (int derivation)
     225{
     226  this->derivation = derivation;
     227  dirCurve=NULL;
     228  this->init();
     229}
     230
     231/**
     232   \brief Deletes a UPointCurve.
     233
     234   It does this by freeing all the space taken over from the nodes
     235*/
     236UPointCurve::~UPointCurve(void)
     237{
     238  PathNode* tmpNode;
     239  currentNode = firstNode;
     240  while (tmpNode != 0)
     241    {
     242      tmpNode = currentNode;
     243      currentNode = currentNode->next;
     244      delete tmpNode;
     245    }
     246  if (dirCurve)
     247    delete dirCurve;
     248}
     249
     250/**
     251   \brief Initializes a UPointCurve
     252*/
     253void UPointCurve::init(void)
     254{
     255  nodeCount = 0;
     256  firstNode = new PathNode;
     257  currentNode = firstNode;
     258
     259  firstNode->position = Vector (.0, .0, .0);
     260  firstNode->number = 0;
     261  firstNode->next = 0; // not sure if this really points to NULL!!
     262
     263  return;
     264}
     265
     266/**
     267   \brief Rebuilds a UPointCurve
     268   
     269   \todo very bad algorithm
     270*/
     271void UPointCurve::rebuild(void)
     272{
     273  // rebuilding the Curve itself
     274  PathNode* tmpNode = this->firstNode;
     275  int i=0;
     276  Matrix xTmpMat = Matrix(this->nodeCount, this->nodeCount);
     277  Matrix yTmpMat = Matrix(this->nodeCount, this->nodeCount);
     278  Matrix zTmpMat = Matrix(this->nodeCount, this->nodeCount);
     279  Matrix xValMat = Matrix(this->nodeCount, 3);
     280  Matrix yValMat = Matrix(this->nodeCount, 3);
     281  Matrix zValMat = Matrix(this->nodeCount, 3);
     282  while(tmpNode)
     283    {
     284      Vector fac = Vector(1,1,1);
     285      for (int j = 0; j < this->nodeCount; j++)
     286        {
     287          xTmpMat(i,j) = fac.x; fac.x *= (float)i/(float)this->nodeCount;//tmpNode->position.x;
     288          yTmpMat(i,j) = fac.y; fac.y *= (float)i/(float)this->nodeCount;//tmpNode->position.y;
     289          zTmpMat(i,j) = fac.z; fac.z *= (float)i/(float)this->nodeCount;//tmpNode->position.z;
     290        }
     291      xValMat(i,0) = tmpNode->position.x;
     292      yValMat(i,0) = tmpNode->position.y;
     293      zValMat(i,0) = tmpNode->position.z;
     294      ++i;
     295      tmpNode = tmpNode->next;
     296    }
     297  tmpNode = this->firstNode;
     298  xValMat = xTmpMat.Inv() *= xValMat;
     299  yValMat = yTmpMat.Inv() *= yValMat;
     300  zValMat = zTmpMat.Inv() *= zValMat;
     301  i = 0;
     302  while(tmpNode)
     303    {
     304      tmpNode->vFactor.x = xValMat(i,0);
     305      tmpNode->vFactor.y = yValMat(i,0);
     306      tmpNode->vFactor.z = zValMat(i,0);
     307
     308      i++;
     309      tmpNode = tmpNode->next;
     310    }
     311
     312  // rebuilding the Derivation curve
     313  if(this->derivation == 0)
     314    {
     315      tmpNode = firstNode;
     316      delete dirCurve;
     317      dirCurve = new UPointCurve(1);
     318      while(tmpNode->next)
     319        {
     320          Vector tmpVector = (tmpNode->next->position)- (tmpNode->position);
     321          tmpVector.x*=(float)nodeCount;
     322          tmpVector.y*=(float)nodeCount;
     323          tmpVector.z*=(float)nodeCount;
     324          tmpVector.normalize();
     325          this->dirCurve->addNode(tmpVector);
     326          tmpNode = tmpNode->next;
     327        }
     328    }
     329}
     330
     331/**
     332   \brief calculates the Position on the curve
     333   \param t The position on the Curve (0<=t<=1)
     334   \return the Position on the Path
     335*/
     336Vector UPointCurve::calcPos(float t)
     337{
     338  PathNode* tmpNode = firstNode;
     339  Vector ret = Vector(0.0,0.0,0.0);
     340  float factor = 1.0;
     341  while(tmpNode)
     342    {
     343      ret.x += tmpNode->vFactor.x * factor;
     344      ret.y += tmpNode->vFactor.y * factor;
     345      ret.z += tmpNode->vFactor.z * factor;
     346      factor *= t;
     347
     348      tmpNode = tmpNode->next;
     349    }
     350  return ret;
     351}
     352
     353/**
     354   \brief Calulates the direction of the Curve at time t.
     355   \param The time at which to evaluate the curve.
     356   \returns The vvaluated Vector.
     357*/
     358Vector UPointCurve::calcDir (float t)
     359{
     360  return dirCurve->calcPos(t);
     361}
     362
     363/**
     364   \brief Calculates the Quaternion needed for our rotations
     365   \param t The time at which to evaluate the cuve.
     366   \returns The evaluated Quaternion.
     367*/
     368Quaternion UPointCurve::calcQuat (float t)
     369{
     370  return Quaternion (calcDir(t), Vector(0,0,1));
     371}
     372
     373
     374/**
     375  \brief returns the Position of the point calculated on the Curve
     376  \return a Vector to the calculated position
     377*/
     378Vector UPointCurve::getPos(void) const
     379{
     380  return curvePoint;
     381}
Note: See TracChangeset for help on using the changeset viewer.