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