3 #include "OsgCalculateBoundingBox.h"
4 #include "OsgMovableItem.h"
6 #include "OsgRigidBody.h"
10 #include "OsgUserData.h"
11 #include "OsgUserDataVisitor.h"
13 #include "OsgMouseSpring.h"
15 #include "OsgCameraManipulator.h"
16 #include "OsgDragger.h"
17 #include "OsgSimulator.h"
28 OsgMovableItem::OsgMovableItem()
30 m_bCullBackfaces =
false;
31 m_eTextureMode = GL_TEXTURE_2D;
37 m_lpParentVsMI = NULL;
41 OsgMovableItem::~OsgMovableItem()
45 void OsgMovableItem::SetThisPointers()
47 m_lpThisAB =
dynamic_cast<AnimatBase *
>(
this);
49 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpThisAB");
51 m_lpThisMI =
dynamic_cast<MovableItem *
>(
this);
53 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpThisMI, " + m_lpThisAB->Name());
57 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpThisVsMI, " + m_lpThisAB->Name());
59 m_lpThisMI->PhysicsMovableItem(
this);
66 m_lpOsgSim =
dynamic_cast<OsgSimulator *
>(m_lpThisAB->GetSimulator());
68 THROW_TEXT_ERROR(Osg_Err_lThisPointerNotDefined, Osg_Err_strThisPointerNotDefined,
"m_lpOsgSim, " + m_lpThisAB->Name());
74 std::string OsgMovableItem::Physics_ID()
77 return m_lpThisAB->ID();
82 void OsgMovableItem::FinalMatrix(osg::Matrix vFinal)
84 m_osgFinalMatrix = vFinal;
86 Physics_UpdateAbsolutePosition();
89 #pragma region Selection-Code
91 void OsgMovableItem::Physics_Selected(
bool bValue,
bool bSelectMultiple)
93 if(m_osgNodeGroup.valid() && m_osgDragger.valid() && m_osgSelectedGroup.valid())
95 bool bIsReceptiveFieldMode = (m_lpThisAB->GetSimulator()->VisualSelectionMode() & RECEPTIVE_FIELD_SELECTION_MODE);
98 bool bNodeFound = m_osgNodeGroup->containsNode(m_osgSelectedGroup.get());
99 if(bValue && !bNodeFound)
101 m_osgNodeGroup->addChild(m_osgSelectedGroup.get());
102 if(!bIsReceptiveFieldMode)
103 m_osgDragger->AddToScene();
105 ShowSelectedVertex();
108 else if(!bValue && bNodeFound)
110 m_osgNodeGroup->removeChild(m_osgSelectedGroup.get());
111 m_osgDragger->RemoveFromScene();
112 HideSelectedVertex();
117 void OsgMovableItem::CreateSelectedGraphics(std::string strName)
119 m_osgSelectedGroup =
new osg::Group();
120 m_osgSelectedGroup->setName(strName +
"_SelectedGroup");
121 m_osgSelectedGroup->addChild(m_osgNode.get());
127 osg::StateSet* stateset =
new osg::StateSet;
128 osg::PolygonOffset* polyoffset =
new osg::PolygonOffset;
129 polyoffset->setFactor(-1.0f);
130 polyoffset->setUnits(-1.0f);
131 osg::PolygonMode* polymode =
new osg::PolygonMode;
132 polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
133 stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
134 stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
136 osg::Material* material =
new osg::Material;
137 stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
138 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
140 stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
142 m_osgSelectedGroup->setStateSet(stateset);
144 CreateDragger(strName);
145 CreateSelectedVertex(strName);
148 if(m_lpThisMI->IsSelected())
149 Physics_Selected(
true,
false);
152 void OsgMovableItem::CreateDragger(std::string strName)
154 if(m_lpThisAB->GetSimulator())
156 if(GetOsgSimulator()->OsgCmdMgr())
158 if(m_osgDragger.valid())
159 m_osgDragger.release();
161 m_osgDragger =
new OsgDragger(
this, m_lpThisMI->AllowTranslateDragX(), m_lpThisMI->AllowTranslateDragY(), m_lpThisMI->AllowTranslateDragX(),
162 m_lpThisMI->AllowRotateDragX(), m_lpThisMI->AllowRotateDragY(), m_lpThisMI->AllowRotateDragZ(),
163 m_lpThisMI->UserDefinedDraggerRadius());
164 m_osgDragger->setName(strName +
"_Dragger");
166 m_osgDragger->setupDefaultGeometry();
168 GetOsgSimulator()->OsgCmdMgr()->connect(*m_osgDragger, *m_osgMT);
177 void OsgMovableItem::CreateSelectedVertex(std::string strName)
179 if(!m_osgSelVertexNode.valid())
181 m_osgSelVertexNode =
new osg::Geode();
182 m_osgSelVertexNode->setName(strName +
"SelVertex");
183 float fltRadius = m_lpThisAB->GetSimulator()->RecFieldSelRadius();
184 osg::ShapeDrawable *osgDraw =
new osg::ShapeDrawable(
new osg::Sphere(osg::Vec3(0, 0, 0), fltRadius));
185 osgDraw->setColor(osg::Vec4(0, 1, 0, 0));
186 m_osgSelVertexNode->addDrawable(osgDraw);
189 if(!m_osgSelVertexMT.valid())
191 m_osgSelVertexMT =
new osg::MatrixTransform();
195 osgMT.makeIdentity();
196 m_osgSelVertexMT->setMatrix(osgMT);
198 m_osgSelVertexMT->addChild(m_osgSelVertexNode.get());
202 void OsgMovableItem::DeleteSelectedVertex()
204 HideSelectedVertex();
206 if(m_osgSelVertexNode.valid()) m_osgSelVertexNode.release();
207 if(m_osgSelVertexMT.valid()) m_osgSelVertexMT.release();
212 float *OsgMovableItem::Physics_GetDataPointer(
const std::string &strDataType) {
return NULL;}
214 void OsgMovableItem::LocalMatrix(osg::Matrix osgLocalMT)
216 m_osgLocalMatrix = osgLocalMT;
217 m_osgFinalMatrix = osgLocalMT;
221 void OsgMovableItem::GeometryRotationMatrix(osg::Matrix osgGeometryMT)
231 void OsgMovableItem::AttachedPartMovedOrRotated(std::string strID)
236 void OsgMovableItem::CreateGraphicsGeometry() {}
238 void OsgMovableItem::CreatePhysicsGeometry() {}
240 void OsgMovableItem::ResizePhysicsGeometry() {}
242 void OsgMovableItem::ResetPhyiscsAndChildJoints()
248 void OsgMovableItem::InitializeGraphicsGeometry()
250 CreateGraphicsGeometry();
251 m_osgGeometry->setName(m_lpThisAB->Name() +
"_Geometry");
253 osg::Geode *osgGroup =
new osg::Geode;
254 osgGroup->addDrawable(m_osgGeometry.get());
255 osgGroup->setName(m_lpThisAB->Name() +
"_Node");
261 CStdFPoint vPos(0, 0, 0), vRot(0, 0, 0);
262 GeometryRotationMatrix(SetupMatrix(vPos, vRot));
269 void OsgMovableItem::CreateGeometry(
bool bOverrideStatic)
271 InitializeGraphicsGeometry();
272 CreatePhysicsGeometry();
275 void OsgMovableItem::SetupGraphics()
277 m_osgParent = ParentOSG();
279 if(m_osgParent.valid())
283 SetColor(*m_lpThisMI->Ambient(), *m_lpThisMI->Diffuse(), *m_lpThisMI->Specular(), m_lpThisMI->Shininess());
284 SetTexture(m_lpThisMI->Texture());
286 SetVisible(m_lpThisMI->IsVisible());
291 if(AddOsgNodeToParent())
292 m_osgParent->addChild(m_osgRoot.get());
294 GetOsgSimulator()->OSGRoot()->addChild(m_osgRoot.get());
297 Physics_UpdateAbsolutePosition();
302 osgVisitor->traverse(*m_osgMT);
306 void OsgMovableItem::DeleteGraphics()
308 if(m_osgParent.valid() && m_osgRoot.valid())
310 if(m_osgParent->containsNode(m_osgRoot.get()))
311 m_osgParent->removeChild(m_osgRoot.get());
314 if(m_osgRoot.valid() && GetOsgSimulator() && GetOsgSimulator()->OSGRoot() && GetOsgSimulator()->OSGRoot()->containsNode(m_osgRoot.get()))
315 GetOsgSimulator()->OSGRoot()->removeChild(m_osgRoot.get());
317 if(m_osgSelVertexNode.valid()) m_osgSelVertexNode.release();
318 if(m_osgSelVertexMT.valid()) m_osgSelVertexMT.release();
320 if(m_osgCull.valid()) m_osgCull.release();
321 if(m_osgTexture.valid()) m_osgTexture.release();
322 if(m_osgStateSet.valid()) m_osgStateSet.release();
323 if(m_osgMaterial.valid()) m_osgMaterial.release();
325 if(m_osgGeometry.valid()) m_osgGeometry.release();
326 if(m_osgNode.valid()) m_osgNode.release();
327 if(m_osgSelectedGroup.valid()) m_osgSelectedGroup.release();
328 if(m_osgNodeGroup.valid()) m_osgNodeGroup.release();
330 if(m_osgMT.valid()) m_osgMT.release();
331 if(m_osgRoot.valid()) m_osgRoot.release();
332 if(m_osgParent.valid()) m_osgParent.release();
337 return m_lpParentVsMI;
340 osg::Matrix OsgMovableItem::GetWorldMatrix()
342 return m_osgWorldMatrix;
345 osg::Matrix OsgMovableItem::GetComMatrix(
bool bInvert)
347 osg::Matrix osgMatrix;
348 osgMatrix.makeIdentity();
352 osg::Matrix OsgMovableItem::GetParentWorldMatrix()
355 return m_lpParentVsMI->GetWorldMatrix();
357 osg::Matrix osgMatrix;
358 osgMatrix.makeIdentity();
362 osg::Matrix OsgMovableItem::GetParentPhysicsWorldMatrix()
365 return m_lpParentVsMI->GetPhysicsWorldMatrix();
367 osg::Matrix osgMatrix;
368 osgMatrix.makeIdentity();
372 osg::Matrix OsgMovableItem::GetParentComMatrix(
bool bInvert)
375 return m_lpParentVsMI->GetComMatrix(bInvert);
377 osg::Matrix osgMatrix;
378 osgMatrix.makeIdentity();
382 void OsgMovableItem::UpdateWorldMatrix()
384 if(AddOsgNodeToParent())
386 osg::Matrix osgParentMatrix = GetParentWorldMatrix();
389 m_osgWorldMatrix = m_osgFinalMatrix * osgParentMatrix;
394 m_osgWorldMatrix = m_osgMT->getMatrix();
398 CStdFPoint OsgMovableItem::GetOSGWorldCoords()
401 osg::Vec3 vCoord = m_osgWorldMatrix.getTrans();
402 CStdFPoint vPoint(vCoord[0], vCoord[1], vCoord[2]);
407 osg::Matrix OsgMovableItem::GetOSGWorldMatrix(
bool bUpdate)
412 return m_osgWorldMatrix;
415 bool OsgMovableItem::Physics_CalculateLocalPosForWorldPos(
float fltWorldX,
float fltWorldY,
float fltWorldZ, CStdFPoint &vLocalPos)
421 fltWorldX *= m_lpThisAB->GetSimulator()->InverseDistanceUnits();
422 fltWorldY *= m_lpThisAB->GetSimulator()->InverseDistanceUnits();
423 fltWorldZ *= m_lpThisAB->GetSimulator()->InverseDistanceUnits();
425 CStdFPoint vPos(fltWorldX, fltWorldY, fltWorldZ), vRot(0, 0, 0);
426 osg::Matrix osgWorldPos = SetupMatrix(vPos, vRot);
429 osg::Matrix osgInverse = osg::Matrix::inverse(lpParent->GetWorldMatrix());
431 osg::Matrix osgCalc = osgWorldPos * osgInverse;
433 osg::Vec3 vCoord = osgCalc.getTrans();
434 vLocalPos.Set(vCoord[0] * m_lpThisAB->GetSimulator()->DistanceUnits(),
435 vCoord[1] * m_lpThisAB->GetSimulator()->DistanceUnits(),
436 vCoord[2] * m_lpThisAB->GetSimulator()->DistanceUnits());
444 osg::MatrixTransform* OsgMovableItem::GetMatrixTransform()
446 return m_osgMT.get();
469 return m_osgMT.get();
472 osg::Matrix OsgMovableItem::CalculateTransformRelativeToParent(osg::Matrix osgLocalMatrix)
474 if(!m_lpParentVsMI || AddOsgNodeToParent())
475 return osgLocalMatrix;
479 osg::Matrix osgInverse = osg::Matrix::inverse(m_lpParentVsMI->GetWorldMatrix());
481 osg::Matrix osgLocal = osgLocalMatrix * osgInverse;
487 void OsgMovableItem::UpdatePositionAndRotationFromMatrix()
490 UpdatePositionAndRotationFromMatrix(m_osgMT->getMatrix());
493 void OsgMovableItem::UpdatePositionAndRotationFromMatrix(osg::Matrix osgMT)
498 m_osgMT->setMatrix(m_osgLocalMatrix);
503 osg::Matrix osgLocal = CalculateTransformRelativeToParent(m_osgLocalMatrix);
507 bool bFirePosChangeEvents = !m_lpThisAB->GetSimulator()->IsResetting();
511 osg::Vec3 vL = osgLocal.getTrans();
512 CStdFPoint vLocal(vL.x(), vL.y(), vL.z());
513 vLocal.ClearNearZero();
514 m_lpThisMI->Position(vLocal,
false, bFirePosChangeEvents,
false);
517 CStdFPoint vRot = EulerRotationFromMatrix(osgLocal);
518 m_lpThisMI->Rotation(vRot, bFirePosChangeEvents,
false);
520 if(m_osgDragger.valid())
521 m_osgDragger->SetupMatrix();
529 void OsgMovableItem::Physics_UpdateMatrix()
533 CStdFPoint vPos = m_lpThisMI->Position();
534 CStdFPoint vRot = m_lpThisMI->Rotation();
536 if(!AddOsgNodeToParent())
538 osg::Matrix osgParentMatrix = GetParentWorldMatrix();
539 osg::Matrix osgLocal = SetupMatrix(vPos, vRot);
540 osg::Matrix osgWorldMT = osgLocal * osgParentMatrix;
542 osg::Vec3d vWorldPos = osgWorldMT.getTrans();
543 vPos.Set(vWorldPos[0], vWorldPos[1], vWorldPos[2]);
544 vRot = EulerRotationFromMatrix(osgWorldMT);
547 LocalMatrix(SetupMatrix(vPos, vRot));
548 m_osgMT->setMatrix(m_osgLocalMatrix);
551 if(m_osgDragger.valid())
552 m_osgDragger->SetupMatrix();
554 Physics_UpdateAbsolutePosition();
558 void OsgMovableItem::Physics_UpdateAbsolutePosition()
561 CStdFPoint vPos = OsgMovableItem::GetOSGWorldCoords();
562 vPos.ClearNearZero();
563 m_lpThisMI->AbsolutePosition(vPos.x, vPos.y, vPos.z);
566 void OsgMovableItem::BuildLocalMatrix()
569 BuildLocalMatrix(m_lpThisMI->Position(), CStdFPoint(0, 0, 0), m_lpThisMI->Rotation(), m_lpThisAB->Name());
572 void OsgMovableItem::BuildLocalMatrix(CStdFPoint vLocalOffset)
575 BuildLocalMatrix(m_lpThisMI->Position(), vLocalOffset, m_lpThisMI->Rotation(), m_lpThisAB->Name());
578 void OsgMovableItem::BuildLocalMatrix(CStdFPoint localPos, CStdFPoint vLocalOffset, CStdFPoint localRot, std::string strName)
582 m_osgMT =
new osgManipulator::Selection;
583 m_osgMT->setName(strName +
"_MT");
586 if(!m_osgRoot.valid())
588 m_osgRoot =
new osg::Group;
589 m_osgRoot->setName(strName +
"_Root");
592 if(!m_osgRoot->containsNode(m_osgMT.get()))
593 m_osgRoot->addChild(m_osgMT.get());
596 CStdFPoint vOffsetPos = (localPos - vLocalOffset);
597 if(AddOsgNodeToParent())
598 localMT = SetupMatrix(vOffsetPos, localRot);
600 localMT = SetupMatrix(vOffsetPos, localRot) * m_osgParent->getMatrix();
602 LocalMatrix(localMT);
605 m_osgMT->setMatrix(m_osgLocalMatrix);
611 if(!m_osgNodeGroup.valid() && m_osgNode.valid())
613 m_osgNodeGroup =
new osg::Group();
614 m_osgNodeGroup->addChild(m_osgNode.get());
615 m_osgNodeGroup->setName(strName +
"_NodeGroup");
617 m_osgMT->addChild(m_osgNodeGroup.get());
619 CreateSelectedGraphics(strName);
623 void OsgMovableItem::Physics_LoadLocalTransformMatrix(CStdXml &oXml)
625 osg::Matrix osgMT = LoadMatrix(oXml,
"LocalMatrix");
626 UpdatePositionAndRotationFromMatrix(osgMT);
629 void OsgMovableItem::Physics_SaveLocalTransformMatrix(CStdXml &oXml)
631 SaveMatrix(oXml,
"LocalMatrix", m_osgMT->getMatrix());
634 std::string OsgMovableItem::Physics_GetLocalTransformMatrixString()
636 return SaveMatrixString(m_osgMT->getMatrix());
639 void OsgMovableItem::Physics_ResizeDragHandler(
float fltRadius)
641 bool bInScene =
false;
642 if(m_osgDragger.valid() && m_osgDragger->IsInScene())
644 m_osgDragger->RemoveFromScene();
648 CreateDragger(m_lpThisAB->Name());
651 m_osgDragger->AddToScene();
654 void OsgMovableItem::Physics_ResetGraphicsAndPhysics()
661 void OsgMovableItem::Physics_PositionChanged()
663 Physics_UpdateMatrix();
666 void OsgMovableItem::Physics_RotationChanged()
668 Physics_UpdateMatrix();
671 BoundingBox OsgMovableItem::Physics_GetBoundingBox()
676 osg::Geode *osgGroup =
dynamic_cast<osg::Geode *
>(m_osgNode.get());
679 bb = osgGroup->getBoundingBox();
680 abb.Set(bb.xMin(), bb.yMin(), bb.zMin(), bb.xMax(), bb.yMax(), bb.zMax());
682 else if(m_osgNode.valid())
684 osg::BoundingSphere osgBound = m_osgNode->getBound();
685 abb.Set(-osgBound.radius(), -osgBound.radius(), -osgBound.radius(), osgBound.radius(), osgBound.radius(), osgBound.radius());
688 abb.Set(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5);
693 float OsgMovableItem::Physics_GetBoundingRadius()
695 if(m_osgNode.valid())
697 osg::BoundingSphere osgBound = m_osgNode->getBound();
698 return osgBound.radius();
704 void OsgMovableItem::SetTexture(std::string strTexture)
706 if(m_osgNode.valid())
710 std::string strFile = AnimatSim::GetFilePath(m_lpThisAB->GetSimulator()->ProjectPath(), strTexture);
711 osg::ref_ptr<osg::Image> image = osgDB::readImageFile(strFile);
713 THROW_PARAM_ERROR(Osg_Err_lTextureLoad, Osg_Err_strTextureLoad,
"Image File", strFile);
715 osg::StateSet* state = m_osgNode->getOrCreateStateSet();
716 m_osgTexture =
new osg::Texture2D(image.get());
717 m_osgTexture->setDataVariance(osg::Object::DYNAMIC);
719 m_osgTexture->setWrap(osg::Texture2D::WRAP_S, osg::Texture2D::REPEAT);
720 m_osgTexture->setWrap(osg::Texture2D::WRAP_T, osg::Texture2D::REPEAT);
722 state->setTextureAttributeAndModes(0, m_osgTexture.get());
723 state->setTextureMode(0, m_eTextureMode, osg::StateAttribute::ON);
724 state->setMode(GL_BLEND,osg::StateAttribute::ON);
728 else if(m_osgTexture.valid())
730 m_osgTexture.release();
731 osg::StateSet* state = m_osgNode->getOrCreateStateSet();
732 state->setTextureAttributeAndModes(0, NULL);
733 state->setTextureMode(0, m_eTextureMode, osg::StateAttribute::OFF);
738 void OsgMovableItem::Physics_CollectData()
741 Physics_UpdateAbsolutePosition();
747 void OsgMovableItem::Physics_ResetSimulation()
754 Physics_UpdateAbsolutePosition();
755 CStdFPoint vRot = m_lpThisMI->Rotation();
756 m_lpThisMI->ReportRotation(vRot);
761 void OsgMovableItem::SetCulling()
767 if(!m_osgCull.valid())
769 m_osgCull =
new osg::CullFace();
770 m_osgCull->setMode(osg::CullFace::BACK);
772 osg::StateSet* ss = m_osgMT->getOrCreateStateSet();
773 ss->setAttributeAndModes(m_osgCull.get(), osg::StateAttribute::ON);
775 else if(m_osgCull.valid())
777 osg::StateSet* ss = m_osgMT->getOrCreateStateSet();
778 ss->setAttributeAndModes(m_osgCull.get(), osg::StateAttribute::OFF);
783 void OsgMovableItem::ShowSelectedVertex() {}
785 void OsgMovableItem::HideSelectedVertex() {}
787 void OsgMovableItem::SetAlpha()
789 switch (m_lpThisAB->GetSimulator()->VisualSelectionMode())
791 case GRAPHICS_SELECTION_MODE:
792 m_lpThisMI->Alpha(m_lpThisMI->GraphicsAlpha());
793 HideSelectedVertex();
796 case COLLISION_SELECTION_MODE:
797 m_lpThisMI->Alpha(m_lpThisMI->CollisionsAlpha());
798 HideSelectedVertex();
801 case JOINT_SELECTION_MODE:
802 m_lpThisMI->Alpha(m_lpThisMI->JointsAlpha());
803 HideSelectedVertex();
806 case RECEPTIVE_FIELD_SELECTION_MODE:
807 m_lpThisMI->Alpha(m_lpThisMI->ReceptiveFieldsAlpha());
808 ShowSelectedVertex();
811 case SIMULATION_SELECTION_MODE:
812 m_lpThisMI->Alpha(m_lpThisMI->SimulationAlpha());
813 HideSelectedVertex();
817 m_lpThisMI->Alpha(m_lpThisMI->GraphicsAlpha());
818 HideSelectedVertex();
822 if(m_osgMaterial.valid() && m_osgStateSet.valid())
823 SetMaterialAlpha(m_osgMaterial.get(), m_osgStateSet.get(), m_lpThisMI->Alpha());
826 void OsgMovableItem::SetMaterialAlpha(osg::Material *osgMat, osg::StateSet *ss,
float fltAlpha)
828 osgMat->setAlpha(osg::Material::FRONT_AND_BACK, fltAlpha);
831 ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
833 ss->setRenderingHint(osg::StateSet::OPAQUE_BIN);
836 void OsgMovableItem::SetColor(CStdColor &vAmbient, CStdColor &vDiffuse, CStdColor &vSpecular,
float fltShininess)
838 if(m_osgNode.valid())
843 m_osgMaterial =
new osg::Material();
846 m_osgStateSet = m_osgNode->getOrCreateStateSet();
849 m_osgMaterial->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(vAmbient[0], vAmbient[1], vAmbient[2], 1));
850 m_osgMaterial->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(vDiffuse[0], vDiffuse[1], vDiffuse[2], vDiffuse[3]));
851 m_osgMaterial->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(vSpecular[0], vSpecular[1], vSpecular[2], 1));
852 m_osgMaterial->setShininess(osg::Material::FRONT_AND_BACK, fltShininess);
853 m_osgStateSet->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
857 m_osgStateSet->setAttribute(m_osgMaterial.get(), osg::StateAttribute::ON);
861 void OsgMovableItem::SetVisible(osg::Node *osgNode,
bool bVisible)
866 osgNode->setNodeMask(0x1);
868 osgNode->setNodeMask(0x0);
872 void OsgMovableItem::SetVisible(
bool bVisible)
874 SetVisible(m_osgNode.get(), bVisible);
877 void OsgMovableItem::CreateItem()
879 m_lpThisAB->Initialize();
884 void OsgMovableItem::StartGripDrag()
888 void OsgMovableItem::EndGripDrag()
890 this->UpdatePositionAndRotationFromMatrix();
966 void OsgMovableItem::Physics_OrientNewPart(
float fltXPos,
float fltYPos,
float fltZPos,
float fltXNorm,
float fltYNorm,
float fltZNorm)
969 if(!m_lpThisMI || !m_lpThisMI->Parent())
972 CStdFPoint vParentPos = m_lpThisMI->Parent()->AbsolutePosition();
973 osg::Vec3 vParent(vParentPos.x, vParentPos.y, vParentPos.z);
975 osg::Vec3 vClickPos(fltXPos, fltYPos, fltZPos), vClickNormal(fltXNorm, fltYNorm, fltZNorm);
978 float fltRadius = Physics_GetBoundingRadius();
981 osg::Vec3 vWorldPos = vClickPos + (vClickNormal*fltRadius);
984 osg::Vec3 vLocalPos = vWorldPos - vParent;
987 m_lpThisMI->Position(vLocalPos[0], vLocalPos[1], vLocalPos[2],
false,
true,
true);
osg::ref_ptr< osg::MatrixTransform > m_osgGeometryRotationMT
Declares the vortex Light class.
virtual osg::MatrixTransform * GetCameraMatrixTransform()
Gets the matrix transform used by the camera for the mouse spring.
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex organism class.
bool Std_IsBlank(std::string strVal)
Trims a string and tests if a string is blank.
Declares the vortex structure class.