Changeset 5211 in orxonox.OLD for trunk/src/lib/math
- Timestamp:
- Sep 21, 2005, 2:21:41 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/math/curve.cc
r4836 r5211 1 /* 1 /* 2 2 orxonox - the future of 3D-vertical-scrollers 3 3 … … 13 13 co-programmer: Patrick Boenzli 14 14 15 ADD: Patrick Boenzli B-Spline 16 17 18 TODO: 15 ADD: Patrick Boenzli B-Spline 16 17 18 TODO: 19 19 local-Time implementation 20 20 NURBS 21 21 tList implementation 22 22 23 23 */ 24 24 … … 33 33 34 34 35 /** 35 /** 36 36 * default constructor for a Curve 37 37 */ … … 71 71 void Curve::addNode(const Vector& newNode, unsigned int insertPosition) 72 72 { 73 74 73 if (this->nodeCount == 0 || insertPosition > this->nodeCount) 75 74 return addNode(newNode); … … 85 84 { 86 85 while (tmpNode->next->number != insertPosition) 87 86 tmpNode= tmpNode->next; 88 87 insNode->next = tmpNode->next; 89 88 tmpNode->next = insNode; … … 199 198 tmpNode->factor = binCoef; 200 199 if (tmpNode =tmpNode->next) 201 202 203 204 200 { 201 binCoef *=(n-k)/(k+1); 202 ++k; 203 } 205 204 } 206 205 … … 212 211 dirCurve = new BezierCurve(1); 213 212 while(tmpNode->next) 214 215 216 217 218 219 220 221 222 213 { 214 Vector tmpVector = (tmpNode->next->position)- (tmpNode->position); 215 tmpVector.x*=(float)nodeCount; 216 tmpVector.y*=(float)nodeCount; 217 tmpVector.z*=(float)nodeCount; 218 tmpVector.normalize(); 219 this->dirCurve->addNode(tmpVector); 220 tmpNode = tmpNode->next; 221 } 223 222 } 224 223 } … … 229 228 * @return the Position on the Path 230 229 */ 231 Vector BezierCurve::calcPos(float t) 230 Vector BezierCurve::calcPos(float t) 232 231 { 233 232 Vector ret = Vector(0.0,0.0,0.0); … … 237 236 double factor = pow(1.0-t,nodeCount-1); 238 237 while(tmpNode) 239 240 241 242 243 244 245 246 238 { 239 ret.x += tmpNode->factor * factor * tmpNode->position.x; 240 ret.y += tmpNode->factor * factor * tmpNode->position.y; 241 ret.z += tmpNode->factor * factor * tmpNode->position.z; 242 factor *= t/(1.0-t); // same as pow but much faster. 243 244 tmpNode = tmpNode->next; 245 } 247 246 } 248 247 else if (nodeCount == 2)
Note: See TracChangeset
for help on using the changeset viewer.