game engine: implement hitMaterial for collision and ray sensors
authorDalai Felinto <dfelinto@gmail.com>
Fri, 24 Jan 2014 04:10:04 +0000 (02:10 -0200)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 24 Jan 2014 04:10:45 +0000 (02:10 -0200)
Reviewed By: moguri, kupoman

Differential Revision: https://developer.blender.org/D167

doc/python_api/rst/bge_types/bge.types.KX_RaySensor.rst
doc/python_api/rst/bge_types/bge.types.KX_TouchSensor.rst
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_RaySensor.h
source/gameengine/Ketsji/KX_TouchSensor.cpp
source/gameengine/Ketsji/KX_TouchSensor.h

index 2ff989729f536608e12c398bbc9547aedaf2ce1c..f182a84409f3c87dd4caa3c16e867d802889a891 100644 (file)
@@ -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).
index fd8f319f6f3380812d095e16bd52613a16094dd8..876d14bc6c87bf749f8465c172aa341439978c17 100644 (file)
@@ -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
+
index afd395571306c4964e0b4fb10bf158f5850ea965..84e615b61abfb89befe56407b1cfd870960fb3e9 100644 (file)
@@ -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
 };
index ca14867e892faf706861f8d758733110797e296d..09e99fe00138d4bbbf5d2215fdbd25ce77dbe068 100644 (file)
@@ -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,
index b231a2191ed3801270ccdfefb6fb35e1d29f58fb..3ff6587e837785805341b8241d2eee4faf2366c1 100644 (file)
@@ -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
index 6bd606db8ebb7146899205e753c697924bf34ea4..0edca44296a25124cff6b4c9be24e15a98b0db54 100644 (file)
@@ -73,6 +73,7 @@ protected:
 
        SCA_IObject*                m_hitObject;
        class CListValue*               m_colliders;
+       STR_String                              m_hitMaterial;
        
 public:
        KX_TouchSensor(class SCA_EventManager* eventmgr,