- Timestamp:
- Jan 3, 2005, 12:23:41 PM (20 years ago)
- Location:
- orxonox/branches/parenting/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/parenting/src/curve.cc
r3319 r3320 24 24 #include "curve.h" 25 25 26 26 #include <math.h> 27 #include <stdio.h> 27 28 28 29 /** … … 39 40 currentNode->next = 0; // not sure if this really points to NULL!! 40 41 currentNode->number = (++nodeCount); 42 this->rebuild(); 41 43 return; 42 44 } … … 77 79 78 80 /** 81 \brief Rebuilds a Curve 82 */ 83 void BezierCurve::rebuild(void) 84 { 85 PathNode* tmpNode = firstNode; 86 87 int k=0; 88 int binCoef = 1; 89 while(tmpNode) 90 { 91 if (k+1 < nodeCount-k) 92 binCoef *=(nodeCount-k)/(k+1); 93 else 94 binCoef /= (k+1)/(nodeCount-k); 95 ++k; 96 tmpNode->factor = binCoef; 97 tmpNode = tmpNode->next; 98 } 99 } 100 101 /** 79 102 \brief calculates the Position on the curve 80 103 \param t The position on the Curve (0<=t<=1) … … 85 108 if (nodeCount <=4) 86 109 { 87 // 110 // if (verbose >= 1) 88 111 // printf ("Please define at least 4 nodes, until now you have only defined %i.\n", nodeCount); 89 112 return Vector(0,0,0); 90 113 } 91 114 PathNode* tmpNode = firstNode; 92 93 115 Vector ret = Vector(0.0,0.0,0.0); 94 double factor; 95 int k=0; 96 while(tmpNode!=0) 116 float factor = 1.0*pow(1.0-t,nodeCount); 117 while(tmpNode) 97 118 { 98 k++; 99 factor = ncr (nodeCount, k); 100 101 for (int j=0; j<nodeCount-k; j++) 102 factor*=(1-t); 103 for (int j=0; j<k; j++) 104 factor*=t; 105 ret.x += factor * tmpNode->position.x; 106 ret.y += factor * tmpNode->position.y; 107 ret.z += factor * tmpNode->position.z; 108 119 factor *= t/(1.0-t); // same as pow but much faster. 120 ret.x += tmpNode->factor * factor * tmpNode->position.x; 121 ret.y += tmpNode->factor * factor * tmpNode->position.y; 122 ret.z += tmpNode->factor * factor * tmpNode->position.z; 123 109 124 tmpNode = tmpNode->next; 110 111 125 } 112 126 return ret; … … 160 174 return curvePoint; 161 175 } 162 163 /**164 \brief ncr-calculator, did not find an other method165 \todo a c++ variante to do this166 */167 int ncr(int n, int i)168 {169 int ret = 1;170 for (int k=1; k<=n; k++)171 ret*=k;172 for (int k=1; k<=i; k++)173 ret/=k;174 for (int k=1; k<=n-i; k++)175 ret/=k;176 177 return ret;178 }179 -
orxonox/branches/parenting/src/curve.h
r3319 r3320 25 25 { 26 26 int number; //!< The N-th node of this curve. 27 float factor; //!< Curve specific multiplier factor. 27 28 Vector position; //!< Vector Pointung to this curve-point. 28 29 PathNode* next; //!< Pointer to the next Node. … … 32 33 PathNode* currentNode; //!< The node we are working with (the Last node). 33 34 35 private: 36 virtual void rebuild(void) = 0; 34 37 public: 35 38 void addNode (const Vector& newNode); … … 46 49 { 47 50 private: 48 // all from Curve-Class51 void rebuild(void); 49 52 public: 50 BezierCurve (void); 51 ~BezierCurve (void); 52 Vector calcPos (float t); 53 Vector calcDir (float t); 54 Quaternion calcQuat (float t); 53 BezierCurve(void); 54 ~BezierCurve(void); 55 56 Vector calcPos(float t); 57 Vector calcDir(float t); 58 Quaternion calcQuat(float t); 55 59 56 60 … … 70 74 71 75 72 int ncr(int n, int i);73 74 75 76 #endif /* _CURVE_H */
Note: See TracChangeset
for help on using the changeset viewer.