TGLPlotCamera.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLPlotCamera.cxx 33579 2010-05-19 12:43:08Z rdm $
00002 // Author: Timur Pocheptsov
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 #include "TGLPlotCamera.h"
00012 #include "TGLIncludes.h"
00013 #include "TVirtualGL.h"
00014 
00015 //______________________________________________________________________________
00016 //
00017 // Camera for TGLPlotPainter and sub-classes.
00018 
00019 ClassImp(TGLPlotCamera);
00020 
00021 //______________________________________________________________________________
00022 TGLPlotCamera::TGLPlotCamera() :
00023    fZoom(1.), fShift(1.5), fCenter(),
00024    fVpChanged(kFALSE)
00025 {
00026    //Construct camera for plot painters.
00027    fOrthoBox[0] = 1.;
00028    fOrthoBox[1] = 1.;
00029    fOrthoBox[2] = -100.;
00030    fOrthoBox[3] = 100.;
00031 }
00032 
00033 //______________________________________________________________________________
00034 void TGLPlotCamera::SetViewport(const TGLRect &vp)
00035 {
00036    //Setup viewport, if it was changed, plus reset arcball.
00037    
00038    if (vp.Width() != fViewport.Width() || vp.Height() != fViewport.Height() ||
00039        vp.X() != fViewport.X() || vp.Y() != fViewport.Y())
00040    {
00041       fVpChanged = kTRUE;
00042       fArcBall.SetBounds(vp.Width(), vp.Height());
00043       fViewport = vp;
00044       
00045    } else
00046       fVpChanged = kFALSE;
00047 }
00048 
00049 //______________________________________________________________________________
00050 void TGLPlotCamera::SetViewVolume(const TGLVertex3* /* box */)
00051 {
00052    //'box' is the TGLPlotPainter's back box's coordinates.
00053 /*   fCenter[0] = (box[0].X() + box[1].X()) / 2;
00054    fCenter[1] = (box[0].Y() + box[2].Y()) / 2;
00055    fCenter[2] = (box[0].Z() + box[4].Z()) / 2;
00056    const Double_t maxDim = box[1].X() - box[0].X();
00057    fOrthoBox[0] = maxDim;
00058    fOrthoBox[1] = maxDim;
00059    fOrthoBox[2] = -100 * maxDim;//100?
00060    fOrthoBox[3] = 100 * maxDim;
00061    fShift = maxDim * 1.5;*/
00062 }
00063 
00064 //______________________________________________________________________________
00065 void TGLPlotCamera::StartRotation(Int_t px, Int_t py)
00066 {
00067    //User clicks somewhere (px, py).
00068    fArcBall.Click(TPoint(px, py));
00069 }
00070 
00071 //______________________________________________________________________________
00072 void TGLPlotCamera::RotateCamera(Int_t px, Int_t py)
00073 {
00074    //Mouse movement.
00075    fArcBall.Drag(TPoint(px, py));
00076 }
00077 
00078 //______________________________________________________________________________
00079 void TGLPlotCamera::StartPan(Int_t px, Int_t py)
00080 {
00081    //User clicks somewhere (px, py).
00082    fMousePos.fX = px;
00083    fMousePos.fY = fViewport.Height() - py;
00084 }
00085 
00086 //______________________________________________________________________________
00087 void TGLPlotCamera::Pan(Int_t px, Int_t py)
00088 {
00089    //Pan camera.
00090    py = fViewport.Height() - py;
00091    //Extract gl matrices.
00092    Double_t mv[16] = {0.};
00093    glGetDoublev(GL_MODELVIEW_MATRIX, mv);
00094    Double_t pr[16] = {0.};
00095    glGetDoublev(GL_PROJECTION_MATRIX, pr);
00096    Int_t vp[] = {0, 0, fViewport.Width(), fViewport.Height()};
00097    //Adjust pan vector.
00098    TGLVertex3 start, end;
00099    gluUnProject(fMousePos.fX, fMousePos.fY, 1., mv, pr, vp, &start.X(), &start.Y(), &start.Z());
00100    gluUnProject(px, py, 1., mv, pr, vp, &end.X(), &end.Y(), &end.Z());
00101    fTruck += (start - end) /= 2.;
00102    fMousePos.fX = px;
00103    fMousePos.fY = py;
00104 }
00105 
00106 //______________________________________________________________________________
00107 void TGLPlotCamera::SetCamera()const
00108 {
00109    //Viewport and projection.
00110    glViewport(fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height());
00111 
00112    glMatrixMode(GL_PROJECTION);
00113    glLoadIdentity();
00114    glOrtho(
00115            -fOrthoBox[0] * fZoom,
00116             fOrthoBox[0] * fZoom,
00117            -fOrthoBox[1] * fZoom,
00118             fOrthoBox[1] * fZoom,
00119             fOrthoBox[2],
00120             fOrthoBox[3]
00121           );
00122 
00123    glMatrixMode(GL_MODELVIEW);
00124    glLoadIdentity();
00125 }
00126 
00127 //______________________________________________________________________________
00128 void TGLPlotCamera::Apply(Double_t phi, Double_t theta)const
00129 {
00130    //Applies rotations and translations before drawing
00131    glTranslated(0., 0., -fShift);
00132    glMultMatrixd(fArcBall.GetRotMatrix());
00133    glRotated(theta - 90., 1., 0., 0.);
00134    glRotated(phi, 0., 0., 1.);
00135    glTranslated(-fTruck[0], -fTruck[1], -fTruck[2]);
00136 //   glTranslated(-fCenter[0], -fCenter[1], -fCenter[2]);
00137 }
00138 
00139 //______________________________________________________________________________
00140 Int_t TGLPlotCamera::GetX()const
00141 {
00142    //viewport[0]
00143    return fViewport.X();
00144 }
00145 
00146 //______________________________________________________________________________
00147 Int_t TGLPlotCamera::GetY()const
00148 {
00149    //viewport[1]
00150    return fViewport.Y();
00151 }
00152 
00153 //______________________________________________________________________________
00154 Int_t TGLPlotCamera::GetWidth()const
00155 {
00156    //viewport[2]
00157    return Int_t(fViewport.Width());
00158 }
00159 
00160 //______________________________________________________________________________
00161 Int_t TGLPlotCamera::GetHeight()const
00162 {
00163    //viewport[3]
00164    return Int_t(fViewport.Height());
00165 }
00166 
00167 //______________________________________________________________________________
00168 void TGLPlotCamera::ZoomIn()
00169 {
00170    //Zoom in.
00171    fZoom /= 1.2;
00172 }
00173 
00174 //______________________________________________________________________________
00175 void TGLPlotCamera::ZoomOut()
00176 {
00177    //Zoom out.
00178    fZoom *= 1.2;
00179 }

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