Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

TridFlatGLFrame.cxx

Go to the documentation of this file.
00001 #include "TridFlatGLFrame.h"
00002 #include "TridPage.h"
00003 #include "TridSketches.h"
00004 #include "TridOpenGLGlobal.h"
00005 
00006 #include "MessageService/MsgService.h"
00007 
00008 #include "TROOT.h"
00009 #include "TGX11.h"
00010 #include "TVirtualX.h"
00011 #include "KeySymbols.h"
00012 
00013 #include <GL/gl.h>
00014 #include <GL/glx.h>
00015 #include <GL/glu.h>
00016 #include "glf.h"
00017 #include <cmath>
00018 #include <cstdlib>
00019 #include <iostream>
00020 
00021 using namespace std;
00022 
00023 CVSID("$Id: TridFlatGLFrame.cxx,v 1.17 2009/02/28 21:46:17 gmieg Exp $");
00024 
00025 TridFlatGLFrame::TridFlatGLFrame(TridPage* tp, TGWindow& parent, TridControl* tc,
00026                                  const TridPOV& min,
00027                                  const TridPOV& max,
00028                                  double scale )
00029   : TridGLFrame( tp, parent, tc, min, max )
00030 {
00031   //
00032   // 'scale' is the way to scale OpenGL units to window size.  This is a course control,
00033   // overridden by the user.
00034   //
00035   // Min/max x/y are not limits for drawing, but rather limits to how far the POV center can be moved.
00036   // These should compare roughly with the drawable area.
00037   // 
00038   //
00039   fScale = scale;
00040 
00041   MSG("TriD",Msg::kDebug) << "TridFlatGLFrame constructor." << endl;
00042 }
00043 
00044 TridFlatGLFrame::~TridFlatGLFrame()
00045 {
00046   MSG("TriD",Msg::kDebug) << "TridFlatGLFrame constructor." << endl;
00047 }
00048 
00049 void TridFlatGLFrame::SetupProjection( void )
00050 {
00051   // Set up the projection for the 3d window.
00052   float ratio = 1;
00053   if(fWidth>0) ratio = (float)fHeight/(float)fWidth;
00054   glOrtho(-1.0,1.0,
00055           -ratio,ratio,
00056           -1000.,1000.);
00057 }
00058 
00059 void TridFlatGLFrame::SetupOptions( ) 
00060 {
00061   // Enables Smooth Color Shading; try GL_FLAT for (lack of) fun.
00062   glShadeModel(GL_SMOOTH);
00063   glEnable(GL_DEPTH_TEST); // Disable depth test if blending
00064   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00065   glEnable(GL_BLEND);
00066  
00067 }
00068 
00069 void TridFlatGLFrame::SetupLighting( Bool_t  )
00070 {
00071   // Always do no lighting in these views.
00072   TridGLFrame::SetupLighting(false);
00073 } 
00074 
00075 void TridFlatGLFrame::TransformToPOV( void )
00076 {
00077   NormalizeAndClipPOV();
00078   
00079   // Need to manipulate the ModelView matrix to move our model around.
00080   glMatrixMode(GL_MODELVIEW);
00081   
00082   // Reset to 0,0,0; no rotation, no scaling.
00083   glLoadIdentity();   
00084   
00085   // 0.647 is a magic number found by trial and error: should match 
00086   // the center of the plot nicely.
00087   double scale = (fScale/(fPOV.GetDist()+1.));
00088   if(fPOV.GetDist()<1)  scale = (fScale*exp(-fPOV.GetDist()) );
00089   glScaled(scale,scale,scale);
00090   
00091   // Rotate to our view.
00092   glRotatef(fPOV.GetTheta(),1.0f,0.0f,0.0f); // Rotate to elevation.
00093   glRotatef(fPOV.GetPhi()  ,0.0f,1.0f,0.0f); // Rotate to side
00094 
00095 
00096   // Move to our viewpoint.
00097   glTranslatef(-fPOV.GetX(), -fPOV.GetY(), -fPOV.GetZ() );  // Move to our viewpoint.
00098 
00099 }
00100 
00101 
00102 
00103 Bool_t TridFlatGLFrame::HandleMotion(Event_t* ev)
00104 {
00105   if(fButton == 0 ) {
00106     // The mouse is travelling.. pick and show.
00107     UInt_t name = Pick(ev->fX,ev->fY);
00108     if(name!=fPicked) {
00109       fPicked = name;
00110       fTridPage->MouseOver(fPicked);
00111       Update();
00112     }
00113   } else {
00114 
00115     int delx, dely;
00116     delx = ev->fX - fMouseLast_x;
00117     dely = ev->fY - fMouseLast_y;
00118     fButtonTraveled+= abs(delx) + abs(dely);
00119     
00120     if(abs(delx) + abs(dely)>0){
00121       if( (fButton ==kButton1) || (fButton ==kButton3) ) {
00122         // Slide.
00123         
00124         GLfloat z;
00125         GLdouble x1, y1, z1;
00126         GLdouble x2, y2, z2;
00127         GLdouble  model[16];
00128         GLdouble  proj[16];
00129         GLint     view[4];
00130         glGetDoublev(GL_MODELVIEW_MATRIX, model);
00131         glGetDoublev(GL_PROJECTION_MATRIX, proj);
00132         glGetIntegerv(GL_VIEWPORT, view); 
00133         
00134         glReadPixels(fMouseLast_x, fHeight-fMouseLast_y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
00135         gluUnProject(fMouseLast_x, fHeight-fMouseLast_y,  z, model, proj, view, &x1, &y1, &z1);
00136         gluUnProject(ev->fX,        fHeight-ev->fY,       z, model, proj, view, &x2, &y2, &z2);
00137         
00138         fPOV.fx -= x2-x1;
00139         fPOV.fy -= y2-y1;
00140         fPOV.fz -= z2-z1;
00141 
00142         fPOV.Push();
00143         Update();
00144       }
00145       
00146       if( fButton == kButton2 ) {
00147         // Scale.  Towards center means shrink, away from center means grow.
00148         if(abs(delx) + abs(dely)>0){
00149           float sdx = (float)(fMouseLast_x - (fWidth/2.));
00150           float sdy = (float)(fMouseLast_y - (fHeight/2.));
00151           float dot = sdx*delx + sdy*dely;
00152           dot = dot/sqrt(sdy*sdy+sdx*sdx);
00153           
00154           fPOV.fDist -= dot*100/(double)(fWidth);
00155           fPOV.PushIfChanged();
00156           Update();
00157         }
00158       }
00159 
00160     }
00161     
00162     fMouseLast_x = ev->fX;
00163     fMouseLast_y = ev->fY;
00164   }
00165 
00166   return true;
00167 }
00168 
00169 
00170 void TridFlatGLFrame::DrawObjects(  )
00171 {
00172   glMatrixMode(GL_MODELVIEW);
00173   TridSketchListItr itr = GetIterator();
00174   TridSketch* sketch;
00175   fNumSketches = 0;
00176   fNumSketchesDrawn = 0;
00177 
00178   itr.Reset();
00179   while( (sketch = itr.Next()) ){
00180     fNumSketches++;
00181     Bool_t drawn = sketch->Draw(fAnimTimeMin, fAnimTimeMax);
00182     if(drawn) fNumSketchesDrawn++;
00183   }
00184 }

Generated on Mon Feb 15 11:07:43 2010 for loon by  doxygen 1.3.9.1