Files Classes Functions Hierarchy
00001 #include <graphmisc.h> 00002 #include <springlineardraw.h> 00003 00004 springlineardraw::springlineardraw 00005 ( 00006 uintc N_, 00007 doublec springradius, 00008 doublec springturns, 00009 uintc springNspikes 00010 ) 00011 { 00012 construct(N_,springradius,springturns,springNspikes); 00013 } 00014 00015 void springlineardraw::construct 00016 ( 00017 uintc N_, 00018 doublec springradius, 00019 doublec springturns, 00020 uintc springNspikes 00021 ) 00022 { 00023 springlineargeom::construct(N_); 00024 00025 sph.resize(N); 00026 hel.resize(N+1); 00027 for (uint i=0; i<N; ++i) 00028 sph[i].quadric = & quadric; 00029 00030 for (uint i=0; i<=N; ++i) 00031 { 00032 hel[i].construct(springturns,springNspikes); 00033 hel[i].radius = springradius; 00034 } 00035 00036 masscolor.resize(N); 00037 for (uint i=0; i<N; ++i) 00038 masscolor[i] = point3<double>( DOUBLECOLOR(218,165,32) ); 00039 00040 } 00041 00042 void springlineardraw::update() 00043 { 00044 if (N==0) 00045 return; 00046 00047 /* 00048 00049 assert(N+1==lengths.size()); 00050 assert(N==xoffsets.size()); 00051 assert(N==sph.size()); 00052 assert(N+1==hel.size()); 00053 00054 // Position the mass points. 00055 double x(0.0); 00056 for (uint i=0; i<N; ++i) 00057 { 00058 x += lengths[i]; 00059 x += xoffsets[i]; 00060 sph[i].x = x; 00061 } 00062 00063 // Set the helix lengths. 00064 hel[0].length = lengths[0]+xoffsets[0]; 00065 if (N>1) 00066 hel[N].length = lengths[N]-xoffsets[N-1]; 00067 for (uint i=1; i<N; ++i) 00068 hel[i].length = lengths[i]+xoffsets[i]-xoffsets[i-1]; 00069 00070 */ 00071 } 00072 00073 00074 00075 void springlineardraw::draw() 00076 { 00077 if (N==0) 00078 return; 00079 00080 assert(N+1==lengths.size()); 00081 assert(N==xoffsets.size()); 00082 assert(N==sph.size()); 00083 assert(N+1==hel.size()); 00084 assert(N==masscolor.size()); 00085 00086 //update(); 00087 00088 lengths_update(); 00089 for (uint i=0; i<=N; ++i) 00090 hel[i].length = lengthscurrent[i]; 00091 00092 /* 00093 cout << SHOW(hel[0].length) << endl; 00094 cout << SHOW(hel[1].length) << endl; 00095 cout << SHOW(hel[2].length) << endl; 00096 */ 00097 00098 glPushAttrib(GL_CURRENT_BIT); 00099 glPushAttrib(GL_LIGHTING); 00100 00101 glPushMatrix(); 00102 00103 glDisable(GL_LIGHTING); 00104 glColor3d(springcolor.x,springcolor.y,springcolor.z); 00105 00106 hel[0].draw(); 00107 00108 for (uint i=0; i<N; ++i) 00109 { 00110 glTranslatef(hel[i].length,0.0,0.0); 00111 glEnable(GL_LIGHTING); 00112 glColor3d(masscolor[i].x,masscolor[i].y,masscolor[i].z); 00113 sph[i].draw(); 00114 glDisable(GL_LIGHTING); 00115 glColor3d(springcolor.x,springcolor.y,springcolor.z); 00116 hel[i+1].draw(); 00117 } 00118 00119 glPopMatrix(); 00120 00121 glPopAttrib(); 00122 glPopAttrib(); 00123 } 00124 00125
1.5.8