2 * Senses touch and collision events
6 * ***** BEGIN GPL LICENSE BLOCK *****
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL LICENSE BLOCK *****
32 #ifndef __KX_TOUCHSENSOR
33 #define __KX_TOUCHSENSOR
35 #include "SCA_ISensor.h"
36 #include "ListValue.h"
40 #include "KX_ClientObjectInfo.h"
43 typedef unsigned __int64 uint_ptr;
45 typedef unsigned long uint_ptr;
48 class KX_TouchEventManager;
50 class KX_TouchSensor : public SCA_ISensor
56 * The sensor should only look for objects with this property.
58 STR_String m_touchedpropname;
60 bool m_bTouchPulse; /* changes in the colliding objects trigger pulses */
61 class SCA_EventManager* m_eventmgr;
63 class PHY_IPhysicsController* m_physCtrl;
67 bool m_bLastTriggered;
69 // Use with m_bTouchPulse to detect changes
70 int m_bLastCount; /* size of m_colliders last tick */
71 uint_ptr m_bColliderHash; /* hash collision objects pointers to trigger incase one object collides and another takes its place */
72 uint_ptr m_bLastColliderHash;
74 SCA_IObject* m_hitObject;
75 class CListValue* m_colliders;
78 KX_TouchSensor(class SCA_EventManager* eventmgr,
79 class KX_GameObject* gameobj,
82 const STR_String& touchedpropname,
83 PyTypeObject* T=&Type) ;
84 virtual ~KX_TouchSensor();
86 virtual CValue* GetReplica();
87 virtual void SynchronizeTransform();
88 virtual bool Evaluate(CValue* event);
90 virtual void ReParent(SCA_IObject* parent);
92 virtual void RegisterSumo(KX_TouchEventManager* touchman);
93 virtual void UnregisterSumo(KX_TouchEventManager* touchman);
94 virtual void UnregisterToManager();
96 // virtual DT_Bool HandleCollision(void* obj1,void* obj2,
97 // const DT_CollData * coll_data);
99 virtual bool NewHandleCollision(void*obj1,void*obj2,const PHY_CollData* colldata);
101 // Allows to do pre-filtering and save computation time
102 // obj1 = sensor physical controller, obj2 = physical controller of second object
103 // return value = true if collision should be checked on pair of object
104 virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
108 virtual bool IsPositiveTrigger() {
109 bool result = m_bTriggered;
110 if (m_invert) result = !result;
115 virtual void EndFrame();
117 // todo: put some info for collision maybe
119 /* --------------------------------------------------------------------- */
120 /* Python interface ---------------------------------------------------- */
121 /* --------------------------------------------------------------------- */
123 virtual PyObject* _getattr(const char *attr);
124 virtual int _setattr(const char *attr, PyObject *value);
127 KX_PYMETHOD_DOC_O(KX_TouchSensor,SetProperty);
129 KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetProperty);
130 /* 3. getHitObject */
131 KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObject);
132 /* 4. getHitObject */
133 KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetHitObjectList);
134 /* 5. getTouchMaterial */
135 KX_PYMETHOD_DOC_NOARGS(KX_TouchSensor,GetTouchMaterial);
137 /* 6. setTouchMaterial */
138 KX_PYMETHOD_DOC_O(KX_TouchSensor,SetTouchMaterial);
143 #endif //__KX_TOUCHSENSOR