2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* KX_MouseFocusSensor determines mouse in/out/over events.
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_MouseFocusSensor.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2012-10-15 02:15:07 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
/* This warning tells us about truncation of __long__ stl-generated names.
|
|
|
|
* It can occasionally cause DevStudio to have internal compiler warnings. */
|
|
|
|
# pragma warning(disable:4786)
|
2002-10-12 11:37:38 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "MT_Point3.h"
|
|
|
|
#include "RAS_FramingManager.h"
|
|
|
|
#include "RAS_ICanvas.h"
|
|
|
|
#include "RAS_IRasterizer.h"
|
|
|
|
#include "SCA_IScene.h"
|
|
|
|
#include "KX_Scene.h"
|
|
|
|
#include "KX_Camera.h"
|
|
|
|
#include "KX_MouseFocusSensor.h"
|
2009-02-25 06:43:03 +00:00
|
|
|
#include "KX_PyMath.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
#include "KX_RayCast.h"
|
|
|
|
#include "PHY_IPhysicsController.h"
|
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
|
|
|
|
|
|
|
|
2004-11-06 04:58:10 +00:00
|
|
|
#include "KX_ClientObjectInfo.h"
|
2004-03-22 22:02:18 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr,
|
2012-10-15 02:15:07 +00:00
|
|
|
int startx,
|
|
|
|
int starty,
|
2014-07-18 06:00:30 +00:00
|
|
|
short int mousemode,
|
|
|
|
int focusmode,
|
|
|
|
bool bTouchPulse,
|
|
|
|
const STR_String& propname,
|
|
|
|
bool bFindMaterial,
|
|
|
|
bool bXRay,
|
|
|
|
KX_Scene* kxscene,
|
|
|
|
KX_KetsjiEngine *kxengine,
|
|
|
|
SCA_IObject* gameobj)
|
2009-06-28 11:22:26 +00:00
|
|
|
: SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj),
|
2002-10-12 11:37:38 +00:00
|
|
|
m_focusmode(focusmode),
|
2009-08-23 06:17:59 +00:00
|
|
|
m_bTouchPulse(bTouchPulse),
|
2014-07-18 06:00:30 +00:00
|
|
|
m_bXRay(bXRay),
|
2014-08-08 04:45:38 +00:00
|
|
|
m_bFindMaterial(bFindMaterial),
|
|
|
|
m_propertyname(propname),
|
2008-09-18 01:46:28 +00:00
|
|
|
m_kxscene(kxscene),
|
|
|
|
m_kxengine(kxengine)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
BGE patch: add state engine support in the logic bricks.
This patch introduces a simple state engine system with the logic bricks. This system features full
backward compatibility, multiple active states, multiple state transitions, automatic disabling of
sensor and actuators, full GUI support and selective display of sensors and actuators.
Note: Python API is available but not documented yet. It will be added asap.
State internals
===============
The state system is object based. The current state mask is stored in the object as a 32 bit value;
each bit set in the mask is an active state. The controllers have a state mask too but only one bit
can be set: a controller belongs to a single state. The game engine will only execute controllers
that belong to active states. Sensors and actuators don't have a state mask but are effectively
attached to states via their links to the controllers. Sensors and actuators can be connected to more
than one state. When a controller becomes inactive because of a state change, its links to sensors
and actuators are temporarily broken (until the state becomes active again). If an actuator gets isolated,
i.e all the links to controllers are broken, it is automatically disabled. If a sensor gets isolated,
the game engine will stop calling it to save CPU. It will also reset the sensor internal state so that
it can react as if the game just started when it gets reconnected to an active controller. For example,
an Always sensor in no pulse mode that is connected to a single state (i.e connected to one or more
controllers of a single state) will generate a pulse each time the state becomes active. This feature is
not available on all sensors, see the notes below.
GUI
===
This system system is fully configurable through the GUI: the object state mask is visible under the
object bar in the controller's colum as an array of buttons just like the 3D view layer mask.
Click on a state bit to only display the controllers of that state. You can select more than one state
with SHIFT-click. The All button sets all the bits so that you can see all the controllers of the object.
The Ini button sets the state mask back to the object default state. You can change the default state
of object by first selecting the desired state mask and storing using the menu under the State button.
If you define a default state mask, it will be loaded into the object state make when you load the blend
file or when you run the game under the blenderplayer. However, when you run the game under Blender,
the current selected state mask will be used as the startup state for the object. This allows you to test
specific state during the game design.
The controller display the state they belong to with a new button in the controller header. When you add
a new controller, it is added by default in the lowest enabled state. You can change the controller state
by clicking on the button and selecting another state. If more than one state is enabled in the object
state mask, controllers are grouped by state for more readibility.
The new Sta button in the sensor and actuator column header allows you to display only the sensors and
actuators that are linked to visible controllers.
A new state actuator is available to modify the state during the game. It defines a bit mask and
the operation to apply on the current object state mask:
Cpy: the bit mask is copied to the object state mask.
Add: the bits that set in the bit mask will be turned on in the object state mask.
Sub: the bits that set in the bit mask will be turned off in the object state mask.
Inv: the bits that set in the bit mask will be inverted in the objecyy state mask.
Notes
=====
- Although states have no name, a simply convention consists in using the name of the first controller
of the state as the state name. The GUI will support that convention by displaying as a hint the name
of the first controller of the state when you move the mouse over a state bit of the object state mask
or of the state actuator bit mask.
- Each object has a state mask and each object can have a state engine but if several objects are
part of a logical group, it is recommended to put the state engine only in the main object and to
link the controllers of that object to the sensors and actuators of the different objects.
- When loading an old blend file, the state mask of all objects and controllers are initialized to 1
so that all the controllers belong to this single state. This ensures backward compatibility with
existing game.
- When the state actuator is activated at the same time as other actuators, these actuators are
guaranteed to execute before being eventually disabled due to the state change. This is useful for
example to send a message or update a property at the time of changing the state.
- Sensors that depend on underlying resource won't reset fully when they are isolated. By the time they
are acticated again, they will behave as follow:
* keyboard sensor: keys already pressed won't be detected. The keyboard sensor is only sensitive
to new key press.
* collision sensor: objects already colliding won't be detected. Only new collisions are
detected.
* near and radar sensor: same as collision sensor.
2008-06-22 14:23:57 +00:00
|
|
|
Init();
|
|
|
|
}
|
2005-08-17 14:29:58 +00:00
|
|
|
|
BGE patch: add state engine support in the logic bricks.
This patch introduces a simple state engine system with the logic bricks. This system features full
backward compatibility, multiple active states, multiple state transitions, automatic disabling of
sensor and actuators, full GUI support and selective display of sensors and actuators.
Note: Python API is available but not documented yet. It will be added asap.
State internals
===============
The state system is object based. The current state mask is stored in the object as a 32 bit value;
each bit set in the mask is an active state. The controllers have a state mask too but only one bit
can be set: a controller belongs to a single state. The game engine will only execute controllers
that belong to active states. Sensors and actuators don't have a state mask but are effectively
attached to states via their links to the controllers. Sensors and actuators can be connected to more
than one state. When a controller becomes inactive because of a state change, its links to sensors
and actuators are temporarily broken (until the state becomes active again). If an actuator gets isolated,
i.e all the links to controllers are broken, it is automatically disabled. If a sensor gets isolated,
the game engine will stop calling it to save CPU. It will also reset the sensor internal state so that
it can react as if the game just started when it gets reconnected to an active controller. For example,
an Always sensor in no pulse mode that is connected to a single state (i.e connected to one or more
controllers of a single state) will generate a pulse each time the state becomes active. This feature is
not available on all sensors, see the notes below.
GUI
===
This system system is fully configurable through the GUI: the object state mask is visible under the
object bar in the controller's colum as an array of buttons just like the 3D view layer mask.
Click on a state bit to only display the controllers of that state. You can select more than one state
with SHIFT-click. The All button sets all the bits so that you can see all the controllers of the object.
The Ini button sets the state mask back to the object default state. You can change the default state
of object by first selecting the desired state mask and storing using the menu under the State button.
If you define a default state mask, it will be loaded into the object state make when you load the blend
file or when you run the game under the blenderplayer. However, when you run the game under Blender,
the current selected state mask will be used as the startup state for the object. This allows you to test
specific state during the game design.
The controller display the state they belong to with a new button in the controller header. When you add
a new controller, it is added by default in the lowest enabled state. You can change the controller state
by clicking on the button and selecting another state. If more than one state is enabled in the object
state mask, controllers are grouped by state for more readibility.
The new Sta button in the sensor and actuator column header allows you to display only the sensors and
actuators that are linked to visible controllers.
A new state actuator is available to modify the state during the game. It defines a bit mask and
the operation to apply on the current object state mask:
Cpy: the bit mask is copied to the object state mask.
Add: the bits that set in the bit mask will be turned on in the object state mask.
Sub: the bits that set in the bit mask will be turned off in the object state mask.
Inv: the bits that set in the bit mask will be inverted in the objecyy state mask.
Notes
=====
- Although states have no name, a simply convention consists in using the name of the first controller
of the state as the state name. The GUI will support that convention by displaying as a hint the name
of the first controller of the state when you move the mouse over a state bit of the object state mask
or of the state actuator bit mask.
- Each object has a state mask and each object can have a state engine but if several objects are
part of a logical group, it is recommended to put the state engine only in the main object and to
link the controllers of that object to the sensors and actuators of the different objects.
- When loading an old blend file, the state mask of all objects and controllers are initialized to 1
so that all the controllers belong to this single state. This ensures backward compatibility with
existing game.
- When the state actuator is activated at the same time as other actuators, these actuators are
guaranteed to execute before being eventually disabled due to the state change. This is useful for
example to send a message or update a property at the time of changing the state.
- Sensors that depend on underlying resource won't reset fully when they are isolated. By the time they
are acticated again, they will behave as follow:
* keyboard sensor: keys already pressed won't be detected. The keyboard sensor is only sensitive
to new key press.
* collision sensor: objects already colliding won't be detected. Only new collisions are
detected.
* near and radar sensor: same as collision sensor.
2008-06-22 14:23:57 +00:00
|
|
|
void KX_MouseFocusSensor::Init()
|
|
|
|
{
|
2008-06-23 20:26:48 +00:00
|
|
|
m_mouse_over_in_previous_frame = (m_invert)?true:false;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_positive_event = false;
|
2005-08-05 17:00:32 +00:00
|
|
|
m_hitObject = 0;
|
2009-08-23 06:17:59 +00:00
|
|
|
m_hitObject_Last = NULL;
|
BGE logic update: new servo control motion actuator, new distance constraint actuator, new orientation constraint actuator, new actuator sensor.
General
=======
- Removal of Damp option in motion actuator (replaced by
Servo control motion).
- No PyDoc at present, will be added soon.
Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.
Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
coordinates of LinV). No limitation means that the force
will grow as large as necessary to achieve the target
speed along that axis. Set a max value to limit the
accelaration along an axis (slow start) and set a min
value (negative) to limit the brake force.
P: Proportional coefficient of servo controller, don't set
directly unless you know what you're doing.
I: Integral coefficient of servo controller. Use low value
(<0.1) for slow reaction (sliding), high values (>0.5)
for hard control. The P coefficient will be automatically
set to 60 times the I coefficient (a reasonable value).
D: Derivate coefficient. Leave to 0 unless you know what
you're doing. High values create instability.
Notes: - This actuator works perfectly in zero friction
environment: the PID controller will simulate friction
by applying force as needed.
- This actuator is compatible with simple Drot motion
actuator but not with LinV and Dloc motion.
- (0,0,0) is a valid target speed.
- All parameters are accessible through Python.
Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp: Time constant (in nb of frames) of distance and
orientation control.
Dist: Select to enable distance control and set target
distance. The object will be position at the given
distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
detected.
N : Select to enable orientation control. The actuator will
change the orientation and the location of the object
so that it is parallel to the surface at the vertical
of the point of contact of the ray.
M/P : Select to enable material detection. Default is property
detection.
Property/Material: name of property/material that the target of
ray must have to be detected. If not set, property/
material filter is disabled and any collisioning object
within range will be detected.
PER : Select to enable persistent operation. Normally the
actuator disables itself automatically if the ray does
not reach a valid target.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
0 : use Damp parameter.
>0: use a different time constant for orientation.
Notes: - If neither N nor Dist options are set, the actuator
does not change the position and orientation of the
object; it works as a ray sensor.
- The ray has no "X-ray" capability: if the first object
hit does not have the required property/material, it
returns no hit and the actuator disables itself unless
PER option is enabled.
- This actuator changes the position and orientation but
not the speed of the object. This has an important
implication in a gravity environment: the gravity will
cause the speed to increase although the object seems
to stay still (it is repositioned at each frame).
The gravity must be compensated in one way or another.
the new servo control motion actuator is the simplest
way: set the target speed along the ray axis to 0
and the servo control will automatically compensate
the gravity.
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is
placed BEFORE the Drot motion actuator (the order of
actuator is important)
- All parameters are accessible through Python.
Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is placed
BEFORE the Drot motion actuator (the order of
actuator is important).
- This actuator doesn't change the location and speed.
It is compatible with gravity.
- All parameters are accessible through Python.
Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.
Notes: - Actuators are disabled at the start of the game; if you
want to detect the On-Off transition of an actuator
after it has been activated at least once, unselect the
Lvl and Inv options and use a NAND controller.
- Some actuators deactivates themselves immediately after
being activated. The sensor detects this situation as
an On-Off transition.
- The actuator name can be set through Python.
2008-07-04 08:14:50 +00:00
|
|
|
m_reset = true;
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
m_hitPosition.setValue(0,0,0);
|
|
|
|
m_prevTargetPoint.setValue(0,0,0);
|
|
|
|
m_prevSourcePoint.setValue(0,0,0);
|
|
|
|
m_hitNormal.setValue(0,0,1);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
bool KX_MouseFocusSensor::Evaluate()
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
bool obHasFocus = false;
|
BGE logic update: new servo control motion actuator, new distance constraint actuator, new orientation constraint actuator, new actuator sensor.
General
=======
- Removal of Damp option in motion actuator (replaced by
Servo control motion).
- No PyDoc at present, will be added soon.
Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.
Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
coordinates of LinV). No limitation means that the force
will grow as large as necessary to achieve the target
speed along that axis. Set a max value to limit the
accelaration along an axis (slow start) and set a min
value (negative) to limit the brake force.
P: Proportional coefficient of servo controller, don't set
directly unless you know what you're doing.
I: Integral coefficient of servo controller. Use low value
(<0.1) for slow reaction (sliding), high values (>0.5)
for hard control. The P coefficient will be automatically
set to 60 times the I coefficient (a reasonable value).
D: Derivate coefficient. Leave to 0 unless you know what
you're doing. High values create instability.
Notes: - This actuator works perfectly in zero friction
environment: the PID controller will simulate friction
by applying force as needed.
- This actuator is compatible with simple Drot motion
actuator but not with LinV and Dloc motion.
- (0,0,0) is a valid target speed.
- All parameters are accessible through Python.
Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp: Time constant (in nb of frames) of distance and
orientation control.
Dist: Select to enable distance control and set target
distance. The object will be position at the given
distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
detected.
N : Select to enable orientation control. The actuator will
change the orientation and the location of the object
so that it is parallel to the surface at the vertical
of the point of contact of the ray.
M/P : Select to enable material detection. Default is property
detection.
Property/Material: name of property/material that the target of
ray must have to be detected. If not set, property/
material filter is disabled and any collisioning object
within range will be detected.
PER : Select to enable persistent operation. Normally the
actuator disables itself automatically if the ray does
not reach a valid target.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
0 : use Damp parameter.
>0: use a different time constant for orientation.
Notes: - If neither N nor Dist options are set, the actuator
does not change the position and orientation of the
object; it works as a ray sensor.
- The ray has no "X-ray" capability: if the first object
hit does not have the required property/material, it
returns no hit and the actuator disables itself unless
PER option is enabled.
- This actuator changes the position and orientation but
not the speed of the object. This has an important
implication in a gravity environment: the gravity will
cause the speed to increase although the object seems
to stay still (it is repositioned at each frame).
The gravity must be compensated in one way or another.
the new servo control motion actuator is the simplest
way: set the target speed along the ray axis to 0
and the servo control will automatically compensate
the gravity.
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is
placed BEFORE the Drot motion actuator (the order of
actuator is important)
- All parameters are accessible through Python.
Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is placed
BEFORE the Drot motion actuator (the order of
actuator is important).
- This actuator doesn't change the location and speed.
It is compatible with gravity.
- All parameters are accessible through Python.
Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.
Notes: - Actuators are disabled at the start of the game; if you
want to detect the On-Off transition of an actuator
after it has been activated at least once, unselect the
Lvl and Inv options and use a NAND controller.
- Some actuators deactivates themselves immediately after
being activated. The sensor detects this situation as
an On-Off transition.
- The actuator name can be set through Python.
2008-07-04 08:14:50 +00:00
|
|
|
bool reset = m_reset && m_level;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
// cout << "evaluate focus mouse sensor "<<endl;
|
BGE logic update: new servo control motion actuator, new distance constraint actuator, new orientation constraint actuator, new actuator sensor.
General
=======
- Removal of Damp option in motion actuator (replaced by
Servo control motion).
- No PyDoc at present, will be added soon.
Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.
Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
coordinates of LinV). No limitation means that the force
will grow as large as necessary to achieve the target
speed along that axis. Set a max value to limit the
accelaration along an axis (slow start) and set a min
value (negative) to limit the brake force.
P: Proportional coefficient of servo controller, don't set
directly unless you know what you're doing.
I: Integral coefficient of servo controller. Use low value
(<0.1) for slow reaction (sliding), high values (>0.5)
for hard control. The P coefficient will be automatically
set to 60 times the I coefficient (a reasonable value).
D: Derivate coefficient. Leave to 0 unless you know what
you're doing. High values create instability.
Notes: - This actuator works perfectly in zero friction
environment: the PID controller will simulate friction
by applying force as needed.
- This actuator is compatible with simple Drot motion
actuator but not with LinV and Dloc motion.
- (0,0,0) is a valid target speed.
- All parameters are accessible through Python.
Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp: Time constant (in nb of frames) of distance and
orientation control.
Dist: Select to enable distance control and set target
distance. The object will be position at the given
distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
detected.
N : Select to enable orientation control. The actuator will
change the orientation and the location of the object
so that it is parallel to the surface at the vertical
of the point of contact of the ray.
M/P : Select to enable material detection. Default is property
detection.
Property/Material: name of property/material that the target of
ray must have to be detected. If not set, property/
material filter is disabled and any collisioning object
within range will be detected.
PER : Select to enable persistent operation. Normally the
actuator disables itself automatically if the ray does
not reach a valid target.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
0 : use Damp parameter.
>0: use a different time constant for orientation.
Notes: - If neither N nor Dist options are set, the actuator
does not change the position and orientation of the
object; it works as a ray sensor.
- The ray has no "X-ray" capability: if the first object
hit does not have the required property/material, it
returns no hit and the actuator disables itself unless
PER option is enabled.
- This actuator changes the position and orientation but
not the speed of the object. This has an important
implication in a gravity environment: the gravity will
cause the speed to increase although the object seems
to stay still (it is repositioned at each frame).
The gravity must be compensated in one way or another.
the new servo control motion actuator is the simplest
way: set the target speed along the ray axis to 0
and the servo control will automatically compensate
the gravity.
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is
placed BEFORE the Drot motion actuator (the order of
actuator is important)
- All parameters are accessible through Python.
Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is placed
BEFORE the Drot motion actuator (the order of
actuator is important).
- This actuator doesn't change the location and speed.
It is compatible with gravity.
- All parameters are accessible through Python.
Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.
Notes: - Actuators are disabled at the start of the game; if you
want to detect the On-Off transition of an actuator
after it has been activated at least once, unselect the
Lvl and Inv options and use a NAND controller.
- Some actuators deactivates themselves immediately after
being activated. The sensor detects this situation as
an On-Off transition.
- The actuator name can be set through Python.
2008-07-04 08:14:50 +00:00
|
|
|
m_reset = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_focusmode) {
|
2012-03-01 12:20:18 +00:00
|
|
|
/* Focus behavior required. Test mouse-on. The rest is
|
2002-10-12 11:37:38 +00:00
|
|
|
* equivalent to handling a key. */
|
|
|
|
obHasFocus = ParentObjectHasFocus();
|
|
|
|
|
|
|
|
if (!obHasFocus) {
|
2008-06-23 20:26:48 +00:00
|
|
|
m_positive_event = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (m_mouse_over_in_previous_frame) {
|
2008-06-23 20:26:48 +00:00
|
|
|
result = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-06-23 20:26:48 +00:00
|
|
|
m_positive_event = true;
|
2002-10-12 11:37:38 +00:00
|
|
|
if (!m_mouse_over_in_previous_frame) {
|
|
|
|
result = true;
|
2009-08-23 06:17:59 +00:00
|
|
|
}
|
2012-03-24 07:52:14 +00:00
|
|
|
else if (m_bTouchPulse && (m_hitObject != m_hitObject_Last)) {
|
2009-08-23 06:17:59 +00:00
|
|
|
result = true;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
BGE logic update: new servo control motion actuator, new distance constraint actuator, new orientation constraint actuator, new actuator sensor.
General
=======
- Removal of Damp option in motion actuator (replaced by
Servo control motion).
- No PyDoc at present, will be added soon.
Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.
Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
coordinates of LinV). No limitation means that the force
will grow as large as necessary to achieve the target
speed along that axis. Set a max value to limit the
accelaration along an axis (slow start) and set a min
value (negative) to limit the brake force.
P: Proportional coefficient of servo controller, don't set
directly unless you know what you're doing.
I: Integral coefficient of servo controller. Use low value
(<0.1) for slow reaction (sliding), high values (>0.5)
for hard control. The P coefficient will be automatically
set to 60 times the I coefficient (a reasonable value).
D: Derivate coefficient. Leave to 0 unless you know what
you're doing. High values create instability.
Notes: - This actuator works perfectly in zero friction
environment: the PID controller will simulate friction
by applying force as needed.
- This actuator is compatible with simple Drot motion
actuator but not with LinV and Dloc motion.
- (0,0,0) is a valid target speed.
- All parameters are accessible through Python.
Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp: Time constant (in nb of frames) of distance and
orientation control.
Dist: Select to enable distance control and set target
distance. The object will be position at the given
distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
detected.
N : Select to enable orientation control. The actuator will
change the orientation and the location of the object
so that it is parallel to the surface at the vertical
of the point of contact of the ray.
M/P : Select to enable material detection. Default is property
detection.
Property/Material: name of property/material that the target of
ray must have to be detected. If not set, property/
material filter is disabled and any collisioning object
within range will be detected.
PER : Select to enable persistent operation. Normally the
actuator disables itself automatically if the ray does
not reach a valid target.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
0 : use Damp parameter.
>0: use a different time constant for orientation.
Notes: - If neither N nor Dist options are set, the actuator
does not change the position and orientation of the
object; it works as a ray sensor.
- The ray has no "X-ray" capability: if the first object
hit does not have the required property/material, it
returns no hit and the actuator disables itself unless
PER option is enabled.
- This actuator changes the position and orientation but
not the speed of the object. This has an important
implication in a gravity environment: the gravity will
cause the speed to increase although the object seems
to stay still (it is repositioned at each frame).
The gravity must be compensated in one way or another.
the new servo control motion actuator is the simplest
way: set the target speed along the ray axis to 0
and the servo control will automatically compensate
the gravity.
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is
placed BEFORE the Drot motion actuator (the order of
actuator is important)
- All parameters are accessible through Python.
Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is placed
BEFORE the Drot motion actuator (the order of
actuator is important).
- This actuator doesn't change the location and speed.
It is compatible with gravity.
- All parameters are accessible through Python.
Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.
Notes: - Actuators are disabled at the start of the game; if you
want to detect the On-Off transition of an actuator
after it has been activated at least once, unselect the
Lvl and Inv options and use a NAND controller.
- Some actuators deactivates themselves immediately after
being activated. The sensor detects this situation as
an On-Off transition.
- The actuator name can be set through Python.
2008-07-04 08:14:50 +00:00
|
|
|
if (reset) {
|
2011-09-01 02:12:53 +00:00
|
|
|
// force an event
|
BGE logic update: new servo control motion actuator, new distance constraint actuator, new orientation constraint actuator, new actuator sensor.
General
=======
- Removal of Damp option in motion actuator (replaced by
Servo control motion).
- No PyDoc at present, will be added soon.
Generalization of the Lvl option
================================
A sensor with the Lvl option selected will always produce an
event at the start of the game or when entering a state or at
object creation. The event will be positive or negative
depending of the sensor condition. A negative pulse makes
sense when used with a NAND controller: it will be converted
into an actuator activation.
Servo control motion
====================
A new variant of the motion actuator allows to control speed
with force. The control if of type "PID" (Propotional, Integral,
Derivate): the force is automatically adapted to achieve the
target speed. All the parameters of the servo controller are
configurable. The result is a great variety of motion style:
anysotropic friction, flying, sliding, pseudo Dloc...
This actuator should be used in preference to Dloc and LinV
as it produces more fluid movements and avoids the collision
problem with Dloc.
LinV : target speed as (X,Y,Z) vector in local or world
coordinates (mostly useful in local coordinates).
Limit: the force can be limited along each axis (in the same
coordinates of LinV). No limitation means that the force
will grow as large as necessary to achieve the target
speed along that axis. Set a max value to limit the
accelaration along an axis (slow start) and set a min
value (negative) to limit the brake force.
P: Proportional coefficient of servo controller, don't set
directly unless you know what you're doing.
I: Integral coefficient of servo controller. Use low value
(<0.1) for slow reaction (sliding), high values (>0.5)
for hard control. The P coefficient will be automatically
set to 60 times the I coefficient (a reasonable value).
D: Derivate coefficient. Leave to 0 unless you know what
you're doing. High values create instability.
Notes: - This actuator works perfectly in zero friction
environment: the PID controller will simulate friction
by applying force as needed.
- This actuator is compatible with simple Drot motion
actuator but not with LinV and Dloc motion.
- (0,0,0) is a valid target speed.
- All parameters are accessible through Python.
Distance constraint actuator
============================
A new variant of the constraint actuator allows to set the
distance and orientation relative to a surface. The controller
uses a ray to detect the surface (or any object) and adapt the
distance and orientation parallel to the surface.
Damp: Time constant (in nb of frames) of distance and
orientation control.
Dist: Select to enable distance control and set target
distance. The object will be position at the given
distance of surface along the ray direction.
Direction: chose a local axis as the ray direction.
Range: length of ray. Objecgt within this distance will be
detected.
N : Select to enable orientation control. The actuator will
change the orientation and the location of the object
so that it is parallel to the surface at the vertical
of the point of contact of the ray.
M/P : Select to enable material detection. Default is property
detection.
Property/Material: name of property/material that the target of
ray must have to be detected. If not set, property/
material filter is disabled and any collisioning object
within range will be detected.
PER : Select to enable persistent operation. Normally the
actuator disables itself automatically if the ray does
not reach a valid target.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
rotDamp: Time constant (in nb of frame) of orientation control.
0 : use Damp parameter.
>0: use a different time constant for orientation.
Notes: - If neither N nor Dist options are set, the actuator
does not change the position and orientation of the
object; it works as a ray sensor.
- The ray has no "X-ray" capability: if the first object
hit does not have the required property/material, it
returns no hit and the actuator disables itself unless
PER option is enabled.
- This actuator changes the position and orientation but
not the speed of the object. This has an important
implication in a gravity environment: the gravity will
cause the speed to increase although the object seems
to stay still (it is repositioned at each frame).
The gravity must be compensated in one way or another.
the new servo control motion actuator is the simplest
way: set the target speed along the ray axis to 0
and the servo control will automatically compensate
the gravity.
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is
placed BEFORE the Drot motion actuator (the order of
actuator is important)
- All parameters are accessible through Python.
Orientation constraint
======================
A new variant of the constraint actuator allows to align an
object axis along a global direction.
Damp : Time constant (in nb of frames) of orientation control.
X,Y,Z: Global coordinates of reference direction.
time : Maximum activation time of actuator.
0 : unlimited.
>0: number of frames before automatic deactivation.
Notes: - (X,Y,Z) = (0,0,0) is not a valid direction
- This actuator changes the orientation of the object
and will conflict with Drot motion unless it is placed
BEFORE the Drot motion actuator (the order of
actuator is important).
- This actuator doesn't change the location and speed.
It is compatible with gravity.
- All parameters are accessible through Python.
Actuator sensor
===============
This sensor detects the activation and deactivation of actuators
of the same object. The sensor generates a positive pulse when
the corresponding sensor is activated and a negative pulse when
it is deactivated (the contrary if the Inv option is selected).
This is mostly useful to chain actions and to detect the loss of
contact of the distance motion actuator.
Notes: - Actuators are disabled at the start of the game; if you
want to detect the On-Off transition of an actuator
after it has been activated at least once, unselect the
Lvl and Inv options and use a NAND controller.
- Some actuators deactivates themselves immediately after
being activated. The sensor detects this situation as
an On-Off transition.
- The actuator name can be set through Python.
2008-07-04 08:14:50 +00:00
|
|
|
result = true;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
} else {
|
2012-03-01 12:20:18 +00:00
|
|
|
/* No focus behavior required: revert to the basic mode. This
|
2011-09-01 02:12:53 +00:00
|
|
|
* mode is never used, because the converter never makes this
|
|
|
|
* sensor for a mouse-key event. It is here for
|
|
|
|
* completeness. */
|
2009-06-08 20:08:19 +00:00
|
|
|
result = SCA_MouseSensor::Evaluate();
|
2002-10-12 11:37:38 +00:00
|
|
|
m_positive_event = (m_val!=0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_mouse_over_in_previous_frame = obHasFocus;
|
2009-08-23 06:17:59 +00:00
|
|
|
m_hitObject_Last = (void *)m_hitObject;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-26 07:29:01 +00:00
|
|
|
bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *result, void * const data)
|
2005-03-25 10:33:39 +00:00
|
|
|
{
|
|
|
|
KX_GameObject* hitKXObj = client_info->m_gameobject;
|
|
|
|
|
|
|
|
/* Is this me? In the ray test, there are a lot of extra checks
|
2012-10-20 20:36:51 +00:00
|
|
|
* for aliasing artifacts from self-hits. That doesn't happen
|
2012-03-09 18:28:30 +00:00
|
|
|
* here, so a simple test suffices. Or does the camera also get
|
|
|
|
* self-hits? (No, and the raysensor shouldn't do it either, since
|
|
|
|
* self-hits are excluded by setting the correct ignore-object.)
|
|
|
|
* Hitspots now become valid. */
|
2005-03-25 10:33:39 +00:00
|
|
|
KX_GameObject* thisObj = (KX_GameObject*) GetParent();
|
2014-07-18 06:00:30 +00:00
|
|
|
|
|
|
|
bool bFound = false;
|
|
|
|
|
2005-08-17 14:29:58 +00:00
|
|
|
if ((m_focusmode == 2) || hitKXObj == thisObj)
|
2005-03-25 10:33:39 +00:00
|
|
|
{
|
2014-07-18 06:00:30 +00:00
|
|
|
if (m_propertyname.Length() == 0)
|
|
|
|
{
|
|
|
|
bFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_bFindMaterial)
|
|
|
|
{
|
|
|
|
if (client_info->m_auxilary_info)
|
|
|
|
{
|
|
|
|
bFound = (m_propertyname== ((char*)client_info->m_auxilary_info));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bFound = hitKXObj->GetProperty(m_propertyname) != NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bFound)
|
|
|
|
{
|
|
|
|
m_hitObject = hitKXObj;
|
|
|
|
m_hitPosition = result->m_hitPoint;
|
|
|
|
m_hitNormal = result->m_hitNormal;
|
|
|
|
m_hitUV = result->m_hitUV;
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true; // object must be visible to trigger
|
|
|
|
//return false; // occluded objects can trigger
|
|
|
|
}
|
|
|
|
|
2014-07-18 06:00:30 +00:00
|
|
|
/* this function is used to pre-filter the object before casting the ray on them.
|
|
|
|
* This is useful for "X-Ray" option when we want to see "through" unwanted object.
|
|
|
|
*/
|
|
|
|
bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo* client)
|
|
|
|
{
|
|
|
|
if (client->m_type > KX_ClientObjectInfo::ACTOR)
|
|
|
|
{
|
|
|
|
// Unknown type of object, skip it.
|
|
|
|
// Should not occur as the sensor objects are filtered in RayTest()
|
|
|
|
printf("Invalid client type %d found ray casting\n", client->m_type);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (m_bXRay && m_propertyname.Length() != 0)
|
|
|
|
{
|
|
|
|
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)))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (client->m_gameobject->GetProperty(m_propertyname) == NULL)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
/* All screen handling in the gameengine is done by GL,
|
|
|
|
* specifically the model/view and projection parts. The viewport
|
|
|
|
* part is in the creator.
|
|
|
|
*
|
|
|
|
* The theory is this:
|
|
|
|
* WCS - world coordinates
|
|
|
|
* -> wcs_camcs_trafo ->
|
|
|
|
* camCS - camera coordinates
|
|
|
|
* -> camcs_clip_trafo ->
|
2007-04-04 13:18:41 +00:00
|
|
|
* clipCS - normalized device coordinates?
|
2002-10-12 11:37:38 +00:00
|
|
|
* -> normview_win_trafo
|
|
|
|
* winCS - window coordinates
|
|
|
|
*
|
|
|
|
* The first two transforms are respectively the model/view and
|
|
|
|
* the projection matrix. These are passed to the rasterizer, and
|
|
|
|
* we store them in the camera for easy access.
|
|
|
|
*
|
2007-04-04 13:18:41 +00:00
|
|
|
* For normalized device coords (xn = x/w, yn = y/w/zw) the
|
2002-10-12 11:37:38 +00:00
|
|
|
* windows coords become (lb = left bottom)
|
|
|
|
*
|
|
|
|
* xwin = [(xn + 1.0) * width]/2 + x_lb
|
|
|
|
* ywin = [(yn + 1.0) * height]/2 + y_lb
|
|
|
|
*
|
|
|
|
* Inverting (blender y is flipped!):
|
|
|
|
*
|
|
|
|
* xn = 2(xwin - x_lb)/width - 1.0
|
|
|
|
* yn = 2(ywin - y_lb)/height - 1.0
|
|
|
|
* = 2(height - y_blender - y_lb)/height - 1.0
|
|
|
|
* = 1.0 - 2(y_blender - y_lb)/height
|
|
|
|
*
|
|
|
|
* */
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* Because we don't want to worry about resize events, camera
|
|
|
|
* changes and all that crap, we just determine this over and
|
|
|
|
* over. Stop whining. We have lots of other calculations to do
|
|
|
|
* here as well. These reads are not the main cost. If there is no
|
|
|
|
* canvas, the test is irrelevant. The 1.0 makes sure the
|
|
|
|
* calculations don't bomb. Maybe we should explicitly guard for
|
|
|
|
* division by 0.0...*/
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2008-09-18 01:46:28 +00:00
|
|
|
RAS_Rect area, viewport;
|
2009-06-08 20:08:19 +00:00
|
|
|
short m_y_inv = m_kxengine->GetCanvas()->GetHeight()-m_y;
|
|
|
|
|
2008-09-18 01:46:28 +00:00
|
|
|
m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
/* 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
|
2009-06-08 20:08:19 +00:00
|
|
|
m_y_inv < viewport.m_y2 && // below top
|
|
|
|
m_y_inv > viewport.m_y1) == 0) // above bottom
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
float height = float(viewport.m_y2 - viewport.m_y1 + 1);
|
|
|
|
float width = float(viewport.m_x2 - viewport.m_x1 + 1);
|
|
|
|
|
|
|
|
float x_lb = float(viewport.m_x1);
|
|
|
|
float y_lb = float(viewport.m_y1);
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
MT_Vector4 frompoint;
|
|
|
|
MT_Vector4 topoint;
|
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* There's some strangeness I don't fully get here... These values
|
2009-04-20 15:06:46 +00:00
|
|
|
* _should_ be wrong! - see from point Z values */
|
|
|
|
|
2008-09-18 01:46:28 +00:00
|
|
|
|
2007-04-04 13:18:41 +00:00
|
|
|
/* build the from and to point in normalized device coordinates
|
2011-10-20 06:38:45 +00:00
|
|
|
* Normalized device coordinates are [-1,1] in x, y, z
|
2012-09-16 04:58:18 +00:00
|
|
|
*
|
2002-10-12 11:37:38 +00:00
|
|
|
* The actual z coordinates used don't have to be exact just infront and
|
|
|
|
* behind of the near and far clip planes.
|
|
|
|
*/
|
2009-04-20 15:06:46 +00:00
|
|
|
frompoint.setValue( (2 * (m_x-x_lb) / width) - 1.0,
|
2009-06-08 20:08:19 +00:00
|
|
|
1.0 - (2 * (m_y_inv - y_lb) / height),
|
2011-10-20 06:38:45 +00:00
|
|
|
-1.0,
|
2009-04-20 15:06:46 +00:00
|
|
|
1.0 );
|
|
|
|
|
|
|
|
topoint.setValue( (2 * (m_x-x_lb) / width) - 1.0,
|
2009-06-08 20:08:19 +00:00
|
|
|
1.0 - (2 * (m_y_inv-y_lb) / height),
|
2011-10-20 06:38:45 +00:00
|
|
|
1.0,
|
2009-04-20 15:06:46 +00:00
|
|
|
1.0 );
|
2004-11-23 10:10:21 +00:00
|
|
|
|
2011-10-20 06:38:45 +00:00
|
|
|
/* camera to world */
|
|
|
|
MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cam->GetCameraToWorld());
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* badly defined, the first time round.... I wonder why... I might
|
|
|
|
* want to guard against floating point errors here.*/
|
2004-04-26 07:19:18 +00:00
|
|
|
MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix());
|
2002-10-12 11:37:38 +00:00
|
|
|
clip_camcs_matrix.invert();
|
|
|
|
|
|
|
|
/* shoot-points: clip to cam to wcs . win to clip was already done.*/
|
|
|
|
frompoint = clip_camcs_matrix * frompoint;
|
|
|
|
topoint = clip_camcs_matrix * topoint;
|
2011-10-20 06:38:45 +00:00
|
|
|
/* clipstart = - (frompoint[2] / frompoint[3])
|
|
|
|
* clipend = - (topoint[2] / topoint[3]) */
|
2002-10-12 11:37:38 +00:00
|
|
|
frompoint = camcs_wcs_matrix * frompoint;
|
|
|
|
topoint = camcs_wcs_matrix * topoint;
|
2004-04-26 07:19:18 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* from hom wcs to 3d wcs: */
|
2009-04-20 15:06:46 +00:00
|
|
|
m_prevSourcePoint.setValue( frompoint[0]/frompoint[3],
|
|
|
|
frompoint[1]/frompoint[3],
|
|
|
|
frompoint[2]/frompoint[3]);
|
|
|
|
|
|
|
|
m_prevTargetPoint.setValue( topoint[0]/topoint[3],
|
|
|
|
topoint[1]/topoint[3],
|
|
|
|
topoint[2]/topoint[3]);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
/* 2. Get the object from PhysicsEnvironment */
|
2002-10-12 11:37:38 +00:00
|
|
|
/* Shoot! Beware that the first argument here is an
|
|
|
|
* ignore-object. We don't ignore anything... */
|
BGE: Cleaning up the BGE's physics code and removing KX_IPhysicsController and KX_BulletPhysicsController. Instead, we just use PHY_IPhysicsController, which removes a lot of duplicate code.
This is a squashed commit of the following:
BGE Physics Cleanup: Fix crashes with LibLoading and replication. Also fixing some memory leaks.
BGE Physics Cleanup: Removing KX_IPhysicsController and KX_BulletPhysicsController.
BGE Physics Cleanup: Moving the replication code outside of KX_BlenderBulletController and switching KX_ConvertPhysicsObjects to create a CcdPhysicsController instead of a KX_BlenderBulletController.
BGE Physics Cleanup: Getting rid of an unsued KX_BulletPhysicsController.h include in KX_Scene.cpp.
BGE Physics Cleanup: Removing unused KX_IPhysicsController and KX_BulletPhysicsController includes.
BGE Physics Cleanup: Removing m_pPhysicsController1 and GetPhysicsController1() from KX_GameObject.
BGE Physics Cleanup: Remove SetRigidBody() from KX_IPhysicsController and remove GetName() from CcdPhysicsController.
BGE Physics Cleanup: Moving Add/RemoveCompoundChild() from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: Removing GetLocalInertia() from KX_IPhysicsController.
BGE Physics Cleanup: Making BlenderBulletCharacterController derive from PHY_ICharacter and removing CharacterWrapper from CcdPhysicsEnvironment.cpp. Also removing the character functions from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetOrientation(), SetOrientation(), SetPosition(), SetScaling(), and GetRadius() from KX_IPhysicsController.
BGE Physics Cleanup: Removing GetReactionForce() since all implementations returned (0, 0, 0). The Python interface for KX_GameObject still has reaction force code, but it still also returns (0, 0, 0). This can probably be removed as well, but removing it can break scripts, so I'll leave it for now.
BGE Physics Cleanup: Removing Get/SetLinVelocityMin() and Get/SetLinVelocityMax() from KX_IPhysicsController.
BGE Physics Cleanup: Removing SetMargin(), RelativeTranslate(), and RelativeRotate() from KX_IPhysicsController.
BGE Physics Cleanup: Using constant references for function arguments in PHY_IPhysicsController where appropriate.
BGE Physics Cleanup: Removing ApplyImpulse() from KX_IPhysicsController.
BGE Physics Cleanup: Removing ResolveCombinedVelocities() from KX_IPhysicsController.
BGE Physics Cleanup: Accidently removed a return when cleaning up KX_GameObject::PyGetVelocity().
BGE Physics Cleanup: Remove GetLinearVelocity(), GetAngularVelocity() and GetVelocity() from KX_IPhysicsController. The corresponding PHY_IPhysicsController functions now also take Moto types instead of scalars to match the KX_IPhysicsController interface.
BGE Physics Cleanup: Moving SuspendDynamics, RestoreDynamics, SetMass, GetMass, and SetTransform from KX_IPhysicsController to PHY_IPhysicsController.
BGE Physics Cleanup: PHY_IPhysicsEnvironment and derived classes now use the same naming scheme as PHY_IController.
BGE Physics Cleanup: PHY_IMotionState and derived classes now use the same naming convention as PHY_IController.
BGE Phsyics Cleanup: Making PHY_IController and its derived classes follow a consistent naming scheme for member functions. They now all start with capital letters (e.g., setWorldOrientation becomes SetWorldOrientation).
BGE Physics Cleanup: Getting rid of KX_GameObject::SuspendDynamics() and KX_GameObject::RestoreDynamics(). Instead, use the functions from the physics controller.
BGE: Some first steps in trying to cleanup the KX_IPhysicsController mess. KX_GameObject now has a GetPhysicsController() and a GetPhysicsController1(). The former returns a PHY_IPhysicsController* while the latter returns a KX_IPhysicsController. The goal is to get everything using GetPhysicsController() instead of GetPhysicsController1().
2013-11-04 19:22:47 +00:00
|
|
|
PHY_IPhysicsController* physics_controller = cam->GetPhysicsController();
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment();
|
|
|
|
|
2009-12-08 08:58:24 +00:00
|
|
|
// get UV mapping
|
|
|
|
KX_RayCast::Callback<KX_MouseFocusSensor> callback(this,physics_controller,NULL,false,true);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
|
|
|
KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback);
|
|
|
|
|
|
|
|
if (m_hitObject)
|
|
|
|
return true;
|
2005-08-17 19:52:56 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
2005-08-17 19:52:56 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
bool KX_MouseFocusSensor::ParentObjectHasFocus()
|
|
|
|
{
|
|
|
|
m_hitObject = 0;
|
|
|
|
m_hitPosition.setValue(0,0,0);
|
|
|
|
m_hitNormal.setValue(1,0,0);
|
|
|
|
|
|
|
|
KX_Camera *cam= m_kxscene->GetActiveCamera();
|
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (ParentObjectHasFocusCamera(cam))
|
2009-04-20 15:06:46 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
list<class KX_Camera*>* cameras = m_kxscene->GetCameras();
|
|
|
|
list<KX_Camera*>::iterator it = cameras->begin();
|
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
while (it != cameras->end()) {
|
2012-03-24 07:52:14 +00:00
|
|
|
if (((*it) != cam) && (*it)->GetViewport())
|
2009-04-20 15:06:46 +00:00
|
|
|
if (ParentObjectHasFocusCamera(*it))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MT_Point3& KX_MouseFocusSensor::RaySource() const
|
|
|
|
{
|
|
|
|
return m_prevSourcePoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MT_Point3& KX_MouseFocusSensor::RayTarget() const
|
|
|
|
{
|
|
|
|
return m_prevTargetPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
const MT_Point3& KX_MouseFocusSensor::HitPosition() const
|
|
|
|
{
|
|
|
|
return m_hitPosition;
|
|
|
|
}
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
const MT_Vector3& KX_MouseFocusSensor::HitNormal() const
|
|
|
|
{
|
|
|
|
return m_hitNormal;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-12-08 08:58:24 +00:00
|
|
|
const MT_Vector2& KX_MouseFocusSensor::HitUV() const
|
|
|
|
{
|
|
|
|
return m_hitUV;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_MouseFocusSensor::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2002-10-12 11:37:38 +00:00
|
|
|
"KX_MouseFocusSensor",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
2009-06-29 12:06:46 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,
|
2009-06-28 11:22:26 +00:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
2009-06-29 12:06:46 +00:00
|
|
|
&SCA_MouseSensor::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_MouseFocusSensor::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("raySource", KX_MouseFocusSensor, pyattr_get_ray_source),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("rayTarget", KX_MouseFocusSensor, pyattr_get_ray_target),
|
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("rayDirection", KX_MouseFocusSensor, pyattr_get_ray_direction),
|
|
|
|
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),
|
2009-12-08 08:58:24 +00:00
|
|
|
KX_PYATTRIBUTE_RO_FUNCTION("hitUV", KX_MouseFocusSensor, pyattr_get_hit_uv),
|
2014-07-18 06:00:30 +00:00
|
|
|
KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor, m_bTouchPulse),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_MouseFocusSensor, m_bXRay),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_MouseFocusSensor, m_bFindMaterial),
|
|
|
|
KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_MouseFocusSensor, m_propertyname),
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
/* Attributes */
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_ray_source(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PyObjectFrom(self->RaySource());
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_ray_target(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PyObjectFrom(self->RayTarget());
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_ray_direction(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
MT_Vector3 dir = self->RayTarget() - self->RaySource();
|
2012-03-24 07:52:14 +00:00
|
|
|
if (MT_fuzzyZero(dir)) dir.setValue(0,0,0);
|
2009-04-20 15:06:46 +00:00
|
|
|
else dir.normalize();
|
|
|
|
return PyObjectFrom(dir);
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_hit_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (self->m_hitObject)
|
2009-04-20 15:06:46 +00:00
|
|
|
return self->m_hitObject->GetProxy();
|
|
|
|
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_hit_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PyObjectFrom(self->HitPosition());
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_hit_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-04-20 15:06:46 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-04-20 15:06:46 +00:00
|
|
|
return PyObjectFrom(self->HitNormal());
|
|
|
|
}
|
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_MouseFocusSensor::pyattr_get_hit_uv(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
2009-12-08 08:58:24 +00:00
|
|
|
{
|
2012-10-22 08:15:51 +00:00
|
|
|
KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
|
2009-12-08 08:58:24 +00:00
|
|
|
return PyObjectFrom(self->HitUV());
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-04-20 15:06:46 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* eof */
|
|
|
|
|