#include "TGLManip.h"
#include "TGLUtil.h"
#include "TGLCamera.h"
#include "TGLViewer.h"
#include "TGLPhysicalShape.h"
#include "TGLIncludes.h"
#include "TVirtualGL.h"
ClassImp(TGLManip)
Float_t TGLManip::fgRed[4] = {0.8, 0.0, 0.0, 1.0 };
Float_t TGLManip::fgGreen[4] = {0.0, 0.8, 0.0, 1.0 };
Float_t TGLManip::fgBlue[4] = {0.0, 0.0, 0.8, 1.0 };
Float_t TGLManip::fgYellow[4] = {0.8, 0.8, 0.0, 1.0 };
Float_t TGLManip::fgWhite[4] = {1.0, 1.0, 1.0, 1.0 };
Float_t TGLManip::fgGrey[4] = {0.5, 0.5, 0.5, 0.4 };
TGLManip::TGLManip() :
fShape(0),
fSelectedWidget(0), fActive(kFALSE),
fFirstMouse(0, 0),
fLastMouse(0, 0)
{
}
TGLManip::TGLManip(TGLPhysicalShape * shape) :
fShape(shape),
fSelectedWidget(0), fActive(kFALSE),
fFirstMouse(0, 0),
fLastMouse(0, 0)
{
}
TGLManip::TGLManip(const TGLManip& gm) :
TVirtualGLManip(gm),
fShape(gm.fShape),
fSelectedWidget(gm.fSelectedWidget),
fActive(gm.fActive),
fFirstMouse(gm.fFirstMouse),
fLastMouse(gm.fLastMouse)
{
for(Int_t i=0; i<4; i++) {
fgRed[i]=gm.fgRed[i];
fgGreen[i]=gm.fgGreen[i];
fgBlue[i]=gm.fgBlue[i];
fgYellow[i]=gm.fgYellow[i];
fgWhite[i]=gm.fgWhite[i];
fgGrey[i]=gm.fgGrey[i];
}
}
TGLManip& TGLManip::operator=(const TGLManip& gm)
{
if(this!=&gm) {
TVirtualGLManip::operator=(gm);
fShape=gm.fShape;
fSelectedWidget=gm.fSelectedWidget;
fActive=gm.fActive;
fFirstMouse=gm.fFirstMouse;
fLastMouse=gm.fLastMouse;
for(Int_t i=0; i<4; i++) {
fgRed[i]=gm.fgRed[i];
fgGreen[i]=gm.fgGreen[i];
fgBlue[i]=gm.fgBlue[i];
fgYellow[i]=gm.fgYellow[i];
fgWhite[i]=gm.fgWhite[i];
fgGrey[i]=gm.fgGrey[i];
}
}
return *this;
}
TGLManip::~TGLManip()
{
}
Bool_t TGLManip::Select(const TGLCamera & camera, const TGLRect & rect, const TGLBoundingBox & sceneBox)
{
UInt_t oldSelection = fSelectedWidget;
TGLRect viewportRect = rect;
camera.WindowToViewport(viewportRect);
camera.Apply(sceneBox, &viewportRect);
static UInt_t selectBuffer[4*4];
glSelectBuffer(4*4, &selectBuffer[0]);
glRenderMode(GL_SELECT);
glInitNames();
Draw(camera);
Int_t hits = glRenderMode(GL_RENDER);
TGLUtil::CheckError("TGLManip::Select");
if (hits < 0) {
Error("TGLManip::Select", "selection buffer overflow");
return kFALSE;
}
if (hits > 0) {
fSelectedWidget = 0;
UInt_t minDepth = kMaxUInt;
for (Int_t i = 0; i < hits; i++) {
if (selectBuffer[i * 4] == 0) {
continue;
}
if (selectBuffer[i * 4 + 1] < minDepth) {
fSelectedWidget = selectBuffer[i * 4 + 3];
minDepth = selectBuffer[i * 4 + 1];
}
}
} else {
fSelectedWidget = 0;
}
return (fSelectedWidget != oldSelection);
}
Bool_t TGLManip::HandleButton(const Event_t & event, const TGLCamera & )
{
if (event.fCode != kButton1) {
return kFALSE;
}
if (event.fType == kButtonPress && fSelectedWidget != 0) {
fFirstMouse.SetX(event.fX);
fFirstMouse.SetY(event.fY);
fLastMouse.SetX(event.fX);
fLastMouse.SetY(event.fY);
fActive = kTRUE;
return kTRUE;
} else if (event.fType == kButtonRelease && fActive) {
fActive = kFALSE;
return kTRUE;
} else {
return kFALSE;
}
}
Bool_t TGLManip::HandleMotion(const Event_t & event, const TGLCamera & camera, const TGLBoundingBox & sceneBox)
{
TGLRect selectRect(event.fX, event.fY, 3, 3);
if (gGLManager)
return gGLManager->SelectManip(this, &camera, &selectRect, &sceneBox);
return gVirtualGL->SelectManip(this, &camera, &selectRect, &sceneBox);
}
void TGLManip::CalcDrawScale(const TGLBoundingBox & box, const TGLCamera & camera,
Double_t & base, TGLVector3 axis[3]) const
{
base = box.Extents().Mag() / 100.0;
TGLVector3 pixelInWorld = camera.ViewportDeltaToWorld(box.Center(), 1, 1);
Double_t pixelScale = pixelInWorld.Mag();
if (base < pixelScale * 3.0) {
base = pixelScale * 3.0;
} else if (base > pixelScale * 6.0) {
base = pixelScale * 6.0;
}
for (UInt_t i = 0; i<3; i++) {
if (box.IsEmpty()) {
axis[i] = box.Axis(i, kTRUE)*base*-10.0;
} else {
axis[i] = box.Axis(i, kFALSE)*-0.51;
if (axis[i].Mag() < base*10.0) {
axis[i] *= base*10.0/axis[i].Mag();
}
}
}
}
ROOT page - Class index - Class Hierarchy - Top of the page
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.