diff options
Diffstat (limited to 'source/gameengine/Ketsji')
23 files changed, 563 insertions, 120 deletions
diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp index 70443ced7a9..c7b2a671f78 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.cpp @@ -13,11 +13,13 @@ #include "KX_ClientObjectInfo.h" #include "PHY_IPhysicsEnvironment.h" +#include "CcdPhysicsEnvironment.h" KX_BulletPhysicsController::KX_BulletPhysicsController (const CcdConstructionInfo& ci, bool dyna) : KX_IPhysicsController(dyna,(PHY_IPhysicsController*)this), -CcdPhysicsController(ci) +CcdPhysicsController(ci), +m_savedCollisionFlags(0) { } @@ -131,9 +133,10 @@ void KX_BulletPhysicsController::getOrientation(MT_Quaternion& orn) CcdPhysicsController::getOrientation(myorn[0],myorn[1],myorn[2],myorn[3]); orn = MT_Quaternion(myorn[0],myorn[1],myorn[2],myorn[3]); } -void KX_BulletPhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_BulletPhysicsController::setOrientation(const MT_Matrix3x3& orn) { - CcdPhysicsController::setOrientation(orn.x(),orn.y(),orn.z(),orn.w()); + btMatrix3x3 btmat(orn[0][0], orn[0][1], orn[1][2], orn[1][0], orn[1][1], orn[1][2], orn[2][0], orn[2][1], orn[2][2]); + CcdPhysicsController::setWorldOrientation(btmat); } void KX_BulletPhysicsController::setPosition(const MT_Point3& pos) { @@ -161,14 +164,37 @@ void KX_BulletPhysicsController::setRigidBody(bool rigid) { } -void KX_BulletPhysicsController::SuspendDynamics() +void KX_BulletPhysicsController::SuspendDynamics(bool ghost) { - GetRigidBody()->setActivationState(DISABLE_SIMULATION); - + btRigidBody *body = GetRigidBody(); + if (body->getActivationState() != DISABLE_SIMULATION) + { + btBroadphaseProxy* handle = body->getBroadphaseHandle(); + m_savedCollisionFlags = body->getCollisionFlags(); + m_savedMass = GetMass(); + m_savedCollisionFilterGroup = handle->m_collisionFilterGroup; + m_savedCollisionFilterMask = handle->m_collisionFilterMask; + body->setActivationState(DISABLE_SIMULATION); + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + 0.0, + btCollisionObject::CF_STATIC_OBJECT|((ghost)?btCollisionObject::CF_NO_CONTACT_RESPONSE:(m_savedCollisionFlags&btCollisionObject::CF_NO_CONTACT_RESPONSE)), + btBroadphaseProxy::StaticFilter, + btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter); + } } + void KX_BulletPhysicsController::RestoreDynamics() { - GetRigidBody()->forceActivationState(ACTIVE_TAG); + btRigidBody *body = GetRigidBody(); + if (body->getActivationState() == DISABLE_SIMULATION) + { + GetPhysicsEnvironment()->updateCcdPhysicsController(this, + m_savedMass, + m_savedCollisionFlags, + m_savedCollisionFilterGroup, + m_savedCollisionFilterMask); + GetRigidBody()->forceActivationState(ACTIVE_TAG); + } } SG_Controller* KX_BulletPhysicsController::GetReplica(class SG_Node* destnode) diff --git a/source/gameengine/Ketsji/KX_BulletPhysicsController.h b/source/gameengine/Ketsji/KX_BulletPhysicsController.h index 0853755dffa..2efe0474b30 100644 --- a/source/gameengine/Ketsji/KX_BulletPhysicsController.h +++ b/source/gameengine/Ketsji/KX_BulletPhysicsController.h @@ -7,6 +7,11 @@ class KX_BulletPhysicsController : public KX_IPhysicsController ,public CcdPhysicsController { +private: + int m_savedCollisionFlags; + short int m_savedCollisionFilterGroup; + short int m_savedCollisionFilterMask; + MT_Scalar m_savedMass; public: @@ -30,7 +35,7 @@ public: virtual void SetAngularVelocity(const MT_Vector3& ang_vel,bool local); virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); @@ -39,7 +44,7 @@ public: virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); - virtual void SuspendDynamics(); + virtual void SuspendDynamics(bool ghost); virtual void RestoreDynamics(); virtual SG_Controller* GetReplica(class SG_Node* destnode); diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp index 27f4870de10..0a97b6f0a2f 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.cpp +++ b/source/gameengine/Ketsji/KX_CameraActuator.cpp @@ -49,7 +49,7 @@ STR_String KX_CameraActuator::Y_AXIS_STRING = "y"; KX_CameraActuator::KX_CameraActuator( SCA_IObject* gameobj, - CValue *obj, + SCA_IObject *obj, MT_Scalar hght, MT_Scalar minhght, MT_Scalar maxhght, @@ -63,11 +63,14 @@ KX_CameraActuator::KX_CameraActuator( m_maxHeight (maxhght), m_x (xytog) { + if (m_ob) + m_ob->RegisterActuator(this); } KX_CameraActuator::~KX_CameraActuator() { - //nothing to do + if (m_ob) + m_ob->UnregisterActuator(this); } CValue* @@ -81,9 +84,36 @@ GetReplica( return replica; }; +void KX_CameraActuator::ProcessReplica() +{ + if (m_ob) + m_ob->RegisterActuator(this); + SCA_IActuator::ProcessReplica(); +} +bool KX_CameraActuator::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; +} +void KX_CameraActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + 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); + } +} + /* three functions copied from blender arith... don't know if there's an equivalent */ static float Kx_Normalize(float *n) @@ -181,8 +211,14 @@ static void Kx_VecUpMat3(float *vec, float mat[][3], short axis) bool KX_CameraActuator::Update(double curtime, bool frame) { - bool result = true; + /* wondering... is it really neccesary/desirable to suppress negative */ + /* events here? */ + bool bNegativeEvent = IsNegativeEvent(); + RemoveAllEvents(); + if (bNegativeEvent || !m_ob) + return false; + KX_GameObject *obj = (KX_GameObject*) GetParent(); MT_Point3 from = obj->NodeGetWorldPosition(); MT_Matrix3x3 frommat = obj->NodeGetWorldOrientation(); @@ -195,13 +231,6 @@ bool KX_CameraActuator::Update(double curtime, bool frame) float mindistsq, maxdistsq, distsq; float mat[3][3]; - /* wondering... is it really neccesary/desirable to suppress negative */ - /* events here? */ - bool bNegativeEvent = IsNegativeEvent(); - RemoveAllEvents(); - - if (bNegativeEvent) return false; - /* The rules: */ /* CONSTRAINT 1: not implemented */ /* CONSTRAINT 2: can camera see actor? */ @@ -315,7 +344,7 @@ bool KX_CameraActuator::Update(double curtime, bool frame) actormat[2][0]= mat[0][2]; actormat[2][1]= mat[1][2]; actormat[2][2]= mat[2][2]; obj->NodeSetLocalOrientation(actormat); - return result; + return true; } CValue *KX_CameraActuator::findObject(char *obName) @@ -404,7 +433,11 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, PyObject* gameobj; if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj)) { - m_ob = (CValue*)gameobj; + if (m_ob) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)gameobj; + if (m_ob) + m_ob->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -412,10 +445,13 @@ PyObject* KX_CameraActuator::PySetObject(PyObject* self, char* objectname; if (PyArg_ParseTuple(args, "s", &objectname)) { - CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); + SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); if(object) { + if (m_ob != NULL) + m_ob->UnregisterActuator(this); m_ob = object; + m_ob->RegisterActuator(this); Py_Return; } } diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h index eb007e403ec..488b36922b0 100644 --- a/source/gameengine/Ketsji/KX_CameraActuator.h +++ b/source/gameengine/Ketsji/KX_CameraActuator.h @@ -49,7 +49,7 @@ class KX_CameraActuator : public SCA_IActuator Py_Header; private : /** Object that will be tracked. */ - CValue *m_ob; + SCA_IObject *m_ob; /** height (float), */ //const MT_Scalar m_height; @@ -87,7 +87,7 @@ private : SCA_IObject *gameobj, //const CValue *ob, - CValue *ob, + SCA_IObject *ob, MT_Scalar hght, MT_Scalar minhght, MT_Scalar maxhght, @@ -103,6 +103,7 @@ private : /** Methods Inherited from CValue */ CValue* GetReplica(); + virtual void ProcessReplica(); /** Methods inherited from SCA_IActuator */ @@ -110,7 +111,10 @@ private : double curtime, bool frame ); + virtual bool UnlinkObject(SCA_IObject* clientobj); + /** Methods inherited from SCA_ILogicBrick */ + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp index 80288a72485..e0b2efb3a25 100644 --- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp +++ b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp @@ -178,16 +178,18 @@ bool KX_ConstraintActuator::Update(double curtime, bool frame) direction[2] = rotation[2][1]; axis = 1; break; - case KX_ACT_CONSTRAINT_ORIZ: + default: direction[0] = rotation[0][2]; direction[1] = rotation[1][2]; direction[2] = rotation[2][2]; axis = 2; break; } - // apply damping on the direction if (m_posDampTime) { + // apply damping on the direction direction = filter*direction + (1.0-filter)*m_refDirection; + } else { + direction = m_refDirection; } obj->AlignAxisToVect(direction, axis); result = true; diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 2ac4f909077..d40fa1e2446 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -61,6 +61,8 @@ typedef unsigned long uint_ptr; #include "KX_RayCast.h" #include "KX_PythonInit.h" #include "KX_PyMath.h" +#include "SCA_IActuator.h" +#include "SCA_ISensor.h" // This file defines relationships between parents and children // in the game engine. @@ -222,6 +224,10 @@ void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj) RemoveParent(scene); obj->GetSGNode()->AddChild(GetSGNode()); + if (m_pPhysicsController1) + { + m_pPhysicsController1->SuspendDynamics(true); + } // Set us to our new scale, position, and orientation scale1[0] = scale1[0]/scale2[0]; scale1[1] = scale1[1]/scale2[1]; @@ -258,6 +264,10 @@ void KX_GameObject::RemoveParent(KX_Scene *scene) if (!rootlist->SearchValue(this)) // object was not in root list, add it now and increment ref count rootlist->Add(AddRef()); + if (m_pPhysicsController1) + { + m_pPhysicsController1->RestoreDynamics(); + } } } @@ -714,8 +724,12 @@ MT_Vector3 KX_GameObject::GetAngularVelocity(bool local) void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { + // don't update physic controller if the object is a child: + // 1) the transformation will not be right + // 2) in this case, the physic controller is necessarily a static object + // that is updated from the normal kinematic synchronization m_pPhysicsController1->setPosition(trans); } @@ -727,25 +741,22 @@ void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans) void KX_GameObject::NodeSetLocalOrientation(const MT_Matrix3x3& rot) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { - m_pPhysicsController1->setOrientation(rot.getRotation()); + // see note above + m_pPhysicsController1->setOrientation(rot); } if (GetSGNode()) GetSGNode()->SetLocalOrientation(rot); - else - { - int i; - i=0; - } } void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale) { - if (m_pPhysicsController1) + if (m_pPhysicsController1 && (!GetSGNode() || !GetSGNode()->GetSGParent())) { + // see note above m_pPhysicsController1->setScaling(scale); } @@ -832,7 +843,7 @@ void KX_GameObject::Resume(void) } } -void KX_GameObject::Suspend(void) +void KX_GameObject::Suspend() { if ((!m_ignore_activity_culling) && (!m_suspended)) { @@ -875,6 +886,8 @@ PyMethodDef KX_GameObject::Methods[] = { {"getParent", (PyCFunction)KX_GameObject::sPyGetParent,METH_NOARGS}, {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_O}, {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS}, + {"getChildren", (PyCFunction)KX_GameObject::sPyGetChildren,METH_NOARGS}, + {"getChildrenRecursive", (PyCFunction)KX_GameObject::sPyGetChildrenRecursive,METH_NOARGS}, {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS}, {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS}, {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS}, @@ -1292,6 +1305,43 @@ PyObject* KX_GameObject::PyRemoveParent(PyObject* self) Py_RETURN_NONE; } + +static void walk_children(SG_Node* node, PyObject *list, bool recursive) +{ + NodeList& children = node->GetSGChildren(); + + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* childnode = (*childit); + KX_GameObject* childobj = (KX_GameObject*)childnode->GetSGClientObject(); + if (childobj != NULL) // This is a GameObject + { + // add to the list + PyList_Append(list, (PyObject *)childobj); + } + + // if the childobj is NULL then this may be an inverse parent link + // so a non recursive search should still look down this node. + if (recursive || childobj==NULL) { + walk_children(childnode, list, recursive); + } + } +} + +PyObject* KX_GameObject::PyGetChildren(PyObject* self) +{ + PyObject * list = PyList_New(0); + walk_children(m_pSGNode, list, 0); + return list; +} + +PyObject* KX_GameObject::PyGetChildrenRecursive(PyObject* self) +{ + PyObject * list = PyList_New(0); + walk_children(m_pSGNode, list, 1); + return list; +} + PyObject* KX_GameObject::PyGetMesh(PyObject* self, PyObject* args, PyObject* kwds) @@ -1660,6 +1710,20 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, * --------------------------------------------------------------------- */ void KX_GameObject::Relink(GEN_Map<GEN_HashedPtr, void*> *map_parameter) { - /* intentionally empty ? */ + // we will relink the sensors and actuators that use object references + // if the object is part of the replicated hierarchy, use the new + // object reference instead + SCA_SensorList& sensorlist = GetSensors(); + SCA_SensorList::iterator sit; + for (sit=sensorlist.begin(); sit != sensorlist.end(); sit++) + { + (*sit)->Relink(map_parameter); + } + SCA_ActuatorList& actuatorlist = GetActuators(); + SCA_ActuatorList::iterator ait; + for (ait=actuatorlist.begin(); ait != actuatorlist.end(); ait++) + { + (*ait)->Relink(map_parameter); + } } diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index ddbf863aa1a..6051cf850b5 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -47,6 +47,7 @@ #include "KX_Scene.h" #include "KX_KetsjiEngine.h" /* for m_anim_framerate */ #include "KX_IPhysicsController.h" /* for suspend/resume */ +#include "DNA_object_types.h" #define KX_OB_DYNAMIC 1 @@ -392,6 +393,13 @@ public: m_pBlenderObject = obj; } + bool IsDupliGroup() + { + return (m_pBlenderObject && + (m_pBlenderObject->transflag & OB_DUPLIGROUP) && + m_pBlenderObject->dup_group != NULL) ? true : false; + } + /** * Set the Scene graph node for this game object. * warning - it is your responsibility to make sure @@ -738,6 +746,8 @@ public: KX_PYMETHOD_NOARGS(KX_GameObject,GetParent); KX_PYMETHOD_O(KX_GameObject,SetParent); KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent); + KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren); + KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive); KX_PYMETHOD(KX_GameObject,GetMesh); KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId); KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames); diff --git a/source/gameengine/Ketsji/KX_IPhysicsController.h b/source/gameengine/Ketsji/KX_IPhysicsController.h index 2ec66a883eb..ecfdb8c4275 100644 --- a/source/gameengine/Ketsji/KX_IPhysicsController.h +++ b/source/gameengine/Ketsji/KX_IPhysicsController.h @@ -71,14 +71,15 @@ public: virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0; virtual void getOrientation(MT_Quaternion& orn)=0; - virtual void setOrientation(const MT_Quaternion& orn)=0; + virtual void setOrientation(const MT_Matrix3x3& orn)=0; + //virtual void setOrientation(const MT_Quaternion& orn)=0; virtual void setPosition(const MT_Point3& pos)=0; virtual void setScaling(const MT_Vector3& scaling)=0; virtual MT_Scalar GetMass()=0; virtual MT_Vector3 getReactionForce()=0; virtual void setRigidBody(bool rigid)=0; - virtual void SuspendDynamics()=0; + virtual void SuspendDynamics(bool ghost=false)=0; virtual void RestoreDynamics()=0; virtual SG_Controller* GetReplica(class SG_Node* destnode)=0; diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp index 4e45ce484e3..05feb11a2bc 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.cpp @@ -133,8 +133,9 @@ void KX_OdePhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool l ODEPhysicsController::SetLinearVelocity(lin_vel[0],lin_vel[1],lin_vel[2],local); } -void KX_OdePhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_OdePhysicsController::setOrientation(const MT_Matrix3x3& rot) { + MT_Quaternion orn = rot.getRotation(); ODEPhysicsController::setOrientation(orn[0],orn[1],orn[2],orn[3]); } @@ -177,7 +178,7 @@ void KX_OdePhysicsController::setRigidBody(bool rigid) } -void KX_OdePhysicsController::SuspendDynamics() +void KX_OdePhysicsController::SuspendDynamics(bool) { ODEPhysicsController::SuspendDynamics(); } diff --git a/source/gameengine/Ketsji/KX_OdePhysicsController.h b/source/gameengine/Ketsji/KX_OdePhysicsController.h index 07a0bee9775..18f9edc6835 100644 --- a/source/gameengine/Ketsji/KX_OdePhysicsController.h +++ b/source/gameengine/Ketsji/KX_OdePhysicsController.h @@ -67,14 +67,14 @@ public: virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local); virtual void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); virtual MT_Scalar GetMass(); virtual MT_Vector3 getReactionForce(); virtual void setRigidBody(bool rigid); - virtual void SuspendDynamics(); + virtual void SuspendDynamics(bool); virtual void RestoreDynamics(); diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp index 8b379bcd44f..fd1b56838e2 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.cpp +++ b/source/gameengine/Ketsji/KX_ParentActuator.cpp @@ -46,19 +46,22 @@ KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj, int mode, - CValue *ob, + SCA_IObject *ob, PyTypeObject* T) : SCA_IActuator(gameobj, T), m_mode(mode), m_ob(ob) { + if (m_ob) + m_ob->RegisterActuator(this); } KX_ParentActuator::~KX_ParentActuator() { - /* intentionally empty */ + if (m_ob) + m_ob->UnregisterActuator(this); } @@ -73,6 +76,36 @@ CValue* KX_ParentActuator::GetReplica() return replica; } +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; +} + +void KX_ParentActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + 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); + } +} + bool KX_ParentActuator::Update() @@ -87,7 +120,8 @@ bool KX_ParentActuator::Update() KX_Scene *scene = PHY_GetActiveScene(); switch (m_mode) { case KX_PARENT_SET: - obj->SetParent(scene, (KX_GameObject*)m_ob); + if (m_ob) + obj->SetParent(scene, (KX_GameObject*)m_ob); break; case KX_PARENT_REMOVE: obj->RemoveParent(scene); @@ -148,7 +182,11 @@ PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* args, PyObjec PyObject* gameobj; if (PyArg_ParseTuple(args, "O!", &KX_GameObject::Type, &gameobj)) { - m_ob = (CValue*)gameobj; + if (m_ob != NULL) + m_ob->UnregisterActuator(this); + m_ob = (SCA_IObject*)gameobj; + if (m_ob) + m_ob->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -156,10 +194,13 @@ PyObject* KX_ParentActuator::PySetObject(PyObject* self, PyObject* args, PyObjec char* objectname; if (PyArg_ParseTuple(args, "s", &objectname)) { - CValue *object = (CValue*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); + SCA_IObject *object = (SCA_IObject*)SCA_ILogicBrick::m_sCurrentLogicManager->GetGameObjectByName(STR_String(objectname)); if(object) { + if (m_ob != NULL) + m_ob->UnregisterActuator(this); m_ob = object; + m_ob->RegisterActuator(this); Py_Return; } } diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h index 86dcd4e6c12..93b07cd424b 100644 --- a/source/gameengine/Ketsji/KX_ParentActuator.h +++ b/source/gameengine/Ketsji/KX_ParentActuator.h @@ -47,7 +47,7 @@ class KX_ParentActuator : public SCA_IActuator int m_mode; /** Object to set as parent */ - CValue *m_ob; + SCA_IObject *m_ob; @@ -62,12 +62,15 @@ class KX_ParentActuator : public SCA_IActuator KX_ParentActuator(class SCA_IObject* gameobj, int mode, - CValue *ob, + SCA_IObject *ob, PyTypeObject* T=&Type); virtual ~KX_ParentActuator(); virtual bool Update(); virtual CValue* GetReplica(); + virtual void ProcessReplica(); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); + virtual bool UnlinkObject(SCA_IObject* clientobj); /* --------------------------------------------------------------------- */ /* Python interface ---------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp index 9dab09f8f2a..de4979ac4c9 100644 --- a/source/gameengine/Ketsji/KX_RadarSensor.cpp +++ b/source/gameengine/Ketsji/KX_RadarSensor.cpp @@ -80,10 +80,7 @@ CValue* KX_RadarSensor::GetReplica() { KX_RadarSensor* replica = new KX_RadarSensor(*this); replica->m_colliders = new CListValue(); - replica->m_bCollision = false; - replica->m_bTriggered= false; - replica->m_hitObject = NULL; - replica->m_bLastTriggered = false; + replica->Init(); // this will copy properties and so on... CValue::AddDataToReplica(replica); @@ -179,8 +176,10 @@ void KX_RadarSensor::SynchronizeTransform() if (m_physCtrl) { - m_physCtrl->setPosition(trans.getOrigin().x(),trans.getOrigin().y(),trans.getOrigin().z()); - m_physCtrl->setOrientation(trans.getRotation().x(),trans.getRotation().y(),trans.getRotation().z(),trans.getRotation().w()); + MT_Quaternion orn = trans.getRotation(); + MT_Point3 pos = trans.getOrigin(); + m_physCtrl->setPosition(pos[0],pos[1],pos[2]); + m_physCtrl->setOrientation(orn[0],orn[1],orn[2],orn[3]); m_physCtrl->calcXform(); } diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp index e5ee4cbddf1..e36891b56f4 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp @@ -137,6 +137,17 @@ bool KX_SCA_AddObjectActuator::UnlinkObject(SCA_IObject* clientobj) return false; } +void KX_SCA_AddObjectActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_OriginalObject]; + if (h_obj) { + if (m_OriginalObject) + m_OriginalObject->UnregisterActuator(this); + m_OriginalObject = (SCA_IObject*)(*h_obj); + m_OriginalObject->RegisterActuator(this); + } +} + /* ------------------------------------------------------------------------- */ /* Python functions */ diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h index 42123b94a68..1359f39278d 100644 --- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h +++ b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h @@ -95,6 +95,9 @@ public: virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void + Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); + virtual bool Update(); diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp index 065800379d8..c374b9d6fd1 100644 --- a/source/gameengine/Ketsji/KX_Scene.cpp +++ b/source/gameengine/Ketsji/KX_Scene.cpp @@ -66,6 +66,8 @@ #include "SG_Controller.h" #include "SG_IObject.h" #include "SG_Tree.h" +#include "DNA_group_types.h" +#include "BKE_anim.h" #include "KX_SG_NodeRelationships.h" @@ -429,6 +431,11 @@ void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gam KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CValue* gameobj) { + // for group duplication, limit the duplication of the hierarchy to the + // objects that are part of the group. + if (!IsObjectInGroup(gameobj)) + return NULL; + KX_GameObject* orgobj = (KX_GameObject*)gameobj; KX_GameObject* newobj = (KX_GameObject*)orgobj->GetReplica(); m_map_gameobject_to_replica.insert(orgobj, newobj); @@ -506,6 +513,11 @@ KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CVal // hierarchy that's because first ALL bricks must exist in the new // replica of the hierarchy in order to make cross-links work properly // ! +// It is VERY important that the order of sensors and actuators in +// the replicated object is preserved: it is is used to reconnect the logic. +// This method is more robust then using the bricks name in case of complex +// group replication. The replication of logic bricks is done in +// SCA_IObject::ReParentLogic(), make sure it preserves the order of the bricks. void KX_Scene::ReplicateLogic(KX_GameObject* newobj) { // also relink the controller to sensors/actuators @@ -528,37 +540,38 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) for (vector<SCA_ISensor*>::iterator its = linkedsensors.begin();!(its==linkedsensors.end());its++) { SCA_ISensor* oldsensor = (*its); - STR_String name = oldsensor->GetName(); - //find this name in the list - SCA_ISensor* newsensor = newobj->FindSensor(name); + SCA_IObject* oldsensorobj = oldsensor->GetParent(); + SCA_IObject* newsensorobj = NULL; - if (newsensor) + // the original owner of the sensor has been replicated? + void **h_obj = m_map_gameobject_to_replica[oldsensorobj]; + if (h_obj) + newsensorobj = (SCA_IObject*)(*h_obj); + if (!newsensorobj) { - // relink this newsensor to the controller - m_logicmgr->RegisterToSensor(cont,newsensor); + // no, then the sensor points outside the hierachy, keep it the same + if (m_objectlist->SearchValue(oldsensorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToSensor(cont,oldsensor); } else { - // it can be linked somewhere in the hierarchy or... - for (vector<KX_GameObject*>::iterator git = m_logicHierarchicalGameObjects.begin(); - !(git==m_logicHierarchicalGameObjects.end());++git) - { - newsensor = (*git)->FindSensor(name); - if (newsensor) - break; - } + // yes, then the new sensor has the same position + SCA_SensorList& sensorlist = oldsensorobj->GetSensors(); + SCA_SensorList::iterator sit; + SCA_ISensor* newsensor = NULL; + int sensorpos; - if (newsensor) - { - // relink this newsensor to the controller somewhere else within this - // hierarchy - m_logicmgr->RegisterToSensor(cont,newsensor); - } - else + for (sensorpos=0, sit=sensorlist.begin(); sit!=sensorlist.end(); sit++, sensorpos++) { - // must be an external sensor, so... - m_logicmgr->RegisterToSensor(cont,oldsensor); + if ((*sit) == oldsensor) + { + newsensor = newsensorobj->GetSensors().at(sensorpos); + break; + } } + assert(newsensor != NULL); + m_logicmgr->RegisterToSensor(cont,newsensor); } } @@ -566,38 +579,40 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) for (vector<SCA_IActuator*>::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());ita++) { SCA_IActuator* oldactuator = (*ita); - STR_String name = oldactuator->GetName(); - //find this name in the list - SCA_IActuator* newactuator = newobj->FindActuator(name); - if (newactuator) + SCA_IObject* oldactuatorobj = oldactuator->GetParent(); + SCA_IObject* newactuatorobj = NULL; + + // the original owner of the sensor has been replicated? + void **h_obj = m_map_gameobject_to_replica[oldactuatorobj]; + if (h_obj) + newactuatorobj = (SCA_IObject*)(*h_obj); + + if (!newactuatorobj) { - // relink this newsensor to the controller - m_logicmgr->RegisterToActuator(cont,newactuator); - newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); + // no, then the sensor points outside the hierachy, keep it the same + if (m_objectlist->SearchValue(oldactuatorobj)) + // only replicate links that points to active objects + m_logicmgr->RegisterToActuator(cont,oldactuator); } else { - // it can be linked somewhere in the hierarchy or... - for (vector<KX_GameObject*>::iterator git = m_logicHierarchicalGameObjects.begin(); - !(git==m_logicHierarchicalGameObjects.end());++git) - { - newactuator= (*git)->FindActuator(name); - if (newactuator) - break; - } + // yes, then the new sensor has the same position + SCA_ActuatorList& actuatorlist = oldactuatorobj->GetActuators(); + SCA_ActuatorList::iterator ait; + SCA_IActuator* newactuator = NULL; + int actuatorpos; - if (newactuator) + for (actuatorpos=0, ait=actuatorlist.begin(); ait!=actuatorlist.end(); ait++, actuatorpos++) { - // relink this actuator to the controller somewhere else within this - // hierarchy - m_logicmgr->RegisterToActuator(cont,newactuator); - newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); - } - else - { - // must be an external actuator, so... - m_logicmgr->RegisterToActuator(cont,oldactuator); + if ((*ait) == oldactuator) + { + newactuator = newactuatorobj->GetActuators().at(actuatorpos); + break; + } } + assert(newactuator != NULL); + m_logicmgr->RegisterToActuator(cont,newactuator); + newactuator->SetUeberExecutePriority(m_ueberExecutionPriority); } } } @@ -605,6 +620,150 @@ void KX_Scene::ReplicateLogic(KX_GameObject* newobj) newobj->ResetState(); } +void KX_Scene::DupliGroupRecurse(CValue* obj, int level) +{ + KX_GameObject* groupobj = (KX_GameObject*) obj; + KX_GameObject* replica; + KX_GameObject* gameobj; + Object* blgroupobj = groupobj->GetBlenderObject(); + Group* group; + GroupObject *go; + vector<KX_GameObject*> duplilist; + + if (!groupobj->IsDupliGroup() || + level>MAX_DUPLI_RECUR) + return; + + // we will add one group at a time + m_logicHierarchicalGameObjects.clear(); + m_map_gameobject_to_replica.clear(); + m_ueberExecutionPriority++; + // for groups will do something special: + // we will force the creation of objects to those in the group only + // Again, this is match what Blender is doing (it doesn't care of parent relationship) + m_groupGameObjects.clear(); + + group = blgroupobj->dup_group; + for(go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next) + { + Object* blenderobj = go->ob; + if (blgroupobj == blenderobj) + // this check is also in group_duplilist() + continue; + gameobj = m_sceneConverter->FindGameObject(blenderobj); + if (gameobj == NULL) + { + // this object has not been converted!!! + // Should not happen as dupli group are created automatically + continue; + } + if (blenderobj->lay & group->layer==0) + { + // object is not visible in the 3D view, will not be instantiated + continue; + } + m_groupGameObjects.insert(gameobj); + } + + set<CValue*>::iterator oit; + for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++) + { + gameobj = (KX_GameObject*)(*oit); + if (gameobj->GetParent() != NULL) + { + // this object is not a top parent. Either it is the child of another + // object in the group and it will be added automatically when the parent + // is added. Or it is the child of an object outside the group and the group + // is inconsistent, skip it anyway + continue; + } + replica = (KX_GameObject*) AddNodeReplicaObject(NULL,gameobj); + // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame) + m_parentlist->Add(replica->AddRef()); + + // recurse replication into children nodes + NodeList& children = gameobj->GetSGNode()->GetSGChildren(); + + replica->GetSGNode()->ClearSGChildren(); + for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) + { + SG_Node* orgnode = (*childit); + SG_Node* childreplicanode = orgnode->GetSGReplica(); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); + } + // don't replicate logic now: we assume that the objects in the group can have + // logic relationship, even outside parent relationship + // In order to match 3D view, the position of groupobj is used as a + // transformation matrix instead of the new position. This means that + // the group reference point is 0,0,0 + + // get the rootnode's scale + MT_Vector3 newscale = groupobj->NodeGetWorldScaling(); + // set the replica's relative scale with the rootnode's scale + replica->NodeSetRelativeScale(newscale); + + MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldOrientation(); + replica->NodeSetLocalOrientation(newori); + + MT_Point3 newpos = groupobj->NodeGetWorldPosition() + + newscale*(groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldPosition()); + replica->NodeSetLocalPosition(newpos); + + if (replica->GetPhysicsController()) + { + // not required, already done in NodeSetLocalOrientation.. + //replica->GetPhysicsController()->setPosition(newpos); + //replica->GetPhysicsController()->setOrientation(newori.getRotation()); + // Scaling has been set relatively hereabove, this does not + // set the scaling of the controller. I don't know why it's just the + // relative scale and not the full scale that has to be put here... + replica->GetPhysicsController()->setScaling(newscale); + } + + replica->GetSGNode()->UpdateWorldData(0); + replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox()); + replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius()); + // done with replica + replica->Release(); + } + + // the logic must be replicated first because we need + // the new logic bricks before relinking + vector<KX_GameObject*>::iterator git; + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + (*git)->ReParentLogic(); + } + + // relink any pointers as necessary, sort of a temporary solution + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + // this will also relink the actuator to objects within the hierarchy + (*git)->Relink(&m_map_gameobject_to_replica); + // add the object in the layer of the parent + (*git)->SetLayer(groupobj->GetLayer()); + } + + // replicate crosslinks etc. between logic bricks + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + ReplicateLogic((*git)); + } + + // now look if object in the hierarchy have dupli group and recurse + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + if ((*git) != groupobj && (*git)->IsDupliGroup()) + // can't instantiate group immediately as it destroys m_logicHierarchicalGameObjects + duplilist.push_back((*git)); + } + + for (git = duplilist.begin(); !(git == duplilist.end()); ++git) + { + DupliGroupRecurse((*git), level+1); + } +} SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, @@ -614,6 +773,7 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, m_logicHierarchicalGameObjects.clear(); m_map_gameobject_to_replica.clear(); + m_groupGameObjects.clear(); // todo: place a timebomb in the object, for temporarily objects :) // lifespan of zero means 'this object lives forever' @@ -647,24 +807,26 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, { SG_Node* orgnode = (*childit); SG_Node* childreplicanode = orgnode->GetSGReplica(); - replica->GetSGNode()->AddChild(childreplicanode); + if (childreplicanode) + replica->GetSGNode()->AddChild(childreplicanode); } - // relink any pointers as necessary, sort of a temporary solution + // now replicate logic vector<KX_GameObject*>::iterator git; for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) { + (*git)->ReParentLogic(); + } + + // relink any pointers as necessary, sort of a temporary solution + for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) + { + // this will also relink the actuators in the hierarchy (*git)->Relink(&m_map_gameobject_to_replica); // add the object in the layer of the parent (*git)->SetLayer(parentobj->GetLayer()); } - // now replicate logic - for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) - { - (*git)->ReParentLogic(); - } - // replicate crosslinks etc. between logic bricks for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git) { @@ -685,8 +847,9 @@ SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject, if (replica->GetPhysicsController()) { - replica->GetPhysicsController()->setPosition(newpos); - replica->GetPhysicsController()->setOrientation(newori.getRotation()); + // not needed, already done in NodeSetLocalPosition() + //replica->GetPhysicsController()->setPosition(newpos); + //replica->GetPhysicsController()->setOrientation(newori.getRotation()); replica->GetPhysicsController()->setScaling(newscale); } diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h index 28dee1b5893..80a2abe287a 100644 --- a/source/gameengine/Ketsji/KX_Scene.h +++ b/source/gameengine/Ketsji/KX_Scene.h @@ -216,6 +216,16 @@ protected: */ std::vector<KX_GameObject*> m_logicHierarchicalGameObjects; + /** + * This temporary variable will contain the list of + * object that can be added during group instantiation. + * objects outside this list will not be added (can + * happen with children that are outside the group). + * Used in AddReplicaObject. If the list is empty, it + * means don't care. + */ + std::set<CValue*> m_groupGameObjects; + /** * Pointer to system variable passed in in constructor * only used in constructor so we do not need to keep it @@ -291,6 +301,12 @@ public: * Update all transforms according to the scenegraph. */ void UpdateParents(double curtime); + void DupliGroupRecurse(CValue* gameobj, int level); + bool IsObjectInGroup(CValue* gameobj) + { + return (m_groupGameObjects.empty() || + m_groupGameObjects.find(gameobj) != m_groupGameObjects.end()); + } SCA_IObject* AddReplicaObject(CValue* gameobj, CValue* locationobj, int lifespan=0); diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp index 8f7cffd506f..d6164dc812a 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.cpp +++ b/source/gameengine/Ketsji/KX_SceneActuator.cpp @@ -58,13 +58,16 @@ KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj, m_KetsjiEngine=ketsjiEngine; m_camera = camera; m_nextSceneName = nextSceneName; + if (m_camera) + m_camera->RegisterActuator(this); } /* End of constructor */ KX_SceneActuator::~KX_SceneActuator() { - // there's nothing to be done here, really.... + if (m_camera) + m_camera->UnregisterActuator(this); } /* end of destructor */ @@ -79,6 +82,34 @@ CValue* KX_SceneActuator::GetReplica() return replica; } +void KX_SceneActuator::ProcessReplica() +{ + if (m_camera) + m_camera->RegisterActuator(this); + SCA_IActuator::ProcessReplica(); +} + +bool KX_SceneActuator::UnlinkObject(SCA_IObject* clientobj) +{ + if (clientobj == (SCA_IObject*)m_camera) + { + // this object is being deleted, we cannot continue to track it. + m_camera = NULL; + return true; + } + return false; +} + +void KX_SceneActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + void **h_obj = (*obj_map)[m_camera]; + if (h_obj) { + if (m_camera) + m_camera->UnregisterActuator(this); + m_camera = (KX_Camera*)(*h_obj); + m_camera->RegisterActuator(this); + } +} bool KX_SceneActuator::Update() @@ -332,7 +363,11 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, PyObject *cam; if (PyArg_ParseTuple(args, "O!", &KX_Camera::Type, &cam)) { + if (m_camera) + m_camera->UnregisterActuator(this); m_camera = (KX_Camera*) cam; + if (m_camera) + m_camera->RegisterActuator(this); Py_Return; } PyErr_Clear(); @@ -345,7 +380,13 @@ PyObject* KX_SceneActuator::PySetCamera(PyObject* self, } KX_Camera *camOb = FindCamera(camName); - if (camOb) m_camera = camOb; + if (camOb) + { + if (m_camera) + m_camera->UnregisterActuator(this); + m_camera = camOb; + m_camera->RegisterActuator(this); + } Py_Return; } diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h index cfc79b93f8e..55aaf629d7c 100644 --- a/source/gameengine/Ketsji/KX_SceneActuator.h +++ b/source/gameengine/Ketsji/KX_SceneActuator.h @@ -82,6 +82,9 @@ class KX_SceneActuator : public SCA_IActuator virtual ~KX_SceneActuator(); virtual CValue* GetReplica(); + virtual void ProcessReplica(); + virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); virtual bool Update(); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp index 6ea5461dbaa..4032a795ce3 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.cpp @@ -101,7 +101,7 @@ void KX_SumoPhysicsController::SetSumoTransform(bool nondynaonly) } -void KX_SumoPhysicsController::SuspendDynamics() +void KX_SumoPhysicsController::SuspendDynamics(bool) { SumoPhysicsController::SuspendDynamics(); } @@ -170,8 +170,9 @@ void KX_SumoPhysicsController::setMargin(float collisionMargin) } -void KX_SumoPhysicsController::setOrientation(const MT_Quaternion& orn) +void KX_SumoPhysicsController::setOrientation(const MT_Matrix3x3& rot) { + MT_Quaternion orn = rot.getRotation(); SumoPhysicsController::setOrientation( orn[0],orn[1],orn[2],orn[3]); diff --git a/source/gameengine/Ketsji/KX_SumoPhysicsController.h b/source/gameengine/Ketsji/KX_SumoPhysicsController.h index 8c061ae4056..1dd930bf3d9 100644 --- a/source/gameengine/Ketsji/KX_SumoPhysicsController.h +++ b/source/gameengine/Ketsji/KX_SumoPhysicsController.h @@ -76,10 +76,10 @@ public: void resolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ); - void SuspendDynamics(); + void SuspendDynamics(bool); void RestoreDynamics(); virtual void getOrientation(MT_Quaternion& orn); - virtual void setOrientation(const MT_Quaternion& orn); + virtual void setOrientation(const MT_Matrix3x3& orn); virtual void setPosition(const MT_Point3& pos); virtual void setScaling(const MT_Vector3& scaling); diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp index 731a610c2eb..c580aa4d4e5 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp +++ b/source/gameengine/Ketsji/KX_TrackToActuator.cpp @@ -210,6 +210,18 @@ bool KX_TrackToActuator::UnlinkObject(SCA_IObject* clientobj) return false; } +void KX_TrackToActuator::Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map) +{ + 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); + } +} + + bool KX_TrackToActuator::Update(double curtime, bool frame) { bool result = false; diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h index a03aa115baa..1d1cf46d21b 100644 --- a/source/gameengine/Ketsji/KX_TrackToActuator.h +++ b/source/gameengine/Ketsji/KX_TrackToActuator.h @@ -68,6 +68,7 @@ class KX_TrackToActuator : public SCA_IActuator virtual void ProcessReplica(); virtual bool UnlinkObject(SCA_IObject* clientobj); + virtual void Relink(GEN_Map<GEN_HashedPtr, void*> *obj_map); virtual bool Update(double curtime, bool frame); /* Python part */ |