2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-01-07 19:13:47 +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-01-07 19:13:47 +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-01-07 19:13:47 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
* Conversion of Blender data blocks to KX sensor system
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:30:41 +00:00
|
|
|
/** \file gameengine/Converter/KX_ConvertSensors.cpp
|
|
|
|
* \ingroup bgeconv
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-09-29 21:42:40 +00:00
|
|
|
#include <stdio.h>
|
2009-07-31 09:05:13 +00:00
|
|
|
|
2010-09-15 16:13:32 +00:00
|
|
|
#if defined(WIN32) && !defined(FREE_WINDOWS)
|
2002-10-12 11:37:38 +00:00
|
|
|
#pragma warning (disable : 4786)
|
|
|
|
#endif //WIN32
|
|
|
|
|
2008-01-01 19:20:49 +00:00
|
|
|
#include "wm_event_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_BlenderSceneConverter.h"
|
|
|
|
#include "KX_ConvertSensors.h"
|
|
|
|
|
|
|
|
/* This little block needed for linking to Blender... */
|
2010-09-15 16:13:32 +00:00
|
|
|
#if defined(WIN32) && !defined(FREE_WINDOWS)
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BLI_winstuff.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
#include "DNA_material_types.h"
|
|
|
|
#include "DNA_sensor_types.h"
|
|
|
|
#include "DNA_actuator_types.h" /* for SENS_ALL_KEYS ? this define is
|
2012-03-09 18:28:30 +00:00
|
|
|
* probably misplaced */
|
2002-10-12 11:37:38 +00:00
|
|
|
/* end of blender include block */
|
|
|
|
|
|
|
|
#include "RAS_IPolygonMaterial.h"
|
|
|
|
// Sensors
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
#include "RAS_MeshObject.h"
|
|
|
|
#include "SCA_KeyboardSensor.h"
|
|
|
|
#include "SCA_MouseSensor.h"
|
|
|
|
#include "SCA_AlwaysSensor.h"
|
|
|
|
#include "KX_TouchSensor.h"
|
|
|
|
#include "KX_NearSensor.h"
|
|
|
|
#include "KX_RadarSensor.h"
|
|
|
|
#include "KX_MouseFocusSensor.h"
|
2009-09-24 21:22:24 +00:00
|
|
|
#include "KX_ArmatureSensor.h"
|
2005-01-23 01:36:29 +00:00
|
|
|
#include "SCA_JoystickSensor.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_NetworkMessageSensor.h"
|
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
|
|
|
#include "SCA_ActuatorSensor.h"
|
2008-08-16 20:45:37 +00:00
|
|
|
#include "SCA_DelaySensor.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-08-22 15:47:56 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "SCA_PropertySensor.h"
|
|
|
|
#include "SCA_RandomSensor.h"
|
|
|
|
#include "KX_RaySensor.h"
|
|
|
|
#include "SCA_EventManager.h"
|
|
|
|
#include "SCA_LogicManager.h"
|
|
|
|
#include "KX_BlenderInputDevice.h"
|
|
|
|
#include "KX_Scene.h"
|
|
|
|
#include "IntValue.h"
|
|
|
|
#include "KX_BlenderKeyboardDevice.h"
|
|
|
|
#include "KX_BlenderGL.h"
|
|
|
|
#include "RAS_ICanvas.h"
|
2005-03-25 10:33:39 +00:00
|
|
|
#include "PHY_IPhysicsEnvironment.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
#include "KX_BlenderSceneConverter.h"
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
#include "BL_BlenderDataConversion.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
void BL_ConvertSensors(struct Object* blenderobject,
|
|
|
|
class KX_GameObject* gameobj,
|
|
|
|
SCA_LogicManager* logicmgr,
|
|
|
|
KX_Scene* kxscene,
|
2008-09-18 01:46:28 +00:00
|
|
|
KX_KetsjiEngine* kxengine,
|
2002-10-12 11:37:38 +00:00
|
|
|
int activeLayerBitInfo,
|
|
|
|
bool isInActiveLayer,
|
|
|
|
RAS_ICanvas* canvas,
|
|
|
|
KX_BlenderSceneConverter* converter
|
|
|
|
)
|
|
|
|
{
|
2009-06-08 20:08:19 +00:00
|
|
|
|
2011-09-01 02:12:53 +00:00
|
|
|
int executePriority = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
int uniqueint = 0;
|
2009-06-08 20:08:19 +00:00
|
|
|
int count = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
bSensor* sens = (bSensor*)blenderobject->sensors.first;
|
|
|
|
bool pos_pulsemode = false;
|
|
|
|
bool neg_pulsemode = false;
|
|
|
|
int frequency = 0;
|
|
|
|
bool invert = false;
|
2008-06-23 20:26:48 +00:00
|
|
|
bool level = false;
|
2009-06-08 20:08:19 +00:00
|
|
|
bool tap = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
while (sens)
|
|
|
|
{
|
|
|
|
sens = sens->next;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
gameobj->ReserveSensor(count);
|
|
|
|
sens = (bSensor*)blenderobject->sensors.first;
|
2002-10-12 11:37:38 +00:00
|
|
|
while(sens)
|
|
|
|
{
|
|
|
|
SCA_ISensor* gamesensor=NULL;
|
|
|
|
/* All sensors have a pulse toggle, frequency, and invert field. */
|
|
|
|
/* These are extracted here, and set when the sensor is added to the */
|
|
|
|
/* list. */
|
|
|
|
pos_pulsemode = (sens->pulse & SENS_PULSE_REPEAT)!=0;
|
|
|
|
neg_pulsemode = (sens->pulse & SENS_NEG_PULSE_MODE)!=0;
|
|
|
|
|
|
|
|
frequency = sens->freq;
|
|
|
|
invert = !(sens->invert == 0);
|
2008-06-23 20:26:48 +00:00
|
|
|
level = !(sens->level == 0);
|
2009-06-08 20:08:19 +00:00
|
|
|
tap = !(sens->tap == 0);
|
2008-06-23 20:26:48 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
switch (sens->type)
|
|
|
|
{
|
|
|
|
case SENS_ALWAYS:
|
|
|
|
{
|
|
|
|
|
2009-09-24 21:22:24 +00:00
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
gamesensor = new SCA_AlwaysSensor(eventmgr, gameobj);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-16 20:45:37 +00:00
|
|
|
case SENS_DELAY:
|
|
|
|
{
|
|
|
|
// we can reuse the Always event manager for the delay sensor
|
2009-09-24 21:22:24 +00:00
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
2008-08-16 20:45:37 +00:00
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
bDelaySensor* delaysensor = (bDelaySensor*)sens->data;
|
|
|
|
gamesensor = new SCA_DelaySensor(eventmgr,
|
|
|
|
gameobj,
|
|
|
|
delaysensor->delay,
|
|
|
|
delaysensor->duration,
|
|
|
|
(delaysensor->flag & SENS_DELAY_REPEAT) != 0);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
case SENS_COLLISION:
|
|
|
|
{
|
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
// collision sensor can sense both materials and properties.
|
|
|
|
|
2009-02-25 17:19:30 +00:00
|
|
|
bool bFindMaterial = false, bTouchPulse = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data;
|
|
|
|
|
2009-02-25 17:19:30 +00:00
|
|
|
bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL);
|
|
|
|
bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
STR_String touchPropOrMatName = ( bFindMaterial ?
|
|
|
|
blendertouchsensor->materialName:
|
|
|
|
(blendertouchsensor->name ? blendertouchsensor->name: ""));
|
|
|
|
|
|
|
|
|
2004-03-22 22:02:18 +00:00
|
|
|
if (gameobj->GetPhysicsController())
|
|
|
|
{
|
|
|
|
gamesensor = new KX_TouchSensor(eventmgr,
|
|
|
|
gameobj,
|
|
|
|
bFindMaterial,
|
2009-02-25 17:19:30 +00:00
|
|
|
bTouchPulse,
|
2004-03-22 22:02:18 +00:00
|
|
|
touchPropOrMatName);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_TOUCH:
|
|
|
|
{
|
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String touchpropertyname;
|
|
|
|
bTouchSensor* blendertouchsensor = (bTouchSensor*)sens->data;
|
|
|
|
|
|
|
|
if (blendertouchsensor->ma)
|
|
|
|
{
|
|
|
|
touchpropertyname = (char*) (blendertouchsensor->ma->id.name+2);
|
|
|
|
}
|
|
|
|
bool bFindMaterial = true;
|
2004-03-22 22:02:18 +00:00
|
|
|
if (gameobj->GetPhysicsController())
|
|
|
|
{
|
|
|
|
gamesensor = new KX_TouchSensor(eventmgr,
|
|
|
|
gameobj,
|
|
|
|
bFindMaterial,
|
2009-02-25 17:19:30 +00:00
|
|
|
false,
|
2004-03-22 22:02:18 +00:00
|
|
|
touchpropertyname);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_MESSAGE:
|
|
|
|
{
|
|
|
|
KX_NetworkEventManager* eventmgr = (KX_NetworkEventManager*)
|
|
|
|
logicmgr->FindEventManager(SCA_EventManager::NETWORK_EVENTMGR);
|
|
|
|
if (eventmgr) {
|
|
|
|
bMessageSensor* msgSens = (bMessageSensor*) sens->data;
|
|
|
|
|
|
|
|
/* Get our NetworkScene */
|
|
|
|
NG_NetworkScene *NetworkScene = kxscene->GetNetworkScene();
|
|
|
|
/* filter on the incoming subjects, might be empty */
|
|
|
|
STR_String subject = (msgSens->subject
|
|
|
|
? (char*)msgSens->subject
|
|
|
|
: "");
|
|
|
|
|
|
|
|
gamesensor = new KX_NetworkMessageSensor(
|
|
|
|
eventmgr, // our eventmanager
|
|
|
|
NetworkScene, // our NetworkScene
|
|
|
|
gameobj, // the sensor controlling object
|
|
|
|
subject); // subject to filter on
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_NEAR:
|
|
|
|
{
|
|
|
|
|
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String nearpropertyname;
|
|
|
|
bNearSensor* blendernearsensor = (bNearSensor*)sens->data;
|
|
|
|
if (blendernearsensor->name)
|
|
|
|
{
|
|
|
|
// only objects that own this property will be taken into account
|
|
|
|
nearpropertyname = (char*) blendernearsensor->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
//DT_ShapeHandle shape = DT_Sphere(0.0);
|
|
|
|
|
|
|
|
// this sumoObject is not deleted by a gameobj, so delete it ourself
|
|
|
|
// later (memleaks)!
|
2005-03-25 10:33:39 +00:00
|
|
|
float radius = blendernearsensor->dist;
|
|
|
|
PHY__Vector3 pos;
|
|
|
|
const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
|
2011-04-10 09:37:04 +00:00
|
|
|
pos[0] = (float)wpos[0];
|
|
|
|
pos[1] = (float)wpos[1];
|
|
|
|
pos[2] = (float)wpos[2];
|
2005-03-25 10:33:39 +00:00
|
|
|
pos[3] = 0.f;
|
2002-10-12 11:37:38 +00:00
|
|
|
bool bFindMaterial = false;
|
2005-03-25 10:33:39 +00:00
|
|
|
PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,pos);
|
|
|
|
|
2008-02-15 23:12:03 +00:00
|
|
|
//will be done in KX_TouchEventManager::RegisterSensor()
|
|
|
|
//if (isInActiveLayer)
|
|
|
|
// kxscene->GetPhysicsEnvironment()->addSensor(physCtrl);
|
2006-05-22 21:03:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-25 10:33:39 +00:00
|
|
|
gamesensor = new KX_NearSensor(eventmgr,gameobj,
|
|
|
|
blendernearsensor->dist,
|
|
|
|
blendernearsensor->resetdist,
|
|
|
|
bFindMaterial,
|
2009-07-31 09:05:13 +00:00
|
|
|
nearpropertyname,
|
|
|
|
physCtrl);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case SENS_KEYBOARD:
|
|
|
|
{
|
|
|
|
/* temporary input device, for converting the code for the keyboard sensor */
|
|
|
|
|
|
|
|
bKeyboardSensor* blenderkeybdsensor = (bKeyboardSensor*)sens->data;
|
|
|
|
SCA_KeyboardManager* eventmgr = (SCA_KeyboardManager*) logicmgr->FindEventManager(SCA_EventManager::KEYBOARD_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
gamesensor = new SCA_KeyboardSensor(eventmgr,
|
Cucumber, first batch of merge - UI changes and custom exit key
---------------------------------------------------------------
This was a test drive to see how painful the merge will be.
Next batches are:
- use desktop option for fullscreen
- multisampling option
- bullet collision mask
- python
- storage (vbo, dl, ...)
- lighting
[lighting still needs review]
[python could use review, although it should be straightforward]
[storage should be tested more I think]
Merged /branches/soc-2011-cucumber:r
36991,37059,37157,37416,37497-37499,37501,37522,39036,40593
36991:
==UI==
* Made some options available in Blender Game that were only available in Blender Render (camera resolution, animation fps)
* Created a panel for the embedded player
* Renamed the FPS option for the standalone player to Refresh Rate
* Moved framing options to display
* Made a button to launch the blender player from within blender (only tested on windows for now)
37059:
==UI==
* Added the option to change the exit key for the BGE. The UI currently just sets a number, and this feature most likely does not work for blenderplayer yet. More work on this to come.
* Removed the physics settings from the scene panel for the BGE.
* Added an Add menu in the logic brick header.
37157:
Making the bake options available in Blender Game
37416:
Making the exit key UI element accept key presses instead of numbers. It still does not work for the Blenderplayer, and it does not limit the input to key presses (other events don't work for exiting)
37497:
Some more work on getting the exit key to work in the Blenderplayer.
Input is now restricted to keyboard events only for the exit key UI.
37498:
Some clean up from the last commit.
The exit key setting affects the Blenderplayer now.
37499:
Cleaning up some duplicate code. Now the reverseTranslateTable for converting blender key codes to ketsji key codes is only defined in BL_BlenderDataConverter.
37501:
Centralizing the exit key methods to the keyboard devices. This should make it easier to get exit key control to the python API.
[37517: committed previously]
37522:
Moved control of the exit key away from the keyboard devices, and moved it to ketsjiengine.
Added setExitKey and getExitKey to the python API
39036:
A couple of the doversions were in the wrong spot. This should fix some issues with the exit key not being set.
[not committed entirely, see below]]
40552: space_logic.py (* fixed an error in space_logic.py *)
40593:
launch blenderplayer from ui not working in OSX fix - by Daniel Stokes and me
########################################################
code left behind (to be included in next commit):
########################################################
{
/* Initialize default values for collision masks */
Object *ob;
for(ob=main->object.first; ob; ob=ob->id.next)
ob->col_group = ob->col_mask = 1;
}
2011-12-20 03:11:56 +00:00
|
|
|
ConvertKeyCode(blenderkeybdsensor->key),
|
|
|
|
ConvertKeyCode(blenderkeybdsensor->qual),
|
|
|
|
ConvertKeyCode(blenderkeybdsensor->qual2),
|
2002-10-12 11:37:38 +00:00
|
|
|
(blenderkeybdsensor->type == SENS_ALL_KEYS),
|
|
|
|
blenderkeybdsensor->targetName,
|
|
|
|
blenderkeybdsensor->toggleName,
|
2012-06-10 19:32:57 +00:00
|
|
|
gameobj,
|
|
|
|
KX_KetsjiEngine::GetExitKey()); // blenderkeybdsensor->pad);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_MOUSE:
|
|
|
|
{
|
|
|
|
int keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_NODEF;
|
2005-08-17 14:29:58 +00:00
|
|
|
int trackfocus = 0;
|
2002-10-12 11:37:38 +00:00
|
|
|
bMouseSensor *bmouse = (bMouseSensor *)sens->data;
|
|
|
|
|
|
|
|
/* There are two main types of mouse sensors. If there is
|
2012-03-09 18:28:30 +00:00
|
|
|
* no focus-related behavior requested, we can make do
|
|
|
|
* with a basic sensor. This cuts down memory usage and
|
|
|
|
* gives a slight performance gain. */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
SCA_MouseManager *eventmgr
|
|
|
|
= (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
|
|
|
|
if (eventmgr) {
|
|
|
|
|
|
|
|
/* Determine key mode. There is at most one active mode. */
|
|
|
|
switch (bmouse->type) {
|
|
|
|
case BL_SENS_MOUSE_LEFT_BUTTON:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_LEFTBUTTON;
|
|
|
|
break;
|
|
|
|
case BL_SENS_MOUSE_MIDDLE_BUTTON:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MIDDLEBUTTON;
|
|
|
|
break;
|
|
|
|
case BL_SENS_MOUSE_RIGHT_BUTTON:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_RIGHTBUTTON;
|
|
|
|
break;
|
2004-05-02 23:45:03 +00:00
|
|
|
case BL_SENS_MOUSE_WHEEL_UP:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELUP;
|
|
|
|
break;
|
|
|
|
case BL_SENS_MOUSE_WHEEL_DOWN:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELDOWN;
|
|
|
|
break;
|
2002-10-12 11:37:38 +00:00
|
|
|
case BL_SENS_MOUSE_MOVEMENT:
|
|
|
|
keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MOVEMENT;
|
|
|
|
break;
|
|
|
|
case BL_SENS_MOUSE_MOUSEOVER:
|
2005-08-17 14:29:58 +00:00
|
|
|
trackfocus = 1;
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
2005-08-17 14:29:58 +00:00
|
|
|
case BL_SENS_MOUSE_MOUSEOVER_ANY:
|
|
|
|
trackfocus = 2;
|
|
|
|
break;
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
default:
|
|
|
|
; /* error */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initial mouse position */
|
|
|
|
int startx = canvas->GetWidth()/2;
|
|
|
|
int starty = canvas->GetHeight()/2;
|
|
|
|
|
|
|
|
if (!trackfocus) {
|
|
|
|
/* plain, simple mouse sensor */
|
|
|
|
gamesensor = new SCA_MouseSensor(eventmgr,
|
|
|
|
startx,starty,
|
|
|
|
keytype,
|
|
|
|
gameobj);
|
|
|
|
} else {
|
|
|
|
/* give us a focus-aware sensor */
|
|
|
|
gamesensor = new KX_MouseFocusSensor(eventmgr,
|
|
|
|
startx,
|
|
|
|
starty,
|
|
|
|
keytype,
|
|
|
|
trackfocus,
|
2009-08-23 06:17:59 +00:00
|
|
|
(bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
|
2002-10-12 11:37:38 +00:00
|
|
|
kxscene,
|
2008-09-18 01:46:28 +00:00
|
|
|
kxengine,
|
2002-10-12 11:37:38 +00:00
|
|
|
gameobj);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// cout << "\n Could't find mouse event manager..."; - should throw an error here...
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_PROPERTY:
|
|
|
|
{
|
|
|
|
bPropertySensor* blenderpropsensor = (bPropertySensor*) sens->data;
|
|
|
|
SCA_EventManager* eventmgr
|
2009-09-24 21:22:24 +00:00
|
|
|
= logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String propname=blenderpropsensor->name;
|
|
|
|
STR_String propval=blenderpropsensor->value;
|
|
|
|
STR_String propmaxval=blenderpropsensor->maxvalue;
|
|
|
|
|
|
|
|
SCA_PropertySensor::KX_PROPSENSOR_TYPE
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NODEF;
|
|
|
|
|
|
|
|
/* Better do an explicit conversion here! (was implicit */
|
|
|
|
/* before...) */
|
|
|
|
switch(blenderpropsensor->type) {
|
|
|
|
case SENS_PROP_EQUAL:
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EQUAL;
|
|
|
|
break;
|
|
|
|
case SENS_PROP_NEQUAL:
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL;
|
|
|
|
break;
|
|
|
|
case SENS_PROP_INTERVAL:
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_INTERVAL;
|
|
|
|
break;
|
|
|
|
case SENS_PROP_CHANGED:
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_CHANGED;
|
|
|
|
break;
|
|
|
|
case SENS_PROP_EXPRESSION:
|
|
|
|
propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION;
|
|
|
|
/* error */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
; /* error */
|
|
|
|
}
|
|
|
|
gamesensor = new SCA_PropertySensor(eventmgr,gameobj,propname,propval,propmaxval,propchecktype);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
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
|
|
|
case SENS_ACTUATOR:
|
|
|
|
{
|
|
|
|
bActuatorSensor* blenderactsensor = (bActuatorSensor*) sens->data;
|
|
|
|
// we will reuse the property event manager, there is nothing special with this sensor
|
|
|
|
SCA_EventManager* eventmgr
|
|
|
|
= logicmgr->FindEventManager(SCA_EventManager::ACTUATOR_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String propname=blenderactsensor->name;
|
|
|
|
gamesensor = new SCA_ActuatorSensor(eventmgr,gameobj,propname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-09-24 21:22:24 +00:00
|
|
|
case SENS_ARMATURE:
|
|
|
|
{
|
|
|
|
bArmatureSensor* blenderarmsensor = (bArmatureSensor*) sens->data;
|
|
|
|
// we will reuse the property event manager, there is nothing special with this sensor
|
|
|
|
SCA_EventManager* eventmgr
|
|
|
|
= logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String bonename=blenderarmsensor->posechannel;
|
|
|
|
STR_String constraintname=blenderarmsensor->constraint;
|
|
|
|
gamesensor = new KX_ArmatureSensor(eventmgr,gameobj,bonename,constraintname, blenderarmsensor->type, blenderarmsensor->value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
case SENS_RADAR:
|
|
|
|
{
|
2004-03-22 22:02:18 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
STR_String radarpropertyname;
|
|
|
|
STR_String touchpropertyname;
|
|
|
|
bRadarSensor* blenderradarsensor = (bRadarSensor*) sens->data;
|
|
|
|
|
|
|
|
int radaraxis = blenderradarsensor->axis;
|
|
|
|
|
|
|
|
if (blenderradarsensor->name)
|
|
|
|
{
|
|
|
|
// only objects that own this property will be taken into account
|
|
|
|
radarpropertyname = (char*) blenderradarsensor->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
MT_Scalar coneheight = blenderradarsensor->range;
|
|
|
|
|
|
|
|
// janco: the angle was doubled, so should I divide the factor in 2
|
|
|
|
// or the blenderradarsensor->angle?
|
|
|
|
// nzc: the angle is the opening angle. We need to init with
|
|
|
|
// the axis-hull angle,so /2.0.
|
|
|
|
MT_Scalar factor = tan(MT_radians((blenderradarsensor->angle)/2.0));
|
|
|
|
//MT_Scalar coneradius = coneheight * (factor / 2);
|
|
|
|
MT_Scalar coneradius = coneheight * factor;
|
|
|
|
|
|
|
|
|
|
|
|
// this sumoObject is not deleted by a gameobj, so delete it ourself
|
|
|
|
// later (memleaks)!
|
|
|
|
MT_Scalar smallmargin = 0.0;
|
2005-01-23 01:36:29 +00:00
|
|
|
MT_Scalar largemargin = 0.0;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bool bFindMaterial = false;
|
2011-04-10 09:37:04 +00:00
|
|
|
PHY_IPhysicsController* ctrl = kxscene->GetPhysicsEnvironment()->CreateConeController((float)coneradius, (float)coneheight);
|
2005-03-25 10:33:39 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
gamesensor = new KX_RadarSensor(
|
|
|
|
eventmgr,
|
|
|
|
gameobj,
|
2005-03-25 10:33:39 +00:00
|
|
|
ctrl,
|
2002-10-12 11:37:38 +00:00
|
|
|
coneradius,
|
|
|
|
coneheight,
|
|
|
|
radaraxis,
|
|
|
|
smallmargin,
|
|
|
|
largemargin,
|
|
|
|
bFindMaterial,
|
2009-07-31 09:05:13 +00:00
|
|
|
radarpropertyname);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
2004-03-22 22:02:18 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_RAY:
|
|
|
|
{
|
|
|
|
bRaySensor* blenderraysensor = (bRaySensor*) sens->data;
|
|
|
|
|
|
|
|
//blenderradarsensor->angle;
|
2009-09-24 21:22:24 +00:00
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
bool bFindMaterial = (blenderraysensor->mode & SENS_COLLISION_MATERIAL);
|
2008-08-28 19:37:49 +00:00
|
|
|
bool bXRay = (blenderraysensor->mode & SENS_RAY_XRAY);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
STR_String checkname = (bFindMaterial? blenderraysensor->matname : blenderraysensor->propname);
|
|
|
|
|
|
|
|
// don't want to get rays of length 0.0 or so
|
|
|
|
double distance = (blenderraysensor->range < 0.01 ? 0.01 : blenderraysensor->range );
|
|
|
|
int axis = blenderraysensor->axisflag;
|
|
|
|
|
|
|
|
|
2004-03-22 22:02:18 +00:00
|
|
|
gamesensor = new KX_RaySensor(eventmgr,
|
2002-10-12 11:37:38 +00:00
|
|
|
gameobj,
|
|
|
|
checkname,
|
|
|
|
bFindMaterial,
|
2008-08-28 19:37:49 +00:00
|
|
|
bXRay,
|
2002-10-12 11:37:38 +00:00
|
|
|
distance,
|
|
|
|
axis,
|
2004-03-22 22:02:18 +00:00
|
|
|
kxscene);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SENS_RANDOM:
|
|
|
|
{
|
|
|
|
bRandomSensor* blenderrndsensor = (bRandomSensor*) sens->data;
|
|
|
|
// some files didn't write randomsensor, avoid crash now for NULL ptr's
|
|
|
|
if (blenderrndsensor)
|
|
|
|
{
|
2009-09-24 21:22:24 +00:00
|
|
|
SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
|
2002-10-12 11:37:38 +00:00
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
int randomSeed = blenderrndsensor->seed;
|
2009-06-08 20:08:19 +00:00
|
|
|
if (randomSeed == 0)
|
|
|
|
{
|
|
|
|
randomSeed = (int)(kxengine->GetRealTime()*100000.0);
|
|
|
|
randomSeed ^= (intptr_t)blenderrndsensor;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
gamesensor = new SCA_RandomSensor(eventmgr, gameobj, randomSeed);
|
|
|
|
}
|
|
|
|
}
|
2005-01-23 01:36:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case SENS_JOYSTICK:
|
|
|
|
{
|
|
|
|
int joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_NODEF;
|
|
|
|
|
|
|
|
bJoystickSensor* bjoy = (bJoystickSensor*) sens->data;
|
|
|
|
|
|
|
|
SCA_JoystickManager *eventmgr
|
|
|
|
= (SCA_JoystickManager*) logicmgr->FindEventManager(SCA_EventManager::JOY_EVENTMGR);
|
|
|
|
if (eventmgr)
|
|
|
|
{
|
|
|
|
int axis =0;
|
|
|
|
int axisf =0;
|
|
|
|
int button =0;
|
|
|
|
int hat =0;
|
|
|
|
int hatf =0;
|
|
|
|
int prec =0;
|
|
|
|
|
|
|
|
switch(bjoy->type)
|
|
|
|
{
|
|
|
|
case SENS_JOY_AXIS:
|
|
|
|
axis = bjoy->axis;
|
|
|
|
axisf = bjoy->axisf;
|
|
|
|
prec = bjoy->precision;
|
|
|
|
joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS;
|
|
|
|
break;
|
|
|
|
case SENS_JOY_BUTTON:
|
|
|
|
button = bjoy->button;
|
|
|
|
joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_BUTTON;
|
|
|
|
break;
|
|
|
|
case SENS_JOY_HAT:
|
|
|
|
hat = bjoy->hat;
|
|
|
|
hatf = bjoy->hatf;
|
|
|
|
joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT;
|
|
|
|
break;
|
2009-04-20 15:06:46 +00:00
|
|
|
case SENS_JOY_AXIS_SINGLE:
|
|
|
|
axis = bjoy->axis_single;
|
|
|
|
prec = bjoy->precision;
|
|
|
|
joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS_SINGLE;
|
|
|
|
break;
|
2005-01-23 01:36:29 +00:00
|
|
|
default:
|
|
|
|
printf("Error: bad case statement\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gamesensor = new SCA_JoystickSensor(
|
|
|
|
eventmgr,
|
|
|
|
gameobj,
|
2008-08-31 18:42:58 +00:00
|
|
|
bjoy->joyindex,
|
2005-01-23 01:36:29 +00:00
|
|
|
joysticktype,
|
|
|
|
axis,axisf,
|
|
|
|
prec,
|
2008-10-07 05:09:24 +00:00
|
|
|
button,
|
|
|
|
hat,hatf,
|
|
|
|
(bjoy->flag & SENS_JOY_ANY_EVENT));
|
2005-01-23 01:36:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("Error there was a problem finding the event manager\n");
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gamesensor)
|
|
|
|
{
|
|
|
|
gamesensor->SetExecutePriority(executePriority++);
|
|
|
|
STR_String uniquename = sens->name;
|
|
|
|
uniquename += "#SENS#";
|
|
|
|
uniqueint++;
|
|
|
|
CIntValue* uniqueval = new CIntValue(uniqueint);
|
|
|
|
uniquename += uniqueval->GetText();
|
|
|
|
uniqueval->Release();
|
|
|
|
|
|
|
|
/* Conversion succeeded, so we can set the generic props here. */
|
|
|
|
gamesensor->SetPulseMode(pos_pulsemode,
|
|
|
|
neg_pulsemode,
|
|
|
|
frequency);
|
|
|
|
gamesensor->SetInvert(invert);
|
2008-06-23 20:26:48 +00:00
|
|
|
gamesensor->SetLevel(level);
|
2009-06-08 20:08:19 +00:00
|
|
|
gamesensor->SetTap(tap);
|
|
|
|
gamesensor->SetName(sens->name);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
gameobj->AddSensor(gamesensor);
|
|
|
|
|
|
|
|
// only register to manager if it's in an active layer
|
2008-07-30 17:41:47 +00:00
|
|
|
// Make registration dynamic: only when sensor is activated
|
|
|
|
//if (isInActiveLayer)
|
|
|
|
// gamesensor->RegisterToManager();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
gamesensor->ReserveController(sens->totlinks);
|
2002-10-12 11:37:38 +00:00
|
|
|
for (int i=0;i<sens->totlinks;i++)
|
|
|
|
{
|
|
|
|
bController* linkedcont = (bController*) sens->links[i];
|
2008-08-16 12:42:34 +00:00
|
|
|
if (linkedcont) {
|
|
|
|
SCA_IController* gamecont = converter->FindGameController(linkedcont);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-08-16 12:42:34 +00:00
|
|
|
if (gamecont) {
|
|
|
|
logicmgr->RegisterToSensor(gamecont,gamesensor);
|
|
|
|
} else {
|
|
|
|
printf(
|
2008-08-27 01:03:55 +00:00
|
|
|
"Warning, sensor \"%s\" could not find its controller "
|
|
|
|
"(link %d of %d) from object \"%s\"\n"
|
2008-08-16 12:42:34 +00:00
|
|
|
"\tthere has been an error converting the blender controller for the game engine,"
|
2008-08-27 01:03:55 +00:00
|
|
|
"logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
|
2008-08-16 12:42:34 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
printf(
|
2008-08-27 01:03:55 +00:00
|
|
|
"Warning, sensor \"%s\" has lost a link to a controller "
|
|
|
|
"(link %d of %d) from object \"%s\"\n"
|
2008-08-16 12:42:34 +00:00
|
|
|
"\tpossible causes are partially appended objects or an error reading the file,"
|
2008-08-27 01:03:55 +00:00
|
|
|
"logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-07 19:58:37 +00:00
|
|
|
// special case: Keyboard sensor with no link
|
|
|
|
// this combination is usually used for key logging.
|
|
|
|
if (sens->type == SENS_KEYBOARD && sens->totlinks == 0) {
|
|
|
|
// Force the registration so that the sensor runs
|
|
|
|
gamesensor->IncLink();
|
|
|
|
}
|
|
|
|
|
2008-03-01 19:46:50 +00:00
|
|
|
// done with gamesensor
|
|
|
|
gamesensor->Release();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
sens=sens->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|