Files Classes Functions Hierarchy
00001 #include <cassert> 00002 00003 #include <mathlib.h> 00004 #include <d2homogeneous.h> 00005 00006 #include <d2arrow.h> 00007 00008 00009 00010 00011 double d2arrow::headlengthfactor = 0.8; 00012 00013 void d2arrow::translate( point2<double> const & x ) 00014 { 00015 for (uint i=0; i<4; ++i) 00016 pi[i] += x; 00017 } 00018 00019 void d2arrow::rotate(doublec theta) 00020 { 00021 d2homogeneous R; 00022 00023 R.setRotateAboutPoint(theta,pi[0]); 00024 00025 for (uint i=1; i<4; ++i) 00026 R.matrixMultiply(pi[i]); 00027 } 00028 00029 d2arrow::d2arrow 00030 ( 00031 doublec arrowlength, 00032 doublec headlength 00033 ) 00034 { 00035 constructOnXaxis(arrowlength,headlength); 00036 } 00037 00038 d2arrow::d2arrow 00039 ( 00040 point2<double> const & pi0, 00041 doublec theta, 00042 doublec arrowlength, 00043 doublec headlength 00044 ) 00045 { 00046 constructOnXaxis(arrowlength,headlength); 00047 translate(pi0); 00048 rotate(theta); 00049 } 00050 00051 d2arrow::d2arrow 00052 ( 00053 point2<double> const & q0, 00054 point2<double> const & q1, 00055 doublec arrowlength, 00056 doublec headlength 00057 ) 00058 { 00059 // Using vector calculus to calculate the arrows 00060 // geometry points. 00061 00062 // Construct unit vectors z1 and z2 where z2 is the normal. 00063 // Further z1 = z2 rotated 90 degrees anticlockwise direction. 00064 00065 // z1 and z2 are at right angles and form a coordinate system. 00066 00067 point2<double> z1(q1-q0); 00068 z1.normalize(); 00069 point2<double> z2(-z1.y,z1.x); 00070 00071 // The head base of the arrow. 00072 point2<double> hb(z2); 00073 hb *= (arrowlength-headlength); 00074 00075 // Half the hight of the arrow head. 00076 double w = headlength*headlengthfactor*0.5; 00077 00078 pi[2] = hb - z1 * w; 00079 pi[3] = hb + z1 * w; 00080 pi[1] = z2*arrowlength; 00081 pi[0] = point2<double>(0.0,0.0); 00082 00083 point2<double> p0(q0+q1); 00084 p0 *= 0.5; 00085 translate(p0); 00086 } 00087 00088 00089 void d2arrow::constructOnXaxis 00090 ( 00091 doublec arrowlength, 00092 doublec headlength 00093 ) 00094 { 00095 assert(arrowlength>headlength); 00096 assert(arrowlength>0.0); 00097 00098 pi[0] = point2<double>(0.0,0.0); 00099 pi[1] = point2<double>(arrowlength,0.0); 00100 doublec q = arrowlength-headlength; 00101 doublec arrowheight = headlength*headlengthfactor*0.5; 00102 pi[2] = point2<double>(q,arrowheight); 00103 pi[3] = point2<double>(q,-arrowheight); 00104 } 00105 00106 void d2arrow::draw() 00107 { 00108 glBegin(GL_LINES); 00109 00110 glVertex3f(pi[0].x,pi[0].y,0.0); 00111 glVertex3f(pi[1].x,pi[1].y,0.0); 00112 00113 glEnd(); 00114 00115 glBegin(GL_TRIANGLES); 00116 00117 glVertex3f(pi[1].x,pi[1].y,0.0); 00118 glVertex3f(pi[2].x,pi[2].y,0.0); 00119 glVertex3f(pi[3].x,pi[3].y,0.0); 00120 00121 glEnd(); 00122 } 00123 00124
1.5.8