EntityTrigger.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #include "core/DebugDraw.h"
  2. #include "core/Entity.h"
  3. #include "core/EntityTrigger.h"
  4. #include "core/ConfigVar.h"
  5. ConfigVar cv_debug_trigger("debug_trigger", "Draw entity trigger debug info", "0");
  6. EntityTrigger::EntityTrigger(const Ogre::String& name):
  7. m_Name(name),
  8. m_Enabled(false),
  9. m_Point1(Ogre::Vector3::ZERO),
  10. m_Point2(Ogre::Vector3::ZERO)
  11. {
  12. }
  13. EntityTrigger::~EntityTrigger()
  14. {
  15. }
  16. void
  17. EntityTrigger::UpdateDebug()
  18. {
  19. if(cv_debug_trigger.GetB() == true)
  20. {
  21. if(m_Enabled == false)
  22. {
  23. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
  24. }
  25. else if(m_Activators.size() > 0)
  26. {
  27. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.9f, 0.5f));
  28. }
  29. else
  30. {
  31. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.5f, 0.9f));
  32. }
  33. DEBUG_DRAW.Line3d(m_Point1, m_Point2);
  34. DEBUG_DRAW.SetColour(Ogre::ColourValue::White);
  35. DEBUG_DRAW.SetScreenSpace(true);
  36. DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.CENTER);
  37. DEBUG_DRAW.SetFadeDistance(30, 40);
  38. Ogre::Vector3 center = m_Point2 - ((m_Point2 - m_Point1) / 2);
  39. DEBUG_DRAW.Text(center, 0, 0, m_Name);
  40. DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.9f, 0.5f));
  41. for(unsigned int i = 0; i < m_Activators.size(); ++i)
  42. {
  43. DEBUG_DRAW.Text(center, 0.0f, static_cast<float>((i + 1) * 16), m_Activators[i]->GetName());
  44. }
  45. }
  46. }
  47. const Ogre::String&
  48. EntityTrigger::GetName() const
  49. {
  50. return m_Name;
  51. }
  52. void
  53. EntityTrigger::SetEnabled(const bool enabled)
  54. {
  55. m_Enabled = enabled;
  56. if(enabled == false)
  57. {
  58. m_Activators.clear();
  59. }
  60. }
  61. bool
  62. EntityTrigger::IsEnabled() const
  63. {
  64. return m_Enabled;
  65. }
  66. void
  67. EntityTrigger::AddActivator(Entity* activator)
  68. {
  69. // add only if this activator don't exist
  70. unsigned int i = 0;
  71. for(; i < m_Activators.size(); ++i)
  72. {
  73. if(m_Activators[i] == activator)
  74. {
  75. break;
  76. }
  77. }
  78. if(i == m_Activators.size())
  79. {
  80. m_Activators.push_back(activator);
  81. }
  82. }
  83. void
  84. EntityTrigger::RemoveActivator(Entity* activator)
  85. {
  86. for(unsigned int i = 0; i < m_Activators.size(); ++i)
  87. {
  88. if(m_Activators[i] == activator)
  89. {
  90. m_Activators.erase(m_Activators.begin() + i);
  91. return;
  92. }
  93. }
  94. }
  95. bool
  96. EntityTrigger::IsActivator(Entity* activator)
  97. {
  98. for(unsigned int i = 0; i < m_Activators.size(); ++i)
  99. {
  100. if(m_Activators[i] == activator)
  101. {
  102. return true;
  103. }
  104. }
  105. return false;
  106. }
  107. void
  108. EntityTrigger::SetPoints(const Ogre::Vector3& point1, const Ogre::Vector3& point2)
  109. {
  110. m_Point1 = point1;
  111. m_Point2 = point2;
  112. }
  113. const Ogre::Vector3&
  114. EntityTrigger::GetPoint1() const
  115. {
  116. return m_Point1;
  117. }
  118. const Ogre::Vector3&
  119. EntityTrigger::GetPoint2() const
  120. {
  121. return m_Point2;
  122. }