[Bf-blender-cvs] [67f1fd2] master: game engine: implement hitMaterial for collision and ray sensors
Dalai Felinto
noreply at git.blender.org
Fri Jan 24 05:11:16 CET 2014
Commit: 67f1fd25ee6361df5f84e254eea103fe7952125f
Author: Dalai Felinto
Date: Fri Jan 24 02:10:04 2014 -0200
https://developer.blender.org/rB67f1fd25ee6361df5f84e254eea103fe7952125f
game engine: implement hitMaterial for collision and ray sensors
Reviewed By: moguri, kupoman
Differential Revision: https://developer.blender.org/D167
===================================================================
M doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst
M doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst
M source/gameengine/Ketsji/KX_RaySensor.cpp
M source/gameengine/Ketsji/KX_RaySensor.h
M source/gameengine/Ketsji/KX_TouchSensor.cpp
M source/gameengine/Ketsji/KX_TouchSensor.h
===================================================================
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst b/doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst
index 2ff9897..f182a84 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst
@@ -51,6 +51,12 @@ base class --- :class:`SCA_ISensor`
:type: list [x, y, z]
+ .. attribute:: hitMaterial
+
+ The material of the object in the face hit by the ray. (read-only).
+
+ :type: string
+
.. attribute:: rayDirection
The direction from the ray (in worldcoordinates). (read-only).
diff --git a/doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst b/doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst
index fd8f319..876d14b 100644
--- a/doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst
+++ b/doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst
@@ -39,3 +39,9 @@ base class --- :class:`SCA_ISensor`
:type: :class:`CListValue` of :class:`KX_GameObject`
+ .. attribute:: hitMaterial
+
+ The material of the object in the face hit by the ray. (read-only).
+
+ :type: string
+
diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp
index afd3955..84e615b 100644
--- a/source/gameengine/Ketsji/KX_RaySensor.cpp
+++ b/source/gameengine/Ketsji/KX_RaySensor.cpp
@@ -64,9 +64,8 @@ KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr,
m_bXRay(bXRay),
m_distance(distance),
m_scene(ketsjiScene),
- m_axis(axis)
-
-
+ m_axis(axis),
+ m_hitMaterial("")
{
Init();
}
@@ -144,6 +143,7 @@ bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void
m_hitNormal[1] = result->m_hitNormal[1];
m_hitNormal[2] = result->m_hitNormal[2];
+ m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : "");
}
// no multi-hit search yet
return true;
@@ -356,6 +356,7 @@ PyAttributeDef KX_RaySensor::Attributes[] = {
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
+ KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_RaySensor, m_hitMaterial),
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject),
{ NULL } //Sentinel
};
diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h
index ca14867..09e99fe 100644
--- a/source/gameengine/Ketsji/KX_RaySensor.h
+++ b/source/gameengine/Ketsji/KX_RaySensor.h
@@ -56,6 +56,7 @@ class KX_RaySensor : public SCA_ISensor
SCA_IObject* m_hitObject;
float m_hitNormal[3];
float m_rayDirection[3];
+ STR_String m_hitMaterial;
public:
KX_RaySensor(class SCA_EventManager* eventmgr,
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp
index b231a21..3ff6587 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.cpp
+++ b/source/gameengine/Ketsji/KX_TouchSensor.cpp
@@ -102,7 +102,8 @@ KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj
:SCA_ISensor(gameobj,eventmgr),
m_touchedpropname(touchedpropname),
m_bFindMaterial(bFindMaterial),
-m_bTouchPulse(bTouchPulse)
+m_bTouchPulse(bTouchPulse),
+m_hitMaterial("")
/*m_sumoObj(sumoObj),*/
{
// KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
@@ -281,6 +282,7 @@ bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_Coll
}
m_bTriggered = true;
m_hitObject = gameobj;
+ m_hitMaterial = (client->m_auxilary_info ? (char*)client->m_auxilary_info : "");
//printf("KX_TouchSensor::HandleCollision\n");
}
@@ -324,6 +326,7 @@ PyAttributeDef KX_TouchSensor::Attributes[] = {
KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,false,KX_TouchSensor,m_touchedpropname),
KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
KX_PYATTRIBUTE_BOOL_RW("usePulseCollision",KX_TouchSensor,m_bTouchPulse),
+ KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_TouchSensor, m_hitMaterial),
KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_TouchSensor, pyattr_get_object_hit),
KX_PYATTRIBUTE_RO_FUNCTION("hitObjectList", KX_TouchSensor, pyattr_get_object_hit_list),
{ NULL } //Sentinel
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h
index 6bd606d..0edca44 100644
--- a/source/gameengine/Ketsji/KX_TouchSensor.h
+++ b/source/gameengine/Ketsji/KX_TouchSensor.h
@@ -73,6 +73,7 @@ protected:
SCA_IObject* m_hitObject;
class CListValue* m_colliders;
+ STR_String m_hitMaterial;
public:
KX_TouchSensor(class SCA_EventManager* eventmgr,
More information about the Bf-blender-cvs
mailing list