2002-10-12 11:37:38 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "KX_RadarSensor.h"
|
|
|
|
#include "KX_GameObject.h"
|
2009-02-25 06:43:03 +00:00
|
|
|
#include "KX_PyMath.h"
|
2005-03-25 10:33:39 +00:00
|
|
|
#include "PHY_IPhysicsController.h"
|
2009-06-08 20:08:19 +00:00
|
|
|
#include "PHY_IMotionState.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,
|
2009-06-28 11:22:26 +00:00
|
|
|
class KX_Scene* kxscene)
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
: 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,
|
2009-06-28 11:22:26 +00:00
|
|
|
physCtrl),
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
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)
|
|
|
|
{
|
2009-06-08 20:08:19 +00:00
|
|
|
m_client_info->m_type = KX_ClientObjectInfo::SENSOR;
|
2004-03-22 22:02:18 +00:00
|
|
|
//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);
|
2009-06-08 20:08:19 +00:00
|
|
|
replica->ProcessReplica();
|
2004-06-04 03:00:13 +00:00
|
|
|
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)
|
|
|
|
{
|
2008-04-05 22:08:15 +00:00
|
|
|
case 0: // +X Axis
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
2008-04-05 22:08:15 +00:00
|
|
|
case 1: // +Y Axis
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
2008-04-05 22:08:15 +00:00
|
|
|
case 2: // +Z Axis
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
};
|
2008-04-05 22:08:15 +00:00
|
|
|
case 3: // -X Axis
|
|
|
|
{
|
2008-08-07 17:29:06 +00:00
|
|
|
MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90));
|
2008-04-05 22:08:15 +00:00
|
|
|
trans.rotate(rotquatje);
|
2008-08-07 17:29:06 +00:00
|
|
|
trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
|
2008-04-05 22:08:15 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
case 4: // -Y Axis
|
|
|
|
{
|
2008-08-07 17:29:06 +00:00
|
|
|
//MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
|
|
|
|
//trans.rotate(rotquatje);
|
|
|
|
trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
|
2008-04-05 22:08:15 +00:00
|
|
|
break;
|
|
|
|
};
|
|
|
|
case 5: // -Z Axis
|
|
|
|
{
|
2008-08-07 17:29:06 +00:00
|
|
|
MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90));
|
2008-04-05 22:08:15 +00:00
|
|
|
trans.rotate(rotquatje);
|
2008-08-07 17:29:06 +00:00
|
|
|
trans.translate(MT_Vector3 (0, -m_coneheight/2.0 ,0));
|
2008-04-05 22:08:15 +00:00
|
|
|
break;
|
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2009-02-28 21:00:27 +00:00
|
|
|
|
|
|
|
//Using a temp variable to translate MT_Point3 to float[3].
|
|
|
|
//float[3] works better for the Python interface.
|
|
|
|
MT_Point3 temp = trans.getOrigin();
|
|
|
|
m_cone_origin[0] = temp[0];
|
|
|
|
m_cone_origin[1] = temp[1];
|
|
|
|
m_cone_origin[2] = temp[2];
|
|
|
|
|
|
|
|
temp = trans(MT_Point3(0, -m_coneheight/2.0 ,0));
|
|
|
|
m_cone_target[0] = temp[0];
|
|
|
|
m_cone_target[1] = temp[1];
|
|
|
|
m_cone_target[2] = temp[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2006-01-06 09:57:27 +00:00
|
|
|
if (m_physCtrl)
|
|
|
|
{
|
2009-06-08 20:08:19 +00:00
|
|
|
PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
|
|
|
|
const MT_Point3& pos = trans.getOrigin();
|
|
|
|
float ori[12];
|
|
|
|
trans.getBasis().getValue(ori);
|
|
|
|
motionState->setWorldPosition(pos[0], pos[1], pos[2]);
|
|
|
|
motionState->setWorldOrientation(ori);
|
|
|
|
m_physCtrl->WriteMotionStateToDynamics(true);
|
2006-01-06 09:57:27 +00:00
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2009-02-28 21:00:27 +00:00
|
|
|
/* Python Functions */
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2009-02-28 21:00:27 +00:00
|
|
|
//Deprecated ----->
|
|
|
|
/* getConeOrigin */
|
|
|
|
const 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.";
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_RadarSensor::PyGetConeOrigin() {
|
2009-02-28 21:00:27 +00:00
|
|
|
ShowDeprecationWarning("getConeOrigin()", "the coneOrigin property");
|
|
|
|
|
|
|
|
PyObject *retVal = PyList_New(3);
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_cone_origin[0]));
|
|
|
|
PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(m_cone_origin[1]));
|
|
|
|
PyList_SET_ITEM(retVal, 2, PyFloat_FromDouble(m_cone_origin[2]));
|
2009-02-28 21:00:27 +00:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* getConeOrigin */
|
|
|
|
const char KX_RadarSensor::GetConeTarget_doc[] =
|
|
|
|
"getConeTarget()\n"
|
|
|
|
"\tReturns the center of the bottom face of the cone with which to test.\n";
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_RadarSensor::PyGetConeTarget() {
|
2009-02-28 21:00:27 +00:00
|
|
|
ShowDeprecationWarning("getConeTarget()", "the coneTarget property");
|
|
|
|
|
|
|
|
PyObject *retVal = PyList_New(3);
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(m_cone_target[0]));
|
|
|
|
PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(m_cone_target[1]));
|
|
|
|
PyList_SET_ITEM(retVal, 2, PyFloat_FromDouble(m_cone_target[2]));
|
2009-02-28 21:00:27 +00:00
|
|
|
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* getConeHeight */
|
|
|
|
const char KX_RadarSensor::GetConeHeight_doc[] =
|
|
|
|
"getConeHeight()\n"
|
|
|
|
"\tReturns the height of the cone with which to test.\n";
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_RadarSensor::PyGetConeHeight() {
|
2009-02-28 21:00:27 +00:00
|
|
|
|
|
|
|
ShowDeprecationWarning("getConeHeight()", "the distance property");
|
|
|
|
|
|
|
|
return PyFloat_FromDouble(m_coneheight);
|
|
|
|
}
|
|
|
|
//<----- Deprecated
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python Integration Hooks */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2002-10-12 11:37:38 +00:00
|
|
|
PyTypeObject KX_RadarSensor::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
#if (PY_VERSION_HEX >= 0x02060000)
|
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
|
|
|
#else
|
|
|
|
/* python 2.5 and below */
|
|
|
|
PyObject_HEAD_INIT( NULL ) /* required py macro */
|
|
|
|
0, /* ob_size */
|
|
|
|
#endif
|
2002-10-12 11:37:38 +00:00
|
|
|
"KX_RadarSensor",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
|
|
|
0,0,0,0,0,0,
|
2009-06-28 11:22:26 +00:00
|
|
|
NULL, //py_base_getattro,
|
|
|
|
NULL, //py_base_setattro,
|
|
|
|
0,
|
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
&KX_NearSensor::Type
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_RadarSensor::Methods[] = {
|
2009-02-28 21:00:27 +00:00
|
|
|
//Deprecated ----->
|
2002-10-12 11:37:38 +00:00
|
|
|
{"getConeOrigin", (PyCFunction) KX_RadarSensor::sPyGetConeOrigin,
|
2009-02-28 21:00:27 +00:00
|
|
|
METH_VARARGS, (PY_METHODCHAR)GetConeOrigin_doc},
|
2002-10-12 11:37:38 +00:00
|
|
|
{"getConeTarget", (PyCFunction) KX_RadarSensor::sPyGetConeTarget,
|
2009-02-28 21:00:27 +00:00
|
|
|
METH_VARARGS, (PY_METHODCHAR)GetConeTarget_doc},
|
2002-10-12 11:37:38 +00:00
|
|
|
{"getConeHeight", (PyCFunction) KX_RadarSensor::sPyGetConeHeight,
|
2009-02-28 21:00:27 +00:00
|
|
|
METH_VARARGS, (PY_METHODCHAR)GetConeHeight_doc},
|
|
|
|
//<-----
|
|
|
|
{NULL} //Sentinel
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_RadarSensor::Attributes[] = {
|
2009-02-28 21:00:27 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3),
|
|
|
|
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RO("distance", KX_RadarSensor, m_coneheight),
|
2009-02-28 21:00:27 +00:00
|
|
|
KX_PYATTRIBUTE_FLOAT_RW("angle", 0, 360, KX_RadarSensor, m_coneradius),
|
|
|
|
KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis),
|
|
|
|
{NULL} //Sentinel
|
2009-02-26 09:04:06 +00:00
|
|
|
};
|
|
|
|
|