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