00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "TGLPlotCamera.h"
00012 #include "TGLIncludes.h"
00013 #include "TVirtualGL.h"
00014
00015
00016
00017
00018
00019 ClassImp(TGLPlotCamera);
00020
00021
00022 TGLPlotCamera::TGLPlotCamera() :
00023 fZoom(1.), fShift(1.5), fCenter(),
00024 fVpChanged(kFALSE)
00025 {
00026
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
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* )
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 }
00063
00064
00065 void TGLPlotCamera::StartRotation(Int_t px, Int_t py)
00066 {
00067
00068 fArcBall.Click(TPoint(px, py));
00069 }
00070
00071
00072 void TGLPlotCamera::RotateCamera(Int_t px, Int_t py)
00073 {
00074
00075 fArcBall.Drag(TPoint(px, py));
00076 }
00077
00078
00079 void TGLPlotCamera::StartPan(Int_t px, Int_t py)
00080 {
00081
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
00090 py = fViewport.Height() - py;
00091
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
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
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
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
00137 }
00138
00139
00140 Int_t TGLPlotCamera::GetX()const
00141 {
00142
00143 return fViewport.X();
00144 }
00145
00146
00147 Int_t TGLPlotCamera::GetY()const
00148 {
00149
00150 return fViewport.Y();
00151 }
00152
00153
00154 Int_t TGLPlotCamera::GetWidth()const
00155 {
00156
00157 return Int_t(fViewport.Width());
00158 }
00159
00160
00161 Int_t TGLPlotCamera::GetHeight()const
00162 {
00163
00164 return Int_t(fViewport.Height());
00165 }
00166
00167
00168 void TGLPlotCamera::ZoomIn()
00169 {
00170
00171 fZoom /= 1.2;
00172 }
00173
00174
00175 void TGLPlotCamera::ZoomOut()
00176 {
00177
00178 fZoom *= 1.2;
00179 }