00001 #include "KX_TouchEventManager.h"
00002 #include "SCA_ISensor.h"
00003 #include "KX_TouchSensor.h"
00004 #include "KX_GameObject.h"
00005 #include "SM_Object.h"
00006
00007 KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
00008 DT_RespTableHandle resphandle,
00009 DT_SceneHandle scenehandle)
00010 : SCA_EventManager(TOUCH_EVENTMGR),
00011 m_resphandle(resphandle),
00012 m_scenehandle(scenehandle),
00013 m_logicmgr(logicmgr) {}
00014
00015 void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
00016 {
00017
00018
00019 KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
00020 m_sensors.push_back(touchsensor);
00021
00022 touchsensor->RegisterSumo(this,m_resphandle);
00023
00024
00025 SM_Object* smobj = touchsensor->GetSumoObject();
00026 if (smobj)
00027 {
00028 smobj->calcXform();
00029 DT_AddObject(m_scenehandle,
00030 smobj->getObjectHandle());
00031 }
00032 }
00033
00034 void KX_TouchEventManager::EndFrame()
00035 {
00036 vector<SCA_ISensor*>::iterator it;
00037 for ( it = m_sensors.begin();
00038 !(it==m_sensors.end());it++)
00039 {
00040 ((KX_TouchSensor*)*it)->EndFrame();
00041
00042 }
00043 }
00044
00045 void KX_TouchEventManager::NextFrame(double curtime,double deltatime)
00046 {
00047 vector<SCA_ISensor*>::iterator it;
00048
00049 for ( it = m_sensors.begin();
00050 !(it==m_sensors.end());it++)
00051 {
00052 ((KX_TouchSensor*)*it)->SynchronizeTransform();
00053 }
00054
00055 if (DT_Test(m_scenehandle,m_resphandle))
00056 {
00057 int i=0;
00058 }
00059
00060
00061 for (it = m_sensors.begin();
00062 !(it==m_sensors.end());it++)
00063 {
00064 (*it)->Activate(m_logicmgr,NULL);
00065 }
00066 }
00067
00068 void KX_TouchEventManager::RemoveSensor(class SCA_ISensor* sensor)
00069 {
00070 std::vector<SCA_ISensor*>::iterator i =
00071 std::find(m_sensors.begin(), m_sensors.end(), sensor);
00072 if (!(i == m_sensors.end()))
00073 {
00074
00075
00076 SM_Object* smobj = ((KX_TouchSensor*)*i)->GetSumoObject();
00077 DT_RemoveObject(m_scenehandle,
00078 smobj->getObjectHandle());
00079 }
00080
00081 SCA_EventManager::RemoveSensor(sensor);
00082 }