AnimatLab  2
Test
OsgHudText.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 #include "OsgHudText.h"
9 
10 namespace OsgAnimatSim
11 {
12  namespace Visualization
13  {
14 
22 {
23  //Default color is white
24  m_aryColor.Set(1, 1, 1, 1);
25  m_ptPosition.Set(10,10, 0); //Default to the lower left corner
26  m_strFont = "fonts/arial.ttf";
27  m_iCharSize = 30;
28  m_strText = "";
29  m_lpDisplayData = NULL;
30  m_lpUpdateData = NULL;
31  m_fltUpdateInterval = 1;
32 }
33 
48 OsgHudText::OsgHudText(float *aryColor, CStdFPoint &ptPosition, std::string strFont, int iCharSize, std::string strText, std::string strDisplayTargetID, std::string strDisplayDataType, std::string strUpdateTargetID, std::string strUpdateDataType, float fltUpdateInterval)
49 {
50  m_aryColor.Set(aryColor[0], aryColor[1], aryColor[2], aryColor[3]);
51  m_ptPosition = ptPosition;
52  m_strFont = strFont;
53  m_iCharSize = iCharSize;
54  m_strText = strText;
55  m_lpDisplayData = NULL;
56  m_lpUpdateData = NULL;
57  m_strDisplayTargetID = strDisplayTargetID;
58  m_strDisplayDataType = strDisplayDataType;
59  m_strUpdateTargetID = strUpdateTargetID;
60  m_strUpdateDataType = strUpdateDataType;
61  m_fltUpdateInterval = fltUpdateInterval;
62 }
63 
71 {
72 }
73 
74 void OsgHudText::Initialize(void *lpVoidProjection)
75 {
76  HudText::Initialize(lpVoidProjection);
77 
78  m_fltPrevious = -1;
79  osg::Projection *lpProjection = (osg::Projection *) (lpVoidProjection);
80  if(!lpProjection)
81  THROW_PARAM_ERROR(Osg_Err_lHudProjectionNotDefined, Osg_Err_strHudProjectionNotDefined, "ID", m_strID);
82 
83  m_osgText = new osgText::Text;
84  m_osgText->setDataVariance(osg::Object::DYNAMIC);
85  m_osgText->setColor(osg::Vec4(m_aryColor[0], m_aryColor[1], m_aryColor[2], m_aryColor[3]));
86  m_osgText->setPosition(osg::Vec3(m_ptPosition.x, m_ptPosition.y, m_ptPosition.z));
87  m_osgText->setFont(m_strFont.c_str());
88  m_osgText->setCharacterSize(m_iCharSize);
89  m_osgText->setText("");
90 
91  m_osgGeode = new osg::Geode;
92  m_osgGeode->addDrawable(m_osgText.get());
93  lpProjection->addChild(m_osgGeode.get());
94 }
95 
97 {
98  m_fltPrevious = -1;
99 }
100 
101 void OsgHudText::Update()
102 {
103  char str[1024];
104 
105  if(m_osgText.valid() && m_lpDisplayData && m_lpUpdateData && (fabs(*m_lpUpdateData-m_fltPrevious) > 0.1) )
106  {
107  sprintf(str, m_strText.c_str(), *m_lpDisplayData);
108  m_osgText->setText(str);
109  m_fltPrevious = *m_lpUpdateData;
110  }
111 }
112 
113  } // Visualization
114 } //OsgAnimatSim
Classes for implementing the cm-labs vortex physics engine for AnimatLab.
virtual void Initialize()
Initializes this object.
Definition: AnimatBase.cpp:573
std::string m_strID
The unique Id for this object.
Definition: AnimatBase.h:55
virtual void ResetSimulation()
Resets the simulation back to time 0.
Definition: OsgHudText.cpp:96
Declares the vortex heads-up display text class.