Changeset View
Changeset View
Standalone View
Standalone View
source/gameengine/GameLogic/SCA_TrackToActuator.cpp
- This file was moved from source/gameengine/Ketsji/KX_TrackToActuator.cpp.
| Show All 19 Lines | |||||
| * | * | ||||
| * The Original Code is: all of this file. | * The Original Code is: all of this file. | ||||
| * | * | ||||
| * Contributor(s): none yet. | * Contributor(s): none yet. | ||||
| * | * | ||||
| * ***** END GPL LICENSE BLOCK ***** | * ***** END GPL LICENSE BLOCK ***** | ||||
| */ | */ | ||||
| /** \file gameengine/Ketsji/KX_TrackToActuator.cpp | /** \file gameengine/GameLogic/SCA_TrackToActuator.cpp | ||||
| * \ingroup ketsji | * \ingroup gamelogic | ||||
| * | * | ||||
| * Replace the mesh for this actuator's parent | * Replace the mesh for this actuator's parent | ||||
| */ | */ | ||||
| /* todo: not all trackflags / upflags are implemented/tested ! | /* todo: not all trackflags / upflags are implemented/tested ! | ||||
| * m_trackflag is used to determine the forward tracking direction | * m_trackflag is used to determine the forward tracking direction | ||||
| * m_upflag for the up direction | * m_upflag for the up direction | ||||
| * normal situation is +y for forward, +z for up */ | * normal situation is +y for forward, +z for up */ | ||||
| #include "MT_Scalar.h" | #include "MT_Scalar.h" | ||||
| #include "SCA_IActuator.h" | #include "SCA_IActuator.h" | ||||
| #include "KX_TrackToActuator.h" | #include "SCA_TrackToActuator.h" | ||||
| #include "SCA_IScene.h" | #include "SCA_IScene.h" | ||||
| #include "SCA_LogicManager.h" | #include "SCA_LogicManager.h" | ||||
| #include <math.h> | #include <math.h> | ||||
| #include <iostream> | #include <iostream> | ||||
| #include "KX_GameObject.h" | #include "KX_GameObject.h" | ||||
| #include "PyObjectPlus.h" | #include "PyObjectPlus.h" | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Native functions */ | /* Native functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj, | SCA_TrackToActuator::SCA_TrackToActuator(SCA_IObject *gameobj, | ||||
| SCA_IObject *ob, | SCA_IObject *ob, | ||||
| int time, | int time, | ||||
| bool allow3D, | bool allow3D, | ||||
| int trackflag, | int trackflag, | ||||
| int upflag) | int upflag) | ||||
| : SCA_IActuator(gameobj, KX_ACT_TRACKTO) | : SCA_IActuator(gameobj, SCA_ACT_TRACKTO) | ||||
| { | { | ||||
| m_time = time; | m_time = time; | ||||
| m_allow3D = allow3D; | m_allow3D = allow3D; | ||||
| m_object = ob; | m_object = ob; | ||||
| m_trackflag = trackflag; | m_trackflag = trackflag; | ||||
| m_upflag = upflag; | m_upflag = upflag; | ||||
| m_parentobj = 0; | m_parentobj = 0; | ||||
| ▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Lines | static MT_Matrix3x3 matrix3x3_interpol(MT_Matrix3x3 oldmat, MT_Matrix3x3 mat, int m_time) | ||||
| eul[1] = (m_time * oldeul[1] + eul[1]) / (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); | eul[2] = (m_time * oldeul[2] + eul[2]) / (1.0f + m_time); | ||||
| return EulToMat3(eul); | return EulToMat3(eul); | ||||
| } | } | ||||
| KX_TrackToActuator::~KX_TrackToActuator() | SCA_TrackToActuator::~SCA_TrackToActuator() | ||||
| { | { | ||||
| if (m_object) | if (m_object) | ||||
| m_object->UnregisterActuator(this); | m_object->UnregisterActuator(this); | ||||
| if (m_parentobj) | if (m_parentobj) | ||||
| m_parentobj->UnregisterActuator(this); | m_parentobj->UnregisterActuator(this); | ||||
| } /* end of destructor */ | } /* end of destructor */ | ||||
| void KX_TrackToActuator::ProcessReplica() | void SCA_TrackToActuator::ProcessReplica() | ||||
| { | { | ||||
| // the replica is tracking the same object => register it | // the replica is tracking the same object => register it | ||||
| if (m_object) | if (m_object) | ||||
| m_object->RegisterActuator(this); | m_object->RegisterActuator(this); | ||||
| if (m_parentobj) | if (m_parentobj) | ||||
| m_parentobj->RegisterActuator(this); | m_parentobj->RegisterActuator(this); | ||||
| SCA_IActuator::ProcessReplica(); | SCA_IActuator::ProcessReplica(); | ||||
| } | } | ||||
| bool KX_TrackToActuator::UnlinkObject(SCA_IObject* clientobj) | bool SCA_TrackToActuator::UnlinkObject(SCA_IObject* clientobj) | ||||
| { | { | ||||
| if (clientobj == m_object) | if (clientobj == m_object) | ||||
| { | { | ||||
| // this object is being deleted, we cannot continue to track it. | // this object is being deleted, we cannot continue to track it. | ||||
| m_object = NULL; | m_object = NULL; | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (clientobj == m_parentobj) | if (clientobj == m_parentobj) | ||||
| { | { | ||||
| m_parentobj = NULL; | m_parentobj = NULL; | ||||
| return true; | return true; | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void KX_TrackToActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map) | void SCA_TrackToActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map) | ||||
| { | { | ||||
| void **h_obj = (*obj_map)[m_object]; | void **h_obj = (*obj_map)[m_object]; | ||||
| if (h_obj) { | if (h_obj) { | ||||
| if (m_object) | if (m_object) | ||||
| m_object->UnregisterActuator(this); | m_object->UnregisterActuator(this); | ||||
| m_object = (SCA_IObject*)(*h_obj); | m_object = (SCA_IObject*)(*h_obj); | ||||
| m_object->RegisterActuator(this); | m_object->RegisterActuator(this); | ||||
| } | } | ||||
| void **h_parobj = (*obj_map)[m_parentobj]; | void **h_parobj = (*obj_map)[m_parentobj]; | ||||
| if (h_parobj) { | if (h_parobj) { | ||||
| if (m_parentobj) | if (m_parentobj) | ||||
| m_parentobj->UnregisterActuator(this); | m_parentobj->UnregisterActuator(this); | ||||
| m_parentobj= (KX_GameObject*)(*h_parobj); | m_parentobj= (KX_GameObject*)(*h_parobj); | ||||
| m_parentobj->RegisterActuator(this); | m_parentobj->RegisterActuator(this); | ||||
| } | } | ||||
| } | } | ||||
| bool KX_TrackToActuator::Update(double curtime, bool frame) | bool SCA_TrackToActuator::Update(double curtime, bool frame) | ||||
| { | { | ||||
| bool result = false; | bool result = false; | ||||
| bool bNegativeEvent = IsNegativeEvent(); | bool bNegativeEvent = IsNegativeEvent(); | ||||
| RemoveAllEvents(); | RemoveAllEvents(); | ||||
| if (bNegativeEvent) | if (bNegativeEvent) | ||||
| { | { | ||||
| // do nothing on negative events | // do nothing on negative events | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | |||||
| #ifdef WITH_PYTHON | #ifdef WITH_PYTHON | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Python functions */ | /* Python functions */ | ||||
| /* ------------------------------------------------------------------------- */ | /* ------------------------------------------------------------------------- */ | ||||
| /* Integration hooks ------------------------------------------------------- */ | /* Integration hooks ------------------------------------------------------- */ | ||||
| PyTypeObject KX_TrackToActuator::Type = { | PyTypeObject SCA_TrackToActuator::Type = { | ||||
| PyVarObject_HEAD_INIT(NULL, 0) | PyVarObject_HEAD_INIT(NULL, 0) | ||||
| "KX_TrackToActuator", | "SCA_TrackToActuator", | ||||
| sizeof(PyObjectPlus_Proxy), | sizeof(PyObjectPlus_Proxy), | ||||
| 0, | 0, | ||||
| py_base_dealloc, | py_base_dealloc, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| py_base_repr, | py_base_repr, | ||||
| 0,0,0,0,0,0,0,0,0, | 0,0,0,0,0,0,0,0,0, | ||||
| Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | ||||
| 0,0,0,0,0,0,0, | 0,0,0,0,0,0,0, | ||||
| Methods, | Methods, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| &SCA_IActuator::Type, | &SCA_IActuator::Type, | ||||
| 0,0,0,0,0,0, | 0,0,0,0,0,0, | ||||
| py_base_new | py_base_new | ||||
| }; | }; | ||||
| PyMethodDef KX_TrackToActuator::Methods[] = { | PyMethodDef SCA_TrackToActuator::Methods[] = { | ||||
| {NULL,NULL} //Sentinel | {NULL,NULL} //Sentinel | ||||
| }; | }; | ||||
| PyAttributeDef KX_TrackToActuator::Attributes[] = { | PyAttributeDef SCA_TrackToActuator::Attributes[] = { | ||||
| KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time), | KX_PYATTRIBUTE_INT_RW("time",0,1000,true,SCA_TrackToActuator,m_time), | ||||
| KX_PYATTRIBUTE_BOOL_RW("use3D",KX_TrackToActuator,m_allow3D), | KX_PYATTRIBUTE_BOOL_RW("use3D",SCA_TrackToActuator,m_allow3D), | ||||
| KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object), | KX_PYATTRIBUTE_RW_FUNCTION("object", SCA_TrackToActuator, pyattr_get_object, pyattr_set_object), | ||||
| { NULL } //Sentinel | { NULL } //Sentinel | ||||
| }; | }; | ||||
| PyObject *KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | PyObject *SCA_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef) | ||||
| { | { | ||||
| KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self); | SCA_TrackToActuator* actuator = static_cast<SCA_TrackToActuator*>(self); | ||||
| if (!actuator->m_object) | if (!actuator->m_object) | ||||
| Py_RETURN_NONE; | Py_RETURN_NONE; | ||||
| else | else | ||||
| return actuator->m_object->GetProxy(); | return actuator->m_object->GetProxy(); | ||||
| } | } | ||||
| int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | int SCA_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value) | ||||
| { | { | ||||
| KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self); | SCA_TrackToActuator* actuator = static_cast<SCA_TrackToActuator*>(self); | ||||
| KX_GameObject *gameobj; | KX_GameObject *gameobj; | ||||
| if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: KX_TrackToActuator")) | if (!ConvertPythonToGameObject(value, &gameobj, true, "actuator.object = value: SCA_TrackToActuator")) | ||||
| return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error | return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error | ||||
| if (actuator->m_object != NULL) | if (actuator->m_object != NULL) | ||||
| actuator->m_object->UnregisterActuator(actuator); | actuator->m_object->UnregisterActuator(actuator); | ||||
| actuator->m_object = (SCA_IObject*) gameobj; | actuator->m_object = (SCA_IObject*) gameobj; | ||||
| if (actuator->m_object) | if (actuator->m_object) | ||||
| actuator->m_object->RegisterActuator(actuator); | actuator->m_object->RegisterActuator(actuator); | ||||
| return PY_SET_ATTR_SUCCESS; | return PY_SET_ATTR_SUCCESS; | ||||
| } | } | ||||
| #endif // WITH_PYTHON | #endif // WITH_PYTHON | ||||
| /* eof */ | /* eof */ | ||||