AnimatLab  2
Test
VsMouseSpring.cpp
1 #include "StdAfx.h"
2 #include "VsMouseSpring.h"
3 
4 
5 namespace VortexAnimatSim
6 {
7  namespace Visualization
8  {
9 
10 VsMouseSpring* VsMouseSpring::m_instance = NULL;
11 
12 VsMouseSpring::VsMouseSpring(void)
13 {
14  m_gdeLine = NULL;
15  m_aryLines = NULL;
16  m_v3Start.set(0,0,0);
17  m_v3End.set(1,0,0);
18  m_osgRB = NULL;
19 }
20 
21 VsMouseSpring::~VsMouseSpring(void)
22 {
23 }
24 
25 void VsMouseSpring::Visible(bool bVal)
26 {
27  if(bVal)
28  m_gdeLine->setNodeMask(0x1);
29  else
30  m_gdeLine->setNodeMask(0x0);
31 }
32 
33 void VsMouseSpring::Initialize()
34 {
35  //create a line geometry
36  m_linesGeom = new osg::Geometry();
37 
38  m_aryLines = new osg::Vec3Array();
39 
40  m_aryLines->push_back(m_v3Start);
41  m_aryLines->push_back(m_v3End);
42 
43  //set the vertex array
44  m_linesGeom->setVertexArray(m_aryLines.get());
45 
46  //add a primativeset to the geometry
47  m_linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP,0,m_aryLines->size()));
48 
49  // set the color
50  osg::Vec4Array* colors = new osg::Vec4Array;
51  colors->push_back(osg::Vec4(1.0f,1.0f,1.0f,1.0f));
52  colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
53  m_linesGeom->setColorArray(colors);
54  m_linesGeom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
55 
56  //m_linesGeom display list so that the geometry updates each frame
57  m_linesGeom->setDataVariance(osg::Object::DYNAMIC);
58  m_linesGeom->setUseDisplayList(false);
59 
60  m_gdeLine = new osg::Geode();
61  m_gdeLine->addDrawable(m_linesGeom.get());
62 
63  osg::StateSet *ss = new osg::StateSet();
64  ss->setMode( GL_LIGHTING, osg::StateAttribute::PROTECTED | osg::StateAttribute::OFF );
65 
66  m_lineWidth = new osg::LineWidth();
67  m_lineWidth->setWidth(1.0f);
68  ss->setAttributeAndModes(m_lineWidth.get(), osg::StateAttribute::ON);
69  ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
70  m_gdeLine->setStateSet(ss);
71 
72  //Initially not visible.
73  Visible(false);
74 }
75 
76 void VsMouseSpring::SetStart(osg::Vec3 v3Start)
77 {
78  m_v3Start = v3Start;
79  Update();
80 }
81 
82 void VsMouseSpring::SetEnd(osg::Vec3 v3End)
83 {
84  m_v3End = v3End;
85  Update();
86 }
87 
88 void VsMouseSpring::Update()
89 {
90  (*m_aryLines)[0].set(m_v3Start);
91  (*m_aryLines)[1].set(m_v3End);
92 
93  m_linesGeom->dirtyBound();
94 }
95 
96  }// end Visualization
97 }// end VortexAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.