| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * $Id$ | 
					
						
							|  |  |  |  * ***** BEGIN GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							|  |  |  |  * of the License, or (at your option) any later version. The Blender | 
					
						
							|  |  |  |  * Foundation also sells licenses for use in proprietary software under | 
					
						
							|  |  |  |  * the Blender License.  See http://www.blender.org/BL/ for information
 | 
					
						
							|  |  |  |  * about this. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * The Original Code is: all of this file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Contributor(s): none yet. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * ***** END GPL/BL DUAL LICENSE BLOCK ***** | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "KX_RadarSensor.h"
 | 
					
						
							|  |  |  | #include "KX_GameObject.h"
 | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | #include "PHY_IPhysicsController.h"
 | 
					
						
							| 
									
										
										
										
											2002-11-25 15:29:57 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef HAVE_CONFIG_H
 | 
					
						
							|  |  |  | #include <config.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * 	RadarSensor constructor. Creates a near-sensor derived class, with a cone collision shape. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2004-03-22 22:02:18 +00:00
										 |  |  | KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr, | 
					
						
							|  |  |  | 		KX_GameObject* gameobj, | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 		PHY_IPhysicsController* physCtrl, | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 			double coneradius, | 
					
						
							|  |  |  | 			double coneheight, | 
					
						
							|  |  |  | 			int	axis, | 
					
						
							|  |  |  | 			double margin, | 
					
						
							|  |  |  | 			double resetmargin, | 
					
						
							|  |  |  | 			bool bFindMaterial, | 
					
						
							|  |  |  | 			const STR_String& touchedpropname, | 
					
						
							|  |  |  | 			class KX_Scene* kxscene, | 
					
						
							|  |  |  | 			PyTypeObject* T) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			: KX_NearSensor( | 
					
						
							|  |  |  | 				eventmgr, | 
					
						
							|  |  |  | 				gameobj, | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 				//DT_NewCone(coneradius,coneheight),
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				margin, | 
					
						
							|  |  |  | 				resetmargin, | 
					
						
							|  |  |  | 				bFindMaterial, | 
					
						
							|  |  |  | 				touchedpropname, | 
					
						
							|  |  |  | 				kxscene, | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 				physCtrl, | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				T), | 
					
						
							|  |  |  | 				m_coneradius(coneradius), | 
					
						
							| 
									
										
										
										
											2004-03-22 22:02:18 +00:00
										 |  |  | 				m_coneheight(coneheight), | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 				m_axis(axis) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2004-03-22 22:02:18 +00:00
										 |  |  | 	m_client_info->m_type = KX_ClientObjectInfo::RADAR; | 
					
						
							|  |  |  | 	//m_client_info->m_clientobject = gameobj;
 | 
					
						
							|  |  |  | 	//m_client_info->m_auxilary_info = NULL;
 | 
					
						
							|  |  |  | 	//sumoObj->setClientObject(&m_client_info);
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | KX_RadarSensor::~KX_RadarSensor() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | CValue* KX_RadarSensor::GetReplica() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	KX_RadarSensor* replica = new KX_RadarSensor(*this); | 
					
						
							|  |  |  | 	replica->m_colliders = new CListValue(); | 
					
						
							|  |  |  | 	replica->m_bCollision = false; | 
					
						
							|  |  |  | 	replica->m_bTriggered= false; | 
					
						
							|  |  |  | 	replica->m_hitObject = NULL; | 
					
						
							|  |  |  | 	replica->m_bLastTriggered = false; | 
					
						
							|  |  |  | 	// this will copy properties and so on...
 | 
					
						
							|  |  |  | 	CValue::AddDataToReplica(replica); | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2004-11-06 04:58:10 +00:00
										 |  |  | 	replica->m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::RADAR); | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2006-01-06 09:57:27 +00:00
										 |  |  | 	if (replica->m_physCtrl) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		replica->m_physCtrl = replica->m_physCtrl->GetReplica(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 	//todo: make sure replication works fine!
 | 
					
						
							|  |  |  | 	//>m_sumoObj = new SM_Object(DT_NewCone(m_coneradius, m_coneheight),NULL,NULL,NULL);
 | 
					
						
							|  |  |  | 	//replica->m_sumoObj->setMargin(m_Margin);
 | 
					
						
							|  |  |  | 	//replica->m_sumoObj->setClientObject(replica->m_client_info);
 | 
					
						
							| 
									
										
										
										
											2004-06-04 03:00:13 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	replica->SynchronizeTransform(); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return replica; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  *	Transforms the collision object. A cone is not correctly centered | 
					
						
							|  |  |  |  *	for usage.  */ | 
					
						
							|  |  |  | void KX_RadarSensor::SynchronizeTransform() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// Getting the parent location was commented out. Why?
 | 
					
						
							|  |  |  | 	MT_Transform trans; | 
					
						
							|  |  |  | 	trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition()); | 
					
						
							|  |  |  | 	trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation()); | 
					
						
							|  |  |  | 	// What is the default orientation? pointing in the -y direction?
 | 
					
						
							|  |  |  | 	// is the geometry correctly converted?
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	// a collision cone is oriented
 | 
					
						
							|  |  |  | 	// center the cone correctly 
 | 
					
						
							|  |  |  | 	// depends on the radar 'axis'
 | 
					
						
							|  |  |  | 	switch (m_axis) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 	case 0: // X Axis
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90)); | 
					
						
							|  |  |  | 			trans.rotate(rotquatje); | 
					
						
							|  |  |  | 			trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	case 1: // Y Axis
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180)); | 
					
						
							|  |  |  | 			trans.rotate(rotquatje); | 
					
						
							|  |  |  | 			trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	case 2: // Z Axis
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90)); | 
					
						
							|  |  |  | 			trans.rotate(rotquatje); | 
					
						
							|  |  |  | 			trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0)); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	m_cone_origin = trans.getOrigin(); | 
					
						
							|  |  |  | 	m_cone_target = trans(MT_Point3(0, -m_coneheight/2.0 ,0)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-06 09:57:27 +00:00
										 |  |  | 	if (m_physCtrl) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		m_physCtrl->setPosition(trans.getOrigin().x(),trans.getOrigin().y(),trans.getOrigin().z()); | 
					
						
							|  |  |  | 		m_physCtrl->setOrientation(trans.getRotation().x(),trans.getRotation().y(),trans.getRotation().z(),trans.getRotation().w()); | 
					
						
							|  |  |  | 		m_physCtrl->calcXform(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-03-25 10:33:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | /* Python functions                                                          */ | 
					
						
							|  |  |  | /* ------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Integration hooks ------------------------------------------------------- */ | 
					
						
							|  |  |  | PyTypeObject KX_RadarSensor::Type = { | 
					
						
							|  |  |  | 	PyObject_HEAD_INIT(&PyType_Type) | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	"KX_RadarSensor", | 
					
						
							|  |  |  | 	sizeof(KX_RadarSensor), | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	PyDestructor, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	__getattr, | 
					
						
							|  |  |  | 	__setattr, | 
					
						
							|  |  |  | 	0, //&MyPyCompare,
 | 
					
						
							|  |  |  | 	__repr, | 
					
						
							|  |  |  | 	0, //&cvalue_as_number,
 | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0, | 
					
						
							|  |  |  | 	0 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyParentObject KX_RadarSensor::Parents[] = { | 
					
						
							|  |  |  | 	&KX_RadarSensor::Type, | 
					
						
							|  |  |  | 	&KX_NearSensor::Type, | 
					
						
							|  |  |  | 	&KX_TouchSensor::Type, | 
					
						
							|  |  |  | 	&SCA_ISensor::Type, | 
					
						
							|  |  |  | 	&SCA_ILogicBrick::Type, | 
					
						
							|  |  |  | 	&CValue::Type, | 
					
						
							|  |  |  | 	NULL | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PyMethodDef KX_RadarSensor::Methods[] = { | 
					
						
							|  |  |  | 	{"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin,  | 
					
						
							|  |  |  | 	 METH_VARARGS, GetConeOrigin_doc}, | 
					
						
							|  |  |  | 	{"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget,  | 
					
						
							|  |  |  | 	 METH_VARARGS, GetConeTarget_doc}, | 
					
						
							|  |  |  | 	{"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight,  | 
					
						
							|  |  |  | 	 METH_VARARGS, GetConeHeight_doc}, | 
					
						
							|  |  |  | 	{NULL,NULL,NULL,NULL} //Sentinel
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-05-16 13:05:15 +00:00
										 |  |  | PyObject* KX_RadarSensor::_getattr(const STR_String& attr) { | 
					
						
							| 
									
										
										
										
											2002-10-12 11:37:38 +00:00
										 |  |  | 	_getattr_up(KX_TouchSensor); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* getConeOrigin */ | 
					
						
							|  |  |  | char KX_RadarSensor::GetConeOrigin_doc[] =  | 
					
						
							|  |  |  | "getConeOrigin()\n" | 
					
						
							|  |  |  | "\tReturns the origin of the cone with which to test. The origin\n" | 
					
						
							|  |  |  | "\tis in the middle of the cone."; | 
					
						
							|  |  |  | PyObject* KX_RadarSensor::PyGetConeOrigin(PyObject* self,  | 
					
						
							|  |  |  | 										  PyObject* args,  | 
					
						
							|  |  |  | 										  PyObject* kwds) { | 
					
						
							|  |  |  | 	PyObject *retVal = PyList_New(3); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_origin[0])); | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_origin[1])); | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_origin[2])); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return retVal; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* getConeOrigin */ | 
					
						
							|  |  |  | char KX_RadarSensor::GetConeTarget_doc[] =  | 
					
						
							|  |  |  | "getConeTarget()\n" | 
					
						
							|  |  |  | "\tReturns the center of the bottom face of the cone with which to test.\n"; | 
					
						
							|  |  |  | PyObject* KX_RadarSensor::PyGetConeTarget(PyObject* self,  | 
					
						
							|  |  |  | 										  PyObject* args,  | 
					
						
							|  |  |  | 										  PyObject* kwds) { | 
					
						
							|  |  |  | 	PyObject *retVal = PyList_New(3); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 0, PyFloat_FromDouble(m_cone_target[0])); | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 1, PyFloat_FromDouble(m_cone_target[1])); | 
					
						
							|  |  |  | 	PyList_SetItem(retVal, 2, PyFloat_FromDouble(m_cone_target[2])); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return retVal; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* getConeOrigin */ | 
					
						
							|  |  |  | char KX_RadarSensor::GetConeHeight_doc[] =  | 
					
						
							|  |  |  | "getConeHeight()\n" | 
					
						
							|  |  |  | "\tReturns the height of the cone with which to test.\n"; | 
					
						
							|  |  |  | PyObject* KX_RadarSensor::PyGetConeHeight(PyObject* self,  | 
					
						
							|  |  |  | 										  PyObject* args,  | 
					
						
							|  |  |  | 										  PyObject* kwds) { | 
					
						
							|  |  |  | 	return PyFloat_FromDouble(m_coneheight); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |