Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3327 in orxonox.OLD


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

Location:
orxonox/branches/parenting/src
Files:
6 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}
  • orxonox/branches/parenting/src/curve.h

    r3322 r3327  
    1313
    1414
    15 //! An abstract class to handle curves.
     15//! An abstract class to handle curves. Needed for the Tracking system in orxonox.
    1616class Curve
    1717{
     
    2828    int number;          //!< The N-th node of this curve.
    2929    float factor;        //!< Curve specific multiplier factor.
     30    Vector vFactor;      //!< A Vector-factor for multipliing.
    3031    Vector position;     //!< Vector Pointung to this curve-point.
    3132    PathNode* next;      //!< Pointer to the next Node.
     
    4647};
    4748
    48 //! Bezier Curve
     49//!    Class to handle bezier curves in 3-dimesnsional space
    4950/**
    50    Class to handle bezier curves in 3-dimesnsional space
    51    
    52    needed for  the Tracking system in OrxOnoX.
     51   This Curve is good, for Fast Interaction. If you want to change it during the game, go on.
     52   !!be aware!! BezierCurves only flow through their first and last Node. Their Tangents at those Points a directed to the second and second-last Point.
    5353*/
    5454class BezierCurve : public Curve
     
    8181};
    8282
     83//! Uniform Point Curve-class
     84/**
     85   A UPoint Curve is a A Curve, that flows through all the nodes given it.
     86   The Algorithm to buid the curve is rather slow, but Painting and tracing along the curve has high speed, so do not change this curve during the Game.
     87
     88   This Curve is very erattic, so i do not recommend to use it.
     89*/
     90class UPointCurve : public Curve
     91{
     92 private:
     93  void rebuild(void);
     94 public:
     95  UPointCurve(void);
     96  UPointCurve(int derivation);
     97  ~UPointCurve(void);
     98  void init(void);
     99
     100  Vector calcPos(float t);
     101  Vector calcDir(float t);
     102  Quaternion calcQuat(float t);
     103 
     104  Vector getPos(void) const;
     105};
    83106
    84107#endif /* _CURVE_H */
  • orxonox/branches/parenting/src/matrix.cc

    r3326 r3327  
    2121#include "matrix.h"
    2222
    23 inline Matrix::Matrix (size_t row, size_t col)
     23Matrix::Matrix (size_t row, size_t col)
    2424{
    2525  _m = new base_mat( row, col, 0);
     
    2727
    2828// copy constructor
    29 inline Matrix::Matrix (const Matrix& m)
     29Matrix::Matrix (const Matrix& m)
    3030{
    3131    _m = m._m;
     
    3434
    3535// Internal copy constructor
    36 inline void Matrix::clone ()
     36void Matrix::clone ()
    3737{
    3838    _m->Refcnt--;
     
    4141
    4242// destructor
    43 inline Matrix::~Matrix ()
     43Matrix::~Matrix ()
    4444{
    4545   if (--_m->Refcnt == 0) delete _m;
     
    4747
    4848// assignment operator
    49 inline Matrix& Matrix::operator = (const Matrix& m)
     49Matrix& Matrix::operator = (const Matrix& m)
    5050{
    5151    m._m->Refcnt++;
     
    5656
    5757//  reallocation method
    58 inline void Matrix::realloc (size_t row, size_t col)
     58void Matrix::realloc (size_t row, size_t col)
    5959{
    6060   if (row == _m->RowSiz && col == _m->ColSiz)
     
    8080
    8181// public method for resizing Matrix
    82 inline void Matrix::SetSize (size_t row, size_t col)
     82void Matrix::SetSize (size_t row, size_t col)
    8383{
    8484   size_t i,j;
     
    101101
    102102// subscript operator to get/set individual elements
    103 inline float& Matrix::operator () (size_t row, size_t col)
     103float& Matrix::operator () (size_t row, size_t col)
    104104{
    105105   if (row >= _m->Row || col >= _m->Col)
     
    110110
    111111// subscript operator to get/set individual elements
    112 inline float Matrix::operator () (size_t row, size_t col) const
     112float Matrix::operator () (size_t row, size_t col) const
    113113{
    114114   if (row >= _m->Row || col >= _m->Col)
     
    118118
    119119// input stream function
    120 inline istream& operator >> (istream& istrm, Matrix& m)
     120istream& operator >> (istream& istrm, Matrix& m)
    121121{
    122122   for (size_t i=0; i < m.RowNo(); i++)
     
    131131
    132132// output stream function
    133 inline ostream& operator << (ostream& ostrm, const Matrix& m)
     133ostream& operator << (ostream& ostrm, const Matrix& m)
    134134{
    135135   for (size_t i=0; i < m.RowNo(); i++)
     
    147147
    148148// logical equal-to operator
    149 inline bool operator == (const Matrix& m1, const Matrix& m2)
     149bool operator == (const Matrix& m1, const Matrix& m2)
    150150{
    151151   if (m1.RowNo() != m2.RowNo() || m1.ColNo() != m2.ColNo())
     
    161161
    162162// logical no-equal-to operator
    163 inline bool operator != (const Matrix& m1, const Matrix& m2)
     163bool operator != (const Matrix& m1, const Matrix& m2)
    164164{
    165165    return (m1 == m2) ? false : true;
     
    167167
    168168// combined addition and assignment operator
    169 inline Matrix& Matrix::operator += (const Matrix& m)
     169Matrix& Matrix::operator += (const Matrix& m)
    170170{
    171171   if (_m->Row != m._m->Row || _m->Col != m._m->Col)
     
    179179
    180180// combined subtraction and assignment operator
    181 inline Matrix& Matrix::operator -= (const Matrix& m)
     181Matrix& Matrix::operator -= (const Matrix& m)
    182182{
    183183   if (_m->Row != m._m->Row || _m->Col != m._m->Col)
     
    191191
    192192// combined scalar multiplication and assignment operator
    193  inline Matrix&
     193 Matrix&
    194194Matrix::operator *= (const float& c)
    195195{
     
    202202
    203203// combined Matrix multiplication and assignment operator
    204  inline Matrix&
     204 Matrix&
    205205Matrix::operator *= (const Matrix& m)
    206206{
     
    223223
    224224// combined scalar division and assignment operator
    225  inline Matrix&
     225 Matrix&
    226226Matrix::operator /= (const float& c)
    227227{
     
    235235
    236236// combined power and assignment operator
    237  inline Matrix&
     237 Matrix&
    238238Matrix::operator ^= (const size_t& pow)
    239239{
     
    247247
    248248// unary negation operator
    249  inline Matrix
     249 Matrix
    250250Matrix::operator - ()
    251251{
     
    260260
    261261// binary addition operator
    262  inline Matrix
     262 Matrix
    263263operator + (const Matrix& m1, const Matrix& m2)
    264264{
     
    269269
    270270// binary subtraction operator
    271  inline Matrix
     271 Matrix
    272272operator - (const Matrix& m1, const Matrix& m2)
    273273{
     
    278278
    279279// binary scalar multiplication operator
    280  inline Matrix
     280 Matrix
    281281operator * (const Matrix& m, const float& no)
    282282{
     
    288288
    289289// binary scalar multiplication operator
    290  inline Matrix
     290 Matrix
    291291operator * (const float& no, const Matrix& m)
    292292{
     
    295295
    296296// binary Matrix multiplication operator
    297  inline Matrix
     297 Matrix
    298298operator * (const Matrix& m1, const Matrix& m2)
    299299{
     
    304304
    305305// binary scalar division operator
    306  inline Matrix
     306 Matrix
    307307operator / (const Matrix& m, const float& no)
    308308{
     
    312312
    313313// binary scalar division operator
    314  inline Matrix
     314 Matrix
    315315operator / (const float& no, const Matrix& m)
    316316{
     
    319319
    320320// binary Matrix division operator
    321  inline Matrix
     321 Matrix
    322322operator / (const Matrix& m1, const Matrix& m2)
    323323{
     
    326326
    327327// binary power operator
    328  inline Matrix
     328 Matrix
    329329operator ^ (const Matrix& m, const size_t& pow)
    330330{
     
    335335
    336336// unary transpose operator
    337  inline Matrix
     337 Matrix
    338338operator ~ (const Matrix& m)
    339339{
     
    350350
    351351// unary inversion operator
    352  inline Matrix
     352 Matrix
    353353operator ! (const Matrix m)
    354354{
     
    358358
    359359// inversion function
    360  inline Matrix
     360 Matrix
    361361Matrix::Inv ()
    362362{
     
    405405
    406406// solve simultaneous equation
    407  inline Matrix
     407 Matrix
    408408Matrix::Solve (const Matrix& v) const
    409409{
     
    451451
    452452// set zero to all elements of this Matrix
    453  inline void
     453 void
    454454Matrix::Null (const size_t& row, const size_t& col)
    455455{
     
    467467
    468468// set zero to all elements of this Matrix
    469  inline void
     469 void
    470470Matrix::Null()
    471471{
     
    478478
    479479// set this Matrix to unity
    480  inline void
     480 void
    481481Matrix::Unit (const size_t& row)
    482482{
     
    494494
    495495// set this Matrix to unity
    496  inline void
     496 void
    497497Matrix::Unit ()
    498498{
     
    508508
    509509// private partial pivoting method
    510  inline int
     510 int
    511511Matrix::pivot (size_t row)
    512512{
     
    534534
    535535// calculate the determinant of a Matrix
    536  inline float
     536 float
    537537Matrix::Det () const
    538538{
     
    565565
    566566// calculate the norm of a Matrix
    567  inline float
     567 float
    568568Matrix::Norm ()
    569569{
     
    579579
    580580// calculate the condition number of a Matrix
    581  inline float
     581 float
    582582Matrix::Cond ()
    583583{
     
    587587
    588588// calculate the cofactor of a Matrix for a given element
    589  inline float
     589 float
    590590Matrix::Cofact (size_t row, size_t col)
    591591{
     
    622622
    623623// calculate adjoin of a Matrix
    624  inline Matrix
     624 Matrix
    625625Matrix::Adj ()
    626626{
     
    637637
    638638// Determine if the Matrix is singular
    639  inline bool
     639 bool
    640640Matrix::IsSingular ()
    641641{
     
    646646
    647647// Determine if the Matrix is diagonal
    648  inline bool
     648 bool
    649649Matrix::IsDiagonal ()
    650650{
     
    659659
    660660// Determine if the Matrix is scalar
    661  inline bool
     661 bool
    662662Matrix::IsScalar ()
    663663{
     
    672672
    673673// Determine if the Matrix is a unit Matrix
    674  inline bool
     674 bool
    675675Matrix::IsUnit ()
    676676{
     
    681681
    682682// Determine if this is a null Matrix
    683  inline bool
     683 bool
    684684Matrix::IsNull ()
    685685{
     
    692692
    693693// Determine if the Matrix is symmetric
    694  inline bool
     694 bool
    695695Matrix::IsSymmetric ()
    696696{
     
    705705           
    706706// Determine if the Matrix is skew-symmetric
    707  inline bool
     707 bool
    708708Matrix::IsSkewSymmetric ()
    709709{
     
    718718   
    719719// Determine if the Matrix is upper triangular
    720  inline bool
     720 bool
    721721Matrix::IsUpperTriangular ()
    722722{
     
    731731
    732732// Determine if the Matrix is lower triangular
    733  inline bool
     733 bool
    734734Matrix::IsLowerTriangular ()
    735735{
  • orxonox/branches/parenting/src/matrix.h

    r3326 r3327  
    1414  // Constructors
    1515  Matrix (const Matrix& m);
    16   Matrix (size_t row = 6, size_t col = 6);
     16  Matrix (size_t row, size_t col);
    1717 
    1818  // Destructor
  • orxonox/branches/parenting/src/world.cc

    r3324 r3327  
    153153        case DEBUG_WORLD_0:
    154154          {
    155             testCurve = new BezierCurve();
    156             testCurve->addNode(Vector(0,0,0));
    157             testCurve->addNode(Vector(5,7,0));
    158             testCurve->addNode(Vector(10,-5,0));
    159             testCurve->addNode(Vector(20, 0,10));
    160             testCurve->addNode(Vector(50, 7,-5));
    161             testCurve->addNode(Vector(60, -20,0));
    162             testCurve->addNode(Vector(60, 10,0));
     155            testCurve = new UPointCurve();
     156            testCurve->addNode(Vector( 0, 0, 0));
     157            testCurve->addNode(Vector(10, 0, 5));
     158            testCurve->addNode(Vector(20, -5,-5));
     159            testCurve->addNode(Vector(30, 5, 10));
     160            testCurve->addNode(Vector(40, 0,-10));
     161            testCurve->addNode(Vector(50, 0,-10));
     162
    163163           
    164164            this->nullParent = NullParent::getInstance ();
     
    447447
    448448  glBegin(GL_LINES);
    449   for(float i=0.0; i<1; i+=.01)
    450     {
    451       printf("%f %f %f\n",testCurve->calcDir(i).x,testCurve->calcDir(i).y,testCurve->calcDir(i).z);
     449  for(float i=0.0; i<1; i+=.001)
     450    {
     451      printf("%f %f %f\n",testCurve->calcPos(i).x,testCurve->calcPos(i).y,testCurve->calcPos(i).z);
    452452      glVertex3f(testCurve->calcPos(i).x, testCurve->calcPos(i).y, testCurve->calcPos(i).z);
    453       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);
     453      //      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);
    454454    }
    455455  glEnd();
  • orxonox/branches/parenting/src/world.h

    r3319 r3327  
    6767
    6868
    69   BezierCurve* testCurve;
     69  UPointCurve* testCurve;
    7070 private:
    7171  Uint32 lastFrame; //!> last time of frame
Note: See TracChangeset for help on using the changeset viewer.