You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovassvepCBasicPainter.cpp 5.0KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. #if defined(TARGET_HAS_ThirdPartyOgre3D)
  2. #include "ovassvepCBasicPainter.h"
  3. #include "ovassvepCApplication.h"
  4. #if (OGRE_VERSION_MAJOR > 1) || ((OGRE_VERSION_MAJOR == 1) && (OGRE_VERSION_MINOR >= 9))
  5. #include "Overlay/OgreOverlayManager.h"
  6. #include "Overlay/OgreOverlaySystem.h"
  7. #endif
  8. namespace OpenViBE {
  9. namespace SSVEP {
  10. //---------------------------------------------------------------------------------------------------
  11. CBasicPainter::CBasicPainter(CApplication* application)
  12. : m_application(application), m_sceneManager(application->getSceneManager())
  13. {
  14. m_aabInf.setInfinite();
  15. #if (OGRE_VERSION_MAJOR > 1) || ((OGRE_VERSION_MAJOR == 1) && (OGRE_VERSION_MINOR >= 9))
  16. // on Ogre 1.9, overlay system needs to be manually created
  17. Ogre::OverlaySystem* pOverlaySystem = OGRE_NEW Ogre::OverlaySystem();
  18. m_sceneManager->addRenderQueueListener(pOverlaySystem);
  19. #endif
  20. m_overlayManager = Ogre::OverlayManager::getSingletonPtr();
  21. (m_application->getLogManager()) << Kernel::LogLevel_Debug << " + Creating OverlayManager\n";
  22. Ogre::Overlay* overlay = m_overlayManager->create("TextOverlay");
  23. m_overlayContainer = dynamic_cast<Ogre::OverlayContainer*>(m_overlayManager->createOverlayElement("Panel", "TextContainer"));
  24. m_overlayContainer->setDimensions(1, 1);
  25. m_overlayContainer->setPosition(0, 0);
  26. overlay->add2D(m_overlayContainer);
  27. overlay->show();
  28. }
  29. //---------------------------------------------------------------------------------------------------
  30. Ogre::ManualObject* CBasicPainter::paintRectangle(const Ogre::RealRect& oRectangle, const Ogre::ColourValue color, const int plane) const
  31. {
  32. Ogre::ManualObject* object = m_sceneManager->createManualObject();
  33. object->begin("BasicSurface/Diffuse", Ogre::RenderOperation::OT_TRIANGLE_FAN);
  34. object->setUseIdentityProjection(true);
  35. object->setUseIdentityView(true);
  36. object->position(oRectangle.right, oRectangle.top, 0.0);
  37. object->colour(color);
  38. object->index(0);
  39. object->position(oRectangle.left, oRectangle.top, 0.0);
  40. object->colour(color);
  41. object->index(1);
  42. object->position(oRectangle.left, oRectangle.bottom, 0.0);
  43. object->colour(color);
  44. object->index(2);
  45. object->position(oRectangle.right, oRectangle.bottom, 0.0);
  46. object->colour(color);
  47. object->index(3);
  48. object->index(0);
  49. object->end();
  50. object->setBoundingBox(m_aabInf);
  51. object->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - plane);
  52. object->setVisible(true);
  53. return object;
  54. }
  55. //---------------------------------------------------------------------------------------------------
  56. Ogre::ManualObject* CBasicPainter::paintTriangle(const Point p1, const Point p2, const Point p3, const Ogre::ColourValue color, const int plane) const
  57. {
  58. Ogre::ManualObject* object = m_sceneManager->createManualObject();
  59. object->begin("BasicSurface/Diffuse", Ogre::RenderOperation::OT_TRIANGLE_FAN);
  60. object->setUseIdentityProjection(true);
  61. object->setUseIdentityView(true);
  62. object->position(p1.m_X, p1.m_Y, 0.0);
  63. object->colour(color);
  64. object->index(0);
  65. object->position(p2.m_X, p2.m_Y, 0.0);
  66. object->colour(color);
  67. object->index(1);
  68. object->position(p3.m_X, p3.m_Y, 0.0);
  69. object->colour(color);
  70. object->index(2);
  71. object->index(0);
  72. object->end();
  73. object->setBoundingBox(m_aabInf);
  74. object->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - plane);
  75. object->setVisible(true);
  76. return object;
  77. }
  78. //---------------------------------------------------------------------------------------------------
  79. Ogre::ManualObject* CBasicPainter::paintCircle(const Ogre::Real rX, const Ogre::Real rY, const Ogre::Real rR, const Ogre::ColourValue color,
  80. const bool bFilled, const int plane) const
  81. {
  82. Ogre::ManualObject* object = m_sceneManager->createManualObject();
  83. if (bFilled) { object->begin("BasicSurface/Diffuse", Ogre::RenderOperation::OT_TRIANGLE_FAN); }
  84. else { object->begin("BasicSurface/Diffuse", Ogre::RenderOperation::OT_LINE_STRIP); }
  85. object->setUseIdentityProjection(true);
  86. object->setUseIdentityView(true);
  87. float const fAccuracy = 16;
  88. unsigned uiIndex = 0;
  89. for (float theta = 0; theta <= 2 * Ogre::Math::PI; theta += Ogre::Math::PI / fAccuracy)
  90. {
  91. object->position(rX + rR * cos(theta), rY + rR * sin(theta), 0);
  92. object->colour(color);
  93. object->index(uiIndex++);
  94. }
  95. object->index(0);
  96. object->end();
  97. object->setBoundingBox(m_aabInf);
  98. object->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - plane);
  99. object->setVisible(true);
  100. return object;
  101. }
  102. //---------------------------------------------------------------------------------------------------
  103. void CBasicPainter::paintText(const std::string& sID, const std::string& sText, const Ogre::Real rX, const Ogre::Real rY,
  104. const Ogre::Real rWidth, const Ogre::Real rHeight, const Ogre::ColourValue& color) const
  105. {
  106. Ogre::OverlayElement* text = m_overlayManager->createOverlayElement("TextArea", sID);
  107. text->setDimensions(rWidth, rHeight);
  108. text->setMetricsMode(Ogre::GMM_PIXELS);
  109. text->setPosition(rX, rY);
  110. text->setParameter("font_name", "DejaVu");
  111. text->setColour(color);
  112. text->setCaption(sText);
  113. m_overlayContainer->addChild(text);
  114. }
  115. #endif
  116. } // namespace SSVEP
  117. } // namespace OpenViBE