BGE patch: add X-Ray option to ray sensor. The option is effective only if a property...
authorBenoit Bolsee <benoit.bolsee@online.be>
Thu, 28 Aug 2008 19:37:49 +0000 (19:37 +0000)
committerBenoit Bolsee <benoit.bolsee@online.be>
Thu, 28 Aug 2008 19:37:49 +0000 (19:37 +0000)
source/blender/makesdna/DNA_sensor_types.h
source/blender/src/buttons_logic.c
source/gameengine/Converter/KX_ConvertSensors.cpp
source/gameengine/Ketsji/KX_RaySensor.cpp
source/gameengine/Ketsji/KX_RaySensor.h

index b5d8511c6981e94979d4228ba3338749c360ddcd..d508ff3a55292af7bfcfd7090d145abc366ce3e8 100644 (file)
@@ -237,6 +237,9 @@ typedef struct bJoystickSensor {
  * */
 /*  #define SENS_COLLISION_PROPERTY 0  */
 #define SENS_COLLISION_MATERIAL 1
+/* ray specific mode */
+/* X-Ray means that the ray will traverse objects that don't have the property/material */
+#define SENS_RAY_XRAY                  2
 
 /* Some stuff for the mouse sensor Type: */
 #define BL_SENS_MOUSE_LEFT_BUTTON    1
index b7ce16f50a6eac8acdd6c3254fc59e2904a75a59..9b41b646bc8914f54c4967a169ab53a4bdd4673b 100644 (file)
@@ -1390,9 +1390,14 @@ static short draw_sensorbuttons(bSensor *sens, uiBlock *block, short xco, short
                                        &raySens->propname, 0, 31, 0, 0,
                                        "Only look for Objects with this property");
                        }
-                       
+
+                       /* X-Ray option */
+                       uiDefButBitS(block, TOG, SENS_RAY_XRAY, 1, "X",
+                               xco + 10,yco - 68, 0.10 * (width-20), 19,
+                               &raySens->mode, 0.0, 0.0, 0, 0,
+                               "Toggle X-Ray option (see through objects that don't have the property)");
                        /* 2. sensing range */
-                       uiDefButF(block, NUM, 1, "Range", xco+10, yco-68, 0.6 * (width-20), 19,
+                       uiDefButF(block, NUM, 1, "Range", xco+10 + 0.10 * (width-20), yco-68, 0.5 * (width-20), 19,
                                &raySens->range, 0.01, 10000.0, 100, 0,
                                "Sense objects no farther than this distance");
                        
index 98e078ccf8daee914d1e7aea249d45f26895c837..db47dc2dd3d7416e6356b8c1be6943741eb84cff 100644 (file)
@@ -633,6 +633,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                if (eventmgr)
                                {
                                        bool bFindMaterial = (blenderraysensor->mode & SENS_COLLISION_MATERIAL);
+                                       bool bXRay = (blenderraysensor->mode & SENS_RAY_XRAY);
                                        
                                        STR_String checkname = (bFindMaterial? blenderraysensor->matname : blenderraysensor->propname);
 
@@ -645,6 +646,7 @@ void BL_ConvertSensors(struct Object* blenderobject,
                                                                                                  gameobj,
                                                                                                  checkname,
                                                                                                  bFindMaterial,
+                                                                                                 bXRay,
                                                                                                  distance,
                                                                                                  axis,
                                                                                                  kxscene);
index 57101b769ea83931b4b59d43c49e063e572e3cf6..8dc22fe13c13bc1f067b9e7bc69a5c3cfc8a9adc 100644 (file)
@@ -51,6 +51,7 @@ KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr,
                                        SCA_IObject* gameobj,
                                        const STR_String& propname,
                                        bool bFindMaterial,
+                                       bool bXRay,
                                        double distance,
                                        int axis,
                                        KX_Scene* ketsjiScene,
@@ -58,6 +59,7 @@ KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr,
                        : SCA_ISensor(gameobj,eventmgr, T),
                                        m_propertyname(propname),
                                        m_bFindMaterial(bFindMaterial),
+                                       m_bXRay(bXRay),
                                        m_distance(distance),
                                        m_scene(ketsjiScene),
                                        m_axis(axis)
@@ -153,7 +155,21 @@ bool KX_RaySensor::NeedRayCast(KX_ClientObjectInfo* client)
                printf("Invalid client type %d found ray casting\n", client->m_type);
                return false;
        }
-       // no X-Ray function yet
+       if (m_bXRay && m_propertyname.Length() != 0)
+       {
+               if (m_bFindMaterial)
+               {
+                       // not quite correct: an object may have multiple material
+                       // should check all the material and not only the first one
+                       if (!client->m_auxilary_info || (m_propertyname != ((char*)client->m_auxilary_info)))
+                               return false;
+               }
+               else
+               {
+                       if (client->m_gameobject->GetProperty(m_propertyname) == NULL)
+                               return false;
+               }
+       }
        return true;
 }
 
index 9e53f80b69ce6637ae9343a0260a9501018747fa..02a755fedc191d840d5c5207649c5c898d035084 100644 (file)
@@ -43,6 +43,7 @@ class KX_RaySensor : public SCA_ISensor
        Py_Header;
        STR_String              m_propertyname;
        bool                    m_bFindMaterial;
+       bool                    m_bXRay;
        double                  m_distance;
        class KX_Scene* m_scene;
        bool                    m_bTriggered;
@@ -57,7 +58,8 @@ public:
        KX_RaySensor(class SCA_EventManager* eventmgr,
                                        SCA_IObject* gameobj,
                                        const STR_String& propname,
-                                       bool fFindMaterial,
+                                       bool bFindMaterial,
+                                       bool bXRay,
                                        double distance,
                                        int axis,
                                        class KX_Scene* ketsjiScene,