2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2008-04-06 18:30:52 +00:00
|
|
|
* Set or remove an objects parent
|
|
|
|
*
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2008-04-06 18:30:52 +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
|
2011-11-29 10:54:47 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2008-04-06 18:30:52 +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.
|
2008-04-06 18:30:52 +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 *****
|
2008-04-06 18:30:52 +00:00
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_ParentActuator.cpp
|
|
|
|
* \ingroup ketsji
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
#include "KX_ParentActuator.h"
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
#include "KX_PythonInit.h"
|
|
|
|
|
2008-09-06 14:13:31 +00:00
|
|
|
#include "PyObjectPlus.h"
|
2008-09-06 02:46:11 +00:00
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj,
|
|
|
|
int mode,
|
2009-06-08 20:08:19 +00:00
|
|
|
bool addToCompound,
|
|
|
|
bool ghost,
|
2009-06-28 11:22:26 +00:00
|
|
|
SCA_IObject *ob)
|
2009-09-24 21:22:24 +00:00
|
|
|
: SCA_IActuator(gameobj, KX_ACT_PARENT),
|
2008-04-06 18:30:52 +00:00
|
|
|
m_mode(mode),
|
2009-06-08 20:08:19 +00:00
|
|
|
m_addToCompound(addToCompound),
|
|
|
|
m_ghost(ghost),
|
2008-04-06 18:30:52 +00:00
|
|
|
m_ob(ob)
|
|
|
|
{
|
2008-07-19 07:45:19 +00:00
|
|
|
if (m_ob)
|
|
|
|
m_ob->RegisterActuator(this);
|
2008-04-06 18:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KX_ParentActuator::~KX_ParentActuator()
|
|
|
|
{
|
2008-07-19 07:45:19 +00:00
|
|
|
if (m_ob)
|
|
|
|
m_ob->UnregisterActuator(this);
|
2008-04-06 18:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CValue* KX_ParentActuator::GetReplica()
|
|
|
|
{
|
|
|
|
KX_ParentActuator* replica = new KX_ParentActuator(*this);
|
|
|
|
// replication just copy the m_base pointer => common random generator
|
|
|
|
replica->ProcessReplica();
|
|
|
|
return replica;
|
|
|
|
}
|
|
|
|
|
2008-07-19 07:45:19 +00:00
|
|
|
void KX_ParentActuator::ProcessReplica()
|
|
|
|
{
|
|
|
|
if (m_ob)
|
|
|
|
m_ob->RegisterActuator(this);
|
|
|
|
SCA_IActuator::ProcessReplica();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool KX_ParentActuator::UnlinkObject(SCA_IObject* clientobj)
|
|
|
|
{
|
|
|
|
if (clientobj == m_ob)
|
|
|
|
{
|
|
|
|
// this object is being deleted, we cannot continue to track it.
|
|
|
|
m_ob = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
void KX_ParentActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
|
2008-07-19 07:45:19 +00:00
|
|
|
{
|
|
|
|
void **h_obj = (*obj_map)[m_ob];
|
|
|
|
if (h_obj) {
|
|
|
|
if (m_ob)
|
|
|
|
m_ob->UnregisterActuator(this);
|
|
|
|
m_ob = (SCA_IObject*)(*h_obj);
|
|
|
|
m_ob->RegisterActuator(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool KX_ParentActuator::Update()
|
|
|
|
{
|
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 bNegativeEvent = IsNegativeEvent();
|
|
|
|
RemoveAllEvents();
|
|
|
|
|
|
|
|
if (bNegativeEvent)
|
|
|
|
return false; // do nothing on negative events
|
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
KX_GameObject *obj = (KX_GameObject*) GetParent();
|
2008-10-31 21:06:48 +00:00
|
|
|
KX_Scene *scene = KX_GetActiveScene();
|
2008-04-06 18:30:52 +00:00
|
|
|
switch (m_mode) {
|
|
|
|
case KX_PARENT_SET:
|
2008-07-19 07:45:19 +00:00
|
|
|
if (m_ob)
|
2009-06-08 20:08:19 +00:00
|
|
|
obj->SetParent(scene, (KX_GameObject*)m_ob, m_addToCompound, m_ghost);
|
2008-04-06 18:30:52 +00:00
|
|
|
break;
|
|
|
|
case KX_PARENT_REMOVE:
|
|
|
|
obj->RemoveParent(scene);
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_ParentActuator::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2008-04-06 18:30:52 +00:00
|
|
|
"KX_ParentActuator",
|
2009-04-20 15:06:46 +00:00
|
|
|
sizeof(PyObjectPlus_Proxy),
|
2008-04-06 18:30:52 +00:00
|
|
|
0,
|
2009-04-20 15:06:46 +00:00
|
|
|
py_base_dealloc,
|
2008-04-06 18:30:52 +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
|
2008-04-06 18:30:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
PyMethodDef KX_ParentActuator::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_ParentActuator::Attributes[] = {
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("object", KX_ParentActuator, pyattr_get_object, pyattr_set_object),
|
2009-06-08 20:08:19 +00:00
|
|
|
KX_PYATTRIBUTE_INT_RW("mode", KX_PARENT_NODEF+1, KX_PARENT_MAX-1, true, KX_ParentActuator, m_mode),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("compound", KX_ParentActuator, m_addToCompound),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("ghost", KX_ParentActuator, m_ghost),
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
PyObject* KX_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
|
|
|
{
|
|
|
|
KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
|
|
|
|
if (!actuator->m_ob)
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
else
|
|
|
|
return actuator->m_ob->GetProxy();
|
2008-04-06 18:30:52 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
|
|
|
{
|
|
|
|
KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
|
|
|
|
KX_GameObject *gameobj;
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
|
2009-06-08 20:08:19 +00:00
|
|
|
return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (actuator->m_ob != NULL)
|
|
|
|
actuator->m_ob->UnregisterActuator(actuator);
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
actuator->m_ob = (SCA_IObject*) gameobj;
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (actuator->m_ob)
|
|
|
|
actuator->m_ob->RegisterActuator(actuator);
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-06-08 20:08:19 +00:00
|
|
|
return PY_SET_ATTR_SUCCESS;
|
2009-04-20 15:06:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#endif // WITH_PYTHON
|
2009-09-29 21:42:40 +00:00
|
|
|
|
2008-04-06 18:30:52 +00:00
|
|
|
/* eof */
|