3 #include "VsMovableItem.h"
6 #include "VsRigidBody.h"
8 #include "VsTrackballDragger.h"
10 #include "VsSimulator.h"
11 #include "VsOsgUserData.h"
15 namespace Visualization
19 osg::Geometry* createCircleGeometry(
float radius,
unsigned int numSegments)
21 const float angleDelta = 2.0f*osg::PI/(float)numSegments;
22 const float r = radius;
24 osg::Vec3Array* vertexArray =
new osg::Vec3Array(numSegments);
25 osg::Vec3Array* normalArray =
new osg::Vec3Array(numSegments);
26 for(
unsigned int i = 0; i < numSegments; ++i,angle+=angleDelta)
28 float c = cosf(angle);
29 float s = sinf(angle);
30 (*vertexArray)[i].set(c*r,s*r,0.0f);
31 (*normalArray)[i].set(c,s,0.0f);
33 osg::Geometry* geometry =
new osg::Geometry();
34 geometry->setVertexArray(vertexArray);
35 geometry->setNormalArray(normalArray);
36 geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX);
37 geometry->addPrimitiveSet(
new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,vertexArray->size()));
41 VsTrackballDragger::VsTrackballDragger(
bool bAllowRotateX,
bool bAllowRotateY,
bool bAllowRotateZ)
45 _xDragger =
new osgManipulator::RotateCylinderDragger();
46 addChild(_xDragger.get());
47 addDragger(_xDragger.get());
52 _yDragger =
new osgManipulator::RotateCylinderDragger();
53 addChild(_yDragger.get());
54 addDragger(_yDragger.get());
59 _zDragger =
new osgManipulator::RotateCylinderDragger();
60 addChild(_zDragger.get());
61 addDragger(_zDragger.get());
64 setParentDragger(getParentDragger());
67 VsTrackballDragger::~VsTrackballDragger(
void)
74 if(!_xDragger.valid() && !_xDragger.valid() && !_xDragger.valid())
77 osg::Geode* geode =
new osg::Geode;
79 osg::TessellationHints* hints =
new osg::TessellationHints;
80 hints->setCreateTop(
false);
81 hints->setCreateBottom(
false);
82 hints->setCreateBackFace(
false);
84 osg::Cylinder* cylinder =
new osg::Cylinder;
85 cylinder->setHeight(0.15f);
86 osg::ShapeDrawable* cylinderDrawable =
new osg::ShapeDrawable(cylinder,hints);
87 geode->addDrawable(cylinderDrawable);
88 osgManipulator::setDrawableToAlwaysCull(*cylinderDrawable);
89 geode->addDrawable(createCircleGeometry(1.0f, 100));
94 osg::PolygonMode* polymode =
new osg::PolygonMode;
95 polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
96 geode->getOrCreateStateSet()->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
97 geode->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
98 geode->getOrCreateStateSet()->setAttributeAndModes(
new osg::LineWidth(5.0f),osg::StateAttribute::ON);
102 _xDragger->addChild(geode);
103 _yDragger->addChild(geode);
104 _zDragger->addChild(geode);
109 osg::Quat rotation; rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(1.0f, 0.0f, 0.0f));
110 _xDragger->setMatrix(osg::Matrix(rotation));
115 osg::Quat rotation; rotation.makeRotate(osg::Vec3(0.0f, 0.0f, 1.0f), osg::Vec3(0.0f, 1.0f, 0.0f));
116 _yDragger->setMatrix(osg::Matrix(rotation));
120 _xDragger->setColor(osg::Vec4(1.0f,0.0f,0.0f,1.0f));
121 _yDragger->setColor(osg::Vec4(0.0f,1.0f,0.0f,1.0f));
122 _zDragger->setColor(osg::Vec4(0.0f,0.0f,1.0f,1.0f));
void setupDefaultGeometry()
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
Declares the vortex structure class.