3 #include "OsgMovableItem.h"
5 #include "OsgRigidBody.h"
7 #include "OsgPrismaticLimit.h"
9 #include "OsgUserData.h"
10 #include "OsgUserDataVisitor.h"
11 #include "OsgDragger.h"
20 OsgPrismaticLimit::OsgPrismaticLimit()
24 OsgPrismaticLimit::~OsgPrismaticLimit()
28 void OsgPrismaticLimit::LimitAlpha(
float fltA)
30 if(m_osgBoxMat.valid() && m_osgBoxSS.valid())
32 m_osgBoxMat->setAlpha(osg::Material::FRONT_AND_BACK, fltA);
35 m_osgBoxSS->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
37 m_osgBoxSS->setRenderingHint(osg::StateSet::OPAQUE_BIN);
40 if(m_osgCylinderMat.valid() && m_osgCylinderSS.valid())
42 m_osgCylinderMat->setAlpha(osg::Material::FRONT_AND_BACK, fltA);
45 m_osgCylinderSS->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
47 m_osgCylinderSS->setRenderingHint(osg::StateSet::OPAQUE_BIN);
51 osg::Geometry *OsgPrismaticLimit::BoxGeometry() {
return m_osgBox.get();}
53 osg::MatrixTransform *OsgPrismaticLimit::BoxMT() {
return m_osgBoxMT.get();}
55 osg::Material *OsgPrismaticLimit::BoxMat() {
return m_osgBoxMat.get();}
57 osg::StateSet *OsgPrismaticLimit::BoxSS() {
return m_osgBoxSS.get();}
59 osg::Geometry *OsgPrismaticLimit::CylinderGeometry() {
return m_osgCylinder.get();}
61 osg::MatrixTransform *OsgPrismaticLimit::CylinderMT() {
return m_osgCylinderMT.get();}
63 osg::Material *OsgPrismaticLimit::CylinderMat() {
return m_osgCylinderMat.get();}
65 osg::StateSet *OsgPrismaticLimit::CylinderSS() {
return m_osgCylinderSS.get();}
67 void OsgPrismaticLimit::SetLimitPos(
float fltRadius)
69 CStdFPoint vPos(0, 0, 0), vRot(0, 0, 0);
70 float fltLimitPos = m_lpThisLimit->LimitPos();
73 if(m_osgBoxMT.valid())
75 vPos.Set(0, 0, -fltLimitPos); vRot.Set(0, 0, 0);
76 m_osgBoxMT->setMatrix(SetupMatrix(vPos, vRot));
80 if(m_osgCylinderMT.valid() && m_osgCylinder.valid() && m_osgCylinderGeode.valid())
83 if(m_osgCylinderGeode->containsDrawable(m_osgCylinder.get()))
84 m_osgCylinderGeode->removeDrawable(m_osgCylinder.get());
85 m_osgCylinder.release();
88 m_osgCylinder =
CreateConeGeometry(fabs(fltLimitPos), fltRadius, fltRadius, 10,
true,
true,
true);
89 m_osgCylinderGeode->addDrawable(m_osgCylinder.get());
91 vPos.Set(0, 0, (-fltLimitPos/2)); vRot.Set(osg::PI/2, 0, 0);
92 m_osgCylinderMT->setMatrix(SetupMatrix(vPos, vRot));
96 void OsgPrismaticLimit::DeleteLimitGraphics()
100 m_osgBoxMat.release();
101 m_osgBoxSS.release();
102 m_osgCylinder.release();
103 m_osgCylinderGeode.release();
104 m_osgCylinderMT.release();
105 m_osgCylinderMat.release();
106 m_osgCylinderSS.release();
109 void OsgPrismaticLimit::SetupLimitGraphics(
float fltBoxSize,
float fltRadius)
111 float fltLimitPos = m_lpThisLimit->LimitPos();
112 CStdColor *vColor = m_lpThisLimit->Color();
115 m_osgBox = CreateBoxGeometry(fltBoxSize, fltBoxSize,
116 fltBoxSize, fltBoxSize,
117 fltBoxSize, fltBoxSize);
118 osg::ref_ptr<osg::Geode> osgBox =
new osg::Geode;
119 osgBox->addDrawable(m_osgBox.get());
121 CStdFPoint vPos(0, 0, 0), vRot(0, 0, 0);
124 vPos.Set(0, 0, -fltLimitPos);
126 m_osgBoxMT =
new osg::MatrixTransform();
127 m_osgBoxMT->setMatrix(SetupMatrix(vPos, vRot));
128 m_osgBoxMT->addChild(osgBox.get());
131 if(!m_osgBoxMat.valid())
132 m_osgBoxMat =
new osg::Material();
135 m_osgBoxSS = m_osgBoxMT->getOrCreateStateSet();
138 m_osgBoxMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.1, 0.1, 0.1, 1));
139 m_osgBoxMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(vColor->r(), vColor->g(), vColor->b(), vColor->a()));
140 m_osgBoxMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25, 0.25, 0.25, 1));
141 m_osgBoxMat->setShininess(osg::Material::FRONT_AND_BACK, 64);
142 m_osgBoxSS->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
145 m_osgBoxSS->setAttribute(m_osgBoxMat.get(), osg::StateAttribute::ON);
151 if(!m_lpThisLimit->IsShowPosition())
153 m_osgCylinder =
CreateConeGeometry(fabs(fltLimitPos), fltRadius, fltRadius, 10,
true,
true,
true);
154 m_osgCylinderGeode =
new osg::Geode;
155 m_osgCylinderGeode->addDrawable(m_osgCylinder.get());
157 CStdFPoint vPos(0, 0, (-fltLimitPos/2)), vRot(osg::PI/2, 0, 0);
158 m_osgCylinderMT =
new osg::MatrixTransform();
159 m_osgCylinderMT->setMatrix(SetupMatrix(vPos, vRot));
160 m_osgCylinderMT->addChild(m_osgCylinderGeode.get());
163 if(!m_osgCylinderMat.valid())
164 m_osgCylinderMat =
new osg::Material();
167 m_osgCylinderSS = m_osgCylinderMT->getOrCreateStateSet();
170 m_osgCylinderMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.1, 0.1, 0.1, 1));
171 m_osgCylinderMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(vColor->r(), vColor->g(), vColor->b(), vColor->a()));
173 m_osgCylinderMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.25, 0.25, 0.25, 1));
174 m_osgCylinderMat->setShininess(osg::Material::FRONT_AND_BACK, 64);
175 m_osgCylinderSS->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
178 m_osgCylinderSS->setAttribute(m_osgCylinderMat.get(), osg::StateAttribute::ON);
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
osg::Geometry ANIMAT_OSG_PORT * CreateConeGeometry(float height, float topradius, float botradius, int sides, bool doSide, bool doTop, bool doBottom)
Declares the vortex structure class.