Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

KX_NearSensor.cpp

Go to the documentation of this file.
00001 
00006 
00007 #include "KX_NearSensor.h"
00008 #include "SCA_LogicManager.h"
00009 #include "SM_Object.h"
00010 #include "KX_GameObject.h"
00011 #include "KX_TouchEventManager.h"
00012 
00013 bool KX_NearSensor::Evaluate(CValue* event)

00014 {
00015         bool result = false;
00016         KX_GameObject* parent = (KX_GameObject*)GetParent();
00017 
00018         if (m_bTriggered != m_bLastTriggered)
00019         {
00020                 m_bLastTriggered = m_bTriggered;
00021                 if (m_bTriggered)
00022                 {
00023                         if (m_sumoObj)
00024                         {
00025                                 m_sumoObj->setMargin(m_ResetMargin);
00026                         }
00027                 } else
00028                 {
00029                         if (m_sumoObj)
00030                         {
00031                                 m_sumoObj->setMargin(m_Margin);
00032                         }
00033 
00034                 }
00035                 result = true;
00036         }
00037 
00038         return result;
00039 }
00040 
00041 KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,double margin,double resetmargin,SM_Object* sumoObj,bool bFindMaterial,const CCString& touchedpropname,PyTypeObject* T)
00042 :KX_TouchSensor(eventmgr,gameobj,sumoObj,bFindMaterial,touchedpropname,T),
00043 m_Margin(margin),
00044 m_ResetMargin(resetmargin)

00045 

00046 {
00047         m_client_info.m_type = 4;
00048         m_client_info.m_clientobject = gameobj;
00049         m_client_info.m_auxilary_info = NULL;
00050         sumoObj->setClientObject(&m_client_info);
00051 }
00052 
00053 void    KX_NearSensor::HandleCollision(void* obj1,void* obj2,const DT_CollData * coll_data)

00054 {
00055         KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr;
00056         KX_GameObject* parent = (KX_GameObject*)GetParent();
00057 
00058         // need the mapping from SM_Objects to gameobjects now
00059         
00060         SM_ClientObjectInfo* client_info =(SM_ClientObjectInfo*) (obj1 == m_sumoObj? 
00061                                         ((SM_Object*)obj2)->getClientObject() : 
00062                                         ((SM_Object*)obj1)->getClientObject());
00063 
00064 
00065         KX_GameObject* gameobj = ( client_info ? 
00066                         (KX_GameObject*)client_info->m_clientobject : 
00067                         NULL);
00068 
00069         if (gameobj && (gameobj != parent))
00070         {
00071                 if (!m_colliders->SearchValue(gameobj))
00072                         m_colliders->Add(gameobj->AddRef());
00073                 
00074                 // only take valid colliders
00075                 if (client_info->m_type == 1)
00076                 {
00077                         if ((m_touchedpropname.Length() == 0) || 
00078                                 (gameobj->GetProperty(m_touchedpropname)))
00079                         {
00080                                 m_bTriggered = true;
00081                                 m_hitObject = gameobj;
00082                         }
00083                 }
00084         } else
00085         {
00086                 
00087         }
00088 }
00089 
00090 
00091 // python embedding
00092 PyTypeObject KX_NearSensor::Type = {
00093         PyObject_HEAD_INIT(&PyType_Type)
00094         0,
00095         "KX_NearSensor",
00096         sizeof(KX_NearSensor),
00097         0,
00098         PyDestructor,
00099         0,
00100         __getattr,
00101         __setattr,
00102         0, //&MyPyCompare,
00103         __repr,
00104         0, //&cvalue_as_number,
00105         0,
00106         0,
00107         0,
00108         0
00109 };
00110 
00111 PyParentObject KX_NearSensor::Parents[] = {
00112         &KX_NearSensor::Type,
00113         &KX_TouchSensor::Type,
00114         &SCA_ISensor::Type,
00115         &SCA_ILogicBrick::Type,
00116         &CValue::Type,
00117         NULL
00118 };
00119 PyMethodDef KX_NearSensor::Methods[] = {
00120   //{"isPositive", (PyCFunction) SCA_ISensor::sPyIsPositive, METH_VARARGS},
00121   {NULL,NULL} //Sentinel
00122 };
00123 
00124 
00125 PyObject*
00126 KX_NearSensor::_getattr(char* attr)

00127 {
00128   _getattr_up(KX_TouchSensor);
00129 }

Generated at Thu Feb 1 13:03:05 2001 for Ketsji Game Engine by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000