remove all python api functions deprecated in 2.49
[blender.git] / source / gameengine / Ketsji / KX_MouseFocusSensor.cpp
index 9106902ca0ed8f5b1d45fa35d30a2f28f7f0afaf..8abc4f6b897d3440f5779bf2b5337ebc760ba60c 100644 (file)
@@ -61,12 +61,13 @@ KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr,
                                                                                 int starty,
                                                                                 short int mousemode,
                                                                                 int focusmode,
+                                                                                bool bTouchPulse,
                                                                                 KX_Scene* kxscene,
                                                                                 KX_KetsjiEngine *kxengine,
-                                                                                SCA_IObject* gameobj, 
-                                                                                PyTypeObject* T)
-    : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj, T),
+                                                                                SCA_IObject* gameobj)
+       : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj),
          m_focusmode(focusmode),
+         m_bTouchPulse(bTouchPulse),
          m_kxscene(kxscene),
          m_kxengine(kxengine)
 {
@@ -78,6 +79,7 @@ void KX_MouseFocusSensor::Init()
        m_mouse_over_in_previous_frame = (m_invert)?true:false;
        m_positive_event = false;
        m_hitObject = 0;
+       m_hitObject_Last = NULL;
        m_reset = true;
        
        m_hitPosition.setValue(0,0,0);
@@ -86,7 +88,7 @@ void KX_MouseFocusSensor::Init()
        m_hitNormal.setValue(0,0,1);
 }
 
-bool KX_MouseFocusSensor::Evaluate(CValue* event)
+bool KX_MouseFocusSensor::Evaluate()
 {
        bool result = false;
        bool obHasFocus = false;
@@ -108,7 +110,10 @@ bool KX_MouseFocusSensor::Evaluate(CValue* event)
                        m_positive_event = true;
                        if (!m_mouse_over_in_previous_frame) {
                                result = true;
-                       } 
+                       }
+                       else if(m_bTouchPulse && (m_hitObject != m_hitObject_Last)) {
+                               result = true;
+                       }
                } 
                if (reset) {
                        // force an event 
@@ -119,12 +124,13 @@ bool KX_MouseFocusSensor::Evaluate(CValue* event)
          * mode is never used, because the converter never makes this
          * sensor for a mouse-key event. It is here for
          * completeness. */
-               result = SCA_MouseSensor::Evaluate(event);
+               result = SCA_MouseSensor::Evaluate();
                m_positive_event = (m_val!=0);
        }
 
        m_mouse_over_in_previous_frame = obHasFocus;
-
+       m_hitObject_Last = (void *)m_hitObject;
+                                          
        return result;
 }
 
@@ -197,13 +203,15 @@ bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam)
         * division by 0.0...*/
        
        RAS_Rect area, viewport;
+       short m_y_inv = m_kxengine->GetCanvas()->GetHeight()-m_y;
+       
        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
-                       m_y < viewport.m_y2 &&  // below top
-                       m_y > viewport.m_y1) == 0)      // above bottom
+                       m_y_inv < viewport.m_y2 &&      // below top
+                       m_y_inv > viewport.m_y1) == 0)  // above bottom
        {
                return false;
        }
@@ -217,6 +225,10 @@ bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam)
        MT_Vector4 frompoint;
        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 = (viewport.m_y2 - m_y_inv) + viewport.m_y1;
+       
+       
        /* There's some strangeness I don't fully get here... These values
         * _should_ be wrong! - see from point Z values */
        
@@ -229,19 +241,18 @@ bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam)
         *      behind of the near and far clip planes.
         */ 
        frompoint.setValue(     (2 * (m_x-x_lb) / width) - 1.0,
-                                               1.0 - (2 * (m_y - y_lb) / height),
+                                               1.0 - (2 * (m_y_inv - y_lb) / height),
+                                               /*cam->GetCameraData()->m_perspective ? 0.0:cdata->m_clipstart,*/ /* real clipstart is scaled in ortho for some reason, zero is ok */
                                                0.0, /* nearclip, see above comments */
                                                1.0 );
        
        topoint.setValue(       (2 * (m_x-x_lb) / width) - 1.0,
-                                               1.0 - (2 * (m_y-y_lb) / height),
-                                               1.0, /* farclip, see above comments */
+                                               1.0 - (2 * (m_y_inv-y_lb) / height),
+                                               cam->GetCameraData()->m_perspective ? 1.0:cam->GetCameraData()->m_clipend, /* farclip, see above comments */
                                                1.0 );
 
        /* camera to world  */
        MT_Transform wcs_camcs_tranform = cam->GetWorldToCamera();
-       if (!cam->GetCameraData()->m_perspective)
-               wcs_camcs_tranform.getOrigin()[2] *= 100.0;
        MT_Transform cams_wcs_transform;
        cams_wcs_transform.invert(wcs_camcs_tranform);
        
@@ -335,13 +346,7 @@ const MT_Vector3& KX_MouseFocusSensor::HitNormal() const
 
 /* Integration hooks ------------------------------------------------------- */
 PyTypeObject KX_MouseFocusSensor::Type = {
-#if (PY_VERSION_HEX >= 0x02060000)
        PyVarObject_HEAD_INIT(NULL, 0)
-#else
-       /* python 2.5 and below */
-       PyObject_HEAD_INIT( NULL )  /* required py macro */
-       0,                          /* ob_size */
-#endif
        "KX_MouseFocusSensor",
        sizeof(PyObjectPlus_Proxy),
        0,
@@ -351,30 +356,18 @@ PyTypeObject KX_MouseFocusSensor::Type = {
        0,
        0,
        py_base_repr,
-       0,0,0,0,0,0,
-       py_base_getattro,
-       py_base_setattro,
        0,0,0,0,0,0,0,0,0,
-       Methods
-};
-
-PyParentObject KX_MouseFocusSensor::Parents[] = {
-       &KX_MouseFocusSensor::Type,
+       Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
+       0,0,0,0,0,0,0,
+       Methods,
+       0,
+       0,
        &SCA_MouseSensor::Type,
-       &SCA_ISensor::Type,
-       &SCA_ILogicBrick::Type,
-       &CValue::Type,
-       NULL
+       0,0,0,0,0,0,
+       py_base_new
 };
 
 PyMethodDef KX_MouseFocusSensor::Methods[] = {
-       {"getRayTarget", (PyCFunction) KX_MouseFocusSensor::sPyGetRayTarget, METH_NOARGS, (PY_METHODCHAR)GetRayTarget_doc},
-       {"getRaySource", (PyCFunction) KX_MouseFocusSensor::sPyGetRaySource, METH_NOARGS, (PY_METHODCHAR)GetRaySource_doc},
-       {"getHitObject",(PyCFunction) KX_MouseFocusSensor::sPyGetHitObject,METH_NOARGS, (PY_METHODCHAR)GetHitObject_doc},
-       {"getHitPosition",(PyCFunction) KX_MouseFocusSensor::sPyGetHitPosition,METH_NOARGS, (PY_METHODCHAR)GetHitPosition_doc},
-       {"getHitNormal",(PyCFunction) KX_MouseFocusSensor::sPyGetHitNormal,METH_NOARGS, (PY_METHODCHAR)GetHitNormal_doc},
-       {"getRayDirection",(PyCFunction) KX_MouseFocusSensor::sPyGetRayDirection,METH_NOARGS, (PY_METHODCHAR)GetRayDirection_doc},
-
        {NULL,NULL} //Sentinel
 };
 
@@ -385,90 +378,10 @@ PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
        KX_PYATTRIBUTE_RO_FUNCTION("hitObject",         KX_MouseFocusSensor, pyattr_get_hit_object),
        KX_PYATTRIBUTE_RO_FUNCTION("hitPosition",       KX_MouseFocusSensor, pyattr_get_hit_position),
        KX_PYATTRIBUTE_RO_FUNCTION("hitNormal",         KX_MouseFocusSensor, pyattr_get_hit_normal),
+       KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor,m_bTouchPulse),
        { NULL }        //Sentinel
 };
 
-PyObject* KX_MouseFocusSensor::py_getattro(PyObject *attr) {
-       py_getattro_up(SCA_MouseSensor);
-}
-
-PyObject* KX_MouseFocusSensor::py_getattro_dict() {
-       py_getattro_dict_up(SCA_MouseSensor);
-}
-
-
-const char KX_MouseFocusSensor::GetHitObject_doc[] = 
-"getHitObject()\n"
-"\tReturns the object that was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitObject()
-{
-       ShowDeprecationWarning("GetHitObject()", "the hitObject property");
-       
-       if (m_hitObject)
-               return m_hitObject->GetProxy();
-       
-       Py_RETURN_NONE;
-}
-
-
-const char KX_MouseFocusSensor::GetHitPosition_doc[] = 
-"getHitPosition()\n"
-"\tReturns the position (in worldcoordinates) where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitPosition()
-{
-       ShowDeprecationWarning("getHitPosition()", "the hitPosition property");
-       
-       return PyObjectFrom(m_hitPosition);
-}
-
-const char KX_MouseFocusSensor::GetRayDirection_doc[] = 
-"getRayDirection()\n"
-"\tReturns the direction from the ray (in worldcoordinates) .\n";
-PyObject* KX_MouseFocusSensor::PyGetRayDirection()
-{
-       ShowDeprecationWarning("getRayDirection()", "the rayDirection property");
-       
-       MT_Vector3 dir = m_prevTargetPoint - m_prevSourcePoint;
-       if(MT_fuzzyZero(dir))   dir.setValue(0,0,0);
-       else                                    dir.normalize();
-       return PyObjectFrom(dir);
-}
-
-const char KX_MouseFocusSensor::GetHitNormal_doc[] = 
-"getHitNormal()\n"
-"\tReturns the normal (in worldcoordinates) at the point of collision where the object was hit by this ray.\n";
-PyObject* KX_MouseFocusSensor::PyGetHitNormal()
-{
-       ShowDeprecationWarning("getHitNormal()", "the hitNormal property");
-       
-       return PyObjectFrom(m_hitNormal);
-}
-
-
-/*  getRayTarget                                                */
-const char KX_MouseFocusSensor::GetRayTarget_doc[] = 
-"getRayTarget()\n"
-"\tReturns the target of the ray that seeks the focus object,\n"
-"\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRayTarget()
-{
-       ShowDeprecationWarning("getRayTarget()", "the rayTarget property");
-       
-       return PyObjectFrom(m_prevTargetPoint);
-}
-
-/*  getRayTarget                                                */
-const char KX_MouseFocusSensor::GetRaySource_doc[] = 
-"getRaySource()\n"
-"\tReturns the source of the ray that seeks the focus object,\n"
-"\tin worldcoordinates.";
-PyObject* KX_MouseFocusSensor::PyGetRaySource()
-{
-       ShowDeprecationWarning("getRaySource()", "the raySource property");
-       
-       return PyObjectFrom(m_prevSourcePoint);
-}
-
 /* Attributes */
 PyObject* KX_MouseFocusSensor::pyattr_get_ray_source(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
 {