Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3605 in orxonox.OLD for orxonox/branches/levelloader/src/lib/math


Ignore:
Timestamp:
Mar 18, 2005, 11:52:15 AM (20 years ago)
Author:
bensch
Message:

orxonox/trunk: merged trunk back to levelloader
merged with command:
svn merge -r 3499:HEAD trunk branches/levelloader

Conflicts in
C track_manager.h
C world_entities/player.cc
C world_entities/player.h
C world_entities/environment.h
C lib/coord/p_node.cc
C defs/debug.h
C track_manager.cc
C story_entities/campaign.h

solved in merge-favouring. It was quite easy because Chris only worked on the headers, and he didi it quite clean. Thats the spirit :)

Conflits in world.cc are a MESS: fix it

Location:
orxonox/branches/levelloader/src/lib/math
Files:
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/levelloader/src/lib/math/curve.cc

    r3499 r3605  
    1919     local-Time implementation
    2020     NURBS
     21     tList implementation
    2122     
    2223*/
    2324
     25#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH
     26
    2427#include "curve.h"
    25 #include "matrix.h"
     28
    2629#include "debug.h"
    2730
    2831#include <math.h>
    2932#include <stdio.h>
     33
     34
     35/**
     36    \brief default constructor for a Curve
     37*/
     38Curve::Curve(void)
     39{
     40  nodeCount = 0;
     41  firstNode = new PathNode;
     42  currentNode = firstNode;
     43
     44  firstNode->position = Vector (.0, .0, .0);
     45  firstNode->number = 0;
     46  firstNode->next = 0; // not sure if this really points to NULL!!
     47}
    3048
    3149/**
     
    131149  this->derivation = 0;
    132150  dirCurve = new BezierCurve(1);
    133   this->init();
    134151}
    135152
     
    141158  this->derivation = derivation;
    142159  dirCurve=NULL;
    143   this->init();
    144160}
    145161
     
    161177  if (dirCurve)
    162178    delete dirCurve;
    163 }
    164 
    165 /**
    166    \brief Initializes a BezierCurve
    167 */
    168 void BezierCurve::init(void)
    169 {
    170   nodeCount = 0;
    171   firstNode = new PathNode;
    172   currentNode = firstNode;
    173 
    174   firstNode->position = Vector (.0, .0, .0);
    175   firstNode->number = 0;
    176   firstNode->next = 0; // not sure if this really points to NULL!!
    177 
    178   return;
    179179}
    180180
     
    285285  return curvePoint;
    286286}
    287 
    288 
    289 
    290 ///////////////////////////////////
    291 //// Uniform Point curve  /////////
    292 ///////////////////////////////////
    293 /**
    294    \brief Creates a new UPointCurve
    295 */
    296 UPointCurve::UPointCurve (void)
    297 {
    298   this->derivation = 0;
    299   this->init();
    300 }
    301 
    302 /**
    303    \brief Creates a new UPointCurve-Derivation-Curve of deriavation'th degree
    304 */
    305 UPointCurve::UPointCurve (int derivation)
    306 {
    307   this->derivation = derivation;
    308   dirCurve=NULL;
    309   this->init();
    310 }
    311 
    312 /**
    313    \brief Deletes a UPointCurve.
    314 
    315    It does this by freeing all the space taken over from the nodes
    316 */
    317 UPointCurve::~UPointCurve(void)
    318 {
    319   PathNode* tmpNode;
    320   currentNode = firstNode;
    321   while (tmpNode != 0)
    322     {
    323       tmpNode = currentNode;
    324       currentNode = currentNode->next;
    325       delete tmpNode;
    326     }
    327   if (dirCurve)
    328     delete dirCurve;
    329 }
    330 
    331 /**
    332    \brief Initializes a UPointCurve
    333 */
    334 void UPointCurve::init(void)
    335 {
    336   nodeCount = 0;
    337   firstNode = new PathNode;
    338   currentNode = firstNode;
    339 
    340   firstNode->position = Vector (.0, .0, .0);
    341   firstNode->number = 0;
    342   firstNode->next = 0; // not sure if this really points to NULL!!
    343 
    344   return;
    345 }
    346 
    347 /**
    348    \brief Rebuilds a UPointCurve
    349    
    350    \todo very bad algorithm
    351 */
    352 void UPointCurve::rebuild(void)
    353 {
    354   // rebuilding the Curve itself
    355   PathNode* tmpNode = this->firstNode;
    356   int i=0;
    357   Matrix xTmpMat = Matrix(this->nodeCount, this->nodeCount);
    358   Matrix yTmpMat = Matrix(this->nodeCount, this->nodeCount);
    359   Matrix zTmpMat = Matrix(this->nodeCount, this->nodeCount);
    360   Matrix xValMat = Matrix(this->nodeCount, 3);
    361   Matrix yValMat = Matrix(this->nodeCount, 3);
    362   Matrix zValMat = Matrix(this->nodeCount, 3);
    363   while(tmpNode)
    364     {
    365       Vector fac = Vector(1,1,1);
    366       for (int j = 0; j < this->nodeCount; j++)
    367         {
    368           xTmpMat(i,j) = fac.x; fac.x *= (float)i/(float)this->nodeCount;//tmpNode->position.x;
    369           yTmpMat(i,j) = fac.y; fac.y *= (float)i/(float)this->nodeCount;//tmpNode->position.y;
    370           zTmpMat(i,j) = fac.z; fac.z *= (float)i/(float)this->nodeCount;//tmpNode->position.z;
    371         }
    372       xValMat(i,0) = tmpNode->position.x;
    373       yValMat(i,0) = tmpNode->position.y;
    374       zValMat(i,0) = tmpNode->position.z;
    375       ++i;
    376       tmpNode = tmpNode->next;
    377     }
    378   tmpNode = this->firstNode;
    379   xValMat = xTmpMat.Inv() *= xValMat;
    380   yValMat = yTmpMat.Inv() *= yValMat;
    381   zValMat = zTmpMat.Inv() *= zValMat;
    382   i = 0;
    383   while(tmpNode)
    384     {
    385       tmpNode->vFactor.x = xValMat(i,0);
    386       tmpNode->vFactor.y = yValMat(i,0);
    387       tmpNode->vFactor.z = zValMat(i,0);
    388 
    389       i++;
    390       tmpNode = tmpNode->next;
    391     }
    392 }
    393 
    394 /**
    395    \brief calculates the Position on the curve
    396    \param t The position on the Curve (0<=t<=1)
    397    \return the Position on the Path
    398 */
    399 Vector UPointCurve::calcPos(float t)
    400 {
    401   PathNode* tmpNode = firstNode;
    402   Vector ret = Vector(0.0,0.0,0.0);
    403   float factor = 1.0;
    404   while(tmpNode)
    405     {
    406       ret.x += tmpNode->vFactor.x * factor;
    407       ret.y += tmpNode->vFactor.y * factor;
    408       ret.z += tmpNode->vFactor.z * factor;
    409       factor *= t;
    410 
    411       tmpNode = tmpNode->next;
    412     }
    413   return ret;
    414 }
    415 
    416 /**
    417    \brief Calulates the direction of the Curve at time t.
    418    \param The time at which to evaluate the curve.
    419    \returns The vvaluated Vector.
    420 */
    421 Vector UPointCurve::calcDir (float t)
    422 {
    423   PathNode* tmpNode = firstNode;
    424   Vector ret = Vector(0.0,0.0,0.0);
    425   float factor = 1.0/t;
    426   int k=0;
    427   while(tmpNode)
    428     {
    429       ret.x += tmpNode->vFactor.x * factor *k;
    430       ret.y += tmpNode->vFactor.y * factor *k;
    431       ret.z += tmpNode->vFactor.z * factor *k;
    432       factor *= t;
    433       k++;
    434       tmpNode = tmpNode->next;
    435     }
    436   ret.normalize();
    437   return ret;
    438 }
    439 
    440 Vector UPointCurve::calcAcc (float t)
    441 {
    442 }
    443 
    444 /**
    445    \brief Calculates the Quaternion needed for our rotations
    446    \param t The time at which to evaluate the cuve.
    447    \returns The evaluated Quaternion.
    448 */
    449 Quaternion UPointCurve::calcQuat (float t)
    450 {
    451   return Quaternion (calcDir(t), Vector(0,0,1));
    452 }
    453 
    454 
    455 /**
    456   \brief returns the Position of the point calculated on the Curve
    457   \return a Vector to the calculated position
    458 */
    459 Vector UPointCurve::getPos(void) const
    460 {
    461   return curvePoint;
    462 }
  • orxonox/branches/levelloader/src/lib/math/curve.h

    r3499 r3605  
    1313
    1414//! An Enumerator that defines what sort of Curves are availible
    15 enum CurveType {BEZIERCURVE, UPOINTCURVE};
     15enum CurveType {BEZIERCURVE};
    1616
    1717
     
    3838  PathNode* currentNode; //!< The node we are working with (the Last node).
    3939
     40
    4041 private:
    4142  virtual void rebuild(void) = 0;
    4243 public:
     44  Curve(void);
     45
    4346  Curve* dirCurve;       //!< The derivation-curve of this Curve.
    4447  void addNode(const Vector& newNode);
     
    6871  BezierCurve(void);
    6972  BezierCurve(int derivation);
    70   ~BezierCurve(void);
    71   void init(void);
     73  virtual ~BezierCurve(void);
    7274
    7375  Vector calcPos(float t);
     
    9193};
    9294
    93 //! Uniform Point Curve-class
    94 /**
    95    A UPoint Curve is a A Curve, that flows through all the nodes given it.
    96    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.
    97 
    98    This Curve is very erattic, so i do not recommend to use it.
    99 */
    100 class UPointCurve : public Curve
    101 {
    102  private:
    103   void rebuild(void);
    104  public:
    105   UPointCurve(void);
    106   UPointCurve(int derivation);
    107   ~UPointCurve(void);
    108   void init(void);
    109 
    110   Vector calcPos(float t);
    111   Vector calcDir(float t);
    112   Vector calcAcc(float t);
    113   Quaternion calcQuat(float t);
    114  
    115   Vector getPos(void) const;
    116 };
    117 
    11895#endif /* _CURVE_H */
  • orxonox/branches/levelloader/src/lib/math/vector.cc

    r3499 r3605  
    1919*/
    2020
     21#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH
    2122
    2223#include "vector.h"
    23 
     24#include "debug.h"
    2425
    2526using namespace std;
     
    201202}
    202203
    203 
    204204/**
    205205   \brief calculate the angle between two vectors in radiances
     
    225225  f = acos( v1 * v2 / (v1.len() * v2.len()));
    226226  return f * 180 / PI;
     227}
     228
     229
     230/**
     231   \brief Outputs the values of the Vector
     232*/
     233void Vector::debug(void)
     234{
     235  PRINT(0)("Vector Debug information\n");
     236  PRINT(0)("x: %f; y: %f; z: %f", x, y, z);
     237  PRINT(3)(" lenght: %f", len());
     238  PRINT(0)("\n");
    227239}
    228240
     
    581593
    582594/**
     595   \brief outputs some nice formated debug information about this quaternion
     596*/
     597void Quaternion::debug(void)
     598{
     599  PRINT(0)("Quaternion Debug Information\n");
     600  PRINT(0)("real a=%f; imag: x=%f y=%f z=%f\n", w, v.x, v.y, v.z);
     601}
     602
     603/**
    583604   \brief create a rotation from a vector
    584605   \param v: a vector
  • orxonox/branches/levelloader/src/lib/math/vector.h

    r3499 r3605  
    4141  Vector* getNormalized();
    4242  Vector abs();
     43
     44  void debug();
    4345};
    4446
     
    5355{
    5456 public:
    55         Vector v;       //!< Imaginary Vector
    56         float w;        //!< Real part of the number
    57 
    58         Quaternion ();
    59         Quaternion (float m[4][4]);
    60         Quaternion (float angle, const Vector& axis);
    61         Quaternion (const Vector& dir, const Vector& up);
    62         Quaternion (float roll, float pitch, float yaw);
    63        
    64         Quaternion operator/ (const float& f) const;
    65         Quaternion operator* (const float& f) const;
    66         Quaternion operator* (const Quaternion& q) const;
    67         Quaternion operator+ (const Quaternion& q) const;
    68         Quaternion operator- (const Quaternion& q) const;
    69         Quaternion conjugate () const;
    70         Quaternion inverse () const;
    71         Vector apply (Vector& f) const;
    72         float norm () const;
    73         void matrix (float m[4][4]) const;
    74         void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res);
    75 
     57  Vector v;     //!< Imaginary Vector
     58  float w;        //!< Real part of the number
     59 
     60  Quaternion ();
     61  Quaternion (float m[4][4]);
     62  Quaternion (float angle, const Vector& axis);
     63  Quaternion (const Vector& dir, const Vector& up);
     64  Quaternion (float roll, float pitch, float yaw);
     65 
     66  Quaternion operator/ (const float& f) const;
     67  Quaternion operator* (const float& f) const;
     68  Quaternion operator* (const Quaternion& q) const;
     69  Quaternion operator+ (const Quaternion& q) const;
     70  Quaternion operator- (const Quaternion& q) const;
     71  Quaternion conjugate () const;
     72  Quaternion inverse () const;
     73  Vector apply (Vector& f) const;
     74  float norm () const;
     75  void matrix (float m[4][4]) const;
     76  void quatSlerp(const Quaternion* from, const Quaternion* to, const float t, Quaternion* res);
     77 
     78  void debug();
    7679 private:
    77         float DELTA;      //!< resolution of calculation
     80  float DELTA;      //!< resolution of calculation
    7881
    7982};
Note: See TracChangeset for help on using the changeset viewer.