TGLCameraGuide.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TGLCameraGuide.cxx 34006 2010-06-21 10:36:05Z matevz $
00002 // Author: Matevz Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TGLCameraGuide.h"
00013 #include "TGLRnrCtx.h"
00014 #include "TGLCamera.h"
00015 #include "TGLUtil.h"
00016 #include "TGLIncludes.h"
00017 #include "TGLSelectRecord.h"
00018 
00019 #include "TMath.h"
00020 
00021 //______________________________________________________________________________
00022 //
00023 // Draws arrows showing camera orientation in the overlay.
00024 // X, Y position is in range 0, 1.
00025 
00026 ClassImp(TGLCameraGuide);
00027 
00028 //______________________________________________________________________________
00029 TGLCameraGuide::TGLCameraGuide(Float_t x, Float_t y, Float_t s,
00030                                ERole role, EState state) :
00031    TGLOverlayElement(role, state),
00032    fXPos(x), fYPos(y), fSize(s),
00033    fSelAxis(-1), fInDrag(kFALSE)
00034 {
00035    // Constructor.
00036 }
00037 
00038 //______________________________________________________________________________
00039 Bool_t TGLCameraGuide::MouseEnter(TGLOvlSelectRecord& /*rec*/)
00040 {
00041    // Mouse has entered overlay area.
00042 
00043    return kTRUE;
00044 }
00045 
00046 
00047 //______________________________________________________________________
00048 Bool_t TGLCameraGuide::Handle(TGLRnrCtx&          rnrCtx,
00049                               TGLOvlSelectRecord&  selRec,
00050                               Event_t*             event)
00051 {
00052    // Handle overlay event.
00053    // Return TRUE if event was handled.
00054 
00055    if (selRec.GetN() < 2) return kFALSE;
00056    Int_t recID = selRec.GetItem(1);
00057 
00058    if (recID == 4)
00059       fSelAxis = 4;
00060    else
00061       fSelAxis = 0;
00062 
00063    switch (event->fType)
00064    {
00065       case kButtonPress:
00066       {
00067          if (recID == 4)
00068             fInDrag = kTRUE;
00069          return kTRUE;
00070       }
00071       case kButtonRelease:
00072       {
00073          fInDrag = kFALSE;
00074          return kTRUE;
00075       }
00076       case kMotionNotify:
00077       {
00078          if (fInDrag)
00079          {
00080             const TGLRect& vp = rnrCtx.RefCamera().RefViewport();
00081             if (vp.Width() == 0 || vp.Height() == 0) return kFALSE;
00082 
00083             fXPos = TMath::Range(0.0f, 1.0f, (Float_t)(event->fX) / vp.Width());
00084             fYPos = TMath::Range(0.0f, 1.0f, 1.0f - (Float_t)(event->fY) / vp.Height());
00085          }
00086          return kTRUE;
00087       }
00088       default:
00089       {
00090          return kFALSE;
00091       }
00092    }
00093 }
00094 
00095 //______________________________________________________________________
00096 void TGLCameraGuide::MouseLeave()
00097 {
00098    // Mouse has left overlay area.
00099 
00100    fSelAxis = -1;
00101    fInDrag  = kFALSE;
00102 }
00103 
00104 //______________________________________________________________________________
00105 void TGLCameraGuide::Render(TGLRnrCtx& rnrCtx)
00106 {
00107    // Render the camera axis arrows.
00108 
00109    TGLCapabilitySwitch lgt_off(GL_LIGHTING, kFALSE);
00110 
00111    rnrCtx.ProjectionMatrixPushIdentity();
00112    glPushMatrix();
00113    glLoadIdentity();
00114    glTranslatef(-1.0f, -1.0f, 0.0f);
00115    glScalef(2.0f, 2.0f, -2.0f);
00116    glTranslatef(fXPos, fYPos, -0.25f);
00117 
00118    Float_t aspect= rnrCtx.RefCamera().RefViewport().Aspect();
00119    if (aspect > 1)
00120       glScalef(1.0f / aspect, 1.0f, 1.0f);
00121    else if (aspect < 1)
00122       glScalef(1.0f, aspect, 1.0f);
00123 
00124    Float_t dr[2];
00125    glGetFloatv(GL_DEPTH_RANGE, dr);
00126    glDepthRange(0, 0.01);
00127 
00128    TGLVertex3 c;
00129    TGLVector3 e;
00130    const TGLMatrix &mv = rnrCtx.RefCamera().RefModelViewMatrix();
00131 
00132    glPushName(1);
00133    mv.GetBaseVec(1, e);
00134    e *= fSize;
00135    TGLUtil::DrawLine(c, e, TGLUtil::kLineHeadArrow, 0.1*fSize,
00136                      fSelAxis == 1 ? TGLUtil::fgYellow : TGLUtil::fgRed);
00137 
00138    glLoadName(2);
00139    mv.GetBaseVec(2, e);
00140    e *= fSize;
00141    TGLUtil::DrawLine(c, e, TGLUtil::kLineHeadArrow, 0.1*fSize,
00142                      fSelAxis == 2 ? TGLUtil::fgYellow : TGLUtil::fgGreen);
00143 
00144    glLoadName(3);
00145    mv.GetBaseVec(3, e);
00146    e *= fSize;
00147    TGLUtil::DrawLine(c, e, TGLUtil::kLineHeadArrow, 0.1*fSize,
00148                      fSelAxis == 3 ? TGLUtil::fgYellow : TGLUtil::fgBlue);
00149 
00150    glLoadName(4);
00151    TGLUtil::DrawSphere(c, 0.08*fSize,
00152                        fSelAxis == 4 ? TGLUtil::fgYellow : rnrCtx.ColorSet().Foreground().CArr());
00153 
00154    glPopName();
00155 
00156    glDepthRange(dr[0], dr[1]);
00157 
00158    glPopMatrix();
00159    rnrCtx.ProjectionMatrixPop();
00160 }

Generated on Tue Jul 5 14:18:06 2011 for ROOT_528-00b_version by  doxygen 1.5.1