Blender V2.61 - r43446

KX_MouseFocusSensor.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
00019  * All rights reserved.
00020  *
00021  * The Original Code is: all of this file.
00022  *
00023  * Contributor(s): none yet.
00024  *
00025  * ***** END GPL LICENSE BLOCK *****
00026  */
00027 
00033 #ifndef __KX_MOUSEFOCUSSENSOR
00034 #define __KX_MOUSEFOCUSSENSOR
00035 
00036 #include "SCA_MouseSensor.h"
00037 
00038 class KX_RayCast;
00039 
00047 class KX_MouseFocusSensor : public SCA_MouseSensor
00048 {
00049 
00050     Py_Header
00051     
00052  public:
00053     
00054     KX_MouseFocusSensor(class SCA_MouseManager* eventmgr,
00055                         int startx,
00056                         int starty,
00057                         short int mousemode,
00058                         int focusmode,
00059                         bool bTouchPulse,
00060                         KX_Scene* kxscene,
00061                         KX_KetsjiEngine* kxengine,
00062                         SCA_IObject* gameobj);
00063 
00064     virtual ~KX_MouseFocusSensor() { ; };
00065     virtual CValue* GetReplica() {
00066         CValue* replica = new KX_MouseFocusSensor(*this);
00067         // this will copy properties and so on...
00068         replica->ProcessReplica();
00069         return replica;
00070     };
00071 
00072     virtual void Replace_IScene(SCA_IScene *val)
00073     {
00074         m_kxscene= static_cast<KX_Scene *>(val);
00075     };
00076 
00077 
00081     virtual bool Evaluate();
00082     virtual void Init();
00083 
00084     virtual bool IsPositiveTrigger() {
00085         bool result = m_positive_event;
00086         if (m_invert) result = !result;
00087         return result;
00088     };
00089 
00090     bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
00091     bool NeedRayCast(KX_ClientObjectInfo* client) { return true; }
00092     
00093     const MT_Point3& RaySource() const;
00094     const MT_Point3& RayTarget() const;
00095     const MT_Point3& HitPosition() const;
00096     const MT_Vector3& HitNormal() const;
00097     const MT_Vector2& HitUV() const;
00098     
00099 #ifdef WITH_PYTHON
00100 
00101     /* --------------------------------------------------------------------- */
00102     /* Python interface ---------------------------------------------------- */
00103     /* --------------------------------------------------------------------- */
00104 
00105     /* attributes */
00106     static PyObject*    pyattr_get_ray_source(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00107     static PyObject*    pyattr_get_ray_target(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00108     static PyObject*    pyattr_get_ray_direction(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00109     static PyObject*    pyattr_get_hit_object(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00110     static PyObject*    pyattr_get_hit_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00111     static PyObject*    pyattr_get_hit_normal(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00112     static PyObject*    pyattr_get_hit_uv(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
00113         
00114 #endif // WITH_PYTHON
00115 
00116     /* --------------------------------------------------------------------- */
00117     SCA_IObject*    m_hitObject;
00118     void*           m_hitObject_Last; /* only use for comparison, never access */
00119 
00120  private:
00124     int m_focusmode;
00125 
00129     bool m_mouse_over_in_previous_frame;
00130 
00134     bool m_bTouchPulse;
00135     
00139     bool m_positive_event;
00140 
00144     bool ParentObjectHasFocusCamera(KX_Camera *cam);
00145     
00149     bool ParentObjectHasFocus(void);
00150 
00154     MT_Point3        m_hitPosition;
00155 
00159     MT_Point3        m_prevTargetPoint;
00160 
00164     MT_Point3        m_prevSourcePoint;
00165     
00169     MT_Vector3       m_hitNormal;
00170 
00174     MT_Vector2       m_hitUV;
00175 
00179     KX_Scene* m_kxscene;
00180 
00183     KX_KetsjiEngine* m_kxengine;
00184 };
00185 
00186 #endif //__KX_MOUSESENSOR
00187