diff options
Diffstat (limited to 'source/gameengine/Ketsji/KX_MouseFocusSensor.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_MouseFocusSensor.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp index a9f6bb0d2ff..46f27e1a2df 100644 --- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp +++ b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp @@ -36,10 +36,13 @@ # pragma warning(disable:4786) #endif +#include <stdio.h> + #include "MT_Point3.h" #include "RAS_FramingManager.h" #include "RAS_ICanvas.h" #include "RAS_IRasterizer.h" +#include "RAS_MeshObject.h" #include "SCA_IScene.h" #include "KX_Scene.h" #include "KX_Camera.h" @@ -163,15 +166,17 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *r } else { - if (m_bFindMaterial) - { - if (client_info->m_auxilary_info) - { - bFound = (m_propertyname== ((char*)client_info->m_auxilary_info)); + if (m_bFindMaterial) { + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (bFound) + break; + } } } - else - { + else { bFound = hitKXObj->GetProperty(m_propertyname) != NULL; } } @@ -195,6 +200,8 @@ bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *r */ bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client) { + KX_GameObject *hitKXObj = client->m_gameobject; + if (client->m_type > KX_ClientObjectInfo::ACTOR) { // Unknown type of object, skip it. @@ -206,14 +213,21 @@ bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client) { 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))) + bool found = false; + for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { + RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); + for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { + found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; + if (found) + break; + } + } + if (!found) return false; } else { - if (client->m_gameobject->GetProperty(m_propertyname) == NULL) + if (hitKXObj->GetProperty(m_propertyname) == NULL) return false; } } @@ -269,8 +283,8 @@ bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam) m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); /* Check if the mouse is in the viewport */ - if (( m_x < viewport.m_x2 && // less then right - m_x > viewport.m_x1 && // more then then left + if (( m_x < viewport.m_x2 && // less than right + m_x > viewport.m_x1 && // more than then left m_y_inv < viewport.m_y2 && // below top m_y_inv > viewport.m_y1) == 0) // above bottom { |