TGLTransManip.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLTransManip.cxx 34006 2010-06-21 10:36:05Z matevz $
00002 // Author:  Richard Maunder  16/09/2005
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2005, 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 "TGLTransManip.h"
00013 #include "TGLPhysicalShape.h"
00014 #include "TGLCamera.h"
00015 #include "TGLIncludes.h"
00016 
00017 //////////////////////////////////////////////////////////////////////////
00018 //                                                                      //
00019 // TGLTransManip                                                        //
00020 //                                                                      //
00021 // Translation manipulator - attaches to physical shape and draws local //
00022 // axes widgets with arrow heads. User can mouse over (turns yellow) and//
00023 // L click/drag to translate along this axis.                           //
00024 // Widgets use standard 3D package axes colours: X red, Y green, Z blue.//
00025 //////////////////////////////////////////////////////////////////////////
00026 
00027 ClassImp(TGLTransManip)
00028 
00029 //______________________________________________________________________________
00030 TGLTransManip::TGLTransManip()
00031 {
00032    // Construct translation manipulator not bound to any physical shape.
00033 }
00034 
00035 //______________________________________________________________________________
00036 TGLTransManip::TGLTransManip(TGLPhysicalShape * shape) :
00037    TGLManip(shape)
00038 {
00039    // Construct translation manipulator, attached to supplied TGLViewer
00040    // 'viewer', bound to TGLPhysicalShape 'shape'.
00041 }
00042 
00043 //______________________________________________________________________________
00044 TGLTransManip::~TGLTransManip()
00045 {
00046    // Destory the translation manipulator
00047 }
00048 
00049 //______________________________________________________________________________
00050 void TGLTransManip::Draw(const TGLCamera & camera) const
00051 {
00052    // Draw translation manipulator - tubes with arrow heads, in local axes of
00053    // attached shape, in red(X), green(Y) and blue(Z), with white center sphere.
00054    // If selected widget (mouse over) this is drawn in active colour (yellow).
00055    if (!fShape) {
00056       return;
00057    }
00058 
00059    // Get draw scales
00060    const TGLBoundingBox & box = fShape->BoundingBox();
00061    Double_t baseScale;
00062    TGLVector3 axisScale[3];
00063    CalcDrawScale(box, camera, baseScale, axisScale);
00064 
00065    // Get permitted manipulations on shape
00066    TGLPhysicalShape::EManip manip = fShape->GetManip();
00067 
00068    glEnable(GL_BLEND);
00069    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
00070    glDisable(GL_CULL_FACE);
00071 
00072    // Draw three axis widgets out of bounding box where permitted
00073    // Not drawing will prevent interaction
00074    // GL name loading for hit testing - 0 reserved for no selection
00075    if (manip & TGLPhysicalShape::kTranslateX) {
00076       glPushName(1);
00077       TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
00078                         baseScale, ColorFor(1));
00079       glPopName();
00080    } else {
00081       TGLUtil::DrawLine(box.Center(), axisScale[0], TGLUtil::kLineHeadArrow,
00082                         baseScale, TGLUtil::fgGrey);
00083    }
00084    if (manip & TGLPhysicalShape::kTranslateY) {
00085       glPushName(2);
00086       TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
00087                         baseScale, ColorFor(2));
00088       glPopName();
00089    } else {
00090       TGLUtil::DrawLine(box.Center(), axisScale[1], TGLUtil::kLineHeadArrow,
00091                         baseScale, TGLUtil::fgGrey);
00092    }
00093    if (manip & TGLPhysicalShape::kTranslateZ) {
00094       glPushName(3);
00095       TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
00096                         baseScale, ColorFor(3));
00097       glPopName();
00098    } else {
00099       TGLUtil::DrawLine(box.Center(), axisScale[2], TGLUtil::kLineHeadArrow,
00100                         baseScale, TGLUtil::fgGrey);
00101    }
00102    // Draw white center sphere
00103    TGLUtil::DrawSphere(box.Center(), baseScale/2.0, TGLUtil::fgWhite);
00104 
00105    glEnable(GL_CULL_FACE);
00106    glDisable(GL_BLEND);
00107 }
00108 
00109 //______________________________________________________________________________
00110 Bool_t TGLTransManip::HandleMotion(const Event_t        & event,
00111                                    const TGLCamera      & camera)
00112 {
00113    // Handle mouse motion over manipulator - if active (selected
00114    // widget) translate physical along selected widget (axis) of the
00115    // manipulator, so it tracks mouse action. Returns kTRUE if redraw
00116    // required kFALSE otherwise.
00117    if (fActive) {
00118       // Find mouse delta projected into world at attached object center
00119       TGLVector3 shift =
00120          camera.ViewportDeltaToWorld( fShape->BoundingBox().Center(),
00121                                       event.fX - fLastMouse.GetX(),
00122                                      -event.fY + fLastMouse.GetY() ); // Y inverted
00123 
00124       // Now project this delta onto the current widget (axis) to give
00125       // a constrained shift along this
00126       UInt_t axisIndex = fSelectedWidget - 1; // Ugg sort out axis / widget id mapping
00127       TGLVector3 widgetAxis = fShape->BoundingBox().Axis(axisIndex, kTRUE);
00128       TGLVector3 constrainedShift = widgetAxis * Dot(shift, widgetAxis);
00129       fShape->Translate(constrainedShift);
00130 
00131       fLastMouse.SetX(event.fX);
00132       fLastMouse.SetY(event.fY);
00133 
00134       return kTRUE;
00135    }
00136    return kFALSE;
00137 }
00138 

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