Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
| Context not available. | |||||
| # pragma warning(disable:4786) | # pragma warning(disable:4786) | ||||
| #endif | #endif | ||||
| #include <stdio.h> | #include "MT_Vector3.h" | ||||
| #include "MT_Point3.h" | |||||
| #include "RAS_FramingManager.h" | #include "RAS_FramingManager.h" | ||||
| #include "RAS_ICanvas.h" | #include "RAS_ICanvas.h" | ||||
| #include "RAS_IRasterizer.h" | #include "RAS_IRasterizer.h" | ||||
| Context not available. | |||||
| #include "PHY_IPhysicsController.h" | #include "PHY_IPhysicsController.h" | ||||
| #include "PHY_IPhysicsEnvironment.h" | #include "PHY_IPhysicsEnvironment.h" | ||||
| #include "KX_ClientObjectInfo.h" | #include "KX_ClientObjectInfo.h" | ||||
| #include "CM_Message.h" | |||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| Context not available. | |||||
| int starty, | int starty, | ||||
| short int mousemode, | short int mousemode, | ||||
| int focusmode, | int focusmode, | ||||
| bool bTouchPulse, | bool bCollisionPulse, | ||||
| const STR_String& propname, | const std::string& propname, | ||||
| bool bFindMaterial, | bool bFindMaterial, | ||||
| bool bXRay, | bool bXRay, | ||||
| KX_Scene* kxscene, | KX_Scene* kxscene, | ||||
| Context not available. | |||||
| SCA_IObject* gameobj) | SCA_IObject* gameobj) | ||||
| : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj), | : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj), | ||||
| m_focusmode(focusmode), | m_focusmode(focusmode), | ||||
| m_bTouchPulse(bTouchPulse), | m_bCollisionPulse(bCollisionPulse), | ||||
| m_bXRay(bXRay), | m_bXRay(bXRay), | ||||
| m_bFindMaterial(bFindMaterial), | m_bFindMaterial(bFindMaterial), | ||||
| m_propertyname(propname), | m_propertyname(propname), | ||||
| Context not available. | |||||
| bool obHasFocus = false; | bool obHasFocus = false; | ||||
| bool reset = m_reset && m_level; | bool reset = m_reset && m_level; | ||||
| // cout << "evaluate focus mouse sensor "<<endl; | |||||
| m_reset = false; | m_reset = false; | ||||
| if (m_focusmode) { | if (m_focusmode) { | ||||
| /* Focus behavior required. Test mouse-on. The rest is | /* Focus behavior required. Test mouse-on. The rest is | ||||
| Context not available. | |||||
| if (!m_mouse_over_in_previous_frame) { | if (!m_mouse_over_in_previous_frame) { | ||||
| result = true; | result = true; | ||||
| } | } | ||||
| else if (m_bTouchPulse && (m_hitObject != m_hitObject_Last)) { | else if (m_bCollisionPulse && (m_hitObject != m_hitObject_Last)) { | ||||
| result = true; | result = true; | ||||
| } | } | ||||
| } | } | ||||
| Context not available. | |||||
| if ((m_focusmode == 2) || hitKXObj == thisObj) | if ((m_focusmode == 2) || hitKXObj == thisObj) | ||||
| { | { | ||||
| if (m_propertyname.Length() == 0) | if (m_propertyname.size() == 0) | ||||
| { | { | ||||
| bFound = true; | bFound = true; | ||||
| } | } | ||||
| Context not available. | |||||
| for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { | for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { | ||||
| RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); | RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); | ||||
| for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { | for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { | ||||
| bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; | bFound = (m_propertyname == std::string(meshObj->GetMaterialName(j), 2)); | ||||
| if (bFound) | if (bFound) | ||||
| break; | break; | ||||
| } | } | ||||
| Context not available. | |||||
| { | { | ||||
| // Unknown type of object, skip it. | // Unknown type of object, skip it. | ||||
| // Should not occur as the sensor objects are filtered in RayTest() | // Should not occur as the sensor objects are filtered in RayTest() | ||||
| printf("Invalid client type %d found ray casting\n", client->m_type); | CM_Error("invalid client type " << client->m_type << " found ray casting"); | ||||
| return false; | return false; | ||||
| } | } | ||||
| if (m_bXRay && m_propertyname.Length() != 0) | if (m_bXRay && m_propertyname.size() != 0) | ||||
| { | { | ||||
| if (m_bFindMaterial) | if (m_bFindMaterial) | ||||
| { | { | ||||
| Context not available. | |||||
| for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { | for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) { | ||||
| RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); | RAS_MeshObject *meshObj = hitKXObj->GetMesh(i); | ||||
| for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { | for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) { | ||||
| found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0; | found = (m_propertyname == std::string(meshObj->GetMaterialName(j), 2)); | ||||
| if (found) | if (found) | ||||
| break; | break; | ||||
| } | } | ||||
| Context not available. | |||||
| m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); | m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport); | ||||
| /* Check if the mouse is in the viewport */ | /* Check if the mouse is in the viewport */ | ||||
| if (( m_x < viewport.m_x2 && // less than right | if (( m_x < viewport.GetRight() && // less than right | ||||
| m_x > viewport.m_x1 && // more than then left | m_x > viewport.GetLeft() && // more than then left | ||||
| m_y_inv < viewport.m_y2 && // below top | m_y_inv < viewport.GetTop() && // below top | ||||
| m_y_inv > viewport.m_y1) == 0) // above bottom | m_y_inv > viewport.GetBottom()) == 0) // above bottom | ||||
| { | { | ||||
| return false; | return false; | ||||
| } | } | ||||
| float height = float(viewport.m_y2 - viewport.m_y1 + 1); | float height = float(viewport.GetTop() - viewport.GetBottom() + 1); | ||||
| float width = float(viewport.m_x2 - viewport.m_x1 + 1); | float width = float(viewport.GetRight() - viewport.GetLeft() + 1); | ||||
| float x_lb = float(viewport.m_x1); | float x_lb = float(viewport.GetLeft()); | ||||
| float y_lb = float(viewport.m_y1); | float y_lb = float(viewport.GetBottom()); | ||||
| MT_Vector4 frompoint; | MT_Vector4 frompoint; | ||||
| MT_Vector4 topoint; | MT_Vector4 topoint; | ||||
| /* m_y_inv - inverting for a bounds check is only part of it, now make relative to view bounds */ | /* m_y_inv - inverting for a bounds check is only part of it, now make relative to view bounds */ | ||||
| m_y_inv = (viewport.m_y2 - m_y_inv) + viewport.m_y1; | m_y_inv = (viewport.GetTop() - m_y_inv) + viewport.GetBottom(); | ||||
| /* There's some strangeness I don't fully get here... These values | /* There's some strangeness I don't fully get here... These values | ||||
| Context not available. | |||||
| m_hitPosition.setValue(0,0,0); | m_hitPosition.setValue(0,0,0); | ||||
| m_hitNormal.setValue(1,0,0); | m_hitNormal.setValue(1,0,0); | ||||
| KX_Camera *cam= m_kxscene->GetActiveCamera(); | KX_Camera *activecam = m_kxscene->GetActiveCamera(); | ||||
| if (ParentObjectHasFocusCamera(cam)) | if (ParentObjectHasFocusCamera(activecam)) | ||||
| return true; | return true; | ||||
| list<class KX_Camera*>* cameras = m_kxscene->GetCameras(); | CListValue *cameras = m_kxscene->GetCameraList(); | ||||
| list<KX_Camera*>::iterator it = cameras->begin(); | |||||
| while (it != cameras->end()) { | for (CListValue::iterator<KX_Camera> it = cameras->GetBegin(), end = cameras->GetEnd(); it != end; ++it) { | ||||
| if (((*it) != cam) && (*it)->GetViewport()) | KX_Camera *cam = *it; | ||||
| if (ParentObjectHasFocusCamera(*it)) | if ((cam != activecam) && cam->GetViewport()) | ||||
| if (ParentObjectHasFocusCamera(cam)) | |||||
| return true; | return true; | ||||
| it++; | |||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| const MT_Point3& KX_MouseFocusSensor::RaySource() const | const MT_Vector3& KX_MouseFocusSensor::RaySource() const | ||||
| { | { | ||||
| return m_prevSourcePoint; | return m_prevSourcePoint; | ||||
| } | } | ||||
| const MT_Point3& KX_MouseFocusSensor::RayTarget() const | const MT_Vector3& KX_MouseFocusSensor::RayTarget() const | ||||
| { | { | ||||
| return m_prevTargetPoint; | return m_prevTargetPoint; | ||||
| } | } | ||||
| const MT_Point3& KX_MouseFocusSensor::HitPosition() const | const MT_Vector3& KX_MouseFocusSensor::HitPosition() const | ||||
| { | { | ||||
| return m_hitPosition; | return m_hitPosition; | ||||
| } | } | ||||
| Context not available. | |||||
| KX_PYATTRIBUTE_RO_FUNCTION("hitPosition", KX_MouseFocusSensor, pyattr_get_hit_position), | KX_PYATTRIBUTE_RO_FUNCTION("hitPosition", KX_MouseFocusSensor, pyattr_get_hit_position), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal), | KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal), | ||||
| KX_PYATTRIBUTE_RO_FUNCTION("hitUV", KX_MouseFocusSensor, pyattr_get_hit_uv), | KX_PYATTRIBUTE_RO_FUNCTION("hitUV", KX_MouseFocusSensor, pyattr_get_hit_uv), | ||||
| KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor, m_bTouchPulse), | KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor, m_bCollisionPulse), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_MouseFocusSensor, m_bXRay), | KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_MouseFocusSensor, m_bXRay), | ||||
| KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_MouseFocusSensor, m_bFindMaterial), | KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_MouseFocusSensor, m_bFindMaterial), | ||||
| KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_MouseFocusSensor, m_propertyname), | KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_MouseFocusSensor, m_propertyname), | ||||
| { NULL } //Sentinel | KX_PYATTRIBUTE_NULL //Sentinel | ||||
| }; | }; | ||||
| /* Attributes */ | /* Attributes */ | ||||
| Context not available. | |||||