2012-07-18 23:03:27 +00:00
|
|
|
/*
|
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 *****
|
|
|
|
*/
|
|
|
|
|
2011-02-25 13:35:59 +00:00
|
|
|
/** \file gameengine/Ketsji/KX_TrackToActuator.cpp
|
|
|
|
* \ingroup ketsji
|
2012-07-18 23:03:27 +00:00
|
|
|
*
|
|
|
|
* Replace the mesh for this actuator's parent
|
2011-02-25 13:35:59 +00:00
|
|
|
*/
|
2012-07-18 23:03:27 +00:00
|
|
|
|
2014-07-15 00:36:56 +00:00
|
|
|
/* m_trackflag is used to determine the forward tracking direction
|
2012-07-18 23:03:27 +00:00
|
|
|
* m_upflag for the up direction
|
|
|
|
* normal situation is +y for forward, +z for up */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
#include "MT_Scalar.h"
|
|
|
|
#include "SCA_IActuator.h"
|
|
|
|
#include "KX_TrackToActuator.h"
|
|
|
|
#include "SCA_IScene.h"
|
|
|
|
#include "SCA_LogicManager.h"
|
|
|
|
#include <math.h>
|
|
|
|
#include <iostream>
|
|
|
|
#include "KX_GameObject.h"
|
|
|
|
|
2008-09-06 14:13:31 +00:00
|
|
|
#include "PyObjectPlus.h"
|
2008-09-06 02:46:11 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Native functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj,
|
2011-09-01 02:12:53 +00:00
|
|
|
SCA_IObject *ob,
|
|
|
|
int time,
|
|
|
|
bool allow3D,
|
|
|
|
int trackflag,
|
|
|
|
int upflag)
|
|
|
|
: SCA_IActuator(gameobj, KX_ACT_TRACKTO)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2011-09-01 02:12:53 +00:00
|
|
|
m_time = time;
|
|
|
|
m_allow3D = allow3D;
|
|
|
|
m_object = ob;
|
2002-10-12 11:37:38 +00:00
|
|
|
m_trackflag = trackflag;
|
|
|
|
m_upflag = upflag;
|
2007-03-23 02:20:12 +00:00
|
|
|
m_parentobj = 0;
|
|
|
|
|
2008-05-14 20:22:57 +00:00
|
|
|
if (m_object)
|
2008-04-26 20:41:25 +00:00
|
|
|
m_object->RegisterActuator(this);
|
2007-03-23 02:20:12 +00:00
|
|
|
|
2008-05-14 20:22:57 +00:00
|
|
|
{
|
|
|
|
// if the object is vertex parented, don't check parent orientation as the link is broken
|
2012-03-28 05:03:24 +00:00
|
|
|
if (!((KX_GameObject*)gameobj)->IsVertexParent()) {
|
2008-05-14 20:22:57 +00:00
|
|
|
m_parentobj = ((KX_GameObject*)gameobj)->GetParent(); // check if the object is parented
|
|
|
|
if (m_parentobj) {
|
|
|
|
// if so, store the initial local rotation
|
|
|
|
// this is needed to revert the effect of the parent inverse node (TBC)
|
|
|
|
m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
|
2009-06-08 20:08:19 +00:00
|
|
|
// use registration mechanism rather than AddRef, it creates zombie objects
|
|
|
|
m_parentobj->RegisterActuator(this);
|
2008-05-14 20:22:57 +00:00
|
|
|
}
|
2007-03-23 02:20:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
} /* End of constructor */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* old function from Blender */
|
2012-09-16 00:22:55 +00:00
|
|
|
static MT_Matrix3x3 EulToMat3(float eul[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
MT_Matrix3x3 mat;
|
|
|
|
float ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
|
|
|
|
|
|
|
|
ci = cos(eul[0]);
|
|
|
|
cj = cos(eul[1]);
|
|
|
|
ch = cos(eul[2]);
|
|
|
|
si = sin(eul[0]);
|
|
|
|
sj = sin(eul[1]);
|
|
|
|
sh = sin(eul[2]);
|
|
|
|
cc = ci*ch;
|
|
|
|
cs = ci*sh;
|
|
|
|
sc = si*ch;
|
|
|
|
ss = si*sh;
|
|
|
|
|
|
|
|
mat[0][0] = cj*ch;
|
|
|
|
mat[1][0] = sj*sc-cs;
|
|
|
|
mat[2][0] = sj*cc+ss;
|
|
|
|
mat[0][1] = cj*sh;
|
|
|
|
mat[1][1] = sj*ss+cc;
|
|
|
|
mat[2][1] = sj*cs-sc;
|
|
|
|
mat[0][2] = -sj;
|
|
|
|
mat[1][2] = cj*si;
|
|
|
|
mat[2][2] = cj*ci;
|
|
|
|
|
|
|
|
return mat;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* old function from Blender */
|
2012-09-16 00:22:55 +00:00
|
|
|
static void Mat3ToEulOld(MT_Matrix3x3 mat, float eul[3])
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-07-18 23:03:27 +00:00
|
|
|
const float cy = sqrtf(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
|
|
|
|
|
|
|
|
if (cy > (float)(16.0f * FLT_EPSILON)) {
|
|
|
|
eul[0] = atan2f( mat[1][2], mat[2][2]);
|
|
|
|
eul[1] = atan2f(-mat[0][2], cy);
|
|
|
|
eul[2] = atan2f( mat[0][1], mat[0][0]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
eul[0] = atan2f(-mat[2][1], mat[1][1]);
|
|
|
|
eul[1] = atan2f(-mat[0][2], cy);
|
2002-10-12 11:37:38 +00:00
|
|
|
eul[2] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* old function from Blender */
|
2012-09-16 00:22:55 +00:00
|
|
|
static void compatible_eulFast(float *eul, float *oldrot)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
float dx, dy, dz;
|
|
|
|
|
2008-07-25 10:52:10 +00:00
|
|
|
/* angular difference of 360 degrees */
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-07-18 23:03:27 +00:00
|
|
|
dx = eul[0] - oldrot[0];
|
|
|
|
dy = eul[1] - oldrot[1];
|
|
|
|
dz = eul[2] - oldrot[2];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-07-18 23:03:27 +00:00
|
|
|
if (fabsf(dx) > (float)MT_PI) {
|
|
|
|
if (dx > 0.0f) eul[0] -= (float)MT_2_PI; else eul[0] += (float)MT_2_PI;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-07-18 23:03:27 +00:00
|
|
|
if (fabsf(dy) > (float)MT_PI) {
|
|
|
|
if (dy > 0.0f) eul[1] -= (float)MT_2_PI; else eul[1] += (float)MT_2_PI;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
2012-07-18 23:03:27 +00:00
|
|
|
if (fabsf(dz) > (float)MT_PI) {
|
|
|
|
if (dz > 0.0f) eul[2] -= (float)MT_2_PI; else eul[2] += (float)MT_2_PI;
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-09-16 00:22:55 +00:00
|
|
|
static MT_Matrix3x3 matrix3x3_interpol(MT_Matrix3x3 oldmat, MT_Matrix3x3 mat, int m_time)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-16 04:58:18 +00:00
|
|
|
float eul[3], oldeul[3];
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2005-08-23 13:16:02 +00:00
|
|
|
Mat3ToEulOld(oldmat, oldeul);
|
|
|
|
Mat3ToEulOld(mat, eul);
|
2002-10-12 11:37:38 +00:00
|
|
|
compatible_eulFast(eul, oldeul);
|
|
|
|
|
2012-07-18 23:03:27 +00:00
|
|
|
eul[0] = (m_time * oldeul[0] + eul[0]) / (1.0f + m_time);
|
|
|
|
eul[1] = (m_time * oldeul[1] + eul[1]) / (1.0f + m_time);
|
|
|
|
eul[2] = (m_time * oldeul[2] + eul[2]) / (1.0f + m_time);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
return EulToMat3(eul);
|
|
|
|
}
|
|
|
|
|
2014-07-15 00:36:56 +00:00
|
|
|
static float basis_cross(int n, int m)
|
|
|
|
{
|
|
|
|
switch (n - m) {
|
|
|
|
case 1:
|
|
|
|
case -2:
|
|
|
|
return 1.0f;
|
|
|
|
|
|
|
|
case -1:
|
|
|
|
case 2:
|
|
|
|
return -1.0f;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 0.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vectomat function obtained from constrain.c and modified to work with MOTO library */
|
|
|
|
static MT_Matrix3x3 vectomat(MT_Vector3 vec, short axis, short upflag, short threedimup)
|
|
|
|
{
|
|
|
|
MT_Matrix3x3 mat;
|
|
|
|
MT_Vector3 y(MT_Scalar(0.0), MT_Scalar(1.0), MT_Scalar(0.0));
|
|
|
|
MT_Vector3 z(MT_Scalar(0.0), MT_Scalar(0.0), MT_Scalar(1.0)); /* world Z axis is the global up axis */
|
|
|
|
MT_Vector3 proj;
|
|
|
|
MT_Vector3 right;
|
|
|
|
MT_Scalar mul;
|
|
|
|
int right_index;
|
|
|
|
|
|
|
|
/* Normalized Vec vector*/
|
|
|
|
vec = vec.safe_normalized_vec(z);
|
|
|
|
|
|
|
|
/* if 2D doesn't move the up vector */
|
|
|
|
if (!threedimup){
|
|
|
|
vec.setValue(MT_Scalar(vec[0]), MT_Scalar(vec[1]), MT_Scalar(0.0));
|
|
|
|
vec = (vec - z.dot(vec)*z).safe_normalized_vec(z);
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-07-15 00:36:56 +00:00
|
|
|
if (axis > 2)
|
|
|
|
axis -= 3;
|
|
|
|
else
|
|
|
|
vec = -vec;
|
|
|
|
|
|
|
|
/* project the up vector onto the plane specified by vec */
|
|
|
|
/* first z onto vec... */
|
|
|
|
mul = z.dot(vec) / vec.dot(vec);
|
|
|
|
proj = vec * mul;
|
|
|
|
/* then onto the plane */
|
|
|
|
proj = z - proj;
|
|
|
|
/* proj specifies the transformation of the up axis */
|
|
|
|
proj = proj.safe_normalized_vec(y);
|
|
|
|
|
|
|
|
/* Normalized cross product of vec and proj specifies transformation of the right axis */
|
|
|
|
right = proj.cross(vec);
|
|
|
|
right.normalize();
|
|
|
|
|
|
|
|
if (axis != upflag) {
|
|
|
|
right_index = 3 - axis - upflag;
|
|
|
|
|
|
|
|
/* account for up direction, track direction */
|
|
|
|
right = right * basis_cross(axis, upflag);
|
|
|
|
mat.setRow(right_index, right);
|
|
|
|
mat.setRow(upflag, proj);
|
|
|
|
mat.setRow(axis, vec);
|
|
|
|
mat = mat.inverse();
|
|
|
|
}
|
|
|
|
/* identity matrix - don't do anything if the two axes are the same */
|
|
|
|
else {
|
|
|
|
mat.setIdentity();
|
|
|
|
}
|
|
|
|
|
|
|
|
return mat;
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
KX_TrackToActuator::~KX_TrackToActuator()
|
2008-04-26 20:41:25 +00:00
|
|
|
{
|
|
|
|
if (m_object)
|
|
|
|
m_object->UnregisterActuator(this);
|
2008-05-14 20:22:57 +00:00
|
|
|
if (m_parentobj)
|
2009-06-08 20:08:19 +00:00
|
|
|
m_parentobj->UnregisterActuator(this);
|
2002-10-12 11:37:38 +00:00
|
|
|
} /* end of destructor */
|
|
|
|
|
2008-04-26 20:41:25 +00:00
|
|
|
void KX_TrackToActuator::ProcessReplica()
|
|
|
|
{
|
|
|
|
// the replica is tracking the same object => register it
|
|
|
|
if (m_object)
|
|
|
|
m_object->RegisterActuator(this);
|
2008-07-30 16:15:15 +00:00
|
|
|
if (m_parentobj)
|
2009-06-08 20:08:19 +00:00
|
|
|
m_parentobj->RegisterActuator(this);
|
2008-04-26 20:41:25 +00:00
|
|
|
SCA_IActuator::ProcessReplica();
|
|
|
|
}
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2008-04-26 20:41:25 +00:00
|
|
|
bool KX_TrackToActuator::UnlinkObject(SCA_IObject* clientobj)
|
|
|
|
{
|
|
|
|
if (clientobj == m_object)
|
|
|
|
{
|
|
|
|
// this object is being deleted, we cannot continue to track it.
|
|
|
|
m_object = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2009-06-08 20:08:19 +00:00
|
|
|
if (clientobj == m_parentobj)
|
|
|
|
{
|
|
|
|
m_parentobj = NULL;
|
|
|
|
return true;
|
|
|
|
}
|
2008-04-26 20:41:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-06 20:18:42 +00:00
|
|
|
void KX_TrackToActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
|
2008-07-19 07:45:19 +00:00
|
|
|
{
|
|
|
|
void **h_obj = (*obj_map)[m_object];
|
|
|
|
if (h_obj) {
|
|
|
|
if (m_object)
|
|
|
|
m_object->UnregisterActuator(this);
|
|
|
|
m_object = (SCA_IObject*)(*h_obj);
|
|
|
|
m_object->RegisterActuator(this);
|
|
|
|
}
|
2008-07-30 16:15:15 +00:00
|
|
|
|
|
|
|
void **h_parobj = (*obj_map)[m_parentobj];
|
|
|
|
if (h_parobj) {
|
|
|
|
if (m_parentobj)
|
2009-06-08 20:08:19 +00:00
|
|
|
m_parentobj->UnregisterActuator(this);
|
2008-07-30 16:15:15 +00:00
|
|
|
m_parentobj= (KX_GameObject*)(*h_parobj);
|
2009-06-08 20:08:19 +00:00
|
|
|
m_parentobj->RegisterActuator(this);
|
2008-07-30 16:15:15 +00:00
|
|
|
}
|
2008-07-19 07:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-16 11:41:50 +00:00
|
|
|
bool KX_TrackToActuator::Update(double curtime, bool frame)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2012-09-16 04:58:18 +00:00
|
|
|
bool result = false;
|
2002-10-12 11:37:38 +00:00
|
|
|
bool bNegativeEvent = IsNegativeEvent();
|
|
|
|
RemoveAllEvents();
|
|
|
|
|
|
|
|
if (bNegativeEvent)
|
|
|
|
{
|
|
|
|
// do nothing on negative events
|
|
|
|
}
|
|
|
|
else if (m_object)
|
|
|
|
{
|
|
|
|
KX_GameObject* curobj = (KX_GameObject*) GetParent();
|
2014-07-15 00:36:56 +00:00
|
|
|
MT_Vector3 dir = curobj->NodeGetWorldPosition() - ((KX_GameObject*)m_object)->NodeGetWorldPosition();
|
2002-10-12 11:37:38 +00:00
|
|
|
MT_Matrix3x3 mat;
|
|
|
|
MT_Matrix3x3 oldmat;
|
2014-07-15 00:36:56 +00:00
|
|
|
|
|
|
|
mat = vectomat(dir, m_trackflag, m_upflag, m_allow3D);
|
|
|
|
oldmat = curobj->NodeGetWorldOrientation();
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* erwin should rewrite this! */
|
2014-07-15 00:36:56 +00:00
|
|
|
mat = matrix3x3_interpol(oldmat, mat, m_time);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2014-07-15 00:36:56 +00:00
|
|
|
/* check if the model is parented and calculate the child transform */
|
|
|
|
if (m_parentobj) {
|
2007-03-23 02:20:12 +00:00
|
|
|
|
|
|
|
MT_Point3 localpos;
|
|
|
|
localpos = curobj->GetSGNode()->GetLocalPosition();
|
|
|
|
// Get the inverse of the parent matrix
|
|
|
|
MT_Matrix3x3 parentmatinv;
|
2014-07-15 00:36:56 +00:00
|
|
|
parentmatinv = m_parentobj->NodeGetWorldOrientation().inverse();
|
2007-03-23 02:20:12 +00:00
|
|
|
// transform the local coordinate system into the parents system
|
|
|
|
mat = parentmatinv * mat;
|
|
|
|
// append the initial parent local rotation matrix
|
|
|
|
mat = m_parentlocalmat * mat;
|
|
|
|
|
|
|
|
// set the models tranformation properties
|
|
|
|
curobj->NodeSetLocalOrientation(mat);
|
|
|
|
curobj->NodeSetLocalPosition(localpos);
|
2009-04-20 15:06:46 +00:00
|
|
|
//curobj->UpdateTransform();
|
2007-03-23 02:20:12 +00:00
|
|
|
}
|
2014-07-15 00:36:56 +00:00
|
|
|
else {
|
2007-03-23 02:20:12 +00:00
|
|
|
curobj->NodeSetLocalOrientation(mat);
|
|
|
|
}
|
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-31 04:11:39 +00:00
|
|
|
#ifdef WITH_PYTHON
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* Python functions */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Integration hooks ------------------------------------------------------- */
|
|
|
|
PyTypeObject KX_TrackToActuator::Type = {
|
2009-06-08 20:08:19 +00:00
|
|
|
PyVarObject_HEAD_INIT(NULL, 0)
|
2002-10-12 11:37:38 +00:00
|
|
|
"KX_TrackToActuator",
|
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_TrackToActuator::Methods[] = {
|
|
|
|
{NULL,NULL} //Sentinel
|
|
|
|
};
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
PyAttributeDef KX_TrackToActuator::Attributes[] = {
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time),
|
|
|
|
KX_PYATTRIBUTE_BOOL_RW("use3D",KX_TrackToActuator,m_allow3D),
|
2014-07-15 00:36:56 +00:00
|
|
|
KX_PYATTRIBUTE_INT_RW("upAxis", 0, 2, true, KX_TrackToActuator,m_upflag),
|
|
|
|
KX_PYATTRIBUTE_INT_RW("trackAxis", 0, 5, true, KX_TrackToActuator,m_trackflag),
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object),
|
|
|
|
|
2009-02-26 09:04:06 +00:00
|
|
|
{ NULL } //Sentinel
|
|
|
|
};
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2012-09-16 04:58:18 +00:00
|
|
|
PyObject *KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
|
2012-09-16 04:58:18 +00:00
|
|
|
if (!actuator->m_object)
|
2009-04-20 15:06:46 +00:00
|
|
|
Py_RETURN_NONE;
|
|
|
|
else
|
|
|
|
return actuator->m_object->GetProxy();
|
2002-10-12 11:37:38 +00:00
|
|
|
}
|
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
|
2009-02-21 12:43:24 +00:00
|
|
|
{
|
2009-04-20 15:06:46 +00:00
|
|
|
KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(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_TrackToActuator"))
|
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_object != NULL)
|
2012-09-16 04:58:18 +00:00
|
|
|
actuator->m_object->UnregisterActuator(actuator);
|
2002-10-12 11:37:38 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
actuator->m_object = (SCA_IObject*) gameobj;
|
2009-02-19 10:34:51 +00:00
|
|
|
|
2009-04-20 15:06:46 +00:00
|
|
|
if (actuator->m_object)
|
|
|
|
actuator->m_object->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
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
/* eof */
|