3 #include "OsgMovableItem.h"
5 #include "OsgRigidBody.h"
8 #include "OsgUserData.h"
9 #include "OsgDragger.h"
10 #include "OsgTrackballDragger.h"
11 #include "OsgTranslateAxisDragger.h"
12 #include "OsgSimulator.h"
16 namespace Visualization
19 OsgDragger::OsgDragger(
OsgMovableItem *lpParent,
bool bAllowTranslateX,
bool bAllowTranslateY,
bool bAllowTranslateZ,
20 bool bAllowRotateX,
bool bAllowRotateY,
bool bAllowRotateZ,
float fltUserDefinedRadius)
23 THROW_ERROR(Al_Err_lParentNotDefined, Al_Err_strParentNotDefined);
25 if(fltUserDefinedRadius <= 0)
26 m_fltUserDefinedRadius = -1;
28 m_fltUserDefinedRadius = fltUserDefinedRadius;
30 m_lpVsParent = lpParent;
33 m_osgGripperMT =
new osg::MatrixTransform();
34 osg::Matrix osgMT; osgMT.makeIdentity();
35 m_osgGripperMT->setMatrix(osgMT);
36 m_osgGripperMT->addChild(
this);
48 _tbDragger->setName(
"TrackballDragger");
49 addChild(_tbDragger.get());
53 _transDragger->setName(
"TranslateAxisDragger");
54 addChild(_transDragger.get());
57 this->addDragger(_tbDragger.get());
58 this->addDragger(_transDragger.get());
59 this->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
60 this->setParentDragger(getParentDragger());
63 OsgDragger::~OsgDragger(
void)
70 _tbDragger->setupDefaultGeometry();
71 _transDragger->setupDefaultGeometry();
76 void OsgDragger::AddToScene()
79 if(m_lpVsParent && m_lpVsParent->RootGroup() && m_osgGripperMT.valid())
80 if(!m_lpVsParent->RootGroup()->containsNode(m_osgGripperMT.get()))
81 m_lpVsParent->RootGroup()->addChild(m_osgGripperMT.get());
84 void OsgDragger::RemoveFromScene()
86 if(m_lpVsParent && m_lpVsParent->RootGroup() && m_osgGripperMT.valid())
87 if(m_lpVsParent->RootGroup()->containsNode(m_osgGripperMT.get()))
88 m_lpVsParent->RootGroup()->removeChild(m_osgGripperMT.get());
91 bool OsgDragger::IsInScene()
93 if(m_lpVsParent && m_lpVsParent->RootGroup() && m_osgGripperMT.valid())
94 if(m_lpVsParent->RootGroup()->containsNode(m_osgGripperMT.get()))
100 void OsgDragger::SetupMatrix()
102 if(m_lpVsParent && m_lpVsParent->RootGroup() && m_osgGripperMT.valid())
107 float fltMaxDim = m_lpVsParent->Physics_GetBoundingRadius();
109 Simulator *lpSim = GetSimulator();
110 if(fltMaxDim > (lpSim->InverseDistanceUnits()/2.0f))
111 fltMaxDim = (lpSim->InverseDistanceUnits()/2.0f);
118 if(m_fltUserDefinedRadius > 0)
119 fltRadius = m_fltUserDefinedRadius;
121 fltRadius = fltMaxDim*0.501794454f + fltMaxDim;
128 m_osgGripperMT->setMatrix(m_lpVsParent->FinalMatrix());
131 osg::Matrix mtNull = osg::Matrix::identity();
132 mtNull *= osg::Matrix::scale(fltRadius,fltRadius,fltRadius);
133 this->setMatrix(mtNull);
137 osg::Matrix tempMT = m_lpVsParent->LocalMatrix(), invMT;
138 tempMT.setTrans(osg::Vec3f(0, 0, 0));
139 invMT.invert(tempMT);
145 float axesScale = 1.5;
146 invMT = invMT * osg::Matrix::scale(axesScale,axesScale,axesScale);
148 _transDragger->setMatrix(invMT);
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
void setupDefaultGeometry()
Declares the vortex structure class.