Changeset 3365 in orxonox.OLD for orxonox/trunk/src/vector.cc
- Timestamp:
- Jan 7, 2005, 1:14:33 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/trunk/src/vector.cc
r3234 r3365 844 844 } 845 845 846 847 /**848 \brief Creates a new BezierCurve849 */850 BezierCurve::BezierCurve (void)851 {852 nodeCount = 0;853 firstNode = new PathNode;854 currentNode = firstNode;855 856 firstNode->position = Vector (.0, .0, .0);857 firstNode->number = 0;858 firstNode->next = 0; // not sure if this really points to NULL!!859 860 return;861 }862 863 /**864 \brief Deletes a BezierCurve.865 It does this by freeing all the space taken over from the nodes866 */867 BezierCurve::~BezierCurve (void)868 {869 PathNode* tmpNode;870 currentNode = firstNode;871 while (tmpNode != 0)872 {873 tmpNode = currentNode;874 currentNode = currentNode->next;875 delete tmpNode;876 }877 }878 879 /**880 \brief adds a new Node to the bezier Curve881 \param newNode a Vector to the position of the new node882 */883 void BezierCurve::addNode(const Vector& newNode)884 {885 PathNode* tmpNode;886 if (nodeCount == 0 )887 tmpNode = firstNode;888 else889 {890 tmpNode = new PathNode;891 currentNode = currentNode->next = tmpNode;892 }893 tmpNode->position = newNode;894 tmpNode->next = 0; // not sure if this really points to NULL!!895 tmpNode->number = (++nodeCount);896 return;897 }898 899 /**900 \brief calculates the Position on the curve901 \param t The position on the Curve (0<=t<=1)902 \return the Position on the Path903 */904 Vector BezierCurve::calcPos(float t)905 {906 if (nodeCount <=4)907 {908 // if (verbose >= 1)909 // printf ("Please define at least 4 nodes, until now you have only defined %i.\n", nodeCount);910 curvePoint = Vector(0,0,0);911 }912 PathNode* tmpNode = firstNode;913 914 int k,kn,nn,nkn;915 double blend,muk,munk;916 Vector b = Vector(0.0,0.0,0.0);917 918 muk = 1;919 munk = pow(1-t,(double)nodeCount);920 921 for (k=0; k<=nodeCount; k++) {922 nn = nodeCount;923 kn = k;924 nkn = nodeCount - k;925 blend = muk * munk;926 muk *= t;927 munk /= (1-t);928 while (nn >= 1) {929 blend *= nn;930 nn--;931 if (kn > 1) {932 blend /= (double)kn;933 kn--;934 }935 if (nkn > 1) {936 blend /= (double)nkn;937 nkn--;938 }939 }940 b.x += tmpNode->position.x * blend;941 b.y += tmpNode->position.y * blend;942 b.z += tmpNode->position.z * blend;943 944 tmpNode = tmpNode->next;945 }946 return b;947 }948 949 Vector BezierCurve::calcDirection (float t)950 {951 double diff = .00000000001;952 953 Vector diffV = ((calcPos(t+diff) - calcPos(t))/diff);954 diffV.normalize();955 return diffV;956 }957 958 /**959 \brief returns the Position of the point calculated on the Curve960 \return a Vector to the calculated position961 */962 Vector BezierCurve::getPos() const963 {964 return curvePoint;965 }
Note: See TracChangeset
for help on using the changeset viewer.