blender/source/gameengine/Converter/KX_ConvertActuators.cpp

1185 lines
34 KiB
C++
Raw Normal View History

2002-10-12 11:37:38 +00:00
/**
* $Id$
*
* ***** 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
* 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,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 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.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
* Convert Blender actuators for use in the GameEngine
*/
#ifdef WIN32
#pragma warning (disable : 4786)
#endif //WIN32
#define BLENDER_HACK_DTIME 0.02
#include "MEM_guardedalloc.h"
2002-10-12 11:37:38 +00:00
#include "KX_BlenderSceneConverter.h"
#include "KX_ConvertActuators.h"
#include "SND_Scene.h"
2002-10-12 11:37:38 +00:00
// Actuators
//SCA logiclibrary native logicbricks
#include "SCA_PropertyActuator.h"
#include "SCA_LogicManager.h"
#include "SCA_RandomActuator.h"
2007-10-22 20:24:26 +00:00
#include "SCA_2DFilterActuator.h"
2002-10-12 11:37:38 +00:00
// Ketsji specific logicbricks
#include "KX_SceneActuator.h"
#include "KX_IpoActuator.h"
#include "KX_SoundActuator.h"
#include "KX_CDActuator.h"
#include "KX_ObjectActuator.h"
#include "KX_TrackToActuator.h"
#include "KX_ConstraintActuator.h"
#include "KX_CameraActuator.h"
#include "KX_GameActuator.h"
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
#include "KX_StateActuator.h"
2002-10-12 11:37:38 +00:00
#include "KX_VisibilityActuator.h"
#include "KX_SCA_AddObjectActuator.h"
#include "KX_SCA_EndObjectActuator.h"
#include "KX_SCA_ReplaceMeshActuator.h"
#include "KX_ParentActuator.h"
#include "KX_SCA_DynamicActuator.h"
2002-10-12 11:37:38 +00:00
#include "KX_Scene.h"
#include "KX_KetsjiEngine.h"
#include "IntValue.h"
#include "KX_GameObject.h"
/* This little block needed for linking to Blender... */
#include "BKE_text.h"
2002-10-12 11:37:38 +00:00
#include "BLI_blenlib.h"
#define FILE_MAX 240 // repeated here to avoid dependency from BKE_utildefines.h
2002-10-12 11:37:38 +00:00
#include "KX_NetworkMessageActuator.h"
#ifdef WIN32
#include "BLI_winstuff.h"
#endif
#include "DNA_object_types.h"
#include "DNA_sound_types.h"
#include "DNA_scene_types.h"
#include "DNA_actuator_types.h"
#include "DNA_packedFile_types.h"
#include "BL_ActionActuator.h"
#include "BL_ShapeActionActuator.h"
2002-10-12 11:37:38 +00:00
/* end of blender include block */
#include "BL_BlenderDataConversion.h"
/**
KX_BLENDERTRUNC needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set
*/
#define KX_BLENDERTRUNC(x) (( x < 0.0001 && x > -0.0001 ) ? 0.0 : x)
void BL_ConvertActuators(char* maggiename,
struct Object* blenderobject,
KX_GameObject* gameobj,
SCA_LogicManager* logicmgr,
KX_Scene* scene,
KX_KetsjiEngine* ketsjiEngine,
int activeLayerBitInfo,
bool isInActiveLayer,
RAS_IRenderTools* rendertools,
KX_BlenderSceneConverter* converter
)
{
int uniqueint = 0;
BGE performance, 4th round: logic This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
int actcount = 0;
int executePriority = 0;
2002-10-12 11:37:38 +00:00
bActuator* bact = (bActuator*) blenderobject->actuators.first;
BGE performance, 4th round: logic This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
while (bact)
{
actcount++;
bact = bact->next;
}
gameobj->ReserveActuator(actcount);
bact = (bActuator*) blenderobject->actuators.first;
2002-10-12 11:37:38 +00:00
while(bact)
{
STR_String uniquename = bact->name;
BGE performance, 4th round: logic This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
STR_String& objectname = gameobj->GetName();
2002-10-12 11:37:38 +00:00
SCA_IActuator* baseact = NULL;
switch (bact->type)
{
case ACT_OBJECT:
{
bObjectActuator* obact = (bObjectActuator*) bact->data;
KX_GameObject* obref = NULL;
2002-10-12 11:37:38 +00:00
MT_Vector3 forcevec(KX_BLENDERTRUNC(obact->forceloc[0]),
KX_BLENDERTRUNC(obact->forceloc[1]),
KX_BLENDERTRUNC(obact->forceloc[2]));
MT_Vector3 torquevec(obact->forcerot[0],obact->forcerot[1],obact->forcerot[2]);
MT_Vector3 dlocvec ( KX_BLENDERTRUNC(obact->dloc[0]),
KX_BLENDERTRUNC(obact->dloc[1]),
KX_BLENDERTRUNC(obact->dloc[2]));
MT_Vector3 drotvec ( KX_BLENDERTRUNC(obact->drot[0]),obact->drot[1],obact->drot[2]);
MT_Vector3 linvelvec ( KX_BLENDERTRUNC(obact->linearvelocity[0]),
KX_BLENDERTRUNC(obact->linearvelocity[1]),
KX_BLENDERTRUNC(obact->linearvelocity[2]));
MT_Vector3 angvelvec ( KX_BLENDERTRUNC(obact->angularvelocity[0]),
KX_BLENDERTRUNC(obact->angularvelocity[1]),
KX_BLENDERTRUNC(obact->angularvelocity[2]));
short damping = obact->damping;
2002-10-12 11:37:38 +00:00
drotvec /= BLENDER_HACK_DTIME;
//drotvec /= BLENDER_HACK_DTIME;
drotvec *= MT_2_PI/360.0;
//dlocvec /= BLENDER_HACK_DTIME;
//linvelvec /= BLENDER_HACK_DTIME;
//angvelvec /= BLENDER_HACK_DTIME;
/* Blender uses a bit vector internally for the local-flags. In */
/* KX, we have four bools. The compiler should be smart enough */
/* to do the right thing. We need to explicitly convert here! */
KX_LocalFlags bitLocalFlag;
bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
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
bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
2002-10-12 11:37:38 +00:00
bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
if (obact->reference && bitLocalFlag.ServoControl)
{
obref = converter->FindGameObject(obact->reference);
}
2002-10-12 11:37:38 +00:00
KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(gameobj,
obref,
2002-10-12 11:37:38 +00:00
forcevec.getValue(),
torquevec.getValue(),
dlocvec.getValue(),
drotvec.getValue(),
linvelvec.getValue(),
angvelvec.getValue(),
damping,
2002-10-12 11:37:38 +00:00
bitLocalFlag
);
baseact = tmpbaseact;
break;
}
case ACT_ACTION:
{
if (blenderobject->type==OB_ARMATURE){
bActionActuator* actact = (bActionActuator*) bact->data;
STR_String propname = (actact->name ? actact->name : "");
STR_String propframe = (actact->frameProp ? actact->frameProp : "");
2002-10-12 11:37:38 +00:00
BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
gameobj,
propname,
propframe,
2002-10-12 11:37:38 +00:00
actact->sta,
actact->end,
actact->act,
actact->type, // + 1, because Blender starts to count at zero,
actact->blendin,
actact->priority,
actact->end_reset,
2002-10-12 11:37:38 +00:00
actact->stridelength
// Ketsji at 1, because zero is reserved for "NoDef"
);
baseact= tmpbaseact;
break;
}
else
printf ("Discarded action actuator from non-armature object [%s]\n", blenderobject->id.name+2);
}
case ACT_SHAPEACTION:
{
if (blenderobject->type==OB_MESH){
bActionActuator* actact = (bActionActuator*) bact->data;
STR_String propname = (actact->name ? actact->name : "");
STR_String propframe = (actact->frameProp ? actact->frameProp : "");
BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
gameobj,
propname,
propframe,
actact->sta,
actact->end,
actact->act,
actact->type, // + 1, because Blender starts to count at zero,
actact->blendin,
actact->priority,
actact->stridelength
// Ketsji at 1, because zero is reserved for "NoDef"
);
baseact= tmpbaseact;
break;
}
else
printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
}
2002-10-12 11:37:38 +00:00
case ACT_IPO:
{
bIpoActuator* ipoact = (bIpoActuator*) bact->data;
bool ipochild = (ipoact->flag & ACT_IPOCHILD) !=0;
STR_String propname = ipoact->name;
STR_String frameProp = ipoact->frameProp;
2002-10-12 11:37:38 +00:00
// first bit?
bool ipo_as_force = (ipoact->flag & ACT_IPOFORCE);
BGE logic patch: new "Add" mode for Ipo actuator, several corrections in state system. New Add mode for Ipo actuator ============================= A new Add button, mutually exclusive with Force button, is available in the Ipo actuator. When selected, it activates the Add mode that consists in adding the Ipo curve to the current object situation in world coordinates, or parent coordinates if the object has a parent. Scale Ipo curves are multiplied instead of added to the object current scale. If the local flag is selected, the Ipo curve is added (multiplied) in the object's local coordinates. Delta Ipo curves are handled identically to normal Ipo curve and there is no need to work with Delta Ipo curves provided that you make sure that the Ipo curve starts from origin. Origin means location 0 for Location Ipo curve, rotation 0 for Rotation Ipo curve and scale 1 for Scale Ipo curve. The "current object situation" means the object's location, rotation and scale at the start of the Ipo curve. For Loop Stop and Loop End Ipo actuators, this means at the start of each loop. This initial state is used as a base during the execution of the Ipo Curve but when the Ipo curve is restarted (later or immediately in case of Loop mode), the object current situation at that time is used as the new base. For reference, here is the exact operation of the Add mode for each type of Ipo curve (oLoc, oRot, oScale, oMat: object's loc/rot/scale and orientation matrix at the start of the curve; iLoc, iRot, iScale, iMat: Ipo curve loc/rot/scale and orientation matrix resulting from the rotation). Location Local=false: newLoc = oLoc+iLoc Local=true : newLoc = oLoc+oScale*(oMat*iLoc) Rotation Local=false: newMat = iMat*oMat Local=true : newMat = oMat*iMat Scale Local=false: newScale = oScale*iScale Local=true : newScale = oScale*iScale Add+Local mode is very useful to have dynamic object executing complex movement relative to their current location/orientation. Of cource, dynamics should be disabled during the execution of the curve. Several corrections in state system =================================== - Object initial state is taken into account when adding object dynamically - Fix bug with link count when adding object dynamically - Fix false on-off detection for Actuator sensor when actuator is trigged on negative event. - Fix Parent actuator false activation on negative event - Loop Ipo curve not restarting at correct frame when start frame is different from one.
2008-07-08 12:18:43 +00:00
bool local = (ipoact->flag & ACT_IPOLOCAL);
bool ipo_add = (ipoact->flag & ACT_IPOADD);
2002-10-12 11:37:38 +00:00
KX_IpoActuator* tmpbaseact = new KX_IpoActuator(
gameobj,
propname ,
frameProp,
2002-10-12 11:37:38 +00:00
ipoact->sta,
ipoact->end,
ipochild,
ipoact->type + 1, // + 1, because Blender starts to count at zero,
// Ketsji at 1, because zero is reserved for "NoDef"
ipo_as_force,
BGE logic patch: new "Add" mode for Ipo actuator, several corrections in state system. New Add mode for Ipo actuator ============================= A new Add button, mutually exclusive with Force button, is available in the Ipo actuator. When selected, it activates the Add mode that consists in adding the Ipo curve to the current object situation in world coordinates, or parent coordinates if the object has a parent. Scale Ipo curves are multiplied instead of added to the object current scale. If the local flag is selected, the Ipo curve is added (multiplied) in the object's local coordinates. Delta Ipo curves are handled identically to normal Ipo curve and there is no need to work with Delta Ipo curves provided that you make sure that the Ipo curve starts from origin. Origin means location 0 for Location Ipo curve, rotation 0 for Rotation Ipo curve and scale 1 for Scale Ipo curve. The "current object situation" means the object's location, rotation and scale at the start of the Ipo curve. For Loop Stop and Loop End Ipo actuators, this means at the start of each loop. This initial state is used as a base during the execution of the Ipo Curve but when the Ipo curve is restarted (later or immediately in case of Loop mode), the object current situation at that time is used as the new base. For reference, here is the exact operation of the Add mode for each type of Ipo curve (oLoc, oRot, oScale, oMat: object's loc/rot/scale and orientation matrix at the start of the curve; iLoc, iRot, iScale, iMat: Ipo curve loc/rot/scale and orientation matrix resulting from the rotation). Location Local=false: newLoc = oLoc+iLoc Local=true : newLoc = oLoc+oScale*(oMat*iLoc) Rotation Local=false: newMat = iMat*oMat Local=true : newMat = oMat*iMat Scale Local=false: newScale = oScale*iScale Local=true : newScale = oScale*iScale Add+Local mode is very useful to have dynamic object executing complex movement relative to their current location/orientation. Of cource, dynamics should be disabled during the execution of the curve. Several corrections in state system =================================== - Object initial state is taken into account when adding object dynamically - Fix bug with link count when adding object dynamically - Fix false on-off detection for Actuator sensor when actuator is trigged on negative event. - Fix Parent actuator false activation on negative event - Loop Ipo curve not restarting at correct frame when start frame is different from one.
2008-07-08 12:18:43 +00:00
ipo_add,
local);
2002-10-12 11:37:38 +00:00
baseact = tmpbaseact;
break;
}
case ACT_LAMP:
{
break;
}
case ACT_CAMERA:
{
bCameraActuator *camact = (bCameraActuator *) bact->data;
if (camact->ob) {
KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
/* visifac, fac and axis are not copied from the struct... */
/* that's some internal state... */
KX_CameraActuator *tmpcamact
= new KX_CameraActuator(gameobj,
tmpgob,
camact->height,
camact->min,
camact->max,
camact->axis=='x');
baseact = tmpcamact;
}
break;
}
case ACT_MESSAGE:
{
bMessageActuator *msgAct = (bMessageActuator *) bact->data;
/**
* Get the name of the properties that objects must own that
* we're sending to, if present
*/
STR_String toPropName = (msgAct->toPropName
? (char*) msgAct->toPropName
: "");
/* BGE Wants "OB" prefix */
if (toPropName != "")
toPropName = "OB" + toPropName;
/**
* Get the Message Subject to send.
2002-10-12 11:37:38 +00:00
*/
STR_String subject = (msgAct->subject
? (char*) msgAct->subject
: "");
/**
* Get the bodyType
2002-10-12 11:37:38 +00:00
*/
int bodyType = msgAct->bodyType;
/**
* Get the body (text message or property name whose value
* we'll be sending, might be empty
*/
STR_String body = (msgAct->body
? (char*) msgAct->body
: "");
KX_NetworkMessageActuator *tmpmsgact =
new KX_NetworkMessageActuator(
gameobj, // actuator controlling object
scene->GetNetworkScene(), // needed for replication
toPropName,
subject,
bodyType,
body);
baseact = tmpmsgact;
break;
}
case ACT_MATERIAL:
{
break;
}
case ACT_SOUND:
{
bSoundActuator* soundact = (bSoundActuator*) bact->data;
/* get type, and possibly a start and end frame */
short startFrame = soundact->sta, stopFrame = soundact->end;
KX_SoundActuator::KX_SOUNDACT_TYPE
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
switch(soundact->type) {
case ACT_SND_PLAY_STOP_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
break;
case ACT_SND_PLAY_END_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
break;
case ACT_SND_LOOP_STOP_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
break;
case ACT_SND_LOOP_END_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
break;
case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
break;
case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
break;
default:
/* This is an error!!! */
soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
}
if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF)
{
SND_Scene* soundscene = scene->GetSoundScene();
STR_String samplename = "";
bool sampleisloaded = false;
2002-10-12 11:37:38 +00:00
if (soundact->sound) {
/* Need to convert the samplename into absolute path
* before checking if its loaded */
char fullpath[FILE_MAX];
2002-10-12 11:37:38 +00:00
/* dont modify soundact->sound->name, only change a copy */
BLI_strncpy(fullpath, soundact->sound->name, sizeof(fullpath));
BLI_convertstringcode(fullpath, maggiename);
samplename = fullpath;
2002-10-12 11:37:38 +00:00
/* let's see if the sample was already loaded */
if (soundscene->IsSampleLoaded(samplename))
{
sampleisloaded = true;
}
else {
2002-10-12 11:37:38 +00:00
/* if not, make it so */
PackedFile* pf = soundact->sound->newpackedfile;
/* but we need a packed file then */
if (pf)
{
if (soundscene->LoadSample(samplename, pf->data, pf->size) > -1)
sampleisloaded = true;
}
/* or else load it from disk */
else
{
if (soundscene->LoadSample(samplename, NULL, 0) > -1) {
2002-10-12 11:37:38 +00:00
sampleisloaded = true;
}
else {
std::cout << "WARNING: Sound actuator \"" << bact->name <<
"\" from object \"" << blenderobject->id.name+2 <<
"\" failed to load sample." << std::endl;
}
2002-10-12 11:37:38 +00:00
}
}
} else {
std::cout << "WARNING: Sound actuator \"" << bact->name <<
"\" from object \"" << blenderobject->id.name+2 <<
"\" has no sound datablock." << std::endl;
}
/* Note, allowing actuators for sounds that are not there was added since 2.47
* This is because python may expect the actuator and raise an exception if it dosnt find it
* better just to add a dummy sound actuator. */
SND_SoundObject* sndobj = NULL;
if (sampleisloaded)
{
/* setup the SND_SoundObject */
sndobj = new SND_SoundObject();
sndobj->SetSampleName(samplename.Ptr());
sndobj->SetObjectName(bact->name);
if (soundact->sound) {
sndobj->SetRollOffFactor(soundact->sound->attenuation);
sndobj->SetGain(soundact->sound->volume);
sndobj->SetPitch(exp((soundact->sound->pitch / 12.0) * log(2.0)));
// sndobj->SetLoopStart(soundact->sound->loopstart);
// sndobj->SetLoopStart(soundact->sound->loopend);
if (soundact->sound->flags & SOUND_FLAGS_LOOP)
{
if (soundact->sound->flags & SOUND_FLAGS_BIDIRECTIONAL_LOOP)
sndobj->SetLoopMode(SND_LOOP_BIDIRECTIONAL);
else
sndobj->SetLoopMode(SND_LOOP_NORMAL);
}
else {
sndobj->SetLoopMode(SND_LOOP_OFF);
}
if (soundact->sound->flags & SOUND_FLAGS_PRIORITY)
sndobj->SetHighPriority(true);
2002-10-12 11:37:38 +00:00
else
sndobj->SetHighPriority(false);
if (soundact->sound->flags & SOUND_FLAGS_3D)
sndobj->Set3D(true);
else
sndobj->Set3D(false);
2002-10-12 11:37:38 +00:00
}
else {
/* dummy values for a NULL sound
* see editsound.c - defaults are unlikely to change soon */
sndobj->SetRollOffFactor(1.0);
sndobj->SetGain(1.0);
sndobj->SetPitch(1.0);
sndobj->SetLoopMode(SND_LOOP_OFF);
sndobj->SetHighPriority(false);
sndobj->Set3D(false);
}
}
KX_SoundActuator* tmpsoundact =
new KX_SoundActuator(gameobj,
sndobj,
scene->GetSoundScene(), // needed for replication!
soundActuatorType,
startFrame,
stopFrame);
tmpsoundact->SetName(bact->name);
baseact = tmpsoundact;
if (sndobj)
soundscene->AddObject(sndobj);
2002-10-12 11:37:38 +00:00
}
break;
}
case ACT_CD:
{
bCDActuator* cdact = (bCDActuator*) bact->data;
/* get type, and possibly a start and end frame */
short startFrame = cdact->sta, stopFrame = cdact->end;
KX_CDActuator::KX_CDACT_TYPE
cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
switch(cdact->type)
{
case ACT_CD_PLAY_ALL:
cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_ALL;
break;
case ACT_CD_PLAY_TRACK:
cdActuatorType = KX_CDActuator::KX_CDACT_PLAY_TRACK;
break;
case ACT_CD_LOOP_TRACK:
cdActuatorType = KX_CDActuator::KX_CDACT_LOOP_TRACK;
break;
case ACT_CD_VOLUME:
cdActuatorType = KX_CDActuator::KX_CDACT_VOLUME;
break;
case ACT_CD_STOP:
cdActuatorType = KX_CDActuator::KX_CDACT_STOP;
break;
case ACT_CD_PAUSE:
cdActuatorType = KX_CDActuator::KX_CDACT_PAUSE;
break;
case ACT_CD_RESUME:
cdActuatorType = KX_CDActuator::KX_CDACT_RESUME;
break;
default:
/* This is an error!!! */
cdActuatorType = KX_CDActuator::KX_CDACT_NODEF;
}
if (cdActuatorType != KX_CDActuator::KX_CDACT_NODEF)
{
SND_CDObject* pCD = SND_CDObject::Instance();
if (pCD)
{
pCD->SetGain(cdact->volume);
KX_CDActuator* tmpcdact =
new KX_CDActuator(gameobj,
scene->GetSoundScene(), // needed for replication!
cdActuatorType,
cdact->track,
startFrame,
stopFrame);
tmpcdact->SetName(bact->name);
baseact = tmpcdact;
}
}
break;
}
case ACT_PROPERTY:
{
bPropertyActuator* propact = (bPropertyActuator*) bact->data;
SCA_IObject* destinationObj = NULL;
2002-10-12 11:37:38 +00:00
/*
here the destinationobject is searched. problem with multiple scenes: other scenes
have not been converted yet, so the destobj will not be found, so the prop will
not be copied.
possible solutions:
- convert everything when possible and not realtime only when needed.
- let the object-with-property report itself to the act when converted
*/
if (propact->ob)
destinationObj = converter->FindGameObject(propact->ob);
2002-10-12 11:37:38 +00:00
SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
gameobj,
destinationObj,
propact->name,
propact->value,
propact->type+1); // + 1 because Ketsji Logic starts
// with 0 for KX_ACT_PROP_NODEF
baseact = tmppropact;
break;
}
case ACT_EDIT_OBJECT:
{
bEditObjectActuator *editobact
= (bEditObjectActuator *) bact->data;
/* There are four different kinds of 'edit object' thingies */
/* The alternative to this lengthy conversion is packing */
/* several actuators in one, which is not very nice design.. */
switch (editobact->type) {
case ACT_EDOB_ADD_OBJECT:
{
// does the 'original' for replication exists, and
// is it in a non-active layer ?
SCA_IObject* originalval = NULL;
if (editobact->ob)
{
if (editobact->ob->lay & activeLayerBitInfo)
{
fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
}
else {
originalval = converter->FindGameObject(editobact->ob);
}
}
KX_SCA_AddObjectActuator* tmpaddact =
new KX_SCA_AddObjectActuator(
gameobj,
originalval,
editobact->time,
scene,
editobact->linVelocity,
(editobact->localflag & ACT_EDOB_LOCAL_LINV)!=0,
editobact->angVelocity,
(editobact->localflag & ACT_EDOB_LOCAL_ANGV)!=0
);
2002-10-12 11:37:38 +00:00
//editobact->ob to gameobj
baseact = tmpaddact;
}
break;
case ACT_EDOB_END_OBJECT:
{
KX_SCA_EndObjectActuator* tmpendact
= new KX_SCA_EndObjectActuator(gameobj,scene);
baseact = tmpendact;
}
break;
case ACT_EDOB_REPLACE_MESH:
{
RAS_MeshObject *tmpmesh = NULL;
2002-10-12 11:37:38 +00:00
if (editobact->me)
tmpmesh = BL_ConvertMesh(
2002-10-12 11:37:38 +00:00
editobact->me,
blenderobject,
rendertools,
scene,
converter
);
KX_SCA_ReplaceMeshActuator* tmpreplaceact
= new KX_SCA_ReplaceMeshActuator(
2002-10-12 11:37:38 +00:00
gameobj,
tmpmesh,
scene
);
baseact = tmpreplaceact;
}
break;
case ACT_EDOB_TRACK_TO:
{
SCA_IObject* originalval = NULL;
2002-10-12 11:37:38 +00:00
if (editobact->ob)
originalval = converter->FindGameObject(editobact->ob);
2002-10-12 11:37:38 +00:00
KX_TrackToActuator* tmptrackact
= new KX_TrackToActuator(gameobj,
2002-10-12 11:37:38 +00:00
originalval,
editobact->time,
editobact->flag,
blenderobject->trackflag,
blenderobject->upflag
);
baseact = tmptrackact;
break;
}
case ACT_EDOB_DYNAMICS:
{
KX_SCA_DynamicActuator* tmpdynact
= new KX_SCA_DynamicActuator(gameobj,
editobact->dyn_operation,
editobact->mass
);
baseact = tmpdynact;
2002-10-12 11:37:38 +00:00
}
}
break;
}
case ACT_CONSTRAINT:
{
float min = 0.0, max = 0.0;
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
char *prop = NULL;
KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
2002-10-12 11:37:38 +00:00
bConstraintActuator *conact
= (bConstraintActuator*) bact->data;
/* convert settings... degrees in the ui become radians */
/* internally */
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 (conact->type == ACT_CONST_TYPE_ORI) {
min = (MT_2_PI * conact->minloc[0])/360.0;
max = (MT_2_PI * conact->maxloc[0])/360.0;
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
switch (conact->mode) {
case ACT_CONST_DIRPX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
break;
case ACT_CONST_DIRPY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
break;
case ACT_CONST_DIRPZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
break;
}
} else if (conact->type == ACT_CONST_TYPE_DIST) {
switch (conact->mode) {
case ACT_CONST_DIRPX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
min = conact->minloc[0];
max = conact->maxloc[0];
break;
case ACT_CONST_DIRPY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
min = conact->minloc[1];
max = conact->maxloc[1];
break;
case ACT_CONST_DIRPZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
min = conact->minloc[2];
max = conact->maxloc[2];
break;
case ACT_CONST_DIRNX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
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
min = conact->minloc[0];
max = conact->maxloc[0];
break;
case ACT_CONST_DIRNY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
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
min = conact->minloc[1];
max = conact->maxloc[1];
break;
case ACT_CONST_DIRNZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
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
min = conact->minloc[2];
max = conact->maxloc[2];
break;
}
prop = conact->matprop;
} else if (conact->type == ACT_CONST_TYPE_FH) {
switch (conact->mode) {
case ACT_CONST_DIRPX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
min = conact->minloc[0];
max = conact->maxloc[0];
break;
case ACT_CONST_DIRPY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
min = conact->minloc[1];
max = conact->maxloc[1];
break;
case ACT_CONST_DIRPZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
min = conact->minloc[2];
max = conact->maxloc[2];
break;
case ACT_CONST_DIRNX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
min = conact->minloc[0];
max = conact->maxloc[0];
break;
case ACT_CONST_DIRNY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
min = conact->minloc[1];
max = conact->maxloc[1];
break;
case ACT_CONST_DIRNZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
min = conact->minloc[2];
max = conact->maxloc[2];
break;
}
prop = conact->matprop;
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
} else {
switch (conact->flag) {
case ACT_CONST_LOCX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX;
min = conact->minloc[0];
max = conact->maxloc[0];
break;
case ACT_CONST_LOCY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY;
min = conact->minloc[1];
max = conact->maxloc[1];
break;
case ACT_CONST_LOCZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
min = conact->minloc[2];
max = conact->maxloc[2];
break;
case ACT_CONST_ROTX:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
min = MT_2_PI * conact->minrot[0] / 360.0;
max = MT_2_PI * conact->maxrot[0] / 360.0;
break;
case ACT_CONST_ROTY:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
min = MT_2_PI * conact->minrot[1] / 360.0;
max = MT_2_PI * conact->maxrot[1] / 360.0;
break;
case ACT_CONST_ROTZ:
locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
min = MT_2_PI * conact->minrot[2] / 360.0;
max = MT_2_PI * conact->maxrot[2] / 360.0;
break;
default:
; /* error */
}
2002-10-12 11:37:38 +00:00
}
KX_ConstraintActuator *tmpconact
= new KX_ConstraintActuator(gameobj,
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
conact->damp,
conact->rotdamp,
min,
max,
conact->maxrot,
locrot,
conact->time,
conact->flag,
prop);
2002-10-12 11:37:38 +00:00
baseact = tmpconact;
break;
}
case ACT_GROUP:
{
// deprecated
}
break;
case ACT_SCENE:
{
bSceneActuator *sceneact = (bSceneActuator *) bact->data;
STR_String nextSceneName("");
2002-10-12 11:37:38 +00:00
KX_SceneActuator* tmpsceneact;
int mode = KX_SceneActuator::KX_SCENE_NODEF;
KX_Camera *cam = NULL;
//KX_Scene* scene = NULL;
switch (sceneact->type)
{
case ACT_SCENE_RESUME:
case ACT_SCENE_SUSPEND:
case ACT_SCENE_ADD_FRONT:
case ACT_SCENE_ADD_BACK:
case ACT_SCENE_REMOVE:
case ACT_SCENE_SET:
{
switch (sceneact->type)
{
case ACT_SCENE_RESUME:
mode = KX_SceneActuator::KX_SCENE_RESUME;
break;
case ACT_SCENE_SUSPEND:
mode = KX_SceneActuator::KX_SCENE_SUSPEND;
break;
case ACT_SCENE_ADD_FRONT:
mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
break;
case ACT_SCENE_ADD_BACK:
mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
break;
case ACT_SCENE_REMOVE:
mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
break;
case ACT_SCENE_SET:
default:
mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
break;
};
if (sceneact->scene)
{
nextSceneName = sceneact->scene->id.name + 2; // this '2' is necessary to remove prefix 'SC'
}
break;
}
case ACT_SCENE_CAMERA:
mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
2002-10-12 11:37:38 +00:00
if (sceneact->camera)
{
cam = (KX_Camera*) converter->FindGameObject(sceneact->camera);
}
break;
case ACT_SCENE_RESTART:
{
mode = KX_SceneActuator::KX_SCENE_RESTART;
break;
}
default:
; /* flag error */
}
tmpsceneact = new KX_SceneActuator(gameobj,
2002-10-12 11:37:38 +00:00
mode,
scene,
ketsjiEngine,
nextSceneName,
cam);
baseact = tmpsceneact;
break;
}
case ACT_GAME:
{
bGameActuator *gameact = (bGameActuator *) bact->data;
KX_GameActuator* tmpgameact;
STR_String filename = maggiename;
STR_String loadinganimationname = "";
int mode = KX_GameActuator::KX_GAME_NODEF;
switch (gameact->type)
{
case ACT_GAME_LOAD:
{
mode = KX_GameActuator::KX_GAME_LOAD;
filename = gameact->filename;
loadinganimationname = gameact->loadaniname;
break;
}
case ACT_GAME_START:
{
mode = KX_GameActuator::KX_GAME_START;
filename = gameact->filename;
loadinganimationname = gameact->loadaniname;
break;
}
case ACT_GAME_RESTART:
{
mode = KX_GameActuator::KX_GAME_RESTART;
break;
}
case ACT_GAME_QUIT:
{
mode = KX_GameActuator::KX_GAME_QUIT;
break;
}
case ACT_GAME_SAVECFG:
{
mode = KX_GameActuator::KX_GAME_SAVECFG;
break;
}
case ACT_GAME_LOADCFG:
{
mode = KX_GameActuator::KX_GAME_LOADCFG;
break;
}
2002-10-12 11:37:38 +00:00
default:
; /* flag error */
}
tmpgameact = new KX_GameActuator(gameobj,
mode,
filename,
loadinganimationname,
scene,
ketsjiEngine);
baseact = tmpgameact;
break;
}
case ACT_RANDOM:
{
bRandomActuator *randAct
= (bRandomActuator *) bact->data;
unsigned long seedArg = randAct->seed;
if (seedArg == 0)
{
seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
seedArg ^= (intptr_t)randAct;
}
2002-10-12 11:37:38 +00:00
SCA_RandomActuator::KX_RANDOMACT_MODE modeArg
= SCA_RandomActuator::KX_RANDOMACT_NODEF;
SCA_RandomActuator *tmprandomact;
float paraArg1 = 0.0;
float paraArg2 = 0.0;
switch (randAct->distribution) {
case ACT_RANDOM_BOOL_CONST:
modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
paraArg1 = (float) randAct->int_arg_1;
break;
case ACT_RANDOM_BOOL_UNIFORM:
modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
break;
case ACT_RANDOM_BOOL_BERNOUILLI:
paraArg1 = randAct->float_arg_1;
modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
break;
case ACT_RANDOM_INT_CONST:
modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
paraArg1 = (float) randAct->int_arg_1;
break;
case ACT_RANDOM_INT_UNIFORM:
paraArg1 = (float) randAct->int_arg_1;
paraArg2 = (float) randAct->int_arg_2;
modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
break;
case ACT_RANDOM_INT_POISSON:
paraArg1 = randAct->float_arg_1;
modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
break;
case ACT_RANDOM_FLOAT_CONST:
paraArg1 = randAct->float_arg_1;
modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
break;
case ACT_RANDOM_FLOAT_UNIFORM:
paraArg1 = randAct->float_arg_1;
paraArg2 = randAct->float_arg_2;
modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
break;
case ACT_RANDOM_FLOAT_NORMAL:
paraArg1 = randAct->float_arg_1;
paraArg2 = randAct->float_arg_2;
modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
break;
case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
paraArg1 = randAct->float_arg_1;
modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
break;
default:
; /* error */
}
tmprandomact = new SCA_RandomActuator(gameobj,
seedArg,
modeArg,
paraArg1,
paraArg2,
randAct->propname);
baseact = tmprandomact;
}
break;
case ACT_VISIBILITY:
{
bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
KX_VisibilityActuator * tmp_vis_act = NULL;
bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
2002-10-12 11:37:38 +00:00
tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
2002-10-12 11:37:38 +00:00
baseact = tmp_vis_act;
}
break;
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
case ACT_STATE:
{
bStateActuator *sta_act = (bStateActuator *) bact->data;
KX_StateActuator * tmp_sta_act = NULL;
tmp_sta_act =
new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
baseact = tmp_sta_act;
}
break;
2007-10-22 20:24:26 +00:00
case ACT_2DFILTER:
{
bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
SCA_2DFilterActuator *tmp = NULL;
2002-10-12 11:37:38 +00:00
2007-10-22 20:24:26 +00:00
RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
switch(_2dfilter->type)
{
case ACT_2DFILTER_MOTIONBLUR:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
break;
case ACT_2DFILTER_BLUR:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
break;
case ACT_2DFILTER_SHARPEN:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
break;
case ACT_2DFILTER_DILATION:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
break;
case ACT_2DFILTER_EROSION:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
break;
case ACT_2DFILTER_LAPLACIAN:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
break;
case ACT_2DFILTER_SOBEL:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
break;
case ACT_2DFILTER_PREWITT:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
break;
case ACT_2DFILTER_GRAYSCALE:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
break;
case ACT_2DFILTER_SEPIA:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
break;
case ACT_2DFILTER_INVERT:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
break;
case ACT_2DFILTER_CUSTOMFILTER:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
break;
2007-10-22 20:24:26 +00:00
case ACT_2DFILTER_NOFILTER:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
break;
case ACT_2DFILTER_DISABLED:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
break;
case ACT_2DFILTER_ENABLED:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
break;
2007-10-22 20:24:26 +00:00
default:
filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
break;
}
tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
_2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools);
2007-10-22 20:24:26 +00:00
if (_2dfilter->text)
{
char *buf;
// this is some blender specific code
buf = txt_to_buf(_2dfilter->text);
if (buf)
{
2009-05-10 21:30:30 +00:00
tmp->SetShaderText(buf);
MEM_freeN(buf);
}
}
2007-10-22 20:24:26 +00:00
baseact = tmp;
}
break;
case ACT_PARENT:
{
bParentActuator *parAct = (bParentActuator *) bact->data;
int mode = KX_ParentActuator::KX_PARENT_NODEF;
BGE: user control to compound shape and setParent. Compound shape control ====================== 1) GUI control It is now possible to control which child shape is added to a parent compound shape in the Physics buttons. The "Compound" shape button becomes "Add to parent" on child objects and determines whether the child shape is to be added to the top parent compound shape when the game is stated. Notes: * "Compound" is only available to top parent objects (objects without parent). * Nesting of compound shape is not possible: a child object with "Add to parent" button set will be added to the top parent compound shape, regardless of its position in the parent-child hierarchy and even if its immediate parent doesn't have the "Add to parent" button set. 2) runtime control It is now possible to control the compound shape at runtime: The SetParent actuator has a new "Compound" button that indicates whether the object shape should be added to the compound shape of the parent object, provided the parent has a compound shape of course. If not, the object retain it's individual state while parented. Similarly, the KX_GameObject.setParent() python function has a new compound parameter. Notes: * When an object is dynamically added to a compound shape, it looses temporarily all its physics capability to the benefit of the parent: it cannot register collisions and the characteristics of its shape are lost (ghost, sensor, dynamic, etc.). * Nested compound shape is not supported: if the object being parented is already a compound shape, it is not added to the compound parent (as if the Compound option was not set in the actuator or the setParent function). * To ensure compatibility with old blend files, the Blender subversion is changed to 2.48.5 and the old blend files are automatically converted to match the old behavior: all children of a Compound object will have the "Add to parent" button set automatically. Child ghost control =================== It is now possible to control if an object should becomes ghost or solid when parented. This is only applicable if the object is not added to the parent compound shape (see above). A new "Ghost" button is available on the SetParent actuator to that effect. Similarly the KX_GameObject.setParent() python function has a new compound parameter. Notes: * This option is not applicable to sensor objects: they stay ghost all the time. * Make sure the child object does not enter in collision with the parent shape when the Ghost option if off and the parent is dynamic: the collision creates a reaction force but the parent cannot escape the child, so the force builds up and produces eratic movements. * The collision capability of an ordinary object (dynamic or static) is limited when it is parented: it becomes automatically static and can only detect dynamic and sensor objects. * A sensor object retain its full collision capability when parented: it can detect static and dynamic object. Python control ============== KX_GameObject.setParent(parent,compound,ghost): Sets this object's parent. Control the shape status with the optional compound and ghost parameters: compound=1: the object shape should be added to the parent compound shape (default) compound=0: the object should keep its individual shape. In that case you can control if it should be ghost or not: ghost=1 if the object should be made ghost while parented (default) ghost=0 if the object should be solid while parented Note: if the object type is sensor, it stays ghost regardless of ghost parameter parent: KX_GameObject reference or string (object name w/o OB prefix)
2009-05-21 13:32:15 +00:00
bool addToCompound = true;
bool ghost = true;
KX_GameObject *tmpgob = NULL;
switch(parAct->type)
{
case ACT_PARENT_SET:
mode = KX_ParentActuator::KX_PARENT_SET;
tmpgob = converter->FindGameObject(parAct->ob);
BGE: user control to compound shape and setParent. Compound shape control ====================== 1) GUI control It is now possible to control which child shape is added to a parent compound shape in the Physics buttons. The "Compound" shape button becomes "Add to parent" on child objects and determines whether the child shape is to be added to the top parent compound shape when the game is stated. Notes: * "Compound" is only available to top parent objects (objects without parent). * Nesting of compound shape is not possible: a child object with "Add to parent" button set will be added to the top parent compound shape, regardless of its position in the parent-child hierarchy and even if its immediate parent doesn't have the "Add to parent" button set. 2) runtime control It is now possible to control the compound shape at runtime: The SetParent actuator has a new "Compound" button that indicates whether the object shape should be added to the compound shape of the parent object, provided the parent has a compound shape of course. If not, the object retain it's individual state while parented. Similarly, the KX_GameObject.setParent() python function has a new compound parameter. Notes: * When an object is dynamically added to a compound shape, it looses temporarily all its physics capability to the benefit of the parent: it cannot register collisions and the characteristics of its shape are lost (ghost, sensor, dynamic, etc.). * Nested compound shape is not supported: if the object being parented is already a compound shape, it is not added to the compound parent (as if the Compound option was not set in the actuator or the setParent function). * To ensure compatibility with old blend files, the Blender subversion is changed to 2.48.5 and the old blend files are automatically converted to match the old behavior: all children of a Compound object will have the "Add to parent" button set automatically. Child ghost control =================== It is now possible to control if an object should becomes ghost or solid when parented. This is only applicable if the object is not added to the parent compound shape (see above). A new "Ghost" button is available on the SetParent actuator to that effect. Similarly the KX_GameObject.setParent() python function has a new compound parameter. Notes: * This option is not applicable to sensor objects: they stay ghost all the time. * Make sure the child object does not enter in collision with the parent shape when the Ghost option if off and the parent is dynamic: the collision creates a reaction force but the parent cannot escape the child, so the force builds up and produces eratic movements. * The collision capability of an ordinary object (dynamic or static) is limited when it is parented: it becomes automatically static and can only detect dynamic and sensor objects. * A sensor object retain its full collision capability when parented: it can detect static and dynamic object. Python control ============== KX_GameObject.setParent(parent,compound,ghost): Sets this object's parent. Control the shape status with the optional compound and ghost parameters: compound=1: the object shape should be added to the parent compound shape (default) compound=0: the object should keep its individual shape. In that case you can control if it should be ghost or not: ghost=1 if the object should be made ghost while parented (default) ghost=0 if the object should be solid while parented Note: if the object type is sensor, it stays ghost regardless of ghost parameter parent: KX_GameObject reference or string (object name w/o OB prefix)
2009-05-21 13:32:15 +00:00
addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
ghost = !(parAct->flag & ACT_PARENT_GHOST);
break;
case ACT_PARENT_REMOVE:
mode = KX_ParentActuator::KX_PARENT_REMOVE;
tmpgob = NULL;
break;
}
KX_ParentActuator *tmpparact
= new KX_ParentActuator(gameobj,
mode,
BGE: user control to compound shape and setParent. Compound shape control ====================== 1) GUI control It is now possible to control which child shape is added to a parent compound shape in the Physics buttons. The "Compound" shape button becomes "Add to parent" on child objects and determines whether the child shape is to be added to the top parent compound shape when the game is stated. Notes: * "Compound" is only available to top parent objects (objects without parent). * Nesting of compound shape is not possible: a child object with "Add to parent" button set will be added to the top parent compound shape, regardless of its position in the parent-child hierarchy and even if its immediate parent doesn't have the "Add to parent" button set. 2) runtime control It is now possible to control the compound shape at runtime: The SetParent actuator has a new "Compound" button that indicates whether the object shape should be added to the compound shape of the parent object, provided the parent has a compound shape of course. If not, the object retain it's individual state while parented. Similarly, the KX_GameObject.setParent() python function has a new compound parameter. Notes: * When an object is dynamically added to a compound shape, it looses temporarily all its physics capability to the benefit of the parent: it cannot register collisions and the characteristics of its shape are lost (ghost, sensor, dynamic, etc.). * Nested compound shape is not supported: if the object being parented is already a compound shape, it is not added to the compound parent (as if the Compound option was not set in the actuator or the setParent function). * To ensure compatibility with old blend files, the Blender subversion is changed to 2.48.5 and the old blend files are automatically converted to match the old behavior: all children of a Compound object will have the "Add to parent" button set automatically. Child ghost control =================== It is now possible to control if an object should becomes ghost or solid when parented. This is only applicable if the object is not added to the parent compound shape (see above). A new "Ghost" button is available on the SetParent actuator to that effect. Similarly the KX_GameObject.setParent() python function has a new compound parameter. Notes: * This option is not applicable to sensor objects: they stay ghost all the time. * Make sure the child object does not enter in collision with the parent shape when the Ghost option if off and the parent is dynamic: the collision creates a reaction force but the parent cannot escape the child, so the force builds up and produces eratic movements. * The collision capability of an ordinary object (dynamic or static) is limited when it is parented: it becomes automatically static and can only detect dynamic and sensor objects. * A sensor object retain its full collision capability when parented: it can detect static and dynamic object. Python control ============== KX_GameObject.setParent(parent,compound,ghost): Sets this object's parent. Control the shape status with the optional compound and ghost parameters: compound=1: the object shape should be added to the parent compound shape (default) compound=0: the object should keep its individual shape. In that case you can control if it should be ghost or not: ghost=1 if the object should be made ghost while parented (default) ghost=0 if the object should be solid while parented Note: if the object type is sensor, it stays ghost regardless of ghost parameter parent: KX_GameObject reference or string (object name w/o OB prefix)
2009-05-21 13:32:15 +00:00
addToCompound,
ghost,
tmpgob);
baseact = tmpparact;
break;
}
2002-10-12 11:37:38 +00:00
default:
; /* generate some error */
}
if (baseact)
{
baseact->SetExecutePriority(executePriority++);
uniquename += "#ACT#";
uniqueint++;
CIntValue* uniqueval = new CIntValue(uniqueint);
uniquename += uniqueval->GetText();
uniqueval->Release();
BGE performance, 4th round: logic This commit extends the technique of dynamic linked list to the logic system to eliminate as much as possible temporaries, map lookup or full scan. The logic engine is now free of memory allocation, which is an important stability factor. The overhead of the logic system is reduced by a factor between 3 and 6 depending on the logic setup. This is the speed-up you can expect on a logic setup using simple bricks. Heavy bricks like python controllers and ray sensors will still take about the same time to execute so the speed up will be less important. The core of the logic engine has been much reworked but the functionality is still the same except for one thing: the priority system on the execution of controllers. The exact same remark applies to actuators but I'll explain for controllers only: Previously, it was possible, with the "executePriority" attribute to set a controller to run before any other controllers in the game. Other than that, the sequential execution of controllers, as defined in Blender was guaranteed by default. With the new system, the sequential execution of controllers is still guaranteed but only within the controllers of one object. the user can no longer set a controller to run before any other controllers in the game. The "executePriority" attribute controls the execution of controllers within one object. The priority is a small number starting from 0 for the first controller and incrementing for each controller. If this missing feature is a must, a special method can be implemented to set a controller to run before all other controllers. Other improvements: - Systematic use of reference in parameter passing to avoid unnecessary data copy - Use pre increment in iterator instead of post increment to avoid temporary allocation - Use const char* instead of STR_String whenever possible to avoid temporary allocation - Fix reference counting bugs (memory leak) - Fix a crash in certain cases of state switching and object deletion - Minor speed up in property sensor - Removal of objects during the game is a lot faster
2009-05-10 20:53:58 +00:00
baseact->SetName(bact->name);
2002-10-12 11:37:38 +00:00
//gameobj->SetProperty(uniquename,baseact);
gameobj->AddActuator(baseact);
converter->RegisterGameActuator(baseact, bact);
// done with baseact, release it
baseact->Release();
2002-10-12 11:37:38 +00:00
}
bact = bact->next;
}
}
2007-10-22 20:24:26 +00:00