diff options
Diffstat (limited to 'source/gameengine/Ketsji')
-rw-r--r-- | source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp | 13 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.cpp | 83 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_GameObject.h | 22 |
3 files changed, 113 insertions, 5 deletions
diff --git a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp index 465a021cd43..ebbca137c5a 100644 --- a/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp +++ b/source/gameengine/Ketsji/KX_ConvertPhysicsObjects.cpp @@ -888,6 +888,10 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, { ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT; } + if (objprop->m_ghost) + { + ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE; + } ci.m_MotionState = motionstate; ci.m_gravity = btVector3(0,0,0); @@ -1141,10 +1145,11 @@ void KX_ConvertBulletObject( class KX_GameObject* gameobj, if (objprop->m_disableSleeping) rbody->setActivationState(DISABLE_DEACTIVATION); - if (objprop->m_ghost) - { - rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); - } + //Now done directly in ci.m_collisionFlags so that it propagates to replica + //if (objprop->m_ghost) + //{ + // rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE); + //} if (objprop->m_dyna && !objprop->m_angular_rigidbody) { /* diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp index bc608d26c50..6f172a11005 100644 --- a/source/gameengine/Ketsji/KX_GameObject.cpp +++ b/source/gameengine/Ketsji/KX_GameObject.cpp @@ -61,6 +61,7 @@ typedef unsigned long uint_ptr; #include "SG_Controller.h" #include "KX_ClientObjectInfo.h" #include "RAS_BucketManager.h" +#include "KX_RayCast.h" #include "KX_PyMath.h" @@ -80,7 +81,9 @@ KX_GameObject::KX_GameObject( m_bUseObjectColor(false), m_bVisible(true), m_pPhysicsController1(NULL), - m_isDeformable(false) + m_pPhysicsEnvironment(NULL), + m_isDeformable(false), + m_pHitObject(NULL) { m_ignore_activity_culling = false; m_pClient_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR); @@ -657,6 +660,7 @@ PyMethodDef KX_GameObject::Methods[] = { {"getMesh", (PyCFunction)KX_GameObject::sPyGetMesh,METH_VARARGS}, {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_VARARGS}, KX_PYMETHODTABLE(KX_GameObject, getDistanceTo), + KX_PYMETHODTABLE(KX_GameObject, rayCastTo), {NULL,NULL} //Sentinel }; @@ -1176,6 +1180,83 @@ KX_PYMETHODDEF_DOC(KX_GameObject, getDistanceTo, return NULL; } +bool KX_GameObject::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data) +{ + + KX_GameObject* hitKXObj = client->m_gameobject; + + if (client->m_type > KX_ClientObjectInfo::ACTOR) + { + // false hit + return false; + } + + if (m_testPropName.Length() == 0 || hitKXObj->GetProperty(m_testPropName) != NULL) + { + m_pHitObject = hitKXObj; + return true; + } + + return false; + +} + +KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo, +"rayCastTo(other,dist,prop): look towards another point/KX_GameObject and return first object hit within dist that match prop\n" +" prop = property name that object must have; can be omitted => detect any object\n" +" dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to other\n" +" other = 3-tuple or object reference") +{ + MT_Point3 toPoint; + PyObject* pyarg; + float dist = 0.0f; + char *propName = NULL; + + if (!PyArg_ParseTuple(args,"O|fs", &pyarg, &dist, &propName)) + return NULL; + + if (!PyVecTo(pyarg, toPoint)) + { + KX_GameObject *other; + PyErr_Clear(); + if (!PyType_IsSubtype(pyarg->ob_type, &KX_GameObject::Type)) + return NULL; + other = static_cast<KX_GameObject*>(pyarg); + toPoint = other->NodeGetWorldPosition(); + } + MT_Point3 fromPoint = NodeGetWorldPosition(); + if (dist != 0.0f) + { + MT_Vector3 toDir = toPoint-fromPoint; + toDir.normalize(); + toPoint = fromPoint + (dist) * toDir; + } + + MT_Point3 resultPoint; + MT_Vector3 resultNormal; + PHY_IPhysicsEnvironment* pe = GetPhysicsEnvironment(); + KX_IPhysicsController *spc = GetPhysicsController(); + KX_GameObject *parent = GetParent(); + if (!spc && parent) + spc = parent->GetPhysicsController(); + if (parent) + parent->Release(); + + m_pHitObject = NULL; + if (propName) + m_testPropName = propName; + else + m_testPropName.SetLength(0); + KX_RayCast::RayTest(spc, pe, fromPoint, toPoint, resultPoint, resultNormal, KX_RayCast::Callback<KX_GameObject>(this)); + + if (m_pHitObject) + { + m_pHitObject->AddRef(); + return m_pHitObject; + } + Py_Return; +} + /* --------------------------------------------------------------------- * Some stuff taken from the header * --------------------------------------------------------------------- */ diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h index db910a46a81..945b769d8be 100644 --- a/source/gameengine/Ketsji/KX_GameObject.h +++ b/source/gameengine/Ketsji/KX_GameObject.h @@ -57,6 +57,7 @@ struct KX_ClientObjectInfo; class RAS_MeshObject; class KX_IPhysicsController; +class PHY_IPhysicsEnvironment; /** @@ -82,6 +83,11 @@ protected: bool m_bVisible; KX_IPhysicsController* m_pPhysicsController1; + // used for ray casting + PHY_IPhysicsEnvironment* m_pPhysicsEnvironment; + STR_String m_testPropName; + KX_GameObject* m_pHitObject; + SG_Node* m_pSGNode; MT_CmMatrix4x4 m_OpenGL_4x4Matrix; @@ -262,6 +268,19 @@ public: /** + * @return a pointer to the physics environment in use during the game, for rayCasting + */ + PHY_IPhysicsEnvironment* GetPhysicsEnvironment() + { + return m_pPhysicsEnvironment; + } + + void SetPhysicsEnvironment(PHY_IPhysicsEnvironment* physicsEnvironment) + { + m_pPhysicsEnvironment = physicsEnvironment; + } + + /** * @return a pointer to the physics controller owned by this class. */ @@ -341,6 +360,8 @@ public: return m_bDyna; } + bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); + /** * @section Physics accessors for this node. @@ -608,6 +629,7 @@ public: KX_PYMETHOD(KX_GameObject,GetMesh); KX_PYMETHOD(KX_GameObject,GetParent); KX_PYMETHOD(KX_GameObject,GetPhysicsId); + KX_PYMETHOD_DOC(KX_GameObject,rayCastTo); KX_PYMETHOD_DOC(KX_GameObject,getDistanceTo); private : |