| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- #include "core/DebugDraw.h"
- #include "core/Entity.h"
- #include "core/EntityTrigger.h"
- #include "core/ConfigVar.h"
- ConfigVar cv_debug_trigger("debug_trigger", "Draw entity trigger debug info", "0");
- EntityTrigger::EntityTrigger(const Ogre::String& name):
- m_Name(name),
- m_Enabled(false),
- m_Point1(Ogre::Vector3::ZERO),
- m_Point2(Ogre::Vector3::ZERO)
- {
- }
- EntityTrigger::~EntityTrigger()
- {
- }
- void
- EntityTrigger::UpdateDebug()
- {
- if(cv_debug_trigger.GetB() == true)
- {
- if(m_Enabled == false)
- {
- DEBUG_DRAW.SetColour(Ogre::ColourValue(0.5f, 0.5f, 0.5f));
- }
- else if(m_Activators.size() > 0)
- {
- DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.9f, 0.5f));
- }
- else
- {
- DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.5f, 0.9f));
- }
- DEBUG_DRAW.Line3d(m_Point1, m_Point2);
- DEBUG_DRAW.SetColour(Ogre::ColourValue::White);
- DEBUG_DRAW.SetScreenSpace(true);
- DEBUG_DRAW.SetTextAlignment(DEBUG_DRAW.CENTER);
- DEBUG_DRAW.SetFadeDistance(30, 40);
- Ogre::Vector3 center = m_Point2 - ((m_Point2 - m_Point1) / 2);
- DEBUG_DRAW.Text(center, 0, 0, m_Name);
- DEBUG_DRAW.SetColour(Ogre::ColourValue(0.04f, 0.9f, 0.5f));
- for(unsigned int i = 0; i < m_Activators.size(); ++i)
- {
- DEBUG_DRAW.Text(center, 0.0f, static_cast<float>((i + 1) * 16), m_Activators[i]->GetName());
- }
- }
- }
- const Ogre::String&
- EntityTrigger::GetName() const
- {
- return m_Name;
- }
- void
- EntityTrigger::SetEnabled(const bool enabled)
- {
- m_Enabled = enabled;
- if(enabled == false)
- {
- m_Activators.clear();
- }
- }
- bool
- EntityTrigger::IsEnabled() const
- {
- return m_Enabled;
- }
- void
- EntityTrigger::AddActivator(Entity* activator)
- {
- // add only if this activator don't exist
- unsigned int i = 0;
- for(; i < m_Activators.size(); ++i)
- {
- if(m_Activators[i] == activator)
- {
- break;
- }
- }
- if(i == m_Activators.size())
- {
- m_Activators.push_back(activator);
- }
- }
- void
- EntityTrigger::RemoveActivator(Entity* activator)
- {
- for(unsigned int i = 0; i < m_Activators.size(); ++i)
- {
- if(m_Activators[i] == activator)
- {
- m_Activators.erase(m_Activators.begin() + i);
- return;
- }
- }
- }
- bool
- EntityTrigger::IsActivator(Entity* activator)
- {
- for(unsigned int i = 0; i < m_Activators.size(); ++i)
- {
- if(m_Activators[i] == activator)
- {
- return true;
- }
- }
- return false;
- }
- void
- EntityTrigger::SetPoints(const Ogre::Vector3& point1, const Ogre::Vector3& point2)
- {
- m_Point1 = point1;
- m_Point2 = point2;
- }
- const Ogre::Vector3&
- EntityTrigger::GetPoint1() const
- {
- return m_Point1;
- }
- const Ogre::Vector3&
- EntityTrigger::GetPoint2() const
- {
- return m_Point2;
- }
|