[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47869] trunk/blender: Fix for [#31813] " bge.types.KX_RadarSensor incorrect attributes" reported by Monster.

Mitchell Stokes mogurijin at gmail.com
Thu Jun 14 10:01:21 CEST 2012


Revision: 47869
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47869
Author:   moguri
Date:     2012-06-14 08:01:20 +0000 (Thu, 14 Jun 2012)
Log Message:
-----------
Fix for [#31813] "bge.types.KX_RadarSensor incorrect attributes" reported by Monster.

KX_RadarSensor.angle was returning the angle that was used to construct Bullet's physics shape, which is calculated from the logic brick gui. KX_RadarSensor.angle now recalculates the original value from the gui. However, m_coneradius isn't actually used by KX_RadarSensor that I can see, so it might be better to just assign the original angle to m_coneradius instead of the calculated value. I've also made KX_RadarSensor.angle read-only, since setting m_coneradius does not appear to have any affect, which means writing to KX_RadarSensor.angle never worked properly.

Modified Paths:
--------------
    trunk/blender/doc/python_api/rst/bge.types.rst
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.h

Modified: trunk/blender/doc/python_api/rst/bge.types.rst
===================================================================
--- trunk/blender/doc/python_api/rst/bge.types.rst	2012-06-14 07:53:52 UTC (rev 47868)
+++ trunk/blender/doc/python_api/rst/bge.types.rst	2012-06-14 08:01:20 UTC (rev 47869)
@@ -2692,7 +2692,7 @@
 
       The angle of the cone (in degrees) with which to test.
 
-      :type: float from 0 to 360
+      :type: float
 
    .. attribute:: axis
 

Modified: trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp	2012-06-14 07:53:52 UTC (rev 47868)
+++ trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp	2012-06-14 08:01:20 UTC (rev 47869)
@@ -212,9 +212,19 @@
 	KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3),
 	KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3),
 	KX_PYATTRIBUTE_FLOAT_RO("distance", KX_RadarSensor, m_coneheight),
-	KX_PYATTRIBUTE_FLOAT_RW("angle", 0, 360, KX_RadarSensor, m_coneradius),
+	KX_PYATTRIBUTE_RO_FUNCTION("angle", KX_RadarSensor, pyattr_get_angle),
 	KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis),
 	{NULL} //Sentinel
 };
 
+PyObject* KX_RadarSensor::pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
+{
+	KX_RadarSensor* self= static_cast<KX_RadarSensor*>(self_v);
+
+	// The original angle from the gui was converted, so we recalculate the value here to maintain
+	// consistency between Python and the gui
+	return PyFloat_FromDouble(MT_degrees(atan(self->m_coneradius / self->m_coneheight)) * 2);
+	
+}
+
 #endif // WITH_PYTHON

Modified: trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.h
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.h	2012-06-14 07:53:52 UTC (rev 47868)
+++ trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.h	2012-06-14 08:01:20 UTC (rev 47869)
@@ -93,6 +93,7 @@
 	/* python */
 	virtual sensortype GetSensorType() { return ST_RADAR; }
 
+	static PyObject*	pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
 };
 
 #endif //__KX_RADARSENSOR_H__




More information about the Bf-blender-cvs mailing list