2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2002-10-12 11:37:38 +00:00
|
|
|
* Do Ipo stuff
|
|
|
|
*
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_IpoActuator.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "KX_IpoActuator.h"
|
|
|
|
#include "KX_GameObject.h"
|
2008-10-01 21:17:00 +00:00
|
|
|
#include "FloatValue.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
#include "KX_KetsjiEngine.h"
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Type strings */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
2009-08-19 10:26:43 +00:00
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_PLAY_STRING = "Play";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_PINGPONG_STRING = "PingPong";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_FLIPPER_STRING = "Flipper";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPSTOP_STRING = "LoopStop";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_LOOPEND_STRING = "LoopEnd";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_KEY2KEY_STRING = "Key2key";
|
|
|
|
const char *KX_IpoActuator::S_KX_ACT_IPO_FROM_PROP_STRING = "FromProp";
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
KX_IpoActuator::KX_IpoActuator(SCA_IObject* gameobj,
|
|
|
|
const STR_String& propname,
|
2008-10-01 21:17:00 +00:00
|
|
|
const STR_String& framePropname,
|
2002-10-12 11:37:38 +00:00
|
|
|
float starttime,
|
|
|
|
float endtime,
|
|
|
|
bool recurse,
|
|
|
|
int acttype,
|
|
|
|
bool 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
|
|
|
bool ipo_add,
|
2009-06-28 11:22:26 +00:00
|
|
|
bool ipo_local)
|
2009-09-24 21:22:24 +00:00
|
|
|
: SCA_IActuator(gameobj, KX_ACT_IPO),
|
2004-03-22 22:02:18 +00:00
|
|
|
m_bNegativeEvent(false),
|
2004-10-16 11:41:50 +00:00
|
|
|
m_startframe (starttime),
|
|
|
|
m_endframe(endtime),
|
2002-10-12 11:37:38 +00:00
|
|
|
m_recurse(recurse),
|
2004-03-22 22:02:18 +00:00
|
|
|
m_localtime(starttime),
|
2002-10-12 11:37:38 +00:00
|
|
|
m_direction(1),
|
|
|
|
m_propname(propname),
|
2008-10-01 21:17:00 +00:00
|
|
|
m_framepropname(framePropname),
|
2002-10-12 11:37:38 +00:00
|
|
|
m_ipo_as_force(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
|
|
|
m_ipo_add(ipo_add),
|
|
|
|
m_ipo_local(ipo_local),
|
2009-04-20 15:06:46 +00:00
|
|
|
m_type(acttype)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2010-12-07 01:54:25 +00:00
|
|
|
this->ResetStartTime();
|
2007-01-21 00:56:10 +00:00
|
|
|
m_bIpoPlaying = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KX_IpoActuator::SetStart(float starttime)
|
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
m_startframe=starttime;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KX_IpoActuator::SetEnd(float endtime)
|
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
m_endframe=endtime;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2004-11-03 10:48:02 +00:00
|
|
|
bool KX_IpoActuator::ClampLocalTime()
|
|
|
|
{
|
|
|
|
if (m_startframe < m_endframe)
|
|
|
|
{
|
|
|
|
if (m_localtime < m_startframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_startframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_localtime > m_endframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_endframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_localtime > m_startframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_startframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (m_localtime < m_endframe)
|
|
|
|
{
|
|
|
|
m_localtime = m_endframe;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
void KX_IpoActuator::SetStartTime(float curtime)
|
|
|
|
{
|
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
|
|
|
float direction = m_startframe < m_endframe ? 1.0f : -1.0f;
|
2005-12-18 19:10:26 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
if (m_direction > 0)
|
2008-06-17 10:06:38 +00:00
|
|
|
m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
|
2004-10-16 11:41:50 +00:00
|
|
|
else
|
2008-06-17 10:06:38 +00:00
|
|
|
m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
void KX_IpoActuator::SetLocalTime(float curtime)
|
|
|
|
{
|
2008-09-16 21:11:38 +00:00
|
|
|
float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
|
2005-12-18 19:10:26 +00:00
|
|
|
|
|
|
|
// negative delta_time is caused by floating point inaccuracy
|
|
|
|
// perhaps the inaccuracy could be reduced a bit
|
|
|
|
if ((m_localtime==m_startframe || m_localtime==m_endframe) && delta_time<0.0)
|
|
|
|
{
|
|
|
|
delta_time = 0.0;
|
|
|
|
}
|
2004-11-03 10:48:02 +00:00
|
|
|
|
|
|
|
if (m_endframe < m_startframe)
|
|
|
|
delta_time = -delta_time;
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
if (m_direction > 0)
|
|
|
|
m_localtime = m_startframe + delta_time;
|
|
|
|
else
|
|
|
|
m_localtime = m_endframe - delta_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KX_IpoActuator::Update(double curtime, bool frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
// result = true if animation has to be continued, false if animation stops
|
|
|
|
// maybe there are events for us in the queue !
|
|
|
|
bool bNegativeEvent = false;
|
2009-06-08 20:08:19 +00:00
|
|
|
bool numevents = false;
|
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 bIpoStart = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2008-09-16 21:11:38 +00:00
|
|
|
curtime -= KX_KetsjiEngine::GetSuspendedDelta();
|
|
|
|
|
2004-12-01 08:43:58 +00:00
|
|
|
if (frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-06-08 20:08:19 +00:00
|
|
|
numevents = m_posevent || m_negevent;
|
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
|
|
|
bNegativeEvent = IsNegativeEvent();
|
|
|
|
RemoveAllEvents();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
float start_smaller_then_end = ( m_startframe < m_endframe ? 1.0f : -1.0f);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
bool result=true;
|
2007-01-21 00:56:10 +00:00
|
|
|
if (!bNegativeEvent)
|
|
|
|
{
|
2010-12-07 01:54:25 +00:00
|
|
|
if (m_starttime < -2.0f*fabs(m_endframe - m_startframe))
|
2007-01-21 00:56:10 +00:00
|
|
|
{
|
2008-02-15 23:12:03 +00:00
|
|
|
// start for all Ipo, initial start for LOOP_STOP
|
2008-09-16 21:11:38 +00:00
|
|
|
m_starttime = curtime;
|
2007-01-21 00:56:10 +00:00
|
|
|
m_bIpoPlaying = true;
|
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
|
|
|
bIpoStart = true;
|
2007-01-21 00:56:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
switch ((IpoActType)m_type)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
case KX_ACT_IPO_PLAY:
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
|
|
|
// Check if playing forwards. result = ! finished
|
2007-01-21 00:56:10 +00:00
|
|
|
|
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
|
|
|
if (start_smaller_then_end > 0.f)
|
2008-02-15 23:12:03 +00:00
|
|
|
result = (m_localtime < m_endframe && m_bIpoPlaying);
|
2004-10-16 11:41:50 +00:00
|
|
|
else
|
2008-02-15 23:12:03 +00:00
|
|
|
result = (m_localtime > m_endframe && m_bIpoPlaying);
|
2004-10-16 11:41:50 +00:00
|
|
|
|
|
|
|
if (result)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
SetLocalTime(curtime);
|
|
|
|
|
|
|
|
/* Perform clamping */
|
2004-11-03 10:48:02 +00:00
|
|
|
ClampLocalTime();
|
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
|
|
|
|
|
|
|
if (bIpoStart)
|
|
|
|
((KX_GameObject*)GetParent())->InitIPO(m_ipo_as_force, m_ipo_add, m_ipo_local);
|
|
|
|
((KX_GameObject*)GetParent())->UpdateIPO(m_localtime,m_recurse);
|
2004-10-16 11:41:50 +00:00
|
|
|
} else
|
|
|
|
{
|
|
|
|
m_localtime=m_startframe;
|
|
|
|
m_direction=1;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2004-10-16 11:41:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KX_ACT_IPO_PINGPONG:
|
|
|
|
{
|
|
|
|
result = true;
|
2008-02-15 23:12:03 +00:00
|
|
|
if (bNegativeEvent && !m_bIpoPlaying)
|
2004-10-16 11:41:50 +00:00
|
|
|
result = false;
|
|
|
|
else
|
|
|
|
SetLocalTime(curtime);
|
2004-11-03 10:48:02 +00:00
|
|
|
|
|
|
|
if (ClampLocalTime())
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
|
|
|
result = false;
|
2004-11-03 10:48:02 +00:00
|
|
|
m_direction = -m_direction;
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
if (bIpoStart && m_direction > 0)
|
|
|
|
((KX_GameObject*)GetParent())->InitIPO(m_ipo_as_force, m_ipo_add, m_ipo_local);
|
|
|
|
((KX_GameObject*)GetParent())->UpdateIPO(m_localtime,m_recurse);
|
2004-10-16 11:41:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
case KX_ACT_IPO_FLIPPER:
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
2008-02-15 23:12:03 +00:00
|
|
|
if (bNegativeEvent && !m_bIpoPlaying)
|
|
|
|
result = false;
|
2004-10-16 11:41:50 +00:00
|
|
|
if (numevents)
|
|
|
|
{
|
2008-02-15 23:12:03 +00:00
|
|
|
float oldDirection = m_direction;
|
2004-10-16 11:41:50 +00:00
|
|
|
if (bNegativeEvent)
|
|
|
|
m_direction = -1;
|
|
|
|
else
|
|
|
|
m_direction = 1;
|
2008-02-15 23:12:03 +00:00
|
|
|
if (m_direction != oldDirection)
|
|
|
|
// changing direction, reset start time
|
|
|
|
SetStartTime(curtime);
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
2004-11-22 10:19:19 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
SetLocalTime(curtime);
|
|
|
|
|
2004-11-03 10:48:02 +00:00
|
|
|
if (ClampLocalTime() && m_localtime == m_startframe)
|
|
|
|
result = false;
|
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
|
|
|
|
|
|
|
if (bIpoStart)
|
|
|
|
((KX_GameObject*)GetParent())->InitIPO(m_ipo_as_force, m_ipo_add, m_ipo_local);
|
|
|
|
((KX_GameObject*)GetParent())->UpdateIPO(m_localtime,m_recurse);
|
2004-10-16 11:41:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KX_ACT_IPO_LOOPSTOP:
|
|
|
|
{
|
|
|
|
if (numevents)
|
|
|
|
{
|
|
|
|
if (bNegativeEvent)
|
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
m_bNegativeEvent = false;
|
2009-06-08 20:08:19 +00:00
|
|
|
numevents = false;
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
2008-02-15 23:12:03 +00:00
|
|
|
if (!m_bIpoPlaying)
|
|
|
|
{
|
|
|
|
// Ipo was stopped, make sure we will restart from where it stopped
|
|
|
|
SetStartTime(curtime);
|
|
|
|
if (!bNegativeEvent)
|
|
|
|
// positive signal will restart the Ipo
|
|
|
|
m_bIpoPlaying = true;
|
|
|
|
}
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
} // fall through to loopend, and quit the ipo animation immediatly
|
|
|
|
}
|
|
|
|
case KX_ACT_IPO_LOOPEND:
|
|
|
|
{
|
|
|
|
if (numevents){
|
2008-02-15 23:12:03 +00:00
|
|
|
if (bNegativeEvent && m_bIpoPlaying){
|
2004-10-16 11:41:50 +00:00
|
|
|
m_bNegativeEvent = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-15 23:12:03 +00:00
|
|
|
if (bNegativeEvent && !m_bIpoPlaying){
|
2004-10-16 11:41:50 +00:00
|
|
|
result = false;
|
|
|
|
}
|
2004-11-03 10:48:02 +00:00
|
|
|
else
|
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
if (m_localtime*start_smaller_then_end < m_endframe*start_smaller_then_end)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2004-10-16 11:41:50 +00:00
|
|
|
SetLocalTime(curtime);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
if (!m_bNegativeEvent){
|
|
|
|
/* Perform wraparound */
|
|
|
|
SetLocalTime(curtime);
|
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
|
|
|
if (start_smaller_then_end > 0.f)
|
|
|
|
m_localtime = m_startframe + fmod(m_localtime - m_startframe, m_endframe - m_startframe);
|
|
|
|
else
|
|
|
|
m_localtime = m_startframe - fmod(m_startframe - m_localtime, m_startframe - m_endframe);
|
2004-10-16 11:41:50 +00:00
|
|
|
SetStartTime(curtime);
|
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
|
|
|
bIpoStart = true;
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
else
|
2004-10-16 11:41:50 +00:00
|
|
|
{
|
|
|
|
/* Perform clamping */
|
|
|
|
m_localtime=m_endframe;
|
|
|
|
result = false;
|
|
|
|
m_bNegativeEvent = false;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2004-10-16 11:41:50 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
if (m_bIpoPlaying && bIpoStart)
|
|
|
|
((KX_GameObject*)GetParent())->InitIPO(m_ipo_as_force, m_ipo_add, m_ipo_local);
|
|
|
|
((KX_GameObject*)GetParent())->UpdateIPO(m_localtime,m_recurse);
|
2004-10-16 11:41:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KX_ACT_IPO_KEY2KEY:
|
|
|
|
{
|
|
|
|
// not implemented yet
|
|
|
|
result = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case KX_ACT_IPO_FROM_PROP:
|
|
|
|
{
|
|
|
|
result = !bNegativeEvent;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
CValue* propval = GetParent()->GetProperty(m_propname);
|
|
|
|
if (propval)
|
|
|
|
{
|
2004-12-06 10:58:38 +00:00
|
|
|
m_localtime = propval->GetNumber();
|
2004-10-16 11:41:50 +00:00
|
|
|
|
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
|
|
|
if (bIpoStart)
|
|
|
|
((KX_GameObject*)GetParent())->InitIPO(m_ipo_as_force, m_ipo_add, m_ipo_local);
|
|
|
|
((KX_GameObject*)GetParent())->UpdateIPO(m_localtime,m_recurse);
|
2004-10-16 11:41:50 +00:00
|
|
|
} else
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
result = false;
|
|
|
|
}
|
2004-10-16 11:41:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
default:
|
2004-10-16 11:41:50 +00:00
|
|
|
result = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2008-10-01 21:17:00 +00:00
|
|
|
|
|
|
|
/* Set the property if its defined */
|
|
|
|
if (m_framepropname[0] != '\0') {
|
|
|
|
CValue* propowner = GetParent();
|
|
|
|
CValue* oldprop = propowner->GetProperty(m_framepropname);
|
|
|
|
CValue* newval = new CFloatValue(m_localtime);
|
|
|
|
if (oldprop) {
|
|
|
|
oldprop->SetValue(newval);
|
|
|
|
} else {
|
|
|
|
propowner->SetProperty(m_framepropname, newval);
|
|
|
|
}
|
|
|
|
newval->Release();
|
|
|
|
}
|
|
|
|
|
2008-02-15 23:12:03 +00:00
|
|
|
if (!result)
|
|
|
|
{
|
|
|
|
if (m_type != KX_ACT_IPO_LOOPSTOP)
|
2010-12-07 01:54:25 +00:00
|
|
|
this->ResetStartTime();
|
2008-02-15 23:12:03 +00:00
|
|
|
m_bIpoPlaying = false;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-12-07 01:54:25 +00:00
|
|
|
void KX_IpoActuator::ResetStartTime()
|
|
|
|
{
|
|
|
|
this->m_starttime = -2.0*fabs(this->m_endframe - this->m_startframe) - 1.0;
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:41:26 +00:00
|
|
|
int KX_IpoActuator::string2mode(const char *modename)
|
|
|
|
{
|
2002-10-12 11:37:38 +00:00
|
|
|
IpoActType res = KX_ACT_IPO_NODEF;
|
|
|
|
|
2009-08-19 10:26:43 +00:00
|
|
|
if (strcmp(modename, S_KX_ACT_IPO_PLAY_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_PLAY;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_PINGPONG_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_PINGPONG;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_FLIPPER_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_FLIPPER;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_LOOPSTOP_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_LOOPSTOP;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_LOOPEND_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_LOOPEND;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_KEY2KEY_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_KEY2KEY;
|
2009-08-19 10:26:43 +00:00
|
|
|
} else if (strcmp(modename, S_KX_ACT_IPO_FROM_PROP_STRING)==0) {
|
2002-10-12 11:37:38 +00:00
|
|
|
res = KX_ACT_IPO_FROM_PROP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_IpoActuator::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2002-10-12 11:37:38 +00:00
|
|
|
"KX_IpoActuator",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2002-10-12 11:37:38 +00:00
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_repr,
|
2009-06-29 12:06:46 +00:00
|
|
|
0,0,0,0,0,0,0,0,0,
|
2009-06-28 11:22:26 +00:00
|
|
|
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
|
|
|
|
0,0,0,0,0,0,0,
|
|
|
|
Methods,
|
|
|
|
0,
|
|
|
|
0,
|
2009-06-29 12:06:46 +00:00
|
|
|
&SCA_IActuator::Type,
|
|
|
|
0,0,0,0,0,0,
|
|
|
|
py_base_new
|
2002-10-12 11:37:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_IpoActuator::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_IpoActuator::Attributes[] = {
|
2010-12-07 01:54:25 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("frameStart", KX_IpoActuator, pyattr_get_frame_start, pyattr_set_frame_start),
|
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("frameEnd", KX_IpoActuator, pyattr_get_frame_end, pyattr_set_frame_end),
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_STRING_RW("propName", 0, 64, false, KX_IpoActuator, m_propname),
|
|
|
|
KX_PYATTRIBUTE_STRING_RW("framePropName", 0, 64, false, KX_IpoActuator, m_framepropname),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_IPO_NODEF+1, KX_ACT_IPO_MAX-1, true, KX_IpoActuator, m_type),
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useIpoAsForce", KX_IpoActuator, m_ipo_as_force),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useIpoAdd", KX_IpoActuator, m_ipo_add),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useIpoLocal", KX_IpoActuator, m_ipo_local),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("useChildren", KX_IpoActuator, m_recurse),
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2010-12-07 01:54:25 +00:00
|
|
|
PyObject* KX_IpoActuator::pyattr_get_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
|
2011-02-11 00:03:26 +00:00
|
|
|
return PyFloat_FromDouble(self->m_startframe);
|
2010-12-07 01:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_IpoActuator::pyattr_set_frame_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
|
2011-02-11 00:03:26 +00:00
|
|
|
float param = PyFloat_AsDouble(value);
|
2010-12-07 01:54:25 +00:00
|
|
|
|
|
|
|
if (PyErr_Occurred()) {
|
2011-02-11 00:03:26 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError, "frameStart = float: KX_IpoActuator, expected a float value");
|
2010-12-07 01:54:25 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->m_startframe = param;
|
|
|
|
self->ResetStartTime();
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
PyObject* KX_IpoActuator::pyattr_get_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
|
2011-02-11 00:03:26 +00:00
|
|
|
return PyFloat_FromDouble(self->m_endframe);
|
2010-12-07 01:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KX_IpoActuator::pyattr_set_frame_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_IpoActuator* self= static_cast<KX_IpoActuator*>(self_v);
|
2011-02-11 00:03:26 +00:00
|
|
|
float param = PyFloat_AsDouble(value);
|
2010-12-07 01:54:25 +00:00
|
|
|
|
|
|
|
if (PyErr_Occurred()) {
|
2011-02-11 00:03:26 +00:00
|
|
|
PyErr_SetString(PyExc_AttributeError, "frameEnd = float: KX_IpoActuator, expected a float value");
|
2010-12-07 01:54:25 +00:00
|
|
|
return PY_SET_ATTR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->m_endframe = param;
|
|
|
|
self->ResetStartTime();
|
|
|
|
return PY_SET_ATTR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* eof */
|