Blender V2.61 - r43446

KX_TouchSensor.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #ifndef __KX_TOUCHSENSOR
00034 #define __KX_TOUCHSENSOR
00035 
00036 #include "SCA_ISensor.h"
00037 #include "ListValue.h"
00038 
00039 struct PHY_CollData;
00040 
00041 #include "KX_ClientObjectInfo.h"
00042 
00043 #if defined(_WIN64)
00044 typedef unsigned __int64 uint_ptr;
00045 #else
00046 typedef unsigned long uint_ptr;
00047 #endif
00048 
00049 class KX_TouchEventManager;
00050 
00051 class KX_TouchSensor : public SCA_ISensor
00052 {
00053 protected:
00054     Py_Header
00055 
00059     STR_String              m_touchedpropname;  
00060     bool                    m_bFindMaterial;
00061     bool                    m_bTouchPulse;      /* changes in the colliding objects trigger pulses */
00062     
00063     class PHY_IPhysicsController*   m_physCtrl;
00064 
00065     bool                    m_bCollision;
00066     bool                    m_bTriggered;
00067     bool                    m_bLastTriggered;
00068 
00069     // Use with m_bTouchPulse to detect changes
00070     int                     m_bLastCount;       /* size of m_colliders last tick */
00071     uint_ptr                m_bColliderHash;    /* hash collision objects pointers to trigger incase one object collides and another takes its place */
00072     uint_ptr                m_bLastColliderHash;
00073 
00074     SCA_IObject*            m_hitObject;
00075     class CListValue*       m_colliders;
00076     
00077 public:
00078     KX_TouchSensor(class SCA_EventManager* eventmgr,
00079         class KX_GameObject* gameobj,
00080         bool bFindMaterial,
00081         bool bTouchPulse,
00082         const STR_String& touchedpropname) ;
00083     virtual ~KX_TouchSensor();
00084 
00085     virtual CValue* GetReplica();
00086     virtual void ProcessReplica();
00087     virtual void SynchronizeTransform();
00088     virtual bool Evaluate();
00089     virtual void Init();
00090     virtual void ReParent(SCA_IObject* parent);
00091     
00092     virtual void RegisterSumo(KX_TouchEventManager* touchman);
00093     virtual void UnregisterSumo(KX_TouchEventManager* touchman);
00094     virtual void UnregisterToManager();
00095 
00096 //  virtual DT_Bool HandleCollision(void* obj1,void* obj2,
00097 //                       const DT_CollData * coll_data); 
00098 
00099     virtual bool    NewHandleCollision(void*obj1,void*obj2,const PHY_CollData* colldata);
00100 
00101     // Allows to do pre-filtering and save computation time
00102     // obj1 = sensor physical controller, obj2 = physical controller of second object
00103     // return value = true if collision should be checked on pair of object
00104     virtual bool    BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
00105     virtual bool    BroadPhaseSensorFilterCollision(void*obj1,void*obj2);
00106     virtual sensortype GetSensorType() { return ST_TOUCH; }
00107   
00108 
00109     virtual bool IsPositiveTrigger() {
00110         bool result = m_bTriggered;
00111         if (m_invert) result = !result;
00112         return result;
00113     }
00114     
00115     virtual void EndFrame();
00116 
00117     class PHY_IPhysicsController* GetPhysicsController() { return m_physCtrl; }
00118 
00119 
00120     // todo: put some info for collision maybe
00121 
00122 #ifdef WITH_PYTHON
00123 
00124     /* --------------------------------------------------------------------- */
00125     /* Python interface ---------------------------------------------------- */
00126     /* --------------------------------------------------------------------- */
00127     
00128     static PyObject*    pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00129     static PyObject*    pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00130 
00131 #endif
00132     
00133 };
00134 
00135 #endif //__KX_TOUCHSENSOR
00136