00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069 #ifndef TRACKUTILS_H
00070 #define TRACKUTILS_H
00071
00072 #include <assert.h>
00073 #include <vcg/math/base.h>
00074 #include <vcg/math/similarity.h>
00075 #include <vcg/space/intersection3.h>
00076 #include <vcg/space/line3.h>
00077 #include <vcg/space/plane3.h>
00078 #include <wrap/gl/math.h>
00079 #include <wrap/gl/space.h>
00080 #include <vector>
00081 #include <iostream>
00082 using namespace std;
00083
00084 namespace vcg {
00085
00092 namespace trackutils {
00093
00101 Plane3f GetViewPlane (const View < float >&camera, const Point3f & center)
00102 {
00103 Point3f vp = camera.ViewPoint ();
00104 Plane3f pl;
00105 Point3f plnorm = vp - center;
00106 plnorm.Normalize();
00107 pl.Set(plnorm, plnorm.dot(center));
00108 return pl;
00109 }
00110
00117 Ray3f line2ray(const Line3f &l){
00118 Ray3f r(l.Origin(),l.Direction());
00119 r.Normalize();
00120 return r;
00121 }
00122
00123
00131 Point3f HitViewPlane (Trackball * tb, const Point3f & p)
00132 {
00133 Plane3f vp = GetViewPlane (tb->camera, tb->center);
00134 Line3fN ln = tb->camera.ViewLineFromWindow (Point3f (p[0], p[1], 0));
00135 Point3f PonVP;
00136 IntersectionLinePlane < float >(vp, ln, PonVP);
00137 return PonVP;
00138 }
00139
00140
00141
00179 bool HitHyper (Point3f center, float radius, Point3f viewpoint, Plane3f vp,
00180 Point3f hitplane, Point3f & hit)
00181 {
00182 float hitplaney = Distance (center, hitplane);
00183 float viewpointx = Distance (center, viewpoint);
00184
00185 float a = hitplaney / viewpointx;
00186 float b = -hitplaney;
00187 float c = radius * radius / 2.0f;
00188 float delta = b * b - 4 * a * c;
00189 float x1, x2, xval, yval;
00190
00191 if (delta > 0) {
00192 x1 = (-b - sqrt (delta)) / (2.0f * a);
00193 x2 = (-b + sqrt (delta)) / (2.0f * a);
00194
00195 xval = x1;
00196 yval = c / xval;
00197 }
00198 else {
00199 return false;
00200 }
00201
00202 Point3f dirRadial = hitplane - center;
00203 dirRadial.Normalize ();
00204 Point3f dirView = vp.Direction ();
00205 dirView.Normalize ();
00206 hit = center + dirRadial * yval + dirView * xval;
00207 return true;
00208 }
00209
00210
00211
00235 Point3f HitSphere (Trackball * tb, const Point3f & p)
00236 {
00237 Point3f center = tb->center;
00238 Line3fN ln = tb->camera.ViewLineFromWindow (Point3f (p[0], p[1], 0));
00239 Plane3f vp = GetViewPlane (tb->camera, center);
00240 Point3f hitPlane(0,0,0),
00241 hitSphere(0,0,0),
00242 hitSphere1(0,0,0),
00243 hitSphere2(0,0,0),
00244 hitHyper(0,0,0);
00245 IntersectionLinePlane < float >(vp, ln, hitPlane);
00246
00247 Sphere3f sphere (center, tb->radius);
00248 bool resSp = IntersectionLineSphere < float >(sphere, ln, hitSphere1, hitSphere2);
00249
00250 Point3f viewpoint = tb->camera.ViewPoint ();
00251 if (resSp == true) {
00252 if (Distance (viewpoint, hitSphere1) < Distance (viewpoint, hitSphere2))
00253 hitSphere = hitSphere1;
00254 else
00255 hitSphere = hitSphere2;
00256 }
00257
00258 Distance (ln, center);
00259 bool resHp = HitHyper (center, tb->radius, viewpoint, vp, hitPlane, hitHyper);
00260
00261
00262
00263
00264 if ((!resSp && !resHp)) {
00265 Point3f hit = ClosestPoint (ln, center);
00266
00267 return hit;
00268 }
00269 if ((resSp && !resHp))
00270 return hitSphere;
00271 if ((!resSp && resHp))
00272 return hitHyper;
00273
00274
00275 float angleDeg = math::ToDeg (Angle ((viewpoint - center), (hitSphere - center)));
00276
00277
00278 if (angleDeg < 45)
00279 return hitSphere;
00280 else
00281 return hitHyper;
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311 }
00312
00331 std::pair< float, bool > LineLineDistance(const Line3f & P,const Line3f & Q,Point3f & P_s, Point3f & Q_t){
00332 Point3f p0 = P.Origin (), Vp = P.Direction ();
00333 Point3f q0 = Q.Origin (), Vq = Q.Direction ();
00334 float VPVP = Vp.dot(Vp);
00335 float VQVQ = Vq.dot(Vq);
00336 float VPVQ = Vp.dot(Vq);
00337 const float det = ( VPVP * VQVQ ) - ( VPVQ * VPVQ );
00338 const float EPSILON = 0.00001f;
00339 if ( fabs(det) < EPSILON ) {
00340 return std::make_pair(Distance(P,q0), true);
00341 }
00342 float b1= (q0 - p0).dot(Vp);
00343 float b2= (p0 - q0).dot(Vq);
00344 float s = ( (VQVQ * b1) + (VPVQ * b2) ) / det;
00345 float t = ( (VPVQ * b1) + (VPVP * b2) ) / det;
00346 P_s = p0 + (Vp * s);
00347 Q_t = q0 + (Vq * t);
00348 return std::make_pair(Distance(P_s,Q_t),false);
00349 }
00350
00367 std::pair< float, bool > RayLineDistance(const Ray3f & R,const Line3f & Q,Point3f & R_s, Point3f & Q_t){
00368 Point3f r0 = R.Origin (), Vr = R.Direction ();
00369 Point3f q0 = Q.Origin (), Vq = Q.Direction ();
00370 float VRVR = Vr.dot(Vr);
00371 float VQVQ = Vq.dot(Vq);
00372 float VRVQ = Vr.dot(Vq);
00373 const float det = ( VRVR * VQVQ ) - ( VRVQ * VRVQ );
00374 const float EPSILON = 0.00001f;
00375 if ( ( det >= 0.0f ? det : -det) < EPSILON ) {
00376 return std::make_pair(Distance(Q,r0), true);
00377 }
00378 float b1= (q0 - r0).dot(Vr);
00379 float b2= (r0 - q0).dot(Vq);
00380 float s = ( (VQVQ * b1) + (VRVQ * b2) ) / det;
00381 float t = ( (VRVQ * b1) + (VRVR * b2) ) / det;
00382 if(s<0){
00383 R_s = r0;
00384 Q_t = ClosestPoint(Q,R_s);
00385 }else {
00386 R_s = r0 + (Vr * s);
00387 Q_t = q0 + (Vq * t);
00388 }
00389 return std::make_pair(Distance(R_s,Q_t),false);
00390 }
00391
00406 std::pair< float, bool > SegmentSegmentDistance(const Segment3f & R, const Segment3f & Q, Point3f & R_s, Point3f & Q_t)
00407 {
00408 float R_len=Distance(R.P0(),R.P1());
00409 float Q_len=Distance(Q.P0(),Q.P1());
00410 const float EPSILON_LENGTH = std::max(R_len,Q_len)*0.0001f;
00411 if(R_len < EPSILON_LENGTH){
00412 R_s=R.P0();
00413 Q_t=ClosestPoint(Q,R_s);
00414 return std::make_pair(Distance(R_s,Q_t),true);
00415 }
00416 if( Q_len < EPSILON_LENGTH){
00417 Q_t=Q.P0();
00418 R_s=ClosestPoint(R,Q_t);
00419 return std::make_pair(Distance(R_s,Q_t),true);
00420 }
00421 Point3f r0 = R.P0(), Vr = (R.P1()-R.P0()).normalized();
00422 Point3f q0 = Q.P0(), Vq = (Q.P1()-Q.P0()).normalized();
00423 float VRVR = Vr.dot(Vr);
00424 float VQVQ = Vq.dot(Vq);
00425 float VRVQ = Vr.dot(Vq);
00426 const float det = ( VRVR * VQVQ ) - ( VRVQ * VRVQ );
00427 const float EPSILON = 0.00001f;
00428 if ( ( det >= 0.0f ? det : -det) < EPSILON ) {
00429 Line3f lR(R.P0(),R.P1());
00430 float qa=lR.Projection(Q.P0());
00431 float qb=lR.Projection(Q.P1());
00432 if( (qa<=0.0f) && qb<=(0.0f)){
00433 R_s=R.P0();
00434 Q_t=ClosestPoint(Q,R_s);
00435 } else if ( (qa >= 1.0f) && (qb >= 1.0f) ){
00436 R_s=R.P1();
00437 Q_t=ClosestPoint(Q,R_s);
00438 } else {
00439 if( (qa >= 0.0f) && (qa <= 1.0f) ){
00440 Q_t=Q.P0();
00441 R_s=ClosestPoint(R,Q_t);
00442 } else if((qb >= 0.0f) && (qb <= 1.0f) ){
00443 Q_t=Q.P1();
00444 R_s=ClosestPoint(R,Q_t);
00445 } else {
00446 if( ( ((qa<=0.0f)&&(qb>=1.0f)) || (((qb<=0.0f)&&(qa>=1.0f))))){
00447 R_s=R.P0();
00448 Q_t=ClosestPoint(Q,R_s);
00449 }else{
00450 assert(0);
00451 }
00452 }
00453 }
00454 return std::make_pair(Distance(R_s,Q_t),true);
00455 }
00456 float b1= (q0 - r0).dot(Vr);
00457 float b2= (r0 - q0).dot(Vq);
00458 float s = ( (VQVQ * b1) + (VRVQ * b2) ) / det;
00459 float t = ( (VRVQ * b1) + (VRVR * b2) ) / det;
00460 if( s < 0 ){
00461 R_s = R.P0();
00462 }else if ( s > R_len ){
00463 R_s = R.P1();
00464 } else {
00465 R_s = r0 + (Vr * s);
00466 }
00467 if( t < 0){
00468 Q_t = Q.P0();
00469 }else if ( t > Q_len ){
00470 Q_t = Q.P1();
00471 }else{
00472 Q_t = q0 + (Vq * t);
00473 }
00474 return std::make_pair(Distance(R_s,Q_t),false);
00475 }
00476
00489 std::pair< Point3f,bool > HitNearestPointOnAxis (Trackball * tb,Line3f axis, Point3f point)
00490 {
00491 Ray3fN ray = line2ray(tb->camera.ViewLineFromWindow (point));
00492 Point3f axis_p(0,0,0), ray_p(0,0,0);
00493 std::pair< float, bool > resp=RayLineDistance(ray,axis,ray_p,axis_p);
00494 if(resp.second || (ray_p == ray.Origin())){
00495 return std::make_pair(Point3f(0,0,0),false);
00496 }
00497 return std::make_pair(axis_p,true);
00498 }
00499
00510 Line3f ProjectLineOnPlane(const Line3f & ln, const Plane3f & pl)
00511 {
00512 Point3f l0=ln.Origin();
00513 Point3f l1=l0+ln.Direction();
00514 Point3f p1,p2;
00515 p1=pl.Projection(l0);
00516 p2=pl.Projection(l1);
00517 Line3f res(p1,p2-p1);
00518 return res;
00519 }
00520
00530 float signedDistance(Line3f line,Point3f pt,Point3f positive_dir)
00531 {
00532 return Distance(line,pt) * ((((pt-ClosestPoint(line,pt)).dot(positive_dir)) >= 0.0f )? 1.0f: -1.0f);
00533 }
00534
00542 float getDeltaY(Trackball * tb, Point3f new_point)
00543 {
00544 float ScreenHeight = float (tb->camera.viewport[3] - tb->camera.viewport[1]);
00545 return (new_point[1] - tb->last_point[1]) / ScreenHeight;
00546 }
00547
00556 template<class T>
00557 inline bool IntersectionRayPlane( const Plane3<T> & pl, const Ray3<T> & ray, Point3<T> &po){
00558 const T epsilon = T(1e-8);
00559
00560 T k = pl.Direction().dot(ray.Direction());
00561 if( (k > -epsilon) && (k < epsilon))
00562 return false;
00563 T r = (pl.Offset() - pl.Direction().dot(ray.Origin()))/k;
00564 if (r < 0)
00565 return false;
00566 po = ray.Origin() + ray.Direction()*r;
00567 return true;
00568 }
00569
00583 std::pair< Point3f, bool > HitPlane (Trackball * tb, Point3f point, Plane3f plane)
00584 {
00585 Ray3fN ray = line2ray(tb->camera.ViewLineFromWindow (point));
00586 Point3f p(0,0,0);
00587 bool res = IntersectionRayPlane < float >(plane, ray, p);
00588 return std::make_pair(p,res);
00589 }
00590
00591
00592
00593
00594
00595
00603 class DrawingHint {
00604 public:
00610 DrawingHint () {
00611 CircleStep = 64;
00612 HideStill = false;
00613 DrawTrack = false;
00614 LineWidthStill = 0.5f;
00615 LineWidthMoving = 1.5f;
00616 color = Color4b::LightBlue;
00617 }
00619 int CircleStep;
00621 bool HideStill;
00623 bool DrawTrack;
00625 Color4b color;
00627 float LineWidthStill;
00629 float LineWidthMoving;
00630 };
00631
00633 DrawingHint DH;
00634
00635
00636
00640 void DrawPlaneHandle ()
00641 {
00642 float r = 1.0;
00643 float dr = r / 10.0f;
00644
00645 glBegin (GL_LINE_STRIP);
00646 glVertex3f (+r + dr, +r, 0.0);
00647 glVertex3f (+r, +r + dr, 0.0);
00648 glVertex3f (+r - dr, +r, 0.0);
00649 glVertex3f (+r, +r - dr, 0.0);
00650 glVertex3f (+r + dr, +r, 0.0);
00651 glEnd ();
00652 glBegin (GL_LINE_STRIP);
00653 glVertex3f (-r + dr, -r, 0.0);
00654 glVertex3f (-r, -r + dr, 0.0);
00655 glVertex3f (-r - dr, -r, 0.0);
00656 glVertex3f (-r, -r - dr, 0.0);
00657 glVertex3f (-r + dr, -r, 0.0);
00658 glEnd ();
00659 }
00660
00661
00662
00666 void DrawCircle ()
00667 {
00668 int nside = DH.CircleStep;
00669 const double pi2 = 3.14159265 * 2.0;
00670 glBegin (GL_LINE_LOOP);
00671 for (double i = 0; i < nside; i++) {
00672 glNormal3d (cos (i * pi2 / nside), sin (i * pi2 / nside), 0.0);
00673 glVertex3d (cos (i * pi2 / nside), sin (i * pi2 / nside), 0.0);
00674 }
00675 glEnd ();
00676 DrawPlaneHandle ();
00677 }
00678
00685 void DrawSphereIcon (Trackball * tb,bool active)
00686 {
00687 glPushAttrib (GL_TRANSFORM_BIT |GL_ENABLE_BIT | GL_LINE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT);
00688 glMatrixMode(GL_MODELVIEW);
00689 glPushMatrix ();
00690
00691 Point3f center = tb->center + tb->track.InverseMatrix()*Point3f(0, 0, 0);
00692 glTranslate(center);
00693 glScale (tb->radius/tb->track.sca);
00694
00695 float amb[4] = { .3f, .3f, .3f, 1.0f };
00696 float col[4] = { .5f, .5f, .8f, 1.0f };
00697 glEnable (GL_LINE_SMOOTH);
00698 if (active)
00699 glLineWidth (DH.LineWidthMoving);
00700 else
00701 glLineWidth (DH.LineWidthStill);
00702 glEnable (GL_LIGHTING);
00703 glEnable (GL_LIGHT0);
00704 glEnable (GL_BLEND);
00705 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00706 glColor (DH.color);
00707 glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, amb);
00708 glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, col);
00709
00710 DrawCircle ();
00711 glRotatef (90, 1, 0, 0);
00712 DrawCircle ();
00713 glRotatef (90, 0, 1, 0);
00714 DrawCircle ();
00715
00716 glPopMatrix ();
00717 glPopAttrib ();
00718 }
00719
00720
00721
00722
00723
00730 void prepare_attrib()
00731 {
00732 float amb[4] = { .3f, .3f, .3f, 1.0f };
00733 float col[4] = { .5f, .5f, .8f, 1.0f };
00734 glEnable (GL_LIGHTING);
00735 glEnable (GL_LIGHT0);
00736 glEnable (GL_LINE_SMOOTH);
00737 glEnable (GL_BLEND);
00738 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00739 glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, amb);
00740 glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, col);
00741 }
00742
00751 void DrawUglyLetter(Trackball * tb,std::vector<Point3f> ugly_letter)
00752 {
00753 Point3f center=tb->camera.Project(tb->center);
00754 float offset=0;
00755 offset=std::max(offset,Distance(center,tb->camera.Project(tb->center+(Point3f(1,0,0) * tb->radius))));
00756 offset=std::max(offset,Distance(center,tb->camera.Project(tb->center+(Point3f(0,1,0) * tb->radius))));
00757 offset=std::max(offset,Distance(center,tb->camera.Project(tb->center+(Point3f(0,0,1) * tb->radius))));
00758 glPushMatrix();
00759 glPushAttrib (GL_ALL_ATTRIB_BITS);
00760
00761 glTranslate (tb->center);
00762 glMultMatrix (tb->track.InverseMatrix ());
00763 glTranslate (-tb->center);
00764 prepare_attrib();
00765 glColor3f(1,1,1);
00766 glLineWidth(4.0);
00767
00768 glBegin(GL_LINE_STRIP);
00769 for(unsigned int i=0;i<ugly_letter.size();i++){
00770 glVertex(tb->camera.UnProject(center+(ugly_letter[i] * offset * 0.25)
00771 +Point3f(-offset,-offset,0)));
00772 }
00773 glEnd();
00774 glPopAttrib ();
00775 glPopMatrix();
00776
00777 }
00778
00786 void DrawUglyPanMode(Trackball * tb)
00787 {
00788 std::vector<Point3f> ugly_p;
00789 ugly_p.push_back(Point3f(-1,-1,0));
00790 ugly_p.push_back(Point3f(-1,1,0));
00791 ugly_p.push_back(Point3f(1,1,0));
00792 ugly_p.push_back(Point3f(1,0,0));
00793 ugly_p.push_back(Point3f(-1,0,0));
00794
00795 DrawUglyLetter(tb,ugly_p);
00796 }
00797
00805 void DrawUglyZMode(Trackball * tb)
00806 {
00807 std::vector<Point3f> ugly_z;
00808 ugly_z.push_back(Point3f(-1,1,0));
00809 ugly_z.push_back(Point3f(1,1,0));
00810 ugly_z.push_back(Point3f(-1,-1,0));
00811 ugly_z.push_back(Point3f(1,-1,0));
00812 DrawUglyLetter(tb,ugly_z);
00813 }
00814
00822 void DrawUglyScaleMode(Trackball * tb)
00823 {
00824 std::vector<Point3f> ugly_s;
00825 ugly_s.push_back(Point3f(1,1,0));
00826 ugly_s.push_back(Point3f(-1,1,0));
00827 ugly_s.push_back(Point3f(-1,0,0));
00828 ugly_s.push_back(Point3f(1,0,0));
00829 ugly_s.push_back(Point3f(1,-1,0));
00830 ugly_s.push_back(Point3f(-1,-1,0));
00831 DrawUglyLetter(tb,ugly_s);
00832 }
00833
00842 void DrawUglyAxisMode(Trackball * tb,Line3f axis)
00843 {
00844 glPushMatrix();
00845 glPushAttrib (GL_ALL_ATTRIB_BITS);
00846
00847 glTranslate (tb->center);
00848 glMultMatrix (tb->track.InverseMatrix ());
00849 glTranslate (-tb->center);
00850 prepare_attrib();
00851 glColor3f(0.9f, 0.9f, 0.2f);
00852 glLineWidth(2.0);
00853 glBegin(GL_LINES);
00854 glVertex(axis.Origin()+(axis.Direction()*100));
00855 glVertex(axis.Origin()-(axis.Direction()*100));
00856 glEnd();
00857 glPointSize(8.0);
00858 glColor3f(0.2f, 0.2f, 0.9f);
00859 glBegin(GL_POINTS);
00860 glVertex(axis.Origin());
00861 glEnd();
00862 glPopAttrib ();
00863 glPopMatrix();
00864 }
00865
00874 void DrawUglyPlaneMode(Trackball * tb,Plane3f plane)
00875 {
00876 glPushMatrix();
00877 glPushAttrib (GL_ALL_ATTRIB_BITS);
00878
00879 glTranslate (tb->center);
00880 glMultMatrix (tb->track.InverseMatrix ());
00881 glTranslate (-tb->center);
00882 prepare_attrib();
00883 Point3f p0,d1,d2,norm;
00884 norm=plane.Direction();
00885 p0=plane.Projection(Point3f(0,0,0));
00886 d1=Point3f(0,1,0);
00887 if(norm == d1 || norm == -d1)
00888 d1 = Point3f(1,0,0);
00889 d2=plane.Projection(d1);
00890 d1=(d2 - p0).normalized();
00891 d2=(d1 ^ norm).normalized();
00892 glLineWidth(3.0);
00893 glColor3f(0.2f, 0.2f, 0.9f);
00894 glBegin(GL_LINES);
00895 glVertex(p0);
00896 glVertex(p0+norm);
00897 glEnd();
00898 glLineWidth(1.0);
00899 for(float i=0.5f; i<100.0f; i+=0.7f){
00900 glBegin(GL_LINE_LOOP);
00901 for(int a=0;a<360;a+=10){
00902 float f0=i*cosf((float(M_PI)*float(a))/180.0f);
00903 float f1=i*sinf((float(M_PI)*float(a))/180.0f);
00904 glVertex(p0+(d1*f0)+(d2*f1));
00905 }
00906 glEnd();
00907 }
00908 glColor3f(0.9f, 0.9f, 0.2f);
00909 glPointSize(8.0f);
00910 glBegin(GL_POINTS);
00911 glVertex(p0);
00912 glEnd();
00913 glColor3f(0.7f, 0.7f, 0.0f);
00914 glPointSize(6.0);
00915 glBegin(GL_POINTS);
00916 glVertex(p0+norm);
00917 glEnd();
00918 glPopAttrib ();
00919 glPopMatrix();
00920 }
00921
00930 void DrawUglyCylinderMode(Trackball * tb,Line3f axis)
00931 {
00932 glPushMatrix();
00933 glPushAttrib (GL_ALL_ATTRIB_BITS);
00934
00935 glTranslate (tb->center);
00936 glMultMatrix (tb->track.InverseMatrix ());
00937 glTranslate (-tb->center);
00938 prepare_attrib();
00939 Plane3f plane;
00940 plane.Init(axis.Origin(),axis.Direction());
00941 Point3f p0,d1,d2,norm;
00942 norm=plane.Direction();
00943 p0=plane.Projection(Point3f(0,0,0));
00944 d1=Point3f(0,1,0);
00945 if(norm == d1 || norm == -d1)
00946 d1 = Point3f(1,0,0);
00947 d2=plane.Projection(d1);
00948 d1=(d2 - p0).normalized();
00949 d2=(d1 ^ norm).normalized();
00950 glLineWidth(1.0);
00951 glColor3f(0.2f, 0.2f, 0.9f);
00952 for(int i=-100;i<100;i++){
00953 glBegin(GL_LINE_LOOP);
00954 for(int a=0;a<360;a+=10){
00955 float f0=(tb->radius)*cosf((float(M_PI)*float(a))/180.0f);
00956 float f1=(tb->radius)*sinf((float(M_PI)*float(a))/180.0f);
00957 glVertex(axis.Origin()+p0+(norm*float(i))+(d1*f0)+(d2*f1));
00958 }
00959 glEnd();
00960 }
00961 glLineWidth(3.0);
00962 glColor3f(0.2f, 0.2f, 0.9f);
00963 glBegin(GL_LINES);
00964 glVertex(axis.Origin());
00965 glVertex(axis.Origin()+(axis.Direction()*100));
00966 glEnd();
00967 glLineWidth(1.5);
00968 glColor3f(0.9f, 0.2f, 0.9f);
00969 glBegin(GL_LINES);
00970 glVertex(axis.Origin());
00971 glVertex(axis.Origin()-(axis.Direction()*100));
00972 glEnd();
00973 glColor3f(0.9f, 0.9f, 0.2f);
00974 glPointSize(8.0);
00975 glBegin(GL_POINTS);
00976 glVertex(axis.Origin());
00977 glEnd();
00978 glPopAttrib ();
00979 glPopMatrix();
00980 }
00981
00995 void DrawUglyPathMode(Trackball * tb,const std::vector < Point3f > &points,
00996 Point3f current_point,Point3f prev_point,
00997 Point3f next_point,Point3f old_hitpoint,bool wrap)
00998 {
00999 glPushMatrix();
01000 glPushAttrib (GL_ALL_ATTRIB_BITS);
01001
01002 glTranslate (tb->center);
01003 glMultMatrix (tb->track.InverseMatrix ());
01004 glTranslate (-tb->center);
01005 prepare_attrib();
01006 glColor3f(0.9f, 0.9f, 0.2f);
01007 glLineWidth(2.0);
01008 if(wrap)
01009 glBegin(GL_LINE_LOOP);
01010 else
01011 glBegin(GL_LINE_STRIP);
01012 for (std::vector < Point3f >::const_iterator i = points.begin (); i != points.end (); ++i){
01013 glVertex(*i);
01014 }
01015 glEnd();
01016 glColor3f(1,0,1);
01017 glPointSize(8.0);
01018 glBegin(GL_POINTS);
01019 glVertex(current_point);
01020 glEnd();
01021 glColor3f(0.6f, 0.0f, 0.6f);
01022 glPointSize(7.0);
01023 glBegin(GL_POINTS);
01024 glVertex(old_hitpoint);
01025 glEnd();
01026 glColor3f(0.7f, 0.7f, 0.7f);
01027 glPointSize(6.5);
01028 glBegin(GL_POINTS);
01029 glVertex(prev_point);
01030 glVertex(next_point);
01031 glEnd();
01032 glPopAttrib ();
01033 glPopMatrix();
01034 }
01035
01049 void DrawUglyAreaMode(Trackball * tb,const std::vector < Point3f > &points,
01050 Point3f status,Point3f old_status,Plane3f plane,
01051 const std::vector < Point3f > &path,Point3f rubberband_handle)
01052 {
01053 glPushMatrix();
01054 glPushAttrib (GL_ALL_ATTRIB_BITS);
01055
01056 glTranslate (tb->center);
01057 glMultMatrix (tb->track.InverseMatrix ());
01058 glTranslate (-tb->center);
01059 prepare_attrib();
01060 glColor3f(0.9f, 0.9f, 0.2f);
01061 glLineWidth(2.0);
01062 glBegin(GL_LINE_LOOP);
01063 for (std::vector < Point3f >::const_iterator i = points.begin (); i != points.end (); ++i){
01064 glVertex(*i);
01065 }
01066 glEnd();
01067 glColor3f(0.0f, 0.9f, 0.2f);
01068 glLineWidth(1.2f);
01069 glBegin(GL_LINE_STRIP);
01070 for (std::vector < Point3f >::const_iterator i = path.begin (); i != path.end (); ++i){
01071 glVertex(*i);
01072 }
01073 glEnd();
01074 glColor3f(1,0,1);
01075 glPointSize(8.0);
01076 glBegin(GL_POINTS);
01077 glVertex(status);
01078 glEnd();
01079 glColor3f(0.6f, 0.0f, 0.6f);
01080 glPointSize(7.0);
01081 glBegin(GL_POINTS);
01082 glVertex(old_status);
01083 glEnd();
01084 glColor3f(0.6f, 0.0f, 0.0f);
01085 glPointSize(6.0);
01086 glBegin(GL_POINTS);
01087 glVertex(rubberband_handle);
01088 glEnd();
01089 glLineWidth(1.0);
01090 glBegin(GL_LINES);
01091 glVertex(rubberband_handle);
01092 glVertex(status);
01093 glEnd();
01094 Point3f p0,d1,d2,norm;
01095 norm=plane.Direction();
01096 p0=plane.Projection(Point3f(0,0,0));
01097 d1=Point3f(0,1,0);
01098 if(norm == d1 || norm == -d1)
01099 d1 = Point3f(1,0,0);
01100 d2=plane.Projection(d1);
01101 d1=(d2 - p0).normalized();
01102 d2=(d1 ^ norm).normalized();
01103 glLineWidth(3.0);
01104 glColor3f(0.2f, 0.2f, 0.9f);
01105 glBegin(GL_LINES);
01106 glVertex(p0);
01107 glVertex(p0+norm);
01108 glEnd();
01109 glLineWidth(0.1f);
01110 for(float i=0.5f;i<100.0f; i+=0.7f){
01111 glBegin(GL_LINE_LOOP);
01112 for(int a=0;a<360;a+=10){
01113 float f0=i*cosf((float(M_PI)*float(a))/180.0f);
01114 float f1=i*sinf((float(M_PI)*float(a))/180.0f);
01115 glVertex(p0+(d1*f0)+(d2*f1));
01116 }
01117 glEnd();
01118 }
01119
01120 glPopAttrib ();
01121 glPopMatrix();
01122 }
01123
01124
01125 }
01126
01127 }
01128
01129 #endif //TRACKUTILS_H