2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * The Original Code is: all of this file.
23 * Contributor(s): none yet.
25 * ***** END GPL LICENSE BLOCK *****
28 /** \file KX_MouseFocusSensor.h
30 * \brief KX_MouseFocusSensor determines mouse in/out/over events.
33 #ifndef __KX_MOUSEFOCUSSENSOR_H__
34 #define __KX_MOUSEFOCUSSENSOR_H__
36 #include "SCA_MouseSensor.h"
41 * The mouse focus sensor extends the basic SCA_MouseSensor. It has
42 * been placed in KX because it needs access to the rasterizer and
45 * - extend the valid modes?
47 class KX_MouseFocusSensor : public SCA_MouseSensor
54 KX_MouseFocusSensor(class SCA_MouseManager* eventmgr,
61 KX_KetsjiEngine* kxengine,
62 SCA_IObject* gameobj);
64 virtual ~KX_MouseFocusSensor() { }
65 virtual CValue* GetReplica() {
66 CValue* replica = new KX_MouseFocusSensor(*this);
67 // this will copy properties and so on...
68 replica->ProcessReplica();
72 virtual void Replace_IScene(SCA_IScene *val)
74 m_kxscene= static_cast<KX_Scene *>(val);
79 * \attention Overrides default evaluate.
81 virtual bool Evaluate();
84 virtual bool IsPositiveTrigger() {
85 bool result = m_positive_event;
86 if (m_invert) result = !result;
90 bool RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data);
91 bool NeedRayCast(KX_ClientObjectInfo* client) { return true; }
93 const MT_Point3& RaySource() const;
94 const MT_Point3& RayTarget() const;
95 const MT_Point3& HitPosition() const;
96 const MT_Vector3& HitNormal() const;
97 const MT_Vector2& HitUV() const;
101 /* --------------------------------------------------------------------- */
102 /* Python interface ---------------------------------------------------- */
103 /* --------------------------------------------------------------------- */
106 static PyObject* pyattr_get_ray_source(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
107 static PyObject* pyattr_get_ray_target(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
108 static PyObject* pyattr_get_ray_direction(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
109 static PyObject* pyattr_get_hit_object(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
110 static PyObject* pyattr_get_hit_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
111 static PyObject* pyattr_get_hit_normal(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
112 static PyObject* pyattr_get_hit_uv(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
114 #endif // WITH_PYTHON
116 /* --------------------------------------------------------------------- */
117 SCA_IObject* m_hitObject;
118 void* m_hitObject_Last; /* only use for comparison, never access */
122 * The focus mode. 1 for handling focus, 0 for not handling, 2 for focus on any object
127 * Flags whether the previous test showed a mouse-over.
129 bool m_mouse_over_in_previous_frame;
132 * Flags whether changes in hit object should trigger a pulse
137 * Flags whether the previous test evaluated positive.
139 bool m_positive_event;
142 * Tests whether the object is in mouse focus for this camera
144 bool ParentObjectHasFocusCamera(KX_Camera *cam);
147 * Tests whether the object is in mouse focus in this scene.
149 bool ParentObjectHasFocus(void);
152 * (in game world coordinates) the place where the object was hit.
154 MT_Point3 m_hitPosition;
157 * (in game world coordinates) the position to which to shoot the ray.
159 MT_Point3 m_prevTargetPoint;
162 * (in game world coordinates) the position from which to shoot the ray.
164 MT_Point3 m_prevSourcePoint;
167 * (in game world coordinates) the face normal of the vertex where
168 * the object was hit. */
169 MT_Vector3 m_hitNormal;
172 * UV texture coordinate of the hit point if any, (0,0) otherwise
177 * The KX scene that holds the camera. The camera position
178 * determines a part of the start location of the picking ray. */
182 * The KX engine is needed for computing the viewport */
183 KX_KetsjiEngine* m_kxengine;
186 #endif //__KX_MOUSESENSOR