Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPorteries Tristan <republicthunderbolt9@gmail.com>2015-10-07 23:14:43 +0300
committerPorteries Tristan <republicthunderbolt9@gmail.com>2015-10-07 23:14:43 +0300
commit720d4521cdd0986d9c6df97924b72eed72e5a3af (patch)
treec90b5192844d4f0cb8c49f32596fcb60e2fe863d /source/gameengine/Ketsji/KX_RayCast.h
parent7a06613b8219684459374b2440dbfc6a6f2cdbd5 (diff)
BGE : Collision mask support in raycast + and raycast cleanup.
I have removed the m_pHitObject, m_xray and m_testPropName and replace them by a temporary struct "RayCastData" which contains these datas and a collision mask. Finally i add a collision mask argument in the python function "rayCast" : ``` rayCast(to, from, dist, prop, face, xray, poly, mask) ``` It can be useful to hit only object which are on the right colision layer. for example if you have hitbox for a charater or vehicle you don't want to hit it with raycast. test file : {F237337} left mouse click on two planes and see console messages. Somewhat more elaborate test file by @sybren: {F237779} Look around and click on the cubes. One cube lamp responds, the other doesn't, based on their collision groups. Reviewers: moguri, hg1, agoose77, campbellbarton, sybren Reviewed By: agoose77, campbellbarton, sybren Subscribers: campbellbarton, sergey, blueprintrandom, sybren Projects: #game_engine, #game_physics Differential Revision: https://developer.blender.org/D1239
Diffstat (limited to 'source/gameengine/Ketsji/KX_RayCast.h')
-rw-r--r--source/gameengine/Ketsji/KX_RayCast.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/source/gameengine/Ketsji/KX_RayCast.h b/source/gameengine/Ketsji/KX_RayCast.h
index e47ac676eb1..c977fb8f385 100644
--- a/source/gameengine/Ketsji/KX_RayCast.h
+++ b/source/gameengine/Ketsji/KX_RayCast.h
@@ -44,12 +44,15 @@ struct KX_ClientObjectInfo;
/**
* Defines a function for doing a ray cast.
*
- * eg KX_RayCast::RayTest(ignore_physics_controller, physics_environment, frompoint, topoint, result_point, result_normal, KX_RayCast::Callback<KX_MyClass>(this, data)
+ * eg KX_RayCast::RayTest(ignore_physics_controller, physics_environment, frompoint, topoint, result_point, result_normal, KX_RayCast::Callback<MyClass, MyDataClass>(this, data)
*
- * Calls myclass->RayHit(client, hit_point, hit_normal, data) for all client
+ * Calls myclass->NeedRayCast(client, data) for all client in environment
+ * and myclass->RayHit(client, hit_point, hit_normal, data) for all client
* between frompoint and topoint
*
- * myclass->RayHit should return true to end the raycast, false to ignore the current client.
+ * myclass->NeedRayCast should return true to ray test the current client.
+ *
+ * myclass->RayHit should return true to end the raycast, false to ignore the current client and to continue.
*
* Returns true if a client was accepted, false if nothing found.
*/
@@ -80,10 +83,10 @@ public:
/**
* Callback wrapper.
*
- * Construct with KX_RayCast::Callback<MyClass>(this, data)
+ * Construct with KX_RayCast::Callback<MyClass, MyDataClass>(this, data)
* and pass to KX_RayCast::RayTest
*/
- template<class T> class Callback;
+ template<class T, class dataT> class Callback;
/// Public interface.
/// Implement bool RayHit in your class to receive ray callbacks.
@@ -99,12 +102,18 @@ public:
#endif
};
-template<class T> class KX_RayCast::Callback : public KX_RayCast
+template<class T, class dataT>
+class KX_RayCast::Callback : public KX_RayCast
{
T *self;
- void *data;
+ /**
+ * Some user info passed as argument in constructor.
+ * It contains all info needed to check client in NeedRayCast
+ * and RayHit.
+ */
+ dataT *data;
public:
- Callback(T *_self, PHY_IPhysicsController* controller=NULL, void *_data = NULL, bool faceNormal=false, bool faceUV=false)
+ Callback(T *_self, PHY_IPhysicsController *controller = NULL, dataT *_data = NULL, bool faceNormal = false, bool faceUV = false)
: KX_RayCast(controller, faceNormal, faceUV),
self(_self),
data(_data)
@@ -127,7 +136,7 @@ public:
MT_assert(info && "Physics controller with no client object info");
return false;
}
- return self->NeedRayCast(info);
+ return self->NeedRayCast(info, data);
}