Changeset 3238 in orxonox.OLD for orxonox/branches/sound/src/vector.cc
- Timestamp:
- Dec 20, 2004, 2:42:54 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
orxonox/branches/sound/src/vector.cc
r2551 r3238 33 33 { 34 34 Vector r; 35 35 36 36 r.x = x + v.x; 37 37 r.y = y + v.y; … … 203 203 \return the angle between the vectors in radians 204 204 */ 205 float angle _rad (const Vector& v1, const Vector& v2)205 float angleRad (const Vector& v1, const Vector& v2) 206 206 { 207 207 return acos( v1 * v2 / (v1.len() * v2.len())); … … 215 215 \return the angle between the vectors in degrees 216 216 */ 217 float angle _deg (const Vector& v1, const Vector& v2)217 float angleDeg (const Vector& v1, const Vector& v2) 218 218 { 219 219 float f; … … 243 243 244 244 /** 245 \brief calculates a look _at rotation245 \brief calculates a lookAt rotation 246 246 \param dir: the direction you want to look 247 247 \param up: specify what direction up should be … … 578 578 Vector axis = x.cross( v); 579 579 axis.normalize(); 580 float angle = angle _rad( x, v);580 float angle = angleRad( x, v); 581 581 float ca = cos(angle); 582 582 float sa = sin(angle); … … 714 714 \return the rotated vector 715 715 */ 716 Vector rotate _vector( const Vector& v, const Rotation& r)716 Vector rotateVector( const Vector& v, const Rotation& r) 717 717 { 718 718 Vector t; … … 745 745 \return the distance between the Line and the point 746 746 */ 747 float Line::distance _point (const Vector& v) const747 float Line::distancePoint (const Vector& v) const 748 748 { 749 749 Vector d = v-r; … … 761 761 Vector* fp = new Vector[2]; 762 762 Plane p = Plane (r + a.cross(l.a), r, r + a); 763 fp[1] = p.intersect _line (l);763 fp[1] = p.intersectLine (l); 764 764 p = Plane (fp[1], l.a); 765 fp[0] = p.intersect _line (*this);765 fp[0] = p.intersectLine (*this); 766 766 return fp; 767 767 } … … 783 783 { 784 784 Vector t = a + r; 785 t = rotate _vector( t, rot);786 r = rotate _vector( r, rot),785 t = rotateVector( t, rot); 786 r = rotateVector( r, rot), 787 787 a = t - r; 788 788 } … … 815 815 \param l: a line 816 816 */ 817 Vector Plane::intersect _line (const Line& l) const817 Vector Plane::intersectLine (const Line& l) const 818 818 { 819 819 if (n.x*l.a.x+n.y*l.a.y+n.z*l.a.z == 0.0) return Vector(0,0,0); … … 827 827 \return the distance between the plane and the point (can be negative) 828 828 */ 829 float Plane::distance _point (const Vector& p) const829 float Plane::distancePoint (const Vector& p) const 830 830 { 831 831 float l = n.len(); … … 839 839 \return 0 if the point is contained within the Plane, positive(negative) if the point is in the positive(negative) semi-space of the Plane 840 840 */ 841 float Plane::locate _point (const Vector& p) const841 float Plane::locatePoint (const Vector& p) const 842 842 { 843 843 return (n.dot(p) + k); 844 844 } 845 846 847 /** 848 \brief Creates a new BezierCurve 849 */ 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 nodes 866 */ 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 Curve 881 \param newNode a Vector to the position of the new node 882 */ 883 void BezierCurve::addNode(const Vector& newNode) 884 { 885 PathNode* tmpNode; 886 if (nodeCount == 0 ) 887 tmpNode = firstNode; 888 else 889 { 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 curve 901 \param t The position on the Curve (0<=t<=1) 902 \return the Position on the Path 903 */ 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 Curve 960 \return a Vector to the calculated position 961 */ 962 Vector BezierCurve::getPos() const 963 { 964 return curvePoint; 965 }
Note: See TracChangeset
for help on using the changeset viewer.