From 8997e5ae0676382b7f2afb59d04819f4c926a330 Mon Sep 17 00:00:00 2001 From: Mitchell Stokes Date: Mon, 11 Feb 2013 18:29:19 +0000 Subject: [PATCH] BGE: Fix for issue #32606 "Raycasts are locked to the scene of calling object" reported by Josiah Lane (solarlune). The raycasting functions were using the active scene instead of the object's scene. --- source/gameengine/Ketsji/KX_GameObject.cpp | 18 ++++++++++++------ source/gameengine/Ketsji/KX_GameObject.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index 63854c6aebd..3a60ccc85e9 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -1400,6 +1400,14 @@ CListValue* KX_GameObject::GetChildrenRecursive() return list; } +KX_Scene* KX_GameObject::GetScene() +{ + SG_Node* node = this->GetSGNode(); + KX_Scene* scene = static_cast(node->GetSGClientInfo()); + + return scene; +} + /* --------------------------------------------------------------------- * Some stuff taken from the header * --------------------------------------------------------------------- */ @@ -1754,8 +1762,7 @@ PyObject *KX_GameObject::PyReplaceMesh(PyObject *args) PyObject *KX_GameObject::PyEndObject() { - SG_Node* node = this->GetSGNode(); - KX_Scene* scene = static_cast(node->GetSGClientInfo()); + KX_Scene* scene = GetScene(); scene->DelayedRemoveObject(this); @@ -2003,8 +2010,7 @@ PyObject *KX_GameObject::pyattr_get_group_members(void *self_v, const KX_PYATTRI PyObject* KX_GameObject::pyattr_get_scene(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef) { KX_GameObject *self = static_cast(self_v); - SG_Node *node = self->GetSGNode(); - KX_Scene *scene = static_cast(node->GetSGClientInfo()); + KX_Scene *scene = self->GetScene(); if (scene) { return scene->GetProxy(); } @@ -3056,7 +3062,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, if (dist != 0.0f) toPoint = fromPoint + dist * (toPoint-fromPoint).safe_normalized(); - PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment(); + PHY_IPhysicsEnvironment* pe = GetScene()->GetPhysicsEnvironment(); KX_IPhysicsController *spc = GetPhysicsController(); KX_GameObject *parent = GetParent(); if (!spc && parent) @@ -3202,7 +3208,7 @@ KX_PYMETHODDEF_DOC(KX_GameObject, rayCast, return none_tuple_3(); } - PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment(); + PHY_IPhysicsEnvironment* pe = GetScene()->GetPhysicsEnvironment(); KX_IPhysicsController *spc = GetPhysicsController(); KX_GameObject *parent = GetParent(); if (!spc && parent) diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index 253b5e26ebe..86c712ea017 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -923,6 +923,8 @@ public: CListValue* GetChildren(); CListValue* GetChildrenRecursive(); + KX_Scene* GetScene(); + #ifdef WITH_PYTHON /** * \section Python interface functions.