#include "TVirtualGL.h"
#include "TMath.h"
#include "TGLOrthoCamera.h"
#include "TGLIncludes.h"
#include "TGLUtil.h"
ClassImp(TGLOrthoCamera)
UInt_t TGLOrthoCamera::fgZoomDeltaSens = 500;
TGLOrthoCamera::TGLOrthoCamera(EType type) :
fType(type), fZoomMin(0.01), fZoomDefault(0.78), fZoomMax(1000.0),
fVolume(TGLVertex3(-100.0, -100.0, -100.0), TGLVertex3(100.0, 100.0, 100.0)),
fZoom(1.0), fTruck(0.0, 0.0, 0.0), fMatrix()
{
Setup(TGLBoundingBox(TGLVertex3(-100,-100,-100), TGLVertex3(100,100,100)));
}
TGLOrthoCamera::TGLOrthoCamera() :
fType(kXOY), fZoomMin(0.01), fZoomDefault(0.78), fZoomMax(1000.0),
fVolume(TGLVertex3(-100.0, -100.0, -100.0), TGLVertex3(100.0, 100.0, 100.0)),
fZoom(1.0), fTruck(0.0, 0.0, 0.0), fShift(0.), fCenter(),
fVpChanged(kFALSE)
{
fOrthoBox[0] = 1.;
fOrthoBox[1] = 1.;
fOrthoBox[2] = -1.;
fOrthoBox[3] = 1.;
}
TGLOrthoCamera::~TGLOrthoCamera()
{
}
void TGLOrthoCamera::Setup(const TGLBoundingBox & box, Bool_t reset)
{
static const Double_t rotMatrixXOY[] = { 1., 0., 0., 0.,
0., 1., 0., 0.,
0., 0., 1., 0.,
0., 0., 0., 1. };
static const Double_t rotMatrixXOZ[] = { 1., 0., 0., 0.,
0., 0., -1., 0.,
0., 1., 0., 0.,
0., 0., 0., 1. };
static const Double_t rotMatrixZOY[] = { 0., 0., -1., 0.,
0., 1., 0., 0.,
1., 0., 0., 0.,
0., 0., 0., 1. };
switch (fType) {
case (kXOY): {
fVolume = box;
fMatrix.Set(rotMatrixXOY);
break;
}
case (kXOZ): {
fVolume.SetAligned(TGLVertex3(box.XMin(), box.ZMin(), box.YMin()),
TGLVertex3(box.XMax(), box.ZMax(), box.YMax()));
fMatrix.Set(rotMatrixXOZ);
break;
}
case (kZOY): {
fVolume.SetAligned(TGLVertex3(box.ZMin(), box.YMin(), box.XMin()),
TGLVertex3(box.ZMax(), box.YMax(), box.XMax()));
fMatrix.Set(rotMatrixZOY);
break;
}
}
if (reset)
Reset();
}
void TGLOrthoCamera::Reset()
{
fTruck.Set(0.0, 0.0, 0.0);
fZoom = fZoomDefault;
IncTimeStamp();
}
Bool_t TGLOrthoCamera::Dolly(Int_t delta, Bool_t mod1, Bool_t mod2)
{
return Zoom(delta, mod1, mod2);
}
Bool_t TGLOrthoCamera::Zoom (Int_t delta, Bool_t mod1, Bool_t mod2)
{
if (AdjustAndClampVal(fZoom, fZoomMin, fZoomMax, -delta*2, fgZoomDeltaSens, mod1, mod2))
{
IncTimeStamp();
return kTRUE;
}
else
{
return kFALSE;
}
}
Bool_t TGLOrthoCamera::Truck(Int_t x, Int_t y, Int_t xDelta, Int_t yDelta)
{
GLint viewport[4] = { fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height() };
TGLVertex3 start, end;
gluUnProject(x, y, 0.0, fModVM.CArr(), fProjM.CArr(), viewport, &start.X(), &start.Y(), &start.Z());
gluUnProject(x + xDelta, y + yDelta, 0.0, fModVM.CArr(), fProjM.CArr(), viewport, &end.X(), &end.Y(), &end.Z());
fTruck = fTruck + (end - start);
IncTimeStamp();
return kTRUE;
}
Bool_t TGLOrthoCamera::Rotate(Int_t , Int_t )
{
return kFALSE;
}
void TGLOrthoCamera::Apply(const TGLBoundingBox & ,
const TGLRect * pickRect) const
{
glViewport(fViewport.X(), fViewport.Y(), fViewport.Width(), fViewport.Height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (pickRect)
{
TGLRect rect(*pickRect);
WindowToViewport(rect);
gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
(Int_t*) fViewport.CArr());
}
if(fViewport.Width() == 0 || fViewport.Height() == 0) {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
return;
}
TGLVector3 extents = fVolume.Extents();
Double_t width = extents.X();
Double_t height = extents.Y();
Double_t halfRange;
if (width > height) {
halfRange = width / 2.0;
} else {
halfRange = height / 2.0;
}
halfRange /= fZoom;
Double_t halfDepth = extents.Mag();
const TGLVertex3 & center = fVolume.Center();
glOrtho(center.X() - halfRange,
center.X() + halfRange,
center.Y() - halfRange,
center.Y() + halfRange,
center.Z() - halfDepth,
center.Z() + halfDepth);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScaled(1.0 / fViewport.Aspect(), 1.0, 1.0);
glMultMatrixd(fMatrix.CArr());
glTranslated(fTruck.X(), fTruck.Y(), fTruck.Z());
if (fCacheDirty) {
UpdateCache();
}
}
void TGLOrthoCamera::Configure(Double_t left, Double_t right,
Double_t top, Double_t bottom)
{
Double_t width = right - left;
Double_t height = top - bottom;
Double_t xZoom = width/fVolume.Extents().X();
Double_t yZoom = height/fVolume.Extents().Y();
fZoom = (xZoom > yZoom) ? xZoom : yZoom;
if (fType == kXOY) {
fTruck.X() = right - left;
fTruck.Y() = top - bottom;
} else if (fType == kXOZ) {
fTruck.X() = right - left;
fTruck.Z() = top - bottom;
} else if (fType == kZOY) {
fTruck.Z() = right - left;
fTruck.Y() = top - bottom;
}
IncTimeStamp();
}
void TGLOrthoCamera::SetViewport(TGLPaintDevice *dev)
{
Int_t vp[4] = {0};
dev->ExtractViewport(vp);
if (vp[2] != Int_t(fViewport.Width()) || vp[3] != Int_t(fViewport.Height()) ||
vp[0] != fViewport.X() || vp[1] != fViewport.Y())
{
fVpChanged = kTRUE;
fArcBall.SetBounds(vp[2], vp[3]);
fViewport.Set(vp[0], vp[1], vp[2], vp[3]);
} else
fVpChanged = kFALSE;
}
void TGLOrthoCamera::SetViewVolume(const TGLVertex3 *box)
{
fCenter[0] = (box[0].X() + box[1].X()) / 2;
fCenter[1] = (box[0].Y() + box[2].Y()) / 2;
fCenter[2] = (box[0].Z() + box[4].Z()) / 2;
const Double_t maxDim = box[1].X() - box[0].X();
fOrthoBox[0] = maxDim;
fOrthoBox[1] = maxDim;
fOrthoBox[2] = -100 * maxDim;
fOrthoBox[3] = 100 * maxDim;
fShift = maxDim * 1.5;
}
void TGLOrthoCamera::StartRotation(Int_t px, Int_t py)
{
fArcBall.Click(TPoint(px, py));
}
void TGLOrthoCamera::RotateCamera(Int_t px, Int_t py)
{
fArcBall.Drag(TPoint(px, py));
}
void TGLOrthoCamera::StartPan(Int_t px, Int_t py)
{
fMousePos.fX = px;
fMousePos.fY = fViewport.Height() - py;
}
void TGLOrthoCamera::Pan(Int_t px, Int_t py)
{
py = fViewport.Height() - py;
Double_t mv[16] = {0.};
glGetDoublev(GL_MODELVIEW_MATRIX, mv);
Double_t pr[16] = {0.};
glGetDoublev(GL_PROJECTION_MATRIX, pr);
Int_t vp[] = {0, 0, fViewport.Width(), fViewport.Height()};
TGLVertex3 start, end;
gluUnProject(fMousePos.fX, fMousePos.fY, 1., mv, pr, vp, &start.X(), &start.Y(), &start.Z());
gluUnProject(px, py, 1., mv, pr, vp, &end.X(), &end.Y(), &end.Z());
fTruck += (start - end) /= 2.;
fMousePos.fX = px;
fMousePos.fY = py;
}
void TGLOrthoCamera::SetCamera()const
{
glViewport(0, 0, fViewport.Width(), fViewport.Height());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(
-fOrthoBox[0] * fZoom,
fOrthoBox[0] * fZoom,
-fOrthoBox[1] * fZoom,
fOrthoBox[1] * fZoom,
fOrthoBox[2],
fOrthoBox[3]
);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void TGLOrthoCamera::Apply()const
{
glTranslated(0., 0., -fShift);
glMultMatrixd(fArcBall.GetRotMatrix());
glRotated(45., 1., 0., 0.);
glRotated(-45., 0., 1., 0.);
glRotated(-90., 0., 1., 0.);
glRotated(-90., 1., 0., 0.);
glTranslated(-fTruck[0], -fTruck[1], -fTruck[2]);
glTranslated(-fCenter[0], -fCenter[1], -fCenter[2]);
}
Int_t TGLOrthoCamera::GetX()const
{
return fViewport.X();
}
Int_t TGLOrthoCamera::GetY()const
{
return fViewport.Y();
}
Int_t TGLOrthoCamera::GetWidth()const
{
return Int_t(fViewport.Width());
}
Int_t TGLOrthoCamera::GetHeight()const
{
return Int_t(fViewport.Height());
}
void TGLOrthoCamera::ZoomIn()
{
fZoom /= 1.2;
}
void TGLOrthoCamera::ZoomOut()
{
fZoom *= 1.2;
}
void TGLOrthoCamera::Markup(TGLCameraMarkupStyle* ms) const
{
TGLVector3 extents = fVolume.Extents();
Double_t width = extents.X()/fZoom;
Double_t maxbarw0 = ms->Barsize()*width;
Int_t exp = (Int_t) TMath::Floor(TMath::Log10(maxbarw0));
Double_t fact = maxbarw0/TMath::Power(10, exp);
Float_t barw;
if (fact > 5) {
barw = 5*TMath::Power(10, exp);
glColor3d(1., 0., 1.0);
}
else if (fact > 2) {
barw = 2*TMath::Power(10, exp);
glColor3d(0., 1., 1.0);
} else {
barw = TMath::Power(10, exp);
glColor3d(0., 0., 1.0);
}
Double_t wproc = barw / width;
Int_t screenw = fViewport.Width();
Int_t screenh = fViewport.Height();
Double_t sX, sY;
Double_t offX, offY, txtOffX, txtOffY;
ms->Offsets(offX, offY, txtOffX, txtOffY);
switch (ms->Position())
{
case TGLCameraMarkupStyle::kLUp:
sX = offX;
sY = screenh - offY - txtOffY - 8;
break;
case TGLCameraMarkupStyle::kLDn:
sX = offX;
sY = offY;
break;
case TGLCameraMarkupStyle::kRUp:
sX = screenw - ms->Barsize()*screenw - offX;
sY = screenh - offY - txtOffY - 8;
break;
case TGLCameraMarkupStyle::kRDn:
sX = screenw - ms->Barsize()*screenw - offX;
sY = offY;
break;
default:
sX = 0.5*screenw;
sY = 0.5*screenh;
break;
}
glTranslatef(sX, sY, 0);
glLineWidth(2.);
glColor3d(1., 1., 1.);
Double_t mH = 2;
glBegin(GL_LINES);
glVertex3d(0, 0.,0.);
glVertex3d(ms->Barsize()*screenw, 0., 0.);
glVertex3d(ms->Barsize()*screenw, mH, 0.);
glVertex3d(ms->Barsize()*screenw, -mH, 0.);
glColor3d(1., 0., 0.);
glVertex3d(0., mH, 0.);
glVertex3d(0., -mH, 0.);
glVertex3d(screenw*wproc, 0., 0.);
glVertex3d(screenw*wproc, mH, 0.);
glVertex3d(0, 0.,0.);
glVertex3d(screenw*wproc, 0., 0.);
glEnd();
glTranslated(-sX, -sY, 0);
TString str = Form("%.*f", (exp < 0) ? -exp : 0, barw);
TGLUtil::DrawNumber(str, TGLVertex3(sX + txtOffX, sY + txtOffY, -1));
}
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.