AnimatLab  2
Test
OsgHinge.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "OsgMovableItem.h"
9 #include "OsgBody.h"
10 #include "OsgJoint.h"
11 #include "OsgRigidBody.h"
12 #include "OsgJoint.h"
13 #include "OsgHingeLimit.h"
14 #include "OsgHinge.h"
15 #include "OsgStructure.h"
16 #include "OsgSimulator.h"
17 #include "OsgUserData.h"
18 #include "OsgUserDataVisitor.h"
19 #include "OsgDragger.h"
20 
21 namespace OsgAnimatSim
22 {
23  namespace Environment
24  {
25  namespace Joints
26  {
27 
35 {
36 }
37 
45 {
46 }
47 
48 
49 void OsgHinge::DeleteHingeGraphics(osg::ref_ptr<osg::MatrixTransform> osgJointMT, OsgHingeLimit *lpUpperLimit, OsgHingeLimit *lpLowerLimit, OsgHingeLimit *lpPosFlap)
50 {
51  if(osgJointMT.valid())
52  {
53  if(m_osgCylinderMT.valid()) osgJointMT->removeChild(m_osgCylinderMT.get());
54  if(lpUpperLimit && lpUpperLimit->FlapTranslateMT()) osgJointMT->removeChild(lpUpperLimit->FlapTranslateMT());
55  if(lpLowerLimit && lpLowerLimit->FlapTranslateMT()) osgJointMT->removeChild(lpLowerLimit->FlapTranslateMT());
56  if(lpPosFlap && lpPosFlap->FlapTranslateMT()) osgJointMT->removeChild(lpPosFlap->FlapTranslateMT());
57  }
58 
59  m_osgCylinder.release();
60  m_osgCylinderGeode.release();
61  m_osgCylinderMT.release();
62  m_osgCylinderMat.release();
63  m_osgCylinderSS.release();
64 }
65 
72 void OsgHinge::CreateCylinderGraphics(float fltHeight, float fltRadius)
73 {
74  //Create the cylinder for the hinge
75  m_osgCylinder = CreateConeGeometry(fltHeight, fltRadius, fltRadius, 30, true, true, true);
76  m_osgCylinderGeode = new osg::Geode;
77  m_osgCylinderGeode->addDrawable(m_osgCylinder.get());
78 
79  CStdFPoint vPos(0, 0, 0), vRot(osg::PI/2, 0, 0);
80  m_osgCylinderMT = new osg::MatrixTransform();
81  m_osgCylinderMT->setMatrix(SetupMatrix(vPos, vRot));
82  m_osgCylinderMT->addChild(m_osgCylinderGeode.get());
83 
84  //create a material to use with the pos flap
85  if(!m_osgCylinderMat.valid())
86  m_osgCylinderMat = new osg::Material();
87 
88  //create a stateset for this node
89  m_osgCylinderSS = m_osgCylinderMT->getOrCreateStateSet();
90 
91  //set the diffuse property of this node to the color of this body
92  m_osgCylinderMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.1, 0.1, 0.1, 1));
93  m_osgCylinderMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 0.25, 1, 1));
94  m_osgCylinderMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25, 0.25, 0.25, 1));
95  m_osgCylinderMat->setShininess(osg::Material::FRONT_AND_BACK, 64);
96  m_osgCylinderSS->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
97 
98  //apply the material
99  m_osgCylinderSS->setAttribute(m_osgCylinderMat.get(), osg::StateAttribute::ON);
100 }
101 
102 void OsgHinge::CreateHingeGraphics(float fltHeight, float fltRadius, float fltFlapWidth,
103  osg::ref_ptr<osg::MatrixTransform> osgJointMT, OsgHingeLimit *lpUpperLimit,
104  OsgHingeLimit *lpLowerLimit, OsgHingeLimit *lpPosFlap)
105 {
106  CreateCylinderGraphics(fltHeight, fltRadius);
107 
108  if(lpUpperLimit) lpUpperLimit->SetupLimitGraphics(fltFlapWidth, fltHeight);
109  if(lpLowerLimit) lpLowerLimit->SetupLimitGraphics(fltFlapWidth, fltHeight);
110  if(lpPosFlap) lpPosFlap->SetupLimitGraphics(fltFlapWidth, fltHeight);
111 
112  osgJointMT->addChild(m_osgCylinderMT.get());
113  osgJointMT->addChild(lpUpperLimit->FlapTranslateMT());
114  osgJointMT->addChild(lpLowerLimit->FlapTranslateMT());
115  osgJointMT->addChild(lpPosFlap->FlapTranslateMT());
116 }
117 
118  } // Joints
119  } // Environment
120 } //OsgAnimatSim
virtual void CreateCylinderGraphics(float fltHeight, float fltRadius)
Creates the cylinder graphics.
Definition: OsgHinge.cpp:72
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
osg::ref_ptr< osg::StateSet > m_osgCylinderSS
The osg cylinder state set.
Definition: OsgHinge.h:48
osg::ref_ptr< osg::MatrixTransform > m_osgCylinderMT
The osg cylinder matrix transform.
Definition: OsgHinge.h:42
osg::Geometry ANIMAT_OSG_PORT * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
osg::ref_ptr< osg::Geometry > m_osgCylinder
The osg cylinder geometry.
Definition: OsgHinge.h:36
osg::ref_ptr< osg::Geode > m_osgCylinderGeode
The osg cylinder geode.
Definition: OsgHinge.h:39
osg::ref_ptr< osg::Material > m_osgCylinderMat
The osg cylinder material.
Definition: OsgHinge.h:45
Declares the vortex structure class.
Declares the vortex hinge class.